| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Design;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Translation extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function addTranslation(array $data): void {
|
| 17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "translation` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `route` = '" . $this->db->escape((string)$data['route']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `date_added` = NOW()");
|
| 18: | }
|
| 19: |
|
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | public function editTranslation(int $translation_id, array $data): void {
|
| 29: | $this->db->query("UPDATE `" . DB_PREFIX . "translation` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `route` = '" . $this->db->escape((string)$data['route']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "' WHERE `translation_id` = '" . (int)$translation_id . "'");
|
| 30: | }
|
| 31: |
|
| 32: | |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: |
|
| 39: | public function deleteTranslation(int $translation_id): void {
|
| 40: | $this->db->query("DELETE FROM `" . DB_PREFIX . "translation` WHERE `translation_id` = '" . (int)$translation_id . "'");
|
| 41: | }
|
| 42: |
|
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: |
|
| 50: | public function deleteTranslationsByStoreId(int $store_id): void {
|
| 51: | $this->db->query("DELETE FROM `" . DB_PREFIX . "translation` WHERE `store_id` = '" . (int)$store_id . "'");
|
| 52: | }
|
| 53: |
|
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: |
|
| 61: | public function deleteTranslationsByLanguageId(int $language_id): void {
|
| 62: | $this->db->query("DELETE FROM `" . DB_PREFIX . "translation` WHERE `language_id` = '" . (int)$language_id . "'");
|
| 63: | }
|
| 64: |
|
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: |
|
| 72: | public function getTranslation(int $translation_id): array {
|
| 73: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "translation` WHERE `translation_id` = '" . (int)$translation_id . "'");
|
| 74: |
|
| 75: | return $query->row;
|
| 76: | }
|
| 77: |
|
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: |
|
| 85: | public function getTranslations(array $data = []): array {
|
| 86: | $sql = "SELECT *, (SELECT `s`.`name` FROM `" . DB_PREFIX . "store` `s` WHERE `s`.`store_id` = `t`.`store_id`) AS `store`, (SELECT `l`.`name` FROM `" . DB_PREFIX . "language` `l` WHERE `l`.`language_id` = `t`.`language_id`) AS `language` FROM `" . DB_PREFIX . "translation` `t`";
|
| 87: |
|
| 88: | $sort_data = [
|
| 89: | 'store',
|
| 90: | 'language',
|
| 91: | 'route',
|
| 92: | 'key',
|
| 93: | 'value'
|
| 94: | ];
|
| 95: |
|
| 96: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
| 97: | $sql .= " ORDER BY " . $data['sort'];
|
| 98: | } else {
|
| 99: | $sql .= " ORDER BY store";
|
| 100: | }
|
| 101: |
|
| 102: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
| 103: | $sql .= " DESC";
|
| 104: | } else {
|
| 105: | $sql .= " ASC";
|
| 106: | }
|
| 107: |
|
| 108: | if (isset($data['start']) || isset($data['limit'])) {
|
| 109: | if ($data['start'] < 0) {
|
| 110: | $data['start'] = 0;
|
| 111: | }
|
| 112: |
|
| 113: | if ($data['limit'] < 1) {
|
| 114: | $data['limit'] = 20;
|
| 115: | }
|
| 116: |
|
| 117: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
| 118: | }
|
| 119: |
|
| 120: | $query = $this->db->query($sql);
|
| 121: |
|
| 122: | return $query->rows;
|
| 123: | }
|
| 124: |
|
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: |
|
| 130: | public function getTotalTranslations(): int {
|
| 131: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "translation`");
|
| 132: |
|
| 133: | return (int)$query->row['total'];
|
| 134: | }
|
| 135: | }
|
| 136: | |