1: | <?php
2: | namespace Opencart\Admin\Model\Design;
3: | /**
4: | * Class Translation
5: | *
6: | * @package Opencart\Admin\Model\Design
7: | */
8: | class Translation extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Translation
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return void
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: | * Edit Translation
22: | *
23: | * @param int $translation_id
24: | * @param array<string, mixed> $data
25: | *
26: | * @return void
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: | * Delete Translation
34: | *
35: | * @param int $translation_id
36: | *
37: | * @return void
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: | * Delete Translations By Store ID
45: | *
46: | * @param int $store_id
47: | *
48: | * @return void
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: | * Delete Translations By Language ID
56: | *
57: | * @param int $language_id
58: | *
59: | * @return void
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: | * Get Translation
67: | *
68: | * @param int $translation_id
69: | *
70: | * @return array<string, mixed>
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: | * Get Translations
80: | *
81: | * @param array<string, mixed> $data
82: | *
83: | * @return array<int, array<string, mixed>>
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: | * Get Total Translations
127: | *
128: | * @return int
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: |

OpenCart API API documentation generated by ApiGen dev-master