| 1: | <?php
|
| 2: | namespace Opencart\Admin\Controller\Localisation;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class SubscriptionStatus extends \Opencart\System\Engine\Controller {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: |
|
| 14: | public function index(): void {
|
| 15: | $this->load->language('localisation/subscription_status');
|
| 16: |
|
| 17: | $this->document->setTitle($this->language->get('heading_title'));
|
| 18: |
|
| 19: | $url = '';
|
| 20: |
|
| 21: | if (isset($this->request->get['sort'])) {
|
| 22: | $url .= '&sort=' . $this->request->get['sort'];
|
| 23: | }
|
| 24: |
|
| 25: | if (isset($this->request->get['order'])) {
|
| 26: | $url .= '&order=' . $this->request->get['order'];
|
| 27: | }
|
| 28: |
|
| 29: | if (isset($this->request->get['page'])) {
|
| 30: | $url .= '&page=' . $this->request->get['page'];
|
| 31: | }
|
| 32: |
|
| 33: | $data['breadcrumbs'] = [];
|
| 34: |
|
| 35: | $data['breadcrumbs'][] = [
|
| 36: | 'text' => $this->language->get('text_home'),
|
| 37: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
| 38: | ];
|
| 39: |
|
| 40: | $data['breadcrumbs'][] = [
|
| 41: | 'text' => $this->language->get('heading_title'),
|
| 42: | 'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
| 43: | ];
|
| 44: |
|
| 45: | $data['add'] = $this->url->link('localisation/subscription_status.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
| 46: | $data['delete'] = $this->url->link('localisation/subscription_status.delete', 'user_token=' . $this->session->data['user_token']);
|
| 47: |
|
| 48: | $data['list'] = $this->getList();
|
| 49: |
|
| 50: | $data['user_token'] = $this->session->data['user_token'];
|
| 51: |
|
| 52: | $data['header'] = $this->load->controller('common/header');
|
| 53: | $data['column_left'] = $this->load->controller('common/column_left');
|
| 54: | $data['footer'] = $this->load->controller('common/footer');
|
| 55: |
|
| 56: | $this->response->setOutput($this->load->view('localisation/subscription_status', $data));
|
| 57: | }
|
| 58: |
|
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: |
|
| 64: | public function list(): void {
|
| 65: | $this->load->language('localisation/subscription_status');
|
| 66: |
|
| 67: | $this->response->setOutput($this->getList());
|
| 68: | }
|
| 69: |
|
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: |
|
| 75: | protected function getList(): string {
|
| 76: | if (isset($this->request->get['sort'])) {
|
| 77: | $sort = (string)$this->request->get['sort'];
|
| 78: | } else {
|
| 79: | $sort = 'name';
|
| 80: | }
|
| 81: |
|
| 82: | if (isset($this->request->get['order'])) {
|
| 83: | $order = (string)$this->request->get['order'];
|
| 84: | } else {
|
| 85: | $order = 'ASC';
|
| 86: | }
|
| 87: |
|
| 88: | if (isset($this->request->get['page'])) {
|
| 89: | $page = (int)$this->request->get['page'];
|
| 90: | } else {
|
| 91: | $page = 1;
|
| 92: | }
|
| 93: |
|
| 94: | $url = '';
|
| 95: |
|
| 96: | if (isset($this->request->get['sort'])) {
|
| 97: | $url .= '&sort=' . $this->request->get['sort'];
|
| 98: | }
|
| 99: |
|
| 100: | if (isset($this->request->get['order'])) {
|
| 101: | $url .= '&order=' . $this->request->get['order'];
|
| 102: | }
|
| 103: |
|
| 104: | if (isset($this->request->get['page'])) {
|
| 105: | $url .= '&page=' . $this->request->get['page'];
|
| 106: | }
|
| 107: |
|
| 108: | $data['action'] = $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
| 109: |
|
| 110: | $data['subscription_statuses'] = [];
|
| 111: |
|
| 112: | $filter_data = [
|
| 113: | 'sort' => $sort,
|
| 114: | 'order' => $order,
|
| 115: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
| 116: | 'limit' => $this->config->get('config_pagination_admin')
|
| 117: | ];
|
| 118: |
|
| 119: | $this->load->model('localisation/subscription_status');
|
| 120: |
|
| 121: | $results = $this->model_localisation_subscription_status->getSubscriptionStatuses($filter_data);
|
| 122: |
|
| 123: | foreach ($results as $result) {
|
| 124: | $data['subscription_statuses'][] = [
|
| 125: | 'subscription_status_id' => $result['subscription_status_id'],
|
| 126: | 'name' => $result['name'] . (($result['subscription_status_id'] == $this->config->get('config_subscription_status_id')) ? $this->language->get('text_default') : ''),
|
| 127: | 'edit' => $this->url->link('localisation/subscription_status.form', 'user_token=' . $this->session->data['user_token'] . '&subscription_status_id=' . $result['subscription_status_id'] . $url)
|
| 128: | ];
|
| 129: | }
|
| 130: |
|
| 131: | $url = '';
|
| 132: |
|
| 133: | if ($order == 'ASC') {
|
| 134: | $url .= '&order=DESC';
|
| 135: | } else {
|
| 136: | $url .= '&order=ASC';
|
| 137: | }
|
| 138: |
|
| 139: | $data['sort_name'] = $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
| 140: |
|
| 141: | $url = '';
|
| 142: |
|
| 143: | if (isset($this->request->get['sort'])) {
|
| 144: | $url .= '&sort=' . $this->request->get['sort'];
|
| 145: | }
|
| 146: |
|
| 147: | if (isset($this->request->get['order'])) {
|
| 148: | $url .= '&order=' . $this->request->get['order'];
|
| 149: | }
|
| 150: |
|
| 151: | $subscription_status_total = $this->model_localisation_subscription_status->getTotalSubscriptionStatuses();
|
| 152: |
|
| 153: | $data['pagination'] = $this->load->controller('common/pagination', [
|
| 154: | 'total' => $subscription_status_total,
|
| 155: | 'page' => $page,
|
| 156: | 'limit' => $this->config->get('config_pagination_admin'),
|
| 157: | 'url' => $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
| 158: | ]);
|
| 159: |
|
| 160: | $data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_status_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($subscription_status_total - $this->config->get('config_pagination_admin'))) ? $subscription_status_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $subscription_status_total, ceil($subscription_status_total / $this->config->get('config_pagination_admin')));
|
| 161: |
|
| 162: | $data['sort'] = $sort;
|
| 163: | $data['order'] = $order;
|
| 164: |
|
| 165: | return $this->load->view('localisation/subscription_status_list', $data);
|
| 166: | }
|
| 167: |
|
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: |
|
| 173: | public function form(): void {
|
| 174: | $this->load->language('localisation/subscription_status');
|
| 175: |
|
| 176: | $this->document->setTitle($this->language->get('heading_title'));
|
| 177: |
|
| 178: | $data['text_form'] = !isset($this->request->get['subscription_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
| 179: |
|
| 180: | $url = '';
|
| 181: |
|
| 182: | if (isset($this->request->get['sort'])) {
|
| 183: | $url .= '&sort=' . $this->request->get['sort'];
|
| 184: | }
|
| 185: |
|
| 186: | if (isset($this->request->get['order'])) {
|
| 187: | $url .= '&order=' . $this->request->get['order'];
|
| 188: | }
|
| 189: |
|
| 190: | if (isset($this->request->get['page'])) {
|
| 191: | $url .= '&page=' . $this->request->get['page'];
|
| 192: | }
|
| 193: |
|
| 194: | $data['breadcrumbs'] = [];
|
| 195: |
|
| 196: | $data['breadcrumbs'][] = [
|
| 197: | 'text' => $this->language->get('text_home'),
|
| 198: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
| 199: | ];
|
| 200: |
|
| 201: | $data['breadcrumbs'][] = [
|
| 202: | 'text' => $this->language->get('heading_title'),
|
| 203: | 'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
| 204: | ];
|
| 205: |
|
| 206: | $data['save'] = $this->url->link('localisation/subscription_status.save', 'user_token=' . $this->session->data['user_token']);
|
| 207: | $data['back'] = $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url);
|
| 208: |
|
| 209: | if (isset($this->request->get['subscription_status_id'])) {
|
| 210: | $data['subscription_status_id'] = (int)$this->request->get['subscription_status_id'];
|
| 211: | } else {
|
| 212: | $data['subscription_status_id'] = 0;
|
| 213: | }
|
| 214: |
|
| 215: | $this->load->model('localisation/language');
|
| 216: |
|
| 217: | $data['languages'] = $this->model_localisation_language->getLanguages();
|
| 218: |
|
| 219: | if (isset($this->request->get['subscription_status_id'])) {
|
| 220: | $this->load->model('localisation/subscription_status');
|
| 221: |
|
| 222: | $data['subscription_status'] = $this->model_localisation_subscription_status->getDescriptions($this->request->get['subscription_status_id']);
|
| 223: | } else {
|
| 224: | $data['subscription_status'] = [];
|
| 225: | }
|
| 226: |
|
| 227: | $data['user_token'] = $this->session->data['user_token'];
|
| 228: |
|
| 229: | $data['header'] = $this->load->controller('common/header');
|
| 230: | $data['column_left'] = $this->load->controller('common/column_left');
|
| 231: | $data['footer'] = $this->load->controller('common/footer');
|
| 232: |
|
| 233: | $this->response->setOutput($this->load->view('localisation/subscription_status_form', $data));
|
| 234: | }
|
| 235: |
|
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: |
|
| 241: | public function save(): void {
|
| 242: | $this->load->language('localisation/subscription_status');
|
| 243: |
|
| 244: | $json = [];
|
| 245: |
|
| 246: | if (!$this->user->hasPermission('modify', 'localisation/subscription_status')) {
|
| 247: | $json['error']['warning'] = $this->language->get('error_permission');
|
| 248: | }
|
| 249: |
|
| 250: | foreach ($this->request->post['subscription_status'] as $language_id => $value) {
|
| 251: | if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
| 252: | $json['error']['name_' . $language_id] = $this->language->get('error_name');
|
| 253: | }
|
| 254: | }
|
| 255: |
|
| 256: | if (!$json) {
|
| 257: | $this->load->model('localisation/subscription_status');
|
| 258: |
|
| 259: | if (!$this->request->post['subscription_status_id']) {
|
| 260: | $json['subscription_status_id'] = $this->model_localisation_subscription_status->addSubscriptionStatus($this->request->post);
|
| 261: | } else {
|
| 262: | $this->model_localisation_subscription_status->editSubscriptionStatus($this->request->post['subscription_status_id'], $this->request->post);
|
| 263: | }
|
| 264: |
|
| 265: | $json['success'] = $this->language->get('text_success');
|
| 266: | }
|
| 267: |
|
| 268: | $this->response->addHeader('Content-Type: application/json');
|
| 269: | $this->response->setOutput(json_encode($json));
|
| 270: | }
|
| 271: |
|
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: |
|
| 277: | public function delete(): void {
|
| 278: | $this->load->language('localisation/subscription_status');
|
| 279: |
|
| 280: | $json = [];
|
| 281: |
|
| 282: | if (isset($this->request->post['selected'])) {
|
| 283: | $selected = $this->request->post['selected'];
|
| 284: | } else {
|
| 285: | $selected = [];
|
| 286: | }
|
| 287: |
|
| 288: | if (!$this->user->hasPermission('modify', 'localisation/subscription_status')) {
|
| 289: | $json['error'] = $this->language->get('error_permission');
|
| 290: | }
|
| 291: |
|
| 292: | $this->load->model('setting/store');
|
| 293: | $this->load->model('sale/subscription');
|
| 294: |
|
| 295: | foreach ($selected as $subscription_status_id) {
|
| 296: | if ($this->config->get('config_subscription_status_id') == $subscription_status_id) {
|
| 297: | $json['error'] = $this->language->get('error_default');
|
| 298: | }
|
| 299: |
|
| 300: | $subscription_total = $this->model_sale_subscription->getTotalSubscriptionsBySubscriptionStatusId($subscription_status_id);
|
| 301: |
|
| 302: | if ($subscription_total) {
|
| 303: | $json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
|
| 304: | }
|
| 305: |
|
| 306: | $subscription_total = $this->model_sale_subscription->getTotalHistoriesBySubscriptionStatusId($subscription_status_id);
|
| 307: |
|
| 308: | if ($subscription_total) {
|
| 309: | $json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
|
| 310: | }
|
| 311: | }
|
| 312: |
|
| 313: | if (!$json) {
|
| 314: | $this->load->model('localisation/subscription_status');
|
| 315: |
|
| 316: | foreach ($selected as $subscription_status_id) {
|
| 317: | $this->model_localisation_subscription_status->deleteSubscriptionStatus($subscription_status_id);
|
| 318: | }
|
| 319: |
|
| 320: | $json['success'] = $this->language->get('text_success');
|
| 321: | }
|
| 322: |
|
| 323: | $this->response->addHeader('Content-Type: application/json');
|
| 324: | $this->response->setOutput(json_encode($json));
|
| 325: | }
|
| 326: | }
|
| 327: | |