docs/api/source-admin.controller.localisation.location.html
| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Localisation; | | 3: | /** | | 4: | * Class Location | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Localisation | | 7: | */ | | 8: | class Location extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('localisation/location'); | | 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/location', 'user_token=' . $this->session->data['user_token'] . $url) | | 43: | ]; | | 44: | | | 45: | $data['add'] = $this->url->link('localisation/location.form', 'user_token=' . $this->session->data['user_token'] . $url); | | 46: | $data['delete'] = $this->url->link('localisation/location.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/location', $data)); | | 57: | } | | 58: | | | 59: | /** | | 60: | * List | | 61: | * | | 62: | * @return void | | 63: | */ | | 64: | public function list(): void { | | 65: | $this->load->language('localisation/location'); | | 66: | | | 67: | $this->response->setOutput($this->getList()); | | 68: | } | | 69: | | | 70: | /** | | 71: | * Get List | | 72: | * | | 73: | * @return string | | 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/location.list', 'user_token=' . $this->session->data['user_token'] . $url); | | 109: | | | 110: | $data['locations'] = []; | | 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/location'); | | 120: | | | 121: | $results = $this->model_localisation_location->getLocations($filter_data); | | 122: | | | 123: | foreach ($results as $result) { | | 124: | $data['locations'][] = [ | | 125: | 'location_id' => $result['location_id'], | | 126: | 'name' => $result['name'], | | 127: | 'address' => $result['address'], | | 128: | 'edit' => $this->url->link('localisation/location.form', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $result['location_id'] . $url) | | 129: | ]; | | 130: | } | | 131: | | | 132: | $url = ''; | | 133: | | | 134: | if ($order == 'ASC') { | | 135: | $url .= '&order=DESC'; | | 136: | } else { | | 137: | $url .= '&order=ASC'; | | 138: | } | | 139: | | | 140: | $data['sort_name'] = $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url); | | 141: | $data['sort_address'] = $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . '&sort=address' . $url); | | 142: | | | 143: | $url = ''; | | 144: | | | 145: | if (isset($this->request->get['sort'])) { | | 146: | $url .= '&sort=' . $this->request->get['sort']; | | 147: | } | | 148: | | | 149: | if (isset($this->request->get['order'])) { | | 150: | $url .= '&order=' . $this->request->get['order']; | | 151: | } | | 152: | | | 153: | $location_total = $this->model_localisation_location->getTotalLocations(); | | 154: | | | 155: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 156: | 'total' => $location_total, | | 157: | 'page' => $page, | | 158: | 'limit' => $this->config->get('config_pagination_admin'), | | 159: | 'url' => $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 160: | ]); | | 161: | | | 162: | $data['results'] = sprintf($this->language->get('text_pagination'), ($location_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($location_total - $this->config->get('config_pagination_admin'))) ? $location_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $location_total, ceil($location_total / $this->config->get('config_pagination_admin'))); | | 163: | | | 164: | $data['sort'] = $sort; | | 165: | $data['order'] = $order; | | 166: | | | 167: | return $this->load->view('localisation/location_list', $data); | | 168: | } | | 169: | | | 170: | /** | | 171: | * Form | | 172: | * | | 173: | * @return void | | 174: | */ | | 175: | public function form(): void { | | 176: | $this->load->language('localisation/location'); | | 177: | | | 178: | $this->document->setTitle($this->language->get('heading_title')); | | 179: | | | 180: | $data['text_form'] = !isset($this->request->get['location_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); | | 181: | | | 182: | $url = ''; | | 183: | | | 184: | if (isset($this->request->get['sort'])) { | | 185: | $url .= '&sort=' . $this->request->get['sort']; | | 186: | } | | 187: | | | 188: | if (isset($this->request->get['order'])) { | | 189: | $url .= '&order=' . $this->request->get['order']; | | 190: | } | | 191: | | | 192: | if (isset($this->request->get['page'])) { | | 193: | $url .= '&page=' . $this->request->get['page']; | | 194: | } | | 195: | | | 196: | $data['breadcrumbs'] = []; | | 197: | | | 198: | $data['breadcrumbs'][] = [ | | 199: | 'text' => $this->language->get('text_home'), | | 200: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 201: | ]; | | 202: | | | 203: | $data['breadcrumbs'][] = [ | | 204: | 'text' => $this->language->get('heading_title'), | | 205: | 'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url) | | 206: | ]; | | 207: | | | 208: | $data['save'] = $this->url->link('localisation/location.save', 'user_token=' . $this->session->data['user_token']); | | 209: | $data['back'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url); | | 210: | | | 211: | if (isset($this->request->get['location_id'])) { | | 212: | $this->load->model('localisation/location'); | | 213: | | | 214: | $location_info = $this->model_localisation_location->getLocation($this->request->get['location_id']); | | 215: | } | | 216: | | | 217: | if (isset($this->request->get['location_id'])) { | | 218: | $data['location_id'] = (int)$this->request->get['location_id']; | | 219: | } else { | | 220: | $data['location_id'] = 0; | | 221: | } | | 222: | | | 223: | if (!empty($location_info)) { | | 224: | $data['name'] = $location_info['name']; | | 225: | } else { | | 226: | $data['name'] = ''; | | 227: | } | | 228: | | | 229: | if (!empty($location_info)) { | | 230: | $data['address'] = $location_info['address']; | | 231: | } else { | | 232: | $data['address'] = ''; | | 233: | } | | 234: | | | 235: | if (!empty($location_info)) { | | 236: | $data['geocode'] = $location_info['geocode']; | | 237: | } else { | | 238: | $data['geocode'] = ''; | | 239: | } | | 240: | | | 241: | if (!empty($location_info)) { | | 242: | $data['telephone'] = $location_info['telephone']; | | 243: | } else { | | 244: | $data['telephone'] = ''; | | 245: | } | | 246: | | | 247: | if (!empty($location_info)) { | | 248: | $data['image'] = $location_info['image']; | | 249: | } else { | | 250: | $data['image'] = ''; | | 251: | } | | 252: | | | 253: | $this->load->model('tool/image'); | | 254: | | | 255: | $data['placeholder'] = $this->model_tool_image->resize('no_image.png', $this->config->get('config_image_default_width'), $this->config->get('config_image_default_height')); | | 256: | | | 257: | if ($data['image'] && is_file(DIR_IMAGE . html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'))) { | | 258: | $data['thumb'] = $this->model_tool_image->resize($data['image'], $this->config->get('config_image_default_width'), $this->config->get('config_image_default_height')); | | 259: | } else { | | 260: | $data['thumb'] = $data['placeholder']; | | 261: | } | | 262: | | | 263: | if (!empty($location_info)) { | | 264: | $data['open'] = $location_info['open']; | | 265: | } else { | | 266: | $data['open'] = ''; | | 267: | } | | 268: | | | 269: | if (!empty($location_info)) { | | 270: | $data['comment'] = $location_info['comment']; | | 271: | } else { | | 272: | $data['comment'] = ''; | | 273: | } | | 274: | | | 275: | $data['user_token'] = $this->session->data['user_token']; | | 276: | | | 277: | $data['header'] = $this->load->controller('common/header'); | | 278: | $data['column_left'] = $this->load->controller('common/column_left'); | | 279: | $data['footer'] = $this->load->controller('common/footer'); | | 280: | | | 281: | $this->response->setOutput($this->load->view('localisation/location_form', $data)); | | 282: | } | | 283: | | | 284: | /** | | 285: | * Save | | 286: | * | | 287: | * @return void | | 288: | */ | | 289: | public function save(): void { | | 290: | $this->load->language('localisation/location'); | | 291: | | | 292: | $json = []; | | 293: | | | 294: | if (!$this->user->hasPermission('modify', 'localisation/location')) { | | 295: | $json['error']['warning'] = $this->language->get('error_permission'); | | 296: | } | | 297: | | | 298: | if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) { | | 299: | $json['error']['name'] = $this->language->get('error_name'); | | 300: | } | | 301: | | | 302: | if ((oc_strlen($this->request->post['address']) < 3) || (oc_strlen($this->request->post['address']) > 128)) { | | 303: | $json['error']['address'] = $this->language->get('error_address'); | | 304: | } | | 305: | | | 306: | if ((oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) { | | 307: | $json['error']['telephone'] = $this->language->get('error_telephone'); | | 308: | } | | 309: | | | 310: | if (!$json) { | | 311: | $this->load->model('localisation/location'); | | 312: | | | 313: | if (!$this->request->post['location_id']) { | | 314: | $json['location_id'] = $this->model_localisation_location->addLocation($this->request->post); | | 315: | } else { | | 316: | $this->model_localisation_location->editLocation($this->request->post['location_id'], $this->request->post); | | 317: | } | | 318: | | | 319: | $json['success'] = $this->language->get('text_success'); | | 320: | } | | 321: | | | 322: | $this->response->addHeader('Content-Type: application/json'); | | 323: | $this->response->setOutput(json_encode($json)); | | 324: | } | | 325: | | | 326: | /** | | 327: | * Delete | | 328: | * | | 329: | * @return void | | 330: | */ | | 331: | public function delete(): void { | | 332: | $this->load->language('localisation/location'); | | 333: | | | 334: | $json = []; | | 335: | | | 336: | if (isset($this->request->post['selected'])) { | | 337: | $selected = $this->request->post['selected']; | | 338: | } else { | | 339: | $selected = []; | | 340: | } | | 341: | | | 342: | if (!$this->user->hasPermission('modify', 'localisation/location')) { | | 343: | $json['error'] = $this->language->get('error_permission'); | | 344: | } | | 345: | | | 346: | if (!$json) { | | 347: | $this->load->model('localisation/location'); | | 348: | | | 349: | foreach ($selected as $location_id) { | | 350: | $this->model_localisation_location->deleteLocation($location_id); | | 351: | } | | 352: | | | 353: | $json['success'] = $this->language->get('text_success'); | | 354: | } | | 355: | | | 356: | $this->response->addHeader('Content-Type: application/json'); | | 357: | $this->response->setOutput(json_encode($json)); | | 358: | } | | 359: | } | | 360: | |
OpenCart API API documentation generated by ApiGen dev-master