docs/api/source-admin.model.localisation.return_action.html
| 1: | <?php |
| 2: | namespace Opencart\Admin\Model\Localisation; |
| 3: | /** |
| 4: | * Class ReturnAction |
| 5: | * |
| 6: | * @package Opencart\Admin\Model\Localisation |
| 7: | */ |
| 8: | class ReturnAction extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Add Return Action |
| 11: | * |
| 12: | * @param array<string, mixed> $data |
| 13: | * |
| 14: | * @return ?int |
| 15: | */ |
| 16: | public function addReturnAction(array $data): ?int { |
| 17: | $return_action_id = 0; |
| 18: | |
| 19: | foreach ($data['return_action'] as $language_id => $return_action) { |
| 20: | if (!$return_action_id) { |
| 21: | $this->db->query("INSERT INTO " . DB\_PREFIX . "return\_action SET language\_id = '" . (int)$language_id . "', name = '" . $this->db->escape($return_action['name']) . "'"); |
| 22: | |
| 23: | $return_action_id = $this->db->getLastId(); |
| 24: | } else { |
| 25: | $this->model_localisation_return_action->addDescription($return_action_id, $language_id, $return_action); |
| 26: | } |
| 27: | } |
| 28: | |
| 29: | $this->cache->delete('return_action'); |
| 30: | |
| 31: | return $return_action_id; |
| 32: | } |
| 33: | |
| 34: | /** |
| 35: | * Edit Return Action |
| 36: | * |
| 37: | * @param int $return_action_id |
| 38: | * @param array<string, mixed> $data |
| 39: | * |
| 40: | * @return void |
| 41: | */ |
| 42: | public function editReturnAction(int $return_action_id, array $data): void { |
| 43: | $this->deleteReturnAction($return_action_id); |
| 44: | |
| 45: | foreach ($data['return_action'] as $language_id => $return_action) { |
| 46: | $this->model_localisation_return_action->addDescription($return_action_id, $language_id, $return_action); |
| 47: | } |
| 48: | |
| 49: | $this->cache->delete('return_action'); |
| 50: | } |
| 51: | |
| 52: | /** |
| 53: | * Delete Return Action |
| 54: | * |
| 55: | * @param int $return_action_id |
| 56: | * |
| 57: | * @return void |
| 58: | */ |
| 59: | public function deleteReturnAction(int $return_action_id): void { |
| 60: | $this->db->query("DELETE FROM " . DB\_PREFIX . "return\_action WHERE return\_action\_id = '" . (int)$return_action_id . "'"); |
| 61: | |
| 62: | $this->cache->delete('return_action'); |
| 63: | } |
| 64: | |
| 65: | /** |
| 66: | * Delete Return Actions By Language ID |
| 67: | * |
| 68: | * @param int $language_id |
| 69: | * |
| 70: | * @return void |
| 71: | */ |
| 72: | public function deleteReturnActionsByLanguageId(int $language_id): void { |
| 73: | $this->db->query("DELETE FROM " . DB\_PREFIX . "return\_action WHERE language\_id = '" . (int)$language_id . "'"); |
| 74: | |
| 75: | $this->cache->delete('return_action'); |
| 76: | } |
| 77: | |
| 78: | /** |
| 79: | * Get Return Action |
| 80: | * |
| 81: | * @param int $return_action_id |
| 82: | * |
| 83: | * @return array<string, mixed> |
| 84: | */ |
| 85: | public function getReturnAction(int $return_action_id): array { |
| 86: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "return\_action WHERE return\_action\_id = '" . (int)$return_action_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); |
| 87: | |
| 88: | return $query->row; |
| 89: | } |
| 90: | |
| 91: | /** |
| 92: | * Get Return Actions |
| 93: | * |
| 94: | * @param array<string, mixed> $data |
| 95: | * |
| 96: | * @return array<int, array<string, mixed>> |
| 97: | */ |
| 98: | public function getReturnActions(array $data = []): array { |
| 99: | $sql = "SELECT * FROM " . DB\_PREFIX . "return\_action WHERE language\_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"; |
| 100: | |
| 101: | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
| 102: | $sql .= " DESC"; |
| 103: | } else { |
| 104: | $sql .= " ASC"; |
| 105: | } |
| 106: | |
| 107: | if (isset($data['start']) || isset($data['limit'])) { |
| 108: | if ($data['start'] < 0) { |
| 109: | $data['start'] = 0; |
| 110: | } |
| 111: | |
| 112: | if ($data['limit'] < 1) { |
| 113: | $data['limit'] = 20; |
| 114: | } |
| 115: | |
| 116: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
| 117: | } |
| 118: | |
| 119: | $key = md5($sql); |
| 120: | |
| 121: | $return_action_data = $this->cache->get('return_action.' . $key); |
| 122: | |
| 123: | if (!$return_action_data) { |
| 124: | $query = $this->db->query($sql); |
| 125: | |
| 126: | $return_action_data = $query->rows; |
| 127: | |
| 128: | $this->cache->set('return_action.' . $key, $return_action_data); |
| 129: | } |
| 130: | |
| 131: | return $return_action_data; |
| 132: | } |
| 133: | |
| 134: | /** |
| 135: | * Add Description |
| 136: | * |
| 137: | * @param int $return_action_id |
| 138: | * @param int $language_id |
| 139: | * @param array<string, mixed> $data |
| 140: | * |
| 141: | * @return void |
| 142: | */ |
| 143: | public function addDescription(int $return_action_id, int $language_id, array $data): void { |
| 144: | $this->db->query("INSERT INTO " . DB\_PREFIX . "return\_action SET return\_action\_id = '" . (int)$return_action_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($data['name']) . "'"); |
| 145: | } |
| 146: | |
| 147: | /** |
| 148: | * Get Descriptions |
| 149: | * |
| 150: | * @param int $return_action_id |
| 151: | * |
| 152: | * @return array<int, array<string, string>> |
| 153: | */ |
| 154: | public function getDescriptions(int $return_action_id): array { |
| 155: | $return_action_data = []; |
| 156: | |
| 157: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "return\_action WHERE return\_action\_id = '" . (int)$return_action_id . "'"); |
| 158: | |
| 159: | foreach ($query->rows as $result) { |
| 160: | $return_action_data[$result['language_id']] = ['name' => $result['name']]; |
| 161: | } |
| 162: | |
| 163: | return $return_action_data; |
| 164: | } |
| 165: | |
| 166: | /** |
| 167: | * Get Descriptions By Language ID |
| 168: | * |
| 169: | * @param int $language_id |
| 170: | * |
| 171: | * @return array<int, array<string, string>> |
| 172: | */ |
| 173: | public function getDescriptionsByLanguageId(int $language_id): array { |
| 174: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "return\_action WHERE language\_id = '" . (int)$language_id . "'"); |
| 175: | |
| 176: | return $query->rows; |
| 177: | } |
| 178: | |
| 179: | /** |
| 180: | * Get Total Return Actions |
| 181: | * |
| 182: | * @return int |
| 183: | */ |
| 184: | public function getTotalReturnActions(): int { |
| 185: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "return\_action WHERE language\_id = '" . (int)$this->config->get('config_language_id') . "'"); |
| 186: | |
| 187: | return (int)$query->row['total']; |
| 188: | } |
| 189: | } |
| 190: | |
OpenCart API API documentation generated by ApiGen dev-master