| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Catalog;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Information extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function addInformation(array $data): int {
|
| 17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "information` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)($data['status'] ?? 0) . "'");
|
| 18: |
|
| 19: | $information_id = $this->db->getLastId();
|
| 20: |
|
| 21: | foreach ($data['information_description'] as $language_id => $information_description) {
|
| 22: | $this->model_catalog_information->addDescription($information_id, $language_id, $information_description);
|
| 23: | }
|
| 24: |
|
| 25: | if (isset($data['information_store'])) {
|
| 26: | foreach ($data['information_store'] as $store_id) {
|
| 27: | $this->model_catalog_information->addStore($information_id, $store_id);
|
| 28: | }
|
| 29: | }
|
| 30: |
|
| 31: |
|
| 32: | $this->load->model('design/seo_url');
|
| 33: |
|
| 34: | foreach ($data['information_seo_url'] as $store_id => $language) {
|
| 35: | foreach ($language as $language_id => $keyword) {
|
| 36: | $this->model_design_seo_url->addSeoUrl('information_id', $information_id, $keyword, $store_id, $language_id);
|
| 37: | }
|
| 38: | }
|
| 39: |
|
| 40: | if (isset($data['information_layout'])) {
|
| 41: | foreach ($data['information_layout'] as $store_id => $layout_id) {
|
| 42: | if ($layout_id) {
|
| 43: | $this->model_catalog_information->addLayout($information_id, $store_id, $layout_id);
|
| 44: | }
|
| 45: | }
|
| 46: | }
|
| 47: |
|
| 48: | $this->cache->delete('information');
|
| 49: |
|
| 50: | return $information_id;
|
| 51: | }
|
| 52: |
|
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: |
|
| 61: | public function editInformation(int $information_id, array $data): void {
|
| 62: | $this->db->query("UPDATE `" . DB_PREFIX . "information` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)($data['status'] ?? 0) . "' WHERE `information_id` = '" . (int)$information_id . "'");
|
| 63: |
|
| 64: | $this->model_catalog_information->deleteDescriptions($information_id);
|
| 65: |
|
| 66: | foreach ($data['information_description'] as $language_id => $information_description) {
|
| 67: | $this->model_catalog_information->addDescription($information_id, $language_id, $information_description);
|
| 68: | }
|
| 69: |
|
| 70: | $this->model_catalog_information->deleteStores($information_id);
|
| 71: |
|
| 72: | if (isset($data['information_store'])) {
|
| 73: | foreach ($data['information_store'] as $store_id) {
|
| 74: | $this->model_catalog_information->addStore($information_id, $store_id);
|
| 75: | }
|
| 76: | }
|
| 77: |
|
| 78: | $this->load->model('design/seo_url');
|
| 79: |
|
| 80: | $this->model_design_seo_url->deleteSeoUrlsByKeyValue('information_id', $information_id);
|
| 81: |
|
| 82: | foreach ($data['information_seo_url'] as $store_id => $language) {
|
| 83: | foreach ($language as $language_id => $keyword) {
|
| 84: | $this->model_design_seo_url->addSeoUrl('information_id', $information_id, $keyword, $store_id, $language_id);
|
| 85: | }
|
| 86: | }
|
| 87: |
|
| 88: | $this->model_catalog_information->deleteLayouts($information_id);
|
| 89: |
|
| 90: | if (isset($data['information_layout'])) {
|
| 91: | foreach ($data['information_layout'] as $store_id => $layout_id) {
|
| 92: | if ($layout_id) {
|
| 93: | $this->model_catalog_information->addLayout($information_id, $store_id, $layout_id);
|
| 94: | }
|
| 95: | }
|
| 96: | }
|
| 97: |
|
| 98: | $this->cache->delete('information');
|
| 99: | }
|
| 100: |
|
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: |
|
| 108: | public function deleteInformation(int $information_id): void {
|
| 109: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 110: |
|
| 111: | $this->model_catalog_information->deleteDescriptions($information_id);
|
| 112: | $this->model_catalog_information->deleteStores($information_id);
|
| 113: | $this->model_catalog_information->deleteLayouts($information_id);
|
| 114: |
|
| 115: | $this->load->model('design/seo_url');
|
| 116: |
|
| 117: | $this->model_design_seo_url->deleteSeoUrlsByKeyValue('information_id', $information_id);
|
| 118: |
|
| 119: | $this->cache->delete('information');
|
| 120: | }
|
| 121: |
|
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: |
|
| 129: | public function getInformation(int $information_id): array {
|
| 130: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "information` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 131: |
|
| 132: | return $query->row;
|
| 133: | }
|
| 134: |
|
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: |
|
| 142: | public function getInformations(array $data = []): array {
|
| 143: | $sql = "SELECT * FROM `" . DB_PREFIX . "information` `i` LEFT JOIN `" . DB_PREFIX . "information_description` `id` ON (`i`.`information_id` = `id`.`information_id`) WHERE `id`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
| 144: |
|
| 145: | $sort_data = [
|
| 146: | 'id.title',
|
| 147: | 'i.sort_order'
|
| 148: | ];
|
| 149: |
|
| 150: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
| 151: | $sql .= " ORDER BY " . $data['sort'];
|
| 152: | } else {
|
| 153: | $sql .= " ORDER BY `id`.`title`";
|
| 154: | }
|
| 155: |
|
| 156: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
| 157: | $sql .= " DESC";
|
| 158: | } else {
|
| 159: | $sql .= " ASC";
|
| 160: | }
|
| 161: |
|
| 162: | if (isset($data['start']) || isset($data['limit'])) {
|
| 163: | if ($data['start'] < 0) {
|
| 164: | $data['start'] = 0;
|
| 165: | }
|
| 166: |
|
| 167: | if ($data['limit'] < 1) {
|
| 168: | $data['limit'] = 20;
|
| 169: | }
|
| 170: |
|
| 171: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
| 172: | }
|
| 173: |
|
| 174: | $key = md5($sql);
|
| 175: |
|
| 176: | $information_data = $this->cache->get('information.' . $key);
|
| 177: |
|
| 178: | if (!$information_data) {
|
| 179: | $query = $this->db->query($sql);
|
| 180: |
|
| 181: | $information_data = $query->rows;
|
| 182: |
|
| 183: | $this->cache->set('information.' . $key, $information_data);
|
| 184: | }
|
| 185: |
|
| 186: | return $information_data;
|
| 187: | }
|
| 188: |
|
| 189: | |
| 190: | |
| 191: | |
| 192: | |
| 193: |
|
| 194: | public function getTotalInformations(): int {
|
| 195: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "information`");
|
| 196: |
|
| 197: | return (int)$query->row['total'];
|
| 198: | }
|
| 199: |
|
| 200: | |
| 201: | |
| 202: | |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: |
|
| 209: | public function addDescription(int $information_id, int $language_id, array $data): void {
|
| 210: | $this->db->query("INSERT INTO `" . DB_PREFIX . "information_description` SET `information_id` = '" . (int)$information_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($data['title']) . "', `description` = '" . $this->db->escape($data['description']) . "', `meta_title` = '" . $this->db->escape($data['meta_title']) . "', `meta_description` = '" . $this->db->escape($data['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($data['meta_keyword']) . "'");
|
| 211: | }
|
| 212: |
|
| 213: | |
| 214: | |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: |
|
| 220: | public function deleteDescriptions(int $information_id): void {
|
| 221: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 222: | }
|
| 223: |
|
| 224: | |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: |
|
| 231: | public function deleteDescriptionsByLanguageId(int $language_id): void {
|
| 232: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
| 233: | }
|
| 234: |
|
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: |
|
| 242: | public function getDescriptions(int $information_id): array {
|
| 243: | $information_description_data = [];
|
| 244: |
|
| 245: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_description` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 246: |
|
| 247: | foreach ($query->rows as $result) {
|
| 248: | $information_description_data[$result['language_id']] = [
|
| 249: | 'title' => $result['title'],
|
| 250: | 'description' => $result['description'],
|
| 251: | 'meta_title' => $result['meta_title'],
|
| 252: | 'meta_description' => $result['meta_description'],
|
| 253: | 'meta_keyword' => $result['meta_keyword']
|
| 254: | ];
|
| 255: | }
|
| 256: |
|
| 257: | return $information_description_data;
|
| 258: | }
|
| 259: |
|
| 260: | |
| 261: | |
| 262: | |
| 263: | |
| 264: | |
| 265: | |
| 266: |
|
| 267: | public function getDescriptionsByLanguageId(int $language_id): array {
|
| 268: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
| 269: |
|
| 270: | return $query->rows;
|
| 271: | }
|
| 272: |
|
| 273: | |
| 274: | |
| 275: | |
| 276: | |
| 277: | |
| 278: | |
| 279: | |
| 280: |
|
| 281: | public function addStore(int $information_id, int $store_id): void {
|
| 282: | $this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_store` SET `information_id` = '" . (int)$information_id . "', `store_id` = '" . (int)$store_id . "'");
|
| 283: | }
|
| 284: |
|
| 285: | |
| 286: | |
| 287: | |
| 288: | |
| 289: | |
| 290: | |
| 291: |
|
| 292: | public function deleteStores(int $information_id): void {
|
| 293: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 294: | }
|
| 295: |
|
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | |
| 301: | |
| 302: |
|
| 303: | public function deleteStoresByStoreId(int $store_id): void {
|
| 304: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 305: | }
|
| 306: |
|
| 307: | |
| 308: | |
| 309: | |
| 310: | |
| 311: | |
| 312: | |
| 313: |
|
| 314: | public function getStores(int $information_id): array {
|
| 315: | $information_store_data = [];
|
| 316: |
|
| 317: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_to_store` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 318: |
|
| 319: | foreach ($query->rows as $result) {
|
| 320: | $information_store_data[] = $result['store_id'];
|
| 321: | }
|
| 322: |
|
| 323: | return $information_store_data;
|
| 324: | }
|
| 325: |
|
| 326: | |
| 327: | |
| 328: | |
| 329: | |
| 330: | |
| 331: | |
| 332: | |
| 333: | |
| 334: |
|
| 335: | public function addLayout(int $information_id, int $store_id, int $layout_id): void {
|
| 336: | $this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_layout` SET `information_id` = '" . (int)$information_id . "', store_id = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
| 337: | }
|
| 338: |
|
| 339: | |
| 340: | |
| 341: | |
| 342: | |
| 343: | |
| 344: | |
| 345: |
|
| 346: | public function deleteLayouts(int $information_id): void {
|
| 347: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 348: | }
|
| 349: |
|
| 350: | |
| 351: | |
| 352: | |
| 353: | |
| 354: | |
| 355: | |
| 356: |
|
| 357: | public function deleteLayoutsByLayoutId(int $layout_id): void {
|
| 358: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
| 359: | }
|
| 360: |
|
| 361: | |
| 362: | |
| 363: | |
| 364: | |
| 365: | |
| 366: | |
| 367: |
|
| 368: | public function deleteLayoutsByStoreId(int $store_id): void {
|
| 369: | $this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 370: | }
|
| 371: |
|
| 372: | |
| 373: | |
| 374: | |
| 375: | |
| 376: | |
| 377: | |
| 378: |
|
| 379: | public function getLayouts(int $information_id): array {
|
| 380: | $information_layout_data = [];
|
| 381: |
|
| 382: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "'");
|
| 383: |
|
| 384: | foreach ($query->rows as $result) {
|
| 385: | $information_layout_data[$result['store_id']] = $result['layout_id'];
|
| 386: | }
|
| 387: |
|
| 388: | return $information_layout_data;
|
| 389: | }
|
| 390: |
|
| 391: | |
| 392: | |
| 393: | |
| 394: | |
| 395: | |
| 396: | |
| 397: |
|
| 398: | public function getTotalLayoutsByLayoutId(int $layout_id): int {
|
| 399: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "information_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
| 400: |
|
| 401: | return (int)$query->row['total'];
|
| 402: | }
|
| 403: | }
|
| 404: | |