docs/api/source-admin.model.tool.notification.html
| 1: | <?php |
| 2: | namespace Opencart\Admin\Model\Tool; |
| 3: | /** |
| 4: | * Class Notification |
| 5: | * |
| 6: | * @package Opencart\Admin\Model\Tool |
| 7: | */ |
| 8: | class Notification extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Add Notification |
| 11: | * |
| 12: | * @param array<string, mixed> $data |
| 13: | * |
| 14: | * @return int |
| 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: | * Edit Status |
| 24: | * |
| 25: | * @param int $notification_id |
| 26: | * @param bool $status |
| 27: | * |
| 28: | * @return void |
| 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: | * Delete Notification |
| 36: | * |
| 37: | * @param int $notification_id |
| 38: | * |
| 39: | * @return void |
| 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: | * Get Notification |
| 47: | * |
| 48: | * @param int $notification_id |
| 49: | * |
| 50: | * @return array<string, mixed> |
| 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: | * Get Notifications |
| 60: | * |
| 61: | * @param array<string, mixed> $data |
| 62: | * |
| 63: | * @return array<int, array<string, mixed>> |
| 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: | * Get Total Notifications |
| 93: | * |
| 94: | * @param array<string, mixed> $data |
| 95: | * |
| 96: | * @return int |
| 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: | |
OpenCart API API documentation generated by ApiGen dev-master