1: | <?php
2: | namespace Opencart\Admin\Model\Cms;
3: | /**
4: | * Class Country
5: | *
6: | * @package Opencart\Admin\Model\Cms
7: | */
8: | class Antispam extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Antispam
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return int
15: | */
16: | public function addAntispam(array $data = []): int {
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "'");
18: |
19: | return $this->db->getLastId();
20: | }
21: |
22: | /**
23: | * Edit Antispam
24: | *
25: | * @param int $antispam_id
26: | * @param array<string, mixed> $data
27: | *
28: | * @return void
29: | */
30: | public function editAntispam(int $antispam_id, array $data = []): void {
31: | $this->db->query("UPDATE `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "' WHERE `antispam_id` = '" . (int)$antispam_id . "'");
32: | }
33: |
34: | /**
35: | * Delete Antispam
36: | *
37: | * @param int $antispam_id
38: | *
39: | * @return void
40: | */
41: | public function deleteAntispam(int $antispam_id): void {
42: | $this->db->query("DELETE FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
43: | }
44: |
45: | /**
46: | * Get Antispam
47: | *
48: | * @param int $antispam_id
49: | *
50: | * @return array<string, mixed>
51: | */
52: | public function getAntispam(int $antispam_id): array {
53: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
54: |
55: | return $query->row;
56: | }
57: |
58: | /**
59: | * Get Antispam(s)
60: | *
61: | * @param array<string, mixed> $data
62: | *
63: | * @return array<int, array<string, mixed>>
64: | */
65: | public function getAntispams(array $data = []): array {
66: | $sql = "SELECT * FROM `" . DB_PREFIX . "antispam`";
67: |
68: | $implode = [];
69: |
70: | if (!empty($data['filter_keyword'])) {
71: | $implode[] = "LCASE(`keyword`) LIKE '" . $this->db->escape(oc_strtolower($data['filter_keyword'])) . "'";
72: | }
73: |
74: | if ($implode) {
75: | $sql .= " WHERE " . implode(" AND ", $implode);
76: | }
77: |
78: | $sort_data = ['keyword'];
79: |
80: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
81: | $sql .= " ORDER BY " . $data['sort'];
82: | } else {
83: | $sql .= " ORDER BY `keyword`";
84: | }
85: |
86: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
87: | $sql .= " DESC";
88: | } else {
89: | $sql .= " ASC";
90: | }
91: |
92: | if (isset($data['start']) || isset($data['limit'])) {
93: | if ($data['start'] < 0) {
94: | $data['start'] = 0;
95: | }
96: |
97: | if ($data['limit'] < 1) {
98: | $data['limit'] = 20;
99: | }
100: |
101: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
102: | }
103: |
104: | $query = $this->db->query($sql);
105: |
106: | return $query->rows;
107: | }
108: |
109: | /**
110: | * Get Total Antispam(s)
111: | *
112: | * @param array<string, mixed> $data
113: | *
114: | * @return int
115: | */
116: | public function getTotalAntispams(array $data = []): int {
117: | $sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "antispam`";
118: |
119: | $implode = [];
120: |
121: | if (!empty($data['filter_keyword'])) {
122: | $implode[] = "LCASE(`keyword`) LIKE '" . $this->db->escape(oc_strtolower($data['filter_keyword'])) . "'";
123: | }
124: |
125: | if ($implode) {
126: | $sql .= " WHERE " . implode(" AND ", $implode);
127: | }
128: |
129: | $query = $this->db->query($sql);
130: |
131: | return (int)$query->row['total'];
132: | }
133: | }
134: |

OpenCart API API documentation generated by ApiGen dev-master