shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

chart.php (6564B)


      1 <?php
      2 class ControllerExtensionDashboardChart extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('extension/dashboard/chart');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		$this->load->model('setting/setting');
     11 
     12 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     13 			$this->model_setting_setting->editSetting('dashboard_chart', $this->request->post);
     14 
     15 			$this->session->data['success'] = $this->language->get('text_success');
     16 
     17 			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true));
     18 		}
     19 
     20 		if (isset($this->error['warning'])) {
     21 			$data['error_warning'] = $this->error['warning'];
     22 		} else {
     23 			$data['error_warning'] = '';
     24 		}
     25 
     26 		$data['breadcrumbs'] = array();
     27 
     28 		$data['breadcrumbs'][] = array(
     29 			'text' => $this->language->get('text_home'),
     30 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     31 		);
     32 
     33 		$data['breadcrumbs'][] = array(
     34 			'text' => $this->language->get('text_extension'),
     35 			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)
     36 		);
     37 
     38 		$data['breadcrumbs'][] = array(
     39 			'text' => $this->language->get('heading_title'),
     40 			'href' => $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true)
     41 		);
     42 
     43 		$data['action'] = $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true);
     44 
     45 		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true);
     46 
     47 		if (isset($this->request->post['dashboard_chart_width'])) {
     48 			$data['dashboard_chart_width'] = $this->request->post['dashboard_chart_width'];
     49 		} else {
     50 			$data['dashboard_chart_width'] = $this->config->get('dashboardchart_width');
     51 		}
     52 	
     53 		$data['columns'] = array();
     54 		
     55 		for ($i = 3; $i <= 12; $i++) {
     56 			$data['columns'][] = $i;
     57 		}
     58 				
     59 		if (isset($this->request->post['dashboard_chart_status'])) {
     60 			$data['dashboard_chart_status'] = $this->request->post['dashboard_chart_status'];
     61 		} else {
     62 			$data['dashboard_chart_status'] = $this->config->get('dashboard_chart_status');
     63 		}
     64 
     65 		if (isset($this->request->post['dashboard_chart_sort_order'])) {
     66 			$data['dashboard_chart_sort_order'] = $this->request->post['dashboard_chart_sort_order'];
     67 		} else {
     68 			$data['dashboard_chart_sort_order'] = $this->config->get('dashboard_chart_sort_order');
     69 		}
     70 
     71 		$data['header'] = $this->load->controller('common/header');
     72 		$data['column_left'] = $this->load->controller('common/column_left');
     73 		$data['footer'] = $this->load->controller('common/footer');
     74 
     75 		$this->response->setOutput($this->load->view('extension/dashboard/chart_form', $data));
     76 	}
     77 
     78 	protected function validate() {
     79 		if (!$this->user->hasPermission('modify', 'extension/dashboard/chart')) {
     80 			$this->error['warning'] = $this->language->get('error_permission');
     81 		}
     82 
     83 		return !$this->error;
     84 	}	
     85 	
     86 	public function dashboard() {
     87 		$this->load->language('extension/dashboard/chart');
     88 
     89 		$data['user_token'] = $this->session->data['user_token'];
     90 
     91 		return $this->load->view('extension/dashboard/chart_info', $data);
     92 	}
     93 
     94 	public function chart() {
     95 		$this->load->language('extension/dashboard/chart');
     96 
     97 		$json = array();
     98 
     99 		$this->load->model('extension/dashboard/chart');
    100 
    101 		$json['order'] = array();
    102 		$json['customer'] = array();
    103 		$json['xaxis'] = array();
    104 
    105 		$json['order']['label'] = $this->language->get('text_order');
    106 		$json['customer']['label'] = $this->language->get('text_customer');
    107 		$json['order']['data'] = array();
    108 		$json['customer']['data'] = array();
    109 
    110 		if (isset($this->request->get['range'])) {
    111 			$range = $this->request->get['range'];
    112 		} else {
    113 			$range = 'day';
    114 		}
    115 
    116 		switch ($range) {
    117 			default:
    118 			case 'day':
    119 				$results = $this->model_extension_dashboard_chart->getTotalOrdersByDay();
    120 
    121 				foreach ($results as $key => $value) {
    122 					$json['order']['data'][] = array($key, $value['total']);
    123 				}
    124 
    125 				$results = $this->model_extension_dashboard_chart->getTotalCustomersByDay();
    126 
    127 				foreach ($results as $key => $value) {
    128 					$json['customer']['data'][] = array($key, $value['total']);
    129 				}
    130 
    131 				for ($i = 0; $i < 24; $i++) {
    132 					$json['xaxis'][] = array($i, $i);
    133 				}
    134 				break;
    135 			case 'week':
    136 				$results = $this->model_extension_dashboard_chart->getTotalOrdersByWeek();
    137 
    138 				foreach ($results as $key => $value) {
    139 					$json['order']['data'][] = array($key, $value['total']);
    140 				}
    141 
    142 				$results = $this->model_extension_dashboard_chart->getTotalCustomersByWeek();
    143 
    144 				foreach ($results as $key => $value) {
    145 					$json['customer']['data'][] = array($key, $value['total']);
    146 				}
    147 
    148 				$date_start = strtotime('-' . date('w') . ' days');
    149 
    150 				for ($i = 0; $i < 7; $i++) {
    151 					$date = date('Y-m-d', $date_start + ($i * 86400));
    152 
    153 					$json['xaxis'][] = array(date('w', strtotime($date)), date('D', strtotime($date)));
    154 				}
    155 				break;
    156 			case 'month':
    157 				$results = $this->model_extension_dashboard_chart->getTotalOrdersByMonth();
    158 
    159 				foreach ($results as $key => $value) {
    160 					$json['order']['data'][] = array($key, $value['total']);
    161 				}
    162 
    163 				$results = $this->model_extension_dashboard_chart->getTotalCustomersByMonth();
    164 
    165 				foreach ($results as $key => $value) {
    166 					$json['customer']['data'][] = array($key, $value['total']);
    167 				}
    168 
    169 				for ($i = 1; $i <= date('t'); $i++) {
    170 					$date = date('Y') . '-' . date('m') . '-' . $i;
    171 
    172 					$json['xaxis'][] = array(date('j', strtotime($date)), date('d', strtotime($date)));
    173 				}
    174 				break;
    175 			case 'year':
    176 				$results = $this->model_extension_dashboard_chart->getTotalOrdersByYear();
    177 
    178 				foreach ($results as $key => $value) {
    179 					$json['order']['data'][] = array($key, $value['total']);
    180 				}
    181 
    182 				$results = $this->model_extension_dashboard_chart->getTotalCustomersByYear();
    183 
    184 				foreach ($results as $key => $value) {
    185 					$json['customer']['data'][] = array($key, $value['total']);
    186 				}
    187 
    188 				for ($i = 1; $i <= 12; $i++) {
    189 					$json['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i)));
    190 				}
    191 				break;
    192 		}
    193 
    194 		$this->response->addHeader('Content-Type: application/json');
    195 		$this->response->setOutput(json_encode($json));
    196 	}
    197 }