1: | <?php
2: | namespace Opencart\Catalog\Model\Localisation;
3: | /**
4: | * Class Language
5: | *
6: | * @package Opencart\Catalog\Model\Localisation
7: | */
8: | class Language extends \Opencart\System\Engine\Model {
9: | /**
10: | * @var array<int|string, array<string, mixed>>
11: | */
12: | private array $data = [];
13: |
14: | /**
15: | * Get Language
16: | *
17: | * @param int $language_id
18: | *
19: | * @return array<string, mixed>
20: | */
21: | public function getLanguage(int $language_id): array {
22: | if (isset($this->data[$language_id])) {
23: | return $this->data[$language_id];
24: | }
25: |
26: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
27: |
28: | $language = $query->row;
29: |
30: | if ($language) {
31: | $language['image'] = HTTP_SERVER;
32: |
33: | if (!$language['extension']) {
34: | $language['image'] .= 'catalog/';
35: | } else {
36: | $language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
37: | }
38: |
39: | $language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
40: | }
41: |
42: | $this->data[$language_id] = $language;
43: |
44: | return $language;
45: | }
46: |
47: | /**
48: | * Get Language By Code
49: | *
50: | * @param string $code
51: | *
52: | * @return array<string, mixed>
53: | */
54: | public function getLanguageByCode(string $code): array {
55: | if (isset($this->data[$code])) {
56: | return $this->data[$code];
57: | }
58: |
59: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `code` = '" . $this->db->escape($code) . "'");
60: |
61: | $language = $query->row;
62: |
63: | if ($language) {
64: | $language['image'] = HTTP_SERVER;
65: |
66: | if (!$language['extension']) {
67: | $language['image'] .= 'catalog/';
68: | } else {
69: | $language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
70: | }
71: |
72: | $language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
73: | }
74: |
75: | $this->data[$code] = $language;
76: |
77: | return $language;
78: | }
79: |
80: | /**
81: | * Get Languages
82: | *
83: | * @return array<string, array<string, mixed>>
84: | */
85: | public function getLanguages(): array {
86: | $sql = "SELECT * FROM `" . DB_PREFIX . "language` WHERE `status` = '1' ORDER BY `sort_order`, `name`";
87: |
88: | $results = $this->cache->get('language.' . md5($sql));
89: |
90: | if (!$results) {
91: | $query = $this->db->query($sql);
92: |
93: | $results = $query->rows;
94: |
95: | $this->cache->set('language.' . md5($sql), $results);
96: | }
97: |
98: | $language_data = [];
99: |
100: | foreach ($results as $result) {
101: | $image = HTTP_SERVER;
102: |
103: | if (!$result['extension']) {
104: | $image .= 'catalog/';
105: | } else {
106: | $image .= 'extension/' . $result['extension'] . '/catalog/';
107: | }
108: |
109: | $language_data[$result['code']] = [
110: | 'language_id' => $result['language_id'],
111: | 'name' => $result['name'],
112: | 'code' => $result['code'],
113: | 'image' => $image . 'language/' . $result['code'] . '/' . $result['code'] . '.png',
114: | 'locale' => $result['locale'],
115: | 'extension' => $result['extension'],
116: | 'sort_order' => $result['sort_order'],
117: | 'status' => $result['status']
118: | ];
119: | }
120: |
121: | return $language_data;
122: | }
123: | }
124: |

OpenCart API API documentation generated by ApiGen dev-master