1: | <?php
|
2: | namespace Opencart\Admin\Model\Tool;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Notification extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function addNotification(array $data): int {
|
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "notification` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `text` = '" . $this->db->escape((string)$data['text']) . "', `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 editStatus(int $notification_id, bool $status): void {
|
31: | $this->db->query("UPDATE `" . DB_PREFIX . "notification` SET `status` = '" . (bool)$status . "' WHERE `notification_id` = '" . (int)$notification_id . "'");
|
32: | }
|
33: |
|
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: |
|
41: | public function deleteNotification(int $notification_id): void {
|
42: | $this->db->query("DELETE FROM `" . DB_PREFIX . "notification` WHERE `notification_id` = '" . (int)$notification_id . "'");
|
43: | }
|
44: |
|
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: |
|
52: | public function getNotification(int $notification_id): array {
|
53: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "notification` WHERE `notification_id` = '" . (int)$notification_id . "'");
|
54: |
|
55: | return $query->row;
|
56: | }
|
57: |
|
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: |
|
65: | public function getNotifications(array $data = []): array {
|
66: | $sql = "SELECT * FROM `" . DB_PREFIX . "notification`";
|
67: |
|
68: | if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
69: | $sql .= " WHERE `status` = '" . (bool)$data['filter_status'] . "'";
|
70: | }
|
71: |
|
72: | $sql .= " ORDER BY `date_added` DESC";
|
73: |
|
74: | if (isset($data['start']) || isset($data['limit'])) {
|
75: | if ($data['start'] < 0) {
|
76: | $data['start'] = 0;
|
77: | }
|
78: |
|
79: | if ($data['limit'] < 1) {
|
80: | $data['limit'] = 20;
|
81: | }
|
82: |
|
83: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
84: | }
|
85: |
|
86: | $query = $this->db->query($sql);
|
87: |
|
88: | return $query->rows;
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: |
|
98: | public function getTotalNotifications(array $data = []): int {
|
99: | $sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "notification`";
|
100: |
|
101: | if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
102: | $sql .= " WHERE `status` = '" . (bool)$data['filter_status'] . "'";
|
103: | }
|
104: |
|
105: | $query = $this->db->query($sql);
|
106: |
|
107: | return (int)$query->row['total'];
|
108: | }
|
109: | }
|
110: | |