1: <?php
2: namespace Opencart\Admin\Model\Setting;
3: /**
4: * Class Modification
5: *
6: * @package Opencart\Admin\Model\Setting
7: */
8: class Modification extends \Opencart\System\Engine\Model {
9: /**
10: * Add Modification
11: *
12: * @param array<string, mixed> $data
13: *
14: * @return void
15: */
16: public function addModification(array $data): void {
17: $this->db->query("INSERT INTO `" . DB_PREFIX . "modification` SET `extension_install_id` = '" . (int)$data['extension_install_id'] . "', `name` = '" . $this->db->escape($data['name']) . "', `description` = '" . $this->db->escape($data['description']) . "', `code` = '" . $this->db->escape($data['code']) . "', `author` = '" . $this->db->escape($data['author']) . "', `version` = '" . $this->db->escape($data['version']) . "', `link` = '" . $this->db->escape($data['link']) . "', `xml` = '" . $this->db->escape($data['xml']) . "', `status` = '" . (int)$data['status'] . "', `date_added` = NOW()");
18: }
19:
20: /**
21: * Delete Modification
22: *
23: * @param int $modification_id
24: *
25: * @return void
26: */
27: public function deleteModification(int $modification_id): void {
28: $this->db->query("DELETE FROM `" . DB_PREFIX . "modification` WHERE `modification_id` = '" . (int)$modification_id . "'");
29: }
30:
31: /**
32: * Delete Modifications By Extension Install ID
33: *
34: * @param int $extension_install_id
35: *
36: * @return void
37: */
38: public function deleteModificationsByExtensionInstallId(int $extension_install_id): void {
39: $this->db->query("DELETE FROM `" . DB_PREFIX . "modification` WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
40: }
41:
42: /**
43: * Edit Status
44: *
45: * @param int $modification_id
46: * @param bool $status
47: *
48: * @return void
49: */
50: public function editStatus(int $modification_id, bool $status): void {
51: $this->db->query("UPDATE `" . DB_PREFIX . "modification` SET `status` = '" . (bool)$status . "' WHERE `modification_id` = '" . (int)$modification_id . "'");
52: }
53:
54: /**
55: * Get Modification
56: *
57: * @param int $modification_id
58: *
59: * @return array<string, mixed>
60: */
61: public function getModification(int $modification_id): array {
62: $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "modification` WHERE `modification_id` = '" . (int)$modification_id . "'");
63:
64: return $query->row;
65: }
66:
67: /**
68: * Get Modifications
69: *
70: * @param array<string, mixed> $data
71: *
72: * @return array<int, array<string, mixed>>
73: */
74: public function getModifications(array $data = []): array {
75: $sql = "SELECT * FROM `" . DB_PREFIX . "modification`";
76:
77: $sort_data = [
78: 'name',
79: 'description',
80: 'author',
81: 'version',
82: 'status',
83: 'date_added'
84: ];
85:
86: if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
87: $sql .= " ORDER BY " . $data['sort'];
88: } else {
89: $sql .= " ORDER BY `name`";
90: }
91:
92: if (isset($data['order']) && ($data['order'] == 'DESC')) {
93: $sql .= " DESC";
94: } else {
95: $sql .= " ASC";
96: }
97:
98: if (isset($data['start']) || isset($data['limit'])) {
99: if ($data['start'] < 0) {
100: $data['start'] = 0;
101: }
102:
103: if ($data['limit'] < 1) {
104: $data['limit'] = 20;
105: }
106:
107: $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
108: }
109:
110: $query = $this->db->query($sql);
111:
112: return $query->rows;
113: }
114:
115: /**
116: * Get Total Modifications
117: *
118: * @return int
119: */
120: public function getTotalModifications(): int {
121: $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "modification`");
122:
123: return $query->row['total'];
124: }
125:
126: /**
127: * Get Modification By Code
128: *
129: * @param string $code
130: *
131: * @return array<string, mixed>
132: */
133: public function getModificationByCode(string $code): array {
134: $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "modification` WHERE `code` = '" . $this->db->escape($code) . "'");
135:
136: return $query->row;
137: }
138: }
139: