1: <?php
2: namespace Opencart\Admin\Model\Design;
3: /**
4: * Class Theme
5: *
6: * @package Opencart\Admin\Model\Design
7: */
8: class Theme extends \Opencart\System\Engine\Model {
9: /**
10: * Add Theme
11: *
12: * @param array<string, mixed> $data
13: *
14: * @return int
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: * Edit Theme
24: *
25: * @param int $theme_id
26: * @param array<string, mixed> $data
27: *
28: * @return void
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: * Delete Theme
36: *
37: * @param int $theme_id
38: *
39: * @return void
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: * Delete Themes By Store ID
47: *
48: * @param int $store_id
49: *
50: * @return void
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: * Get Theme
58: *
59: * @param int $theme_id
60: *
61: * @return array<string, mixed>
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: * Get Themes
71: *
72: * @param int $start
73: * @param int $limit
74: *
75: * @return array<int, array<string, mixed>>
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: * Get Total Themes
93: *
94: * @return int
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: