1: | <?php
|
2: | namespace Opencart\Admin\Model\Design;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Theme extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function addTheme(array $data): int {
|
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "theme` SET `store_id` = '" . (int)$data['store_id'] . "', `route` = '" . $this->db->escape($data['route']) . "', `code` = '" . $this->db->escape($data['code']) . "', `status` = '" . (bool)$data['status'] . "', `date_added` = NOW()");
|
18: |
|
19: | return $this->db->getLastId();
|
20: | }
|
21: |
|
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: |
|
30: | public function editTheme(int $theme_id, array $data): void {
|
31: | $this->db->query("UPDATE `" . DB_PREFIX . "theme` SET `store_id` = '" . (int)$data['store_id'] . "', `route` = '" . $this->db->escape($data['route']) . "', `code` = '" . $this->db->escape($data['code']) . "', `status` = '" . (bool)$data['status'] . "', `date_added` = NOW() WHERE `theme_id` = '" . (int)$theme_id . "'");
|
32: | }
|
33: |
|
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: |
|
41: | public function deleteTheme(int $theme_id): void {
|
42: | $this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE `theme_id` = '" . (int)$theme_id . "'");
|
43: | }
|
44: |
|
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: |
|
52: | public function deleteThemesByStoreId(int $store_id): void {
|
53: | $this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE `store_id` = '" . (int)$store_id . "'");
|
54: | }
|
55: |
|
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: |
|
63: | public function getTheme(int $theme_id): array {
|
64: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "theme` WHERE `theme_id` = '" . (int)$theme_id . "'");
|
65: |
|
66: | return $query->row;
|
67: | }
|
68: |
|
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: |
|
77: | public function getThemes(int $start = 0, int $limit = 10): array {
|
78: | if ($start < 0) {
|
79: | $start = 0;
|
80: | }
|
81: |
|
82: | if ($limit < 1) {
|
83: | $limit = 10;
|
84: | }
|
85: |
|
86: | $query = $this->db->query("SELECT *, (SELECT `name` FROM `" . DB_PREFIX . "store` `s` WHERE `s`.`store_id` = `t`.`store_id`) AS `store` FROM `" . DB_PREFIX . "theme` `t` ORDER BY `t`.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
87: |
|
88: | return $query->rows;
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: |
|
96: | public function getTotalThemes(): int {
|
97: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "theme`");
|
98: |
|
99: | return (int)$query->row['total'];
|
100: | }
|
101: | }
|
102: | |