Back to Opencart

File admin\controller\design\layout.php

docs/api/source-admin.controller.design.layout.html

4.1.0.322.8 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Design; | | 3: | /** | | 4: | * Class Layout | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Design | | 7: | */ | | 8: | class Layout extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('design/layout'); | | 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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url) | | 43: | ]; | | 44: | | | 45: | $data['add'] = $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . $url); | | 46: | $data['delete'] = $this->url->link('design/layout.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('design/layout', $data)); | | 57: | } | | 58: | | | 59: | /** | | 60: | * List | | 61: | * | | 62: | * @return void | | 63: | */ | | 64: | public function list(): void { | | 65: | $this->load->language('design/layout'); | | 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('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url); | | 109: | | | 110: | $data['layouts'] = []; | | 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('design/layout'); | | 120: | | | 121: | $results = $this->model_design_layout->getLayouts($filter_data); | | 122: | | | 123: | foreach ($results as $result) { | | 124: | $data['layouts'][] = [ | | 125: | 'layout_id' => $result['layout_id'], | | 126: | 'name' => $result['name'], | | 127: | 'edit' => $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_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('design/layout.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: | $layout_total = $this->model_design_layout->getTotalLayouts(); | | 152: | | | 153: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 154: | 'total' => $layout_total, | | 155: | 'page' => $page, | | 156: | 'limit' => $this->config->get('config_pagination_admin'), | | 157: | 'url' => $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 158: | ]); | | 159: | | | 160: | $data['results'] = sprintf($this->language->get('text_pagination'), ($layout_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($layout_total - $this->config->get('config_pagination_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $layout_total, ceil($layout_total / $this->config->get('config_pagination_admin'))); | | 161: | | | 162: | $data['sort'] = $sort; | | 163: | $data['order'] = $order; | | 164: | | | 165: | return $this->load->view('design/layout_list', $data); | | 166: | } | | 167: | | | 168: | /** | | 169: | * Form | | 170: | * | | 171: | * @return void | | 172: | */ | | 173: | public function form(): void { | | 174: | $this->load->language('design/layout'); | | 175: | | | 176: | $this->document->setTitle($this->language->get('heading_title')); | | 177: | | | 178: | $data['text_form'] = !isset($this->request->get['layout_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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url) | | 204: | ]; | | 205: | | | 206: | $data['save'] = $this->url->link('design/layout.save', 'user_token=' . $this->session->data['user_token']); | | 207: | $data['back'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url); | | 208: | | | 209: | if (isset($this->request->get['layout_id'])) { | | 210: | $this->load->model('design/layout'); | | 211: | | | 212: | $layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']); | | 213: | } | | 214: | | | 215: | if (isset($this->request->get['layout_id'])) { | | 216: | $data['layout_id'] = (int)$this->request->get['layout_id']; | | 217: | } else { | | 218: | $data['layout_id'] = 0; | | 219: | } | | 220: | | | 221: | if (!empty($layout_info)) { | | 222: | $data['name'] = $layout_info['name']; | | 223: | } else { | | 224: | $data['name'] = ''; | | 225: | } | | 226: | | | 227: | $this->load->model('setting/store'); | | 228: | | | 229: | $data['stores'] = $this->model_setting_store->getStores(); | | 230: | | | 231: | if (isset($this->request->get['layout_id'])) { | | 232: | $data['layout_routes'] = $this->model_design_layout->getRoutes($this->request->get['layout_id']); | | 233: | } else { | | 234: | $data['layout_routes'] = []; | | 235: | } | | 236: | | | 237: | $this->load->model('setting/extension'); | | 238: | $this->load->model('setting/module'); | | 239: | | | 240: | $data['extensions'] = []; | | 241: | | | 242: | // Get a list of installed modules | | 243: | $extensions = $this->model_setting_extension->getExtensionsByType('module'); | | 244: | | | 245: | // Add all the modules which have multiple settings for each module | | 246: | foreach ($extensions as $extension) { | | 247: | $this->load->language('extension/' . $extension['extension'] . '/module/' . $extension['code'], $extension['code']); | | 248: | | | 249: | $module_data = []; | | 250: | | | 251: | $modules = $this->model_setting_module->getModulesByCode($extension['extension'] . '.' . $extension['code']); | | 252: | | | 253: | foreach ($modules as $module) { | | 254: | $module_data[] = [ | | 255: | 'name' => strip_tags($module['name']), | | 256: | 'code' => $extension['extension'] . '.' . $extension['code'] . '.' . $module['module_id'] | | 257: | ]; | | 258: | } | | 259: | | | 260: | if ($this->config->has('module_' . $extension['code'] . '_status') || $module_data) { | | 261: | $data['extensions'][] = [ | | 262: | 'name' => strip_tags($this->language->get($extension['code'] . '_heading_title')), | | 263: | 'code' => $extension['extension'] . '.' . $extension['code'], | | 264: | 'module' => $module_data | | 265: | ]; | | 266: | } | | 267: | } | | 268: | | | 269: | // Modules layout | | 270: | if (!empty($layout_info)) { | | 271: | $layout_modules = $this->model_design_layout->getModules($this->request->get['layout_id']); | | 272: | } else { | | 273: | $layout_modules = []; | | 274: | } | | 275: | | | 276: | $data['layout_modules'] = []; | | 277: | | | 278: | // Add all the modules which have multiple settings for each module | | 279: | foreach ($layout_modules as $layout_module) { | | 280: | $part = explode('.', $layout_module['code']); | | 281: | | | 282: | if (!isset($part[2])) { | | 283: | $data['layout_modules'][] = [ | | 284: | 'code' => $layout_module['code'], | | 285: | 'position' => $layout_module['position'], | | 286: | 'sort_order' => $layout_module['sort_order'], | | 287: | 'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token']) | | 288: | ]; | | 289: | } else { | | 290: | $module_info = $this->model_setting_module->getModule((int)$part[2]); | | 291: | | | 292: | if ($module_info) { | | 293: | $data['layout_modules'][] = [ | | 294: | 'code' => $layout_module['code'], | | 295: | 'position' => $layout_module['position'], | | 296: | 'sort_order' => $layout_module['sort_order'], | | 297: | 'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[2]) | | 298: | ]; | | 299: | } | | 300: | } | | 301: | } | | 302: | | | 303: | $data['user_token'] = $this->session->data['user_token']; | | 304: | | | 305: | $data['header'] = $this->load->controller('common/header'); | | 306: | $data['column_left'] = $this->load->controller('common/column_left'); | | 307: | $data['footer'] = $this->load->controller('common/footer'); | | 308: | | | 309: | $this->response->setOutput($this->load->view('design/layout_form', $data)); | | 310: | } | | 311: | | | 312: | /** | | 313: | * Save | | 314: | * | | 315: | * @return void | | 316: | */ | | 317: | public function save(): void { | | 318: | $this->load->language('design/layout'); | | 319: | | | 320: | $json = []; | | 321: | | | 322: | if (!$this->user->hasPermission('modify', 'design/layout')) { | | 323: | $json['error']['warning'] = $this->language->get('error_permission'); | | 324: | } | | 325: | | | 326: | if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) { | | 327: | $json['error']['name'] = $this->language->get('error_name'); | | 328: | } | | 329: | | | 330: | if (!$json) { | | 331: | $this->load->model('design/layout'); | | 332: | | | 333: | if (!$this->request->post['layout_id']) { | | 334: | $json['layout_id'] = $this->model_design_layout->addLayout($this->request->post); | | 335: | } else { | | 336: | $this->model_design_layout->editLayout($this->request->post['layout_id'], $this->request->post); | | 337: | } | | 338: | | | 339: | $json['success'] = $this->language->get('text_success'); | | 340: | } | | 341: | | | 342: | $this->response->addHeader('Content-Type: application/json'); | | 343: | $this->response->setOutput(json_encode($json)); | | 344: | } | | 345: | | | 346: | /** | | 347: | * Delete | | 348: | * | | 349: | * @return void | | 350: | */ | | 351: | public function delete(): void { | | 352: | $this->load->language('design/layout'); | | 353: | | | 354: | $json = []; | | 355: | | | 356: | if (isset($this->request->post['selected'])) { | | 357: | $selected = $this->request->post['selected']; | | 358: | } else { | | 359: | $selected = []; | | 360: | } | | 361: | | | 362: | if (!$this->user->hasPermission('modify', 'design/layout')) { | | 363: | $json['error'] = $this->language->get('error_permission'); | | 364: | } | | 365: | | | 366: | $this->load->model('setting/store'); | | 367: | $this->load->model('catalog/product'); | | 368: | $this->load->model('catalog/category'); | | 369: | $this->load->model('catalog/manufacturer'); | | 370: | $this->load->model('catalog/information'); | | 371: | | | 372: | foreach ($selected as $layout_id) { | | 373: | if ($this->config->get('config_layout_id') == $layout_id) { | | 374: | $json['error'] = $this->language->get('error_default'); | | 375: | } | | 376: | | | 377: | $store_total = $this->model_setting_store->getTotalLayoutsByLayoutId($layout_id); | | 378: | | | 379: | if ($store_total) { | | 380: | $json['error'] = sprintf($this->language->get('error_store'), $store_total); | | 381: | } | | 382: | | | 383: | $product_total = $this->model_catalog_product->getTotalLayoutsByLayoutId($layout_id); | | 384: | | | 385: | if ($product_total) { | | 386: | $json['error'] = sprintf($this->language->get('error_product'), $product_total); | | 387: | } | | 388: | | | 389: | $category_total = $this->model_catalog_category->getTotalLayoutsByLayoutId($layout_id); | | 390: | | | 391: | if ($category_total) { | | 392: | $json['error'] = sprintf($this->language->get('error_category'), $category_total); | | 393: | } | | 394: | | | 395: | $manufacturer_total = $this->model_catalog_manufacturer->getTotalLayoutsByLayoutId($layout_id); | | 396: | | | 397: | if ($manufacturer_total) { | | 398: | $json['error'] = sprintf($this->language->get('error_manufacturer'), $manufacturer_total); | | 399: | } | | 400: | | | 401: | $information_total = $this->model_catalog_information->getTotalLayoutsByLayoutId($layout_id); | | 402: | | | 403: | if ($information_total) { | | 404: | $json['error'] = sprintf($this->language->get('error_information'), $information_total); | | 405: | } | | 406: | } | | 407: | | | 408: | if (!$json) { | | 409: | $this->load->model('design/layout'); | | 410: | | | 411: | foreach ($selected as $layout_id) { | | 412: | $this->model_design_layout->deleteLayout($layout_id); | | 413: | } | | 414: | | | 415: | $json['success'] = $this->language->get('text_success'); | | 416: | } | | 417: | | | 418: | $this->response->addHeader('Content-Type: application/json'); | | 419: | $this->response->setOutput(json_encode($json)); | | 420: | } | | 421: | } | | 422: | |

OpenCart API API documentation generated by ApiGen dev-master