1: | <?php
2: | namespace Opencart\Admin\Model\Customer;
3: | /**
4: | * Class GDPR
5: | *
6: | * @package Opencart\Admin\Model\Customer
7: | */
8: | class Gdpr extends \Opencart\System\Engine\Model {
9: | /**
10: | * Edit Status
11: | *
12: | * @param int $gdpr_id
13: | * @param int $status
14: | *
15: | * @return void
16: | */
17: | public function editStatus(int $gdpr_id, int $status): void {
18: | $this->db->query("UPDATE `" . DB_PREFIX . "gdpr` SET `status` = '" . (int)$status . "' WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
19: | }
20: |
21: | /**
22: | * Delete Gdpr
23: | *
24: | * @param int $gdpr_id
25: | *
26: | * @return void
27: | */
28: | public function deleteGdpr(int $gdpr_id): void {
29: | $this->db->query("DELETE FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
30: | }
31: |
32: | /**
33: | * Delete Gdpr(s) By Store ID
34: | *
35: | * @param int $store_id
36: | *
37: | * @return void
38: | */
39: | public function deleteGdprsByStoreId(int $store_id): void {
40: | $this->db->query("DELETE FROM `" . DB_PREFIX . "gdpr` WHERE `store_id` = '" . (int)$store_id . "'");
41: | }
42: |
43: | /**
44: | * Get Gdpr(s)
45: | *
46: | * @param array<string, mixed> $data
47: | *
48: | * @return array<int, array<string, mixed>>
49: | */
50: | public function getGdprs(array $data = []): array {
51: | $sql = "SELECT * FROM `" . DB_PREFIX . "gdpr`";
52: |
53: | $implode = [];
54: |
55: | if (!empty($data['filter_email'])) {
56: | $implode[] = "LCASE(`email`) LIKE '" . $this->db->escape(oc_strtolower($data['filter_email'])) . "'";
57: | }
58: |
59: | if (!empty($data['filter_action'])) {
60: | $implode[] = "`action` = '" . $this->db->escape($data['filter_action']) . "'";
61: | }
62: |
63: | if (isset($data['filter_status']) && $data['filter_status'] !== '') {
64: | $implode[] = "`status` = '" . (bool)$data['filter_status'] . "'";
65: | }
66: |
67: | if (!empty($data['filter_date_from'])) {
68: | $implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
69: | }
70: |
71: | if (!empty($data['filter_date_to'])) {
72: | $implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
73: | }
74: |
75: | if ($implode) {
76: | $sql .= " WHERE " . implode(" AND ", $implode);
77: | }
78: |
79: | $sql .= " ORDER BY `date_added` DESC";
80: |
81: | if (isset($data['start']) || isset($data['limit'])) {
82: | if ($data['start'] < 0) {
83: | $data['start'] = 0;
84: | }
85: |
86: | if ($data['limit'] < 1) {
87: | $data['limit'] = 20;
88: | }
89: |
90: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
91: | }
92: |
93: | $query = $this->db->query($sql);
94: |
95: | return $query->rows;
96: | }
97: |
98: | /**
99: | * Get Gdpr
100: | *
101: | * @param int $gdpr_id
102: | *
103: | * @return array<string, mixed>
104: | */
105: | public function getGdpr(int $gdpr_id): array {
106: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
107: |
108: | return $query->row;
109: | }
110: |
111: | /**
112: | * Get Total Gdpr(s)
113: | *
114: | * @param array<string, mixed> $data
115: | *
116: | * @return int
117: | */
118: | public function getTotalGdprs(array $data = []): int {
119: | $sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "gdpr`";
120: |
121: | $implode = [];
122: |
123: | if (!empty($data['filter_email'])) {
124: | $implode[] = "LCASE(`email`) LIKE '" . $this->db->escape(oc_strtolower($data['filter_email'])) . "'";
125: | }
126: |
127: | if (!empty($data['filter_action'])) {
128: | $implode[] = "`action` = '" . $this->db->escape($data['filter_action']) . "'";
129: | }
130: |
131: | if (isset($data['filter_status']) && $data['filter_status'] !== '') {
132: | $implode[] = "`status` = '" . (bool)$data['filter_status'] . "'";
133: | }
134: |
135: | if (!empty($data['filter_date_from'])) {
136: | $implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
137: | }
138: |
139: | if (!empty($data['filter_date_to'])) {
140: | $implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
141: | }
142: |
143: | if ($implode) {
144: | $sql .= " WHERE " . implode(" AND ", $implode);
145: | }
146: |
147: | $query = $this->db->query($sql);
148: |
149: | return (int)$query->row['total'];
150: | }
151: |
152: | /**
153: | * Get Expires
154: | *
155: | * @return array<int, array<string, mixed>>
156: | */
157: | public function getExpires(): array {
158: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `status` = '2' AND DATE(`date_added`) <= DATE('" . $this->db->escape(date('Y-m-d', strtotime('+' . (int)$this->config->get('config_gdpr_limit') . ' days'))) . "') ORDER BY `date_added` DESC");
159: |
160: | return $query->rows;
161: | }
162: | }
163: |

OpenCart API API documentation generated by ApiGen dev-master