| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Setting;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Setting extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function getSettings(int $store_id = 0): array {
|
| 17: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' OR `store_id` = '0' ORDER BY `store_id` ASC");
|
| 18: |
|
| 19: | return $query->rows;
|
| 20: | }
|
| 21: |
|
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: |
|
| 30: | public function getSetting(string $code, int $store_id = 0): array {
|
| 31: | $setting_data = [];
|
| 32: |
|
| 33: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
| 34: |
|
| 35: | foreach ($query->rows as $result) {
|
| 36: | if (!$result['serialized']) {
|
| 37: | $setting_data[$result['key']] = $result['value'];
|
| 38: | } else {
|
| 39: | $setting_data[$result['key']] = json_decode($result['value'], true);
|
| 40: | }
|
| 41: | }
|
| 42: |
|
| 43: | return $setting_data;
|
| 44: | }
|
| 45: |
|
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: |
|
| 55: | public function editSetting(string $code, array $data, int $store_id = 0): void {
|
| 56: | $this->deleteSetting($code, $store_id);
|
| 57: |
|
| 58: | foreach ($data as $key => $value) {
|
| 59: | if (substr($key, 0, strlen($code)) == $code) {
|
| 60: | $this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `store_id` = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(!is_array($value) ? $value : json_encode($value)) . "', `serialized` = '" . (bool)is_array($value) . "'");
|
| 61: | }
|
| 62: | }
|
| 63: | }
|
| 64: |
|
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: |
|
| 73: | public function deleteSetting(string $code, int $store_id = 0): void {
|
| 74: | $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
| 75: | }
|
| 76: |
|
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: |
|
| 84: | public function deleteSettingsByCode(string $code): void {
|
| 85: | $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = '" . $this->db->escape($code) . "'");
|
| 86: | }
|
| 87: |
|
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: |
|
| 95: | public function deleteSettingsByStoreId(int $store_id): void {
|
| 96: | $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 97: | }
|
| 98: |
|
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: |
|
| 107: | public function getValue(string $key, int $store_id = 0): string {
|
| 108: | $query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
|
| 109: |
|
| 110: | if ($query->num_rows) {
|
| 111: | return $query->row['value'];
|
| 112: | } else {
|
| 113: | return '';
|
| 114: | }
|
| 115: | }
|
| 116: |
|
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: |
|
| 127: | public function editValue(string $code = '', string $key = '', $value = '', int $store_id = 0): void {
|
| 128: | $this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape(!is_array($value) ? $value : json_encode($value)) . "', `serialized` = '" . (bool)is_array($value) . "' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND `store_id` = '" . (int)$store_id . "'");
|
| 129: | }
|
| 130: | }
|
| 131: | |