docs/api/source-admin.controller.tool.notification.html
| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Tool; | | 3: | /** | | 4: | * Class Notification | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Tool | | 7: | */ | | 8: | class Notification extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('tool/notification'); | | 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('heading_title'), | | 28: | 'href' => $this->url->link('tool/notification', 'user_token=' . $this->session->data['user_token']) | | 29: | ]; | | 30: | | | 31: | $data['list'] = $this->getList(); | | 32: | | | 33: | $data['user_token'] = $this->session->data['user_token']; | | 34: | | | 35: | $data['header'] = $this->load->controller('common/header'); | | 36: | $data['column_left'] = $this->load->controller('common/column_left'); | | 37: | $data['footer'] = $this->load->controller('common/footer'); | | 38: | | | 39: | $this->response->setOutput($this->load->view('tool/notification', $data)); | | 40: | } | | 41: | | | 42: | /** | | 43: | * List | | 44: | * | | 45: | * @return void | | 46: | */ | | 47: | public function list(): void { | | 48: | $this->load->language('tool/notification'); | | 49: | | | 50: | $this->response->setOutput($this->getList()); | | 51: | } | | 52: | | | 53: | /** | | 54: | * Get List | | 55: | * | | 56: | * @return string | | 57: | */ | | 58: | public function getList(): string { | | 59: | if (isset($this->request->get['page'])) { | | 60: | $page = (int)$this->request->get['page']; | | 61: | } else { | | 62: | $page = 1; | | 63: | } | | 64: | | | 65: | $url = ''; | | 66: | | | 67: | if (isset($this->request->get['page'])) { | | 68: | $url .= '&page=' . $this->request->get['page']; | | 69: | } | | 70: | | | 71: | $data['notifications'] = []; | | 72: | | | 73: | $filter_data = [ | | 74: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'), | | 75: | 'limit' => $this->config->get('config_pagination_admin') | | 76: | ]; | | 77: | | | 78: | $this->load->model('tool/notification'); | | 79: | | | 80: | $results = $this->model_tool_notification->getNotifications($filter_data); | | 81: | | | 82: | foreach ($results as $result) { | | 83: | $second = time() - strtotime($result['date_added']); | | 84: | | | 85: | $ranges = [ | | 86: | 'second' => $second, | | 87: | 'minute' => floor($second / 60), | | 88: | 'hour' => floor($second / 3600), | | 89: | 'day' => floor($second / 86400), | | 90: | 'week' => floor($second / 604800), | | 91: | 'month' => floor($second / 2629743), | | 92: | 'year' => floor($second / 31556926) | | 93: | ]; | | 94: | | | 95: | $date_added = 0; | | 96: | $code = 'seconds'; | | 97: | | | 98: | foreach ($ranges as $range => $value) { | | 99: | if ($value) { | | 100: | $date_added = $value; | | 101: | $code = ($value > 1) ? $range . 's' : $range; | | 102: | } | | 103: | } | | 104: | | | 105: | $data['notifications'][] = [ | | 106: | 'notification_id' => $result['notification_id'], | | 107: | 'title' => $result['title'], | | 108: | 'status' => $result['status'], | | 109: | 'date_added' => sprintf($this->language->get('text_' . $code . '_ago'), $date_added), | | 110: | 'view' => $this->url->link('tool/notification.info', 'user_token=' . $this->session->data['user_token'] . '¬ification_id=' . $result['notification_id'] . $url), | | 111: | 'delete' => $this->url->link('tool/notification.delete', 'user_token=' . $this->session->data['user_token'] . '¬ification_id=' . $result['notification_id'] . $url) | | 112: | ]; | | 113: | } | | 114: | | | 115: | $notification_total = $this->model_tool_notification->getTotalNotifications(); | | 116: | | | 117: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 118: | 'total' => $notification_total, | | 119: | 'page' => $page, | | 120: | 'limit' => $this->config->get('config_pagination_admin'), | | 121: | 'url' => $this->url->link('tool/notification.list', 'user_token=' . $this->session->data['user_token'] . '&page={page}') | | 122: | ]); | | 123: | | | 124: | $data['results'] = sprintf($this->language->get('text_pagination'), ($notification_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($notification_total - $this->config->get('config_pagination_admin'))) ? $notification_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $notification_total, ceil($notification_total / $this->config->get('config_pagination_admin'))); | | 125: | | | 126: | return $this->load->view('tool/notification_list', $data); | | 127: | } | | 128: | | | 129: | /** | | 130: | * Info | | 131: | * | | 132: | * @return void | | 133: | */ | | 134: | public function info(): void { | | 135: | if (isset($this->request->get['notification_id'])) { | | 136: | $notification_id = $this->request->get['notification_id']; | | 137: | } else { | | 138: | $notification_id = 0; | | 139: | } | | 140: | | | 141: | $this->load->model('tool/notification'); | | 142: | | | 143: | $notification_info = $this->model_tool_notification->getNotification($notification_id); | | 144: | | | 145: | if ($notification_info) { | | 146: | $this->load->language('tool/notification'); | | 147: | | | 148: | $data['title'] = $notification_info['title']; | | 149: | | | 150: | $data['text'] = html_entity_decode($notification_info['text'], ENT_QUOTES, 'UTF-8'); | | 151: | | | 152: | $this->model_tool_notification->editStatus($notification_id, true); | | 153: | | | 154: | $this->response->setOutput($this->load->view('tool/notification_info', $data)); | | 155: | } | | 156: | } | | 157: | | | 158: | /** | | 159: | * Delete | | 160: | * | | 161: | * @return void | | 162: | */ | | 163: | public function delete(): void { | | 164: | $this->load->language('tool/notification'); | | 165: | | | 166: | $json = []; | | 167: | | | 168: | if (isset($this->request->post['selected'])) { | | 169: | $selected = $this->request->post['selected']; | | 170: | } else { | | 171: | $selected = []; | | 172: | } | | 173: | | | 174: | if (!$this->user->hasPermission('modify', 'tool/notification')) { | | 175: | $json['error'] = $this->language->get('error_permission'); | | 176: | } | | 177: | | | 178: | if (!$json) { | | 179: | $this->load->model('tool/notification'); | | 180: | | | 181: | foreach ($selected as $notification_id) { | | 182: | $this->model_tool_notification->deleteNotification($notification_id); | | 183: | } | | 184: | | | 185: | $json['success'] = $this->language->get('text_success'); | | 186: | } | | 187: | | | 188: | $this->response->addHeader('Content-Type: application/json'); | | 189: | $this->response->setOutput(json_encode($json)); | | 190: | } | | 191: | } | | 192: | |
OpenCart API API documentation generated by ApiGen dev-master