1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Divine CMS - Open source CMS for widespread use. |
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
5
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
7
|
|
|
|
8
|
|
|
This file is part of Divine CMS. |
9
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
22
|
|
|
|
23
|
|
|
class ModelLocalisationZone extends \Divine\Engine\Core\Model |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function addZone($data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->db->query(" |
28
|
|
|
INSERT INTO zone |
29
|
|
|
SET status = '" . (int)$data['status'] . "', |
30
|
|
|
name = '" . $this->db->escape($data['name']) . "', |
31
|
|
|
code = '" . $this->db->escape($data['code']) . "', |
32
|
|
|
country_id = '" . (int)$data['country_id'] . "' |
33
|
|
|
"); |
34
|
|
|
|
35
|
|
|
$this->cache->delete('zone'); |
36
|
|
|
|
37
|
|
|
return $this->db->getLastId(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function editZone($zone_id, $data) |
41
|
|
|
{ |
42
|
|
|
$this->db->query(" |
43
|
|
|
UPDATE zone |
44
|
|
|
SET status = '" . (int)$data['status'] . "', |
45
|
|
|
name = '" . $this->db->escape($data['name']) . "', |
46
|
|
|
code = '" . $this->db->escape($data['code']) . "', |
47
|
|
|
country_id = '" . (int)$data['country_id'] . "' |
48
|
|
|
WHERE zone_id = '" . (int)$zone_id . "' |
49
|
|
|
"); |
50
|
|
|
|
51
|
|
|
$this->cache->delete('zone'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function deleteZone($zone_id) |
55
|
|
|
{ |
56
|
|
|
$this->db->query(" |
57
|
|
|
DELETE |
58
|
|
|
FROM zone |
59
|
|
|
WHERE zone_id = '" . (int)$zone_id . "' |
60
|
|
|
"); |
61
|
|
|
|
62
|
|
|
$this->cache->delete('zone'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getZone($zone_id) |
66
|
|
|
{ |
67
|
|
|
$query = $this->db->query(" |
68
|
|
|
SELECT DISTINCT * |
69
|
|
|
FROM zone |
70
|
|
|
WHERE zone_id = '" . (int)$zone_id . "' |
71
|
|
|
"); |
72
|
|
|
|
73
|
|
|
return $query->row; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getZones($data = array()) |
77
|
|
|
{ |
78
|
|
|
$sql = " |
|
|
|
|
79
|
|
|
SELECT *, |
80
|
|
|
z.name, |
81
|
|
|
c.name AS country |
82
|
|
|
FROM zone z |
83
|
|
|
LEFT JOIN country c ON (z.country_id = c.country_id) |
84
|
|
|
"; |
85
|
|
|
|
86
|
|
|
$sort_data = array( |
87
|
|
|
'c.name', |
88
|
|
|
'z.name', |
89
|
|
|
'z.code' |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
93
|
|
|
$sql .= " ORDER BY " . $data['sort']; |
|
|
|
|
94
|
|
|
} else { |
95
|
|
|
$sql .= " ORDER BY c.name"; |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (isset($data['order']) && ($data['order'] == 'DESC')) { |
99
|
|
|
$sql .= " DESC"; |
|
|
|
|
100
|
|
|
} else { |
101
|
|
|
$sql .= " ASC"; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if (isset($data['start']) || isset($data['limit'])) { |
105
|
|
|
if ($data['start'] < 0) { |
106
|
|
|
$data['start'] = 0; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if ($data['limit'] < 1) { |
110
|
|
|
$data['limit'] = 20; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$query = $this->db->query($sql); |
117
|
|
|
|
118
|
|
|
return $query->rows; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getZonesByCountryId($country_id) |
122
|
|
|
{ |
123
|
|
|
$zone_data = $this->cache->get('zone.' . (int)$country_id); |
124
|
|
|
|
125
|
|
|
if (!$zone_data) { |
126
|
|
|
$query = $this->db->query(" |
127
|
|
|
SELECT * |
128
|
|
|
FROM zone |
129
|
|
|
WHERE country_id = '" . (int)$country_id . "' |
130
|
|
|
AND status = '1' |
131
|
|
|
ORDER BY name |
132
|
|
|
"); |
133
|
|
|
|
134
|
|
|
$zone_data = $query->rows; |
135
|
|
|
|
136
|
|
|
$this->cache->set( |
137
|
|
|
'zone.' . (int)$country_id, |
138
|
|
|
$zone_data |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $zone_data; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function getTotalZones() |
146
|
|
|
{ |
147
|
|
|
$query = $this->db->query(" |
|
|
|
|
148
|
|
|
SELECT COUNT(*) AS total |
149
|
|
|
FROM zone |
150
|
|
|
"); |
151
|
|
|
|
152
|
|
|
return $query->row['total']; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function getTotalZonesByCountryId($country_id) |
156
|
|
|
{ |
157
|
|
|
$query = $this->db->query(" |
158
|
|
|
SELECT COUNT(*) AS total |
159
|
|
|
FROM zone |
160
|
|
|
WHERE country_id = '" . (int)$country_id . "' |
161
|
|
|
"); |
162
|
|
|
|
163
|
|
|
return $query->row['total']; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.