1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: | /**
4: | * Class Customer Search
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: | */
8: | class CustomerSearch 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_search');
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_search', 'user_token=' . $this->session->data['user_token'])
34: | ];
35: |
36: | $data['save'] = $this->url->link('extension/opencart/report/customer_search.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_search_status'] = $this->config->get('report_customer_search_status');
40: | $data['report_customer_search_sort_order'] = $this->config->get('report_customer_search_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_search_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_search');
56: |
57: | $json = [];
58: |
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer_search')) {
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_search', $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_search');
82: |
83: | $data['list'] = $this->getReport();
84: |
85: | $data['user_token'] = $this->session->data['user_token'];
86: |
87: | $this->response->setOutput($this->load->view('extension/opencart/report/customer_search', $data));
88: | }
89: |
90: | /**
91: | * List
92: | *
93: | * @return void
94: | */
95: | public function list(): void {
96: | $this->load->language('extension/opencart/report/customer_search');
97: |
98: | $this->response->setOutput($this->getReport());
99: | }
100: |
101: | /**
102: | * Get Report
103: | *
104: | * @return string
105: | */
106: | public function getReport(): string {
107: | if (isset($this->request->get['filter_date_start'])) {
108: | $filter_date_start = $this->request->get['filter_date_start'];
109: | } else {
110: | $filter_date_start = '';
111: | }
112: |
113: | if (isset($this->request->get['filter_date_end'])) {
114: | $filter_date_end = $this->request->get['filter_date_end'];
115: | } else {
116: | $filter_date_end = '';
117: | }
118: |
119: | if (isset($this->request->get['filter_keyword'])) {
120: | $filter_keyword = $this->request->get['filter_keyword'];
121: | } else {
122: | $filter_keyword = '';
123: | }
124: |
125: | if (isset($this->request->get['filter_customer'])) {
126: | $filter_customer = $this->request->get['filter_customer'];
127: | } else {
128: | $filter_customer = '';
129: | }
130: |
131: | if (isset($this->request->get['filter_ip'])) {
132: | $filter_ip = $this->request->get['filter_ip'];
133: | } else {
134: | $filter_ip = '';
135: | }
136: |
137: | if (isset($this->request->get['page'])) {
138: | $page = (int)$this->request->get['page'];
139: | } else {
140: | $page = 1;
141: | }
142: |
143: | $data['searches'] = [];
144: |
145: | $filter_data = [
146: | 'filter_date_start' => $filter_date_start,
147: | 'filter_date_end' => $filter_date_end,
148: | 'filter_keyword' => $filter_keyword,
149: | 'filter_customer' => $filter_customer,
150: | 'filter_ip' => $filter_ip,
151: | 'start' => ($page - 1) * $this->config->get('config_pagination'),
152: | 'limit' => $this->config->get('config_pagination')
153: | ];
154: |
155: | $this->load->model('extension/opencart/report/customer');
156: | $this->load->model('catalog/category');
157: |
158: | $search_total = $this->model_extension_opencart_report_customer->getTotalCustomerSearches($filter_data);
159: |
160: | $results = $this->model_extension_opencart_report_customer->getCustomerSearches($filter_data);
161: |
162: | foreach ($results as $result) {
163: | $category_info = $this->model_catalog_category->getCategory($result['category_id']);
164: |
165: | if ($category_info) {
166: | $category = ($category_info['path']) ? $category_info['path'] . ' &gt; ' . $category_info['name'] : $category_info['name'];
167: | } else {
168: | $category = '';
169: | }
170: |
171: | if ($result['customer_id'] > 0) {
172: | $customer = sprintf($this->language->get('text_customer'), $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id']), $result['customer']);
173: | } else {
174: | $customer = $this->language->get('text_guest');
175: | }
176: |
177: | $data['searches'][] = [
178: | 'keyword' => $result['keyword'],
179: | 'products' => $result['products'],
180: | 'category' => $category,
181: | 'customer' => $customer,
182: | 'ip' => $result['ip'],
183: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added']))
184: | ];
185: | }
186: |
187: | $url = '';
188: |
189: | if (isset($this->request->get['filter_date_start'])) {
190: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
191: | }
192: |
193: | if (isset($this->request->get['filter_date_end'])) {
194: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
195: | }
196: |
197: | if (isset($this->request->get['filter_keyword'])) {
198: | $url .= '&filter_keyword=' . urlencode($this->request->get['filter_keyword']);
199: | }
200: |
201: | if (isset($this->request->get['filter_customer'])) {
202: | $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']);
203: | }
204: |
205: | if (isset($this->request->get['filter_ip'])) {
206: | $url .= '&filter_ip=' . $this->request->get['filter_ip'];
207: | }
208: |
209: | $data['pagination'] = $this->load->controller('common/pagination', [
210: | 'total' => $search_total,
211: | 'page' => $page,
212: | 'limit' => $this->config->get('config_pagination'),
213: | 'url' => $this->url->link('extension/opencart/report/customer_search.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_search' . $url . '&page={page}')
214: | ]);
215: |
216: | $data['results'] = sprintf($this->language->get('text_pagination'), ($search_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($search_total - $this->config->get('config_pagination'))) ? $search_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $search_total, ceil($search_total / $this->config->get('config_pagination')));
217: |
218: | $data['filter_date_start'] = $filter_date_start;
219: | $data['filter_date_end'] = $filter_date_end;
220: | $data['filter_keyword'] = $filter_keyword;
221: | $data['filter_customer'] = $filter_customer;
222: | $data['filter_ip'] = $filter_ip;
223: |
224: | $data['user_token'] = $this->session->data['user_token'];
225: |
226: | return $this->load->view('extension/opencart/report/customer_search_list', $data);
227: | }
228: | }
229: |

OpenCart API API documentation generated by ApiGen dev-master