docs/api/source-extension.opencart.admin.controller.report.customer_activity.html
| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report; | | 3: | /** | | 4: | * Class Customer Activity | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report | | 7: | */ | | 8: | class CustomerActivity 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_activity'); | | 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_activity', 'user_token=' . $this->session->data['user_token']) | | 34: | ]; | | 35: | | | 36: | $data['save'] = $this->url->link('extension/opencart/report/customer_activity.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_activity_status'] = $this->config->get('report_customer_activity_status'); | | 40: | $data['report_customer_activity_sort_order'] = $this->config->get('report_customer_activity_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_activity_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_activity'); | | 56: | | | 57: | $json = []; | | 58: | | | 59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer_activity')) { | | 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_activity', $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_activity'); | | 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_activity', $data)); | | 88: | } | | 89: | | | 90: | /** | | 91: | * List | | 92: | * | | 93: | * @return void | | 94: | */ | | 95: | public function list(): void { | | 96: | $this->load->language('extension/opencart/report/customer_activity'); | | 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_customer'])) { | | 108: | $filter_customer = $this->request->get['filter_customer']; | | 109: | } else { | | 110: | $filter_customer = ''; | | 111: | } | | 112: | | | 113: | if (isset($this->request->get['filter_ip'])) { | | 114: | $filter_ip = $this->request->get['filter_ip']; | | 115: | } else { | | 116: | $filter_ip = ''; | | 117: | } | | 118: | | | 119: | if (isset($this->request->get['filter_date_start'])) { | | 120: | $filter_date_start = $this->request->get['filter_date_start']; | | 121: | } else { | | 122: | $filter_date_start = ''; | | 123: | } | | 124: | | | 125: | if (isset($this->request->get['filter_date_end'])) { | | 126: | $filter_date_end = $this->request->get['filter_date_end']; | | 127: | } else { | | 128: | $filter_date_end = ''; | | 129: | } | | 130: | | | 131: | if (isset($this->request->get['page'])) { | | 132: | $page = (int)$this->request->get['page']; | | 133: | } else { | | 134: | $page = 1; | | 135: | } | | 136: | | | 137: | $data['activities'] = []; | | 138: | | | 139: | $filter_data = [ | | 140: | 'filter_customer' => $filter_customer, | | 141: | 'filter_ip' => $filter_ip, | | 142: | 'filter_date_start' => $filter_date_start, | | 143: | 'filter_date_end' => $filter_date_end, | | 144: | 'start' => ($page - 1) * 20, | | 145: | 'limit' => 20 | | 146: | ]; | | 147: | | | 148: | $this->load->model('extension/opencart/report/customer'); | | 149: | | | 150: | $activity_total = $this->model_extension_opencart_report_customer->getTotalCustomerActivities($filter_data); | | 151: | | | 152: | $results = $this->model_extension_opencart_report_customer->getCustomerActivities($filter_data); | | 153: | | | 154: | foreach ($results as $result) { | | 155: | $comment = vsprintf($this->language->get('text_activity_' . $result['key']), json_decode($result['data'], true)); | | 156: | | | 157: | $find = [ | | 158: | 'customer_id=', | | 159: | 'order_id=' | | 160: | ]; | | 161: | | | 162: | $replace = [ | | 163: | $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id='), | | 164: | $this->url->link('sale/order.info', 'user_token=' . $this->session->data['user_token'] . '&order_id=') | | 165: | ]; | | 166: | | | 167: | $data['activities'][] = [ | | 168: | 'comment' => str_replace($find, $replace, $comment), | | 169: | 'ip' => $result['ip'], | | 170: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) | | 171: | ]; | | 172: | } | | 173: | | | 174: | $url = ''; | | 175: | | | 176: | if (isset($this->request->get['filter_customer'])) { | | 177: | $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); | | 178: | } | | 179: | | | 180: | if (isset($this->request->get['filter_ip'])) { | | 181: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 182: | } | | 183: | | | 184: | if (isset($this->request->get['filter_date_start'])) { | | 185: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; | | 186: | } | | 187: | | | 188: | if (isset($this->request->get['filter_date_end'])) { | | 189: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; | | 190: | } | | 191: | | | 192: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 193: | 'total' => $activity_total, | | 194: | 'page' => $page, | | 195: | 'limit' => $this->config->get('config_pagination'), | | 196: | 'url' => $this->url->link('extension/opencart/report/customer_activity.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_activity' . $url . '&page={page}') | | 197: | ]); | | 198: | | | 199: | $data['results'] = sprintf($this->language->get('text_pagination'), ($activity_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($activity_total - $this->config->get('config_pagination'))) ? $activity_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $activity_total, ceil($activity_total / $this->config->get('config_pagination'))); | | 200: | | | 201: | $data['filter_customer'] = $filter_customer; | | 202: | $data['filter_ip'] = $filter_ip; | | 203: | $data['filter_date_start'] = $filter_date_start; | | 204: | $data['filter_date_end'] = $filter_date_end; | | 205: | | | 206: | $data['user_token'] = $this->session->data['user_token']; | | 207: | | | 208: | return $this->load->view('extension/opencart/report/customer_activity_list', $data); | | 209: | } | | 210: | } | | 211: | |
OpenCart API API documentation generated by ApiGen dev-master