Back to Opencart

File extension\opencart\admin\controller\report\customer_reward.php

docs/api/source-extension.opencart.admin.controller.report.customer_reward.html

4.1.0.315.7 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report; | | 3: | /** | | 4: | * Class Customer Reward | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report | | 7: | */ | | 8: | class CustomerReward 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_reward'); | | 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_reward', 'user_token=' . $this->session->data['user_token']) | | 34: | ]; | | 35: | | | 36: | $data['save'] = $this->url->link('extension/opencart/report/customer_reward.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_reward_status'] = $this->config->get('report_customer_reward_status'); | | 40: | $data['report_customer_reward_sort_order'] = $this->config->get('report_customer_reward_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_reward_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_reward'); | | 56: | | | 57: | $json = []; | | 58: | | | 59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer_reward')) { | | 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_reward', $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_reward'); | | 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_reward', $data)); | | 88: | } | | 89: | | | 90: | /** | | 91: | * List | | 92: | * | | 93: | * @return void | | 94: | */ | | 95: | public function list(): void { | | 96: | $this->load->language('extension/opencart/report/customer_reward'); | | 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_customer'])) { | | 120: | $filter_customer = $this->request->get['filter_customer']; | | 121: | } else { | | 122: | $filter_customer = ''; | | 123: | } | | 124: | | | 125: | if (isset($this->request->get['page'])) { | | 126: | $page = (int)$this->request->get['page']; | | 127: | } else { | | 128: | $page = 1; | | 129: | } | | 130: | | | 131: | $data['customers'] = []; | | 132: | | | 133: | $filter_data = [ | | 134: | 'filter_date_start' => $filter_date_start, | | 135: | 'filter_date_end' => $filter_date_end, | | 136: | 'filter_customer' => $filter_customer, | | 137: | 'start' => ($page - 1) * $this->config->get('config_pagination'), | | 138: | 'limit' => $this->config->get('config_pagination') | | 139: | ]; | | 140: | | | 141: | $this->load->model('extension/opencart/report/customer'); | | 142: | | | 143: | $customer_total = $this->model_extension_opencart_report_customer->getTotalRewardPoints($filter_data); | | 144: | | | 145: | $results = $this->model_extension_opencart_report_customer->getRewardPoints($filter_data); | | 146: | | | 147: | foreach ($results as $result) { | | 148: | $data['customers'][] = [ | | 149: | 'customer' => $result['customer'], | | 150: | 'email' => $result['email'], | | 151: | 'customer_group' => $result['customer_group'], | | 152: | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), | | 153: | 'points' => $result['points'], | | 154: | 'orders' => $result['orders'], | | 155: | 'total' => $this->currency->format((float)$result['total'], $this->config->get('config_currency')), | | 156: | 'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id']) | | 157: | ]; | | 158: | } | | 159: | | | 160: | $url = ''; | | 161: | | | 162: | if (isset($this->request->get['filter_date_start'])) { | | 163: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; | | 164: | } | | 165: | | | 166: | if (isset($this->request->get['filter_date_end'])) { | | 167: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; | | 168: | } | | 169: | | | 170: | if (isset($this->request->get['filter_customer'])) { | | 171: | $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); | | 172: | } | | 173: | | | 174: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 175: | 'total' => $customer_total, | | 176: | 'page' => $page, | | 177: | 'limit' => $this->config->get('config_pagination'), | | 178: | 'url' => $this->url->link('extension/opencart/report/customer_reward.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_reward' . $url . '&page={page}') | | 179: | ]); | | 180: | | | 181: | $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'))); | | 182: | | | 183: | $data['filter_date_start'] = $filter_date_start; | | 184: | $data['filter_date_end'] = $filter_date_end; | | 185: | $data['filter_customer'] = $filter_customer; | | 186: | | | 187: | $data['user_token'] = $this->session->data['user_token']; | | 188: | | | 189: | return $this->load->view('extension/opencart/report/customer_reward_list', $data); | | 190: | } | | 191: | } | | 192: | |

OpenCart API API documentation generated by ApiGen dev-master