1: | <?php
|
2: | namespace Opencart\Admin\Model\Localisation;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Location extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function addLocation(array $data): int {
|
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', address = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "'");
|
18: |
|
19: | return $this->db->getLastId();
|
20: | }
|
21: |
|
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: |
|
30: | public function editLocation(int $location_id, array $data): void {
|
31: | $this->db->query("UPDATE `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address` = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "' WHERE `location_id` = '" . (int)$location_id . "'");
|
32: | }
|
33: |
|
34: | |
35: | |
36: | |
37: | |
38: | |
39: | |
40: |
|
41: | public function deleteLocation(int $location_id): void {
|
42: | $this->db->query("DELETE FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
43: | }
|
44: |
|
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: |
|
52: | public function getLocation(int $location_id): array {
|
53: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
54: |
|
55: | return $query->row;
|
56: | }
|
57: |
|
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: |
|
65: | public function getLocations(array $data = []): array {
|
66: | $sql = "SELECT `location_id`, `name`, `address` FROM `" . DB_PREFIX . "location`";
|
67: |
|
68: | $sort_data = [
|
69: | 'name',
|
70: | 'address',
|
71: | ];
|
72: |
|
73: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
74: | $sql .= " ORDER BY " . $data['sort'];
|
75: | } else {
|
76: | $sql .= " ORDER BY `name`";
|
77: | }
|
78: |
|
79: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
80: | $sql .= " DESC";
|
81: | } else {
|
82: | $sql .= " ASC";
|
83: | }
|
84: |
|
85: | if (isset($data['start']) || isset($data['limit'])) {
|
86: | if ($data['start'] < 0) {
|
87: | $data['start'] = 0;
|
88: | }
|
89: |
|
90: | if ($data['limit'] < 1) {
|
91: | $data['limit'] = 20;
|
92: | }
|
93: |
|
94: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
95: | }
|
96: |
|
97: | $query = $this->db->query($sql);
|
98: |
|
99: | return $query->rows;
|
100: | }
|
101: |
|
102: | |
103: | |
104: | |
105: | |
106: |
|
107: | public function getTotalLocations(): int {
|
108: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "location`");
|
109: |
|
110: | return (int)$query->row['total'];
|
111: | }
|
112: | }
|
113: | |