1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: | /**
4: | * Class Customer
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: | */
8: | class Customer extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('extension/opencart/report/customer');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $data['breadcrumbs'] = [];
20: |
21: | $data['breadcrumbs'][] = [
22: | 'text' => $this->language->get('text_home'),
23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: | ];
25: |
26: | $data['breadcrumbs'][] = [
27: | 'text' => $this->language->get('text_extension'),
28: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report')
29: | ];
30: |
31: | $data['breadcrumbs'][] = [
32: | 'text' => $this->language->get('heading_title'),
33: | 'href' => $this->url->link('extension/opencart/report/customer', 'user_token=' . $this->session->data['user_token'])
34: | ];
35: |
36: | $data['save'] = $this->url->link('extension/opencart/report/customer.save', 'user_token=' . $this->session->data['user_token']);
37: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report');
38: |
39: | $data['report_customer_status'] = $this->config->get('report_customer_status');
40: | $data['report_customer_sort_order'] = $this->config->get('report_customer_sort_order');
41: |
42: | $data['header'] = $this->load->controller('common/header');
43: | $data['column_left'] = $this->load->controller('common/column_left');
44: | $data['footer'] = $this->load->controller('common/footer');
45: |
46: | $this->response->setOutput($this->load->view('extension/opencart/report/customer_form', $data));
47: | }
48: |
49: | /**
50: | * Save
51: | *
52: | * @return void
53: | */
54: | public function save(): void {
55: | $this->load->language('extension/opencart/report/customer');
56: |
57: | $json = [];
58: |
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer')) {
60: | $json['error'] = $this->language->get('error_permission');
61: | }
62: |
63: | if (!$json) {
64: | $this->load->model('setting/setting');
65: |
66: | $this->model_setting_setting->editSetting('report_customer', $this->request->post);
67: |
68: | $json['success'] = $this->language->get('text_success');
69: | }
70: |
71: | $this->response->addHeader('Content-Type: application/json');
72: | $this->response->setOutput(json_encode($json));
73: | }
74: |
75: | /**
76: | * Report
77: | *
78: | * @return void
79: | */
80: | public function report(): void {
81: | $this->load->language('extension/opencart/report/customer');
82: |
83: | $data['list'] = $this->getReport();
84: |
85: | $data['groups'] = [];
86: |
87: | $data['groups'][] = [
88: | 'text' => $this->language->get('text_year'),
89: | 'value' => 'year',
90: | ];
91: |
92: | $data['groups'][] = [
93: | 'text' => $this->language->get('text_month'),
94: | 'value' => 'month',
95: | ];
96: |
97: | $data['groups'][] = [
98: | 'text' => $this->language->get('text_week'),
99: | 'value' => 'week',
100: | ];
101: |
102: | $data['groups'][] = [
103: | 'text' => $this->language->get('text_day'),
104: | 'value' => 'day',
105: | ];
106: |
107: | $data['user_token'] = $this->session->data['user_token'];
108: |
109: | $this->response->setOutput($this->load->view('extension/opencart/report/customer', $data));
110: | }
111: |
112: | /**
113: | * List
114: | *
115: | * @return void
116: | */
117: | public function list(): void {
118: | $this->load->language('extension/opencart/report/customer');
119: |
120: | $this->response->setOutput($this->getReport());
121: | }
122: |
123: | /**
124: | * Get Report
125: | *
126: | * @return string
127: | */
128: | public function getReport(): string {
129: | if (isset($this->request->get['filter_date_start'])) {
130: | $filter_date_start = $this->request->get['filter_date_start'];
131: | } else {
132: | $filter_date_start = '';
133: | }
134: |
135: | if (isset($this->request->get['filter_date_end'])) {
136: | $filter_date_end = $this->request->get['filter_date_end'];
137: | } else {
138: | $filter_date_end = '';
139: | }
140: |
141: | if (isset($this->request->get['filter_group'])) {
142: | $filter_group = $this->request->get['filter_group'];
143: | } else {
144: | $filter_group = 'week';
145: | }
146: |
147: | if (isset($this->request->get['page'])) {
148: | $page = (int)$this->request->get['page'];
149: | } else {
150: | $page = 1;
151: | }
152: |
153: | $data['customers'] = [];
154: |
155: | $filter_data = [
156: | 'filter_date_start' => $filter_date_start,
157: | 'filter_date_end' => $filter_date_end,
158: | 'filter_group' => $filter_group,
159: | 'start' => ($page - 1) * 20,
160: | 'limit' => 20
161: | ];
162: |
163: | $this->load->model('extension/opencart/report/customer');
164: |
165: | $customer_total = $this->model_extension_opencart_report_customer->getTotalCustomers($filter_data);
166: |
167: | $results = $this->model_extension_opencart_report_customer->getCustomers($filter_data);
168: |
169: | foreach ($results as $result) {
170: | $data['customers'][] = [
171: | 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
172: | 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
173: | 'total' => $result['total'],
174: | ];
175: | }
176: |
177: | $url = '';
178: |
179: | if (isset($this->request->get['filter_date_start'])) {
180: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
181: | }
182: |
183: | if (isset($this->request->get['filter_date_end'])) {
184: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
185: | }
186: |
187: | if (isset($this->request->get['filter_group'])) {
188: | $url .= '&filter_group=' . $this->request->get['filter_group'];
189: | }
190: |
191: | $data['pagination'] = $this->load->controller('common/pagination', [
192: | 'total' => $customer_total,
193: | 'page' => $page,
194: | 'limit' => $this->config->get('config_pagination'),
195: | 'url' => $this->url->link('extension/opencart/report/customer.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer' . $url . '&page={page}')
196: | ]);
197: |
198: | $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($customer_total - $this->config->get('config_pagination'))) ? $customer_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $customer_total, ceil($customer_total / $this->config->get('config_pagination')));
199: |
200: | $data['filter_date_start'] = $filter_date_start;
201: | $data['filter_date_end'] = $filter_date_end;
202: | $data['filter_group'] = $filter_group;
203: |
204: | $data['user_token'] = $this->session->data['user_token'];
205: |
206: | return $this->load->view('extension/opencart/report/customer_list', $data);
207: | }
208: | }
209: |

OpenCart API API documentation generated by ApiGen dev-master