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 ModelLocalisationLocation extends \Divine\Engine\Core\Model |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function addLocation($data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->db->query(" |
28
|
|
|
INSERT INTO location |
29
|
|
|
SET name = '" . $this->db->escape($data['name']) . "', |
30
|
|
|
address = '" . $this->db->escape($data['address']) . "', |
31
|
|
|
geocode = '" . $this->db->escape($data['geocode']) . "', |
32
|
|
|
telephone = '" . $this->db->escape($data['telephone']) . "', |
33
|
|
|
fax = '" . $this->db->escape($data['fax']) . "', |
34
|
|
|
image = '" . $this->db->escape($data['image']) . "', |
35
|
|
|
open = '" . $this->db->escape($data['open']) . "', |
36
|
|
|
comment = '" . $this->db->escape($data['comment']) . "' |
37
|
|
|
"); |
38
|
|
|
|
39
|
|
|
return $this->db->getLastId(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function editLocation($location_id, $data) |
43
|
|
|
{ |
44
|
|
|
$this->db->query(" |
45
|
|
|
UPDATE location |
46
|
|
|
SET name = '" . $this->db->escape($data['name']) . "', |
47
|
|
|
address = '" . $this->db->escape($data['address']) . "', |
48
|
|
|
geocode = '" . $this->db->escape($data['geocode']) . "', |
49
|
|
|
telephone = '" . $this->db->escape($data['telephone']) . "', |
50
|
|
|
fax = '" . $this->db->escape($data['fax']) . "', |
51
|
|
|
image = '" . $this->db->escape($data['image']) . "', |
52
|
|
|
open = '" . $this->db->escape($data['open']) . "', |
53
|
|
|
comment = '" . $this->db->escape($data['comment']) . "' |
54
|
|
|
WHERE location_id = '" . (int)$location_id . "' |
55
|
|
|
"); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function deleteLocation($location_id) |
59
|
|
|
{ |
60
|
|
|
$this->db->query(" |
61
|
|
|
DELETE |
62
|
|
|
FROM location |
63
|
|
|
WHERE location_id = '" . (int)$location_id . "' |
64
|
|
|
"); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getLocation($location_id) |
68
|
|
|
{ |
69
|
|
|
$query = $this->db->query(" |
70
|
|
|
SELECT DISTINCT * |
71
|
|
|
FROM location |
72
|
|
|
WHERE location_id = '" . (int)$location_id . "' |
73
|
|
|
"); |
74
|
|
|
|
75
|
|
|
return $query->row; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getLocations($data = array()) |
79
|
|
|
{ |
80
|
|
|
$sql = " |
|
|
|
|
81
|
|
|
SELECT location_id, |
82
|
|
|
name, |
83
|
|
|
address |
84
|
|
|
FROM location"; |
85
|
|
|
|
86
|
|
|
$sort_data = array( |
87
|
|
|
'name', |
88
|
|
|
'address', |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
92
|
|
|
$sql .= " ORDER BY " . $data['sort']; |
|
|
|
|
93
|
|
|
} else { |
94
|
|
|
$sql .= " ORDER BY name"; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (isset($data['order']) && ($data['order'] == 'DESC')) { |
98
|
|
|
$sql .= " DESC"; |
|
|
|
|
99
|
|
|
} else { |
100
|
|
|
$sql .= " ASC"; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (isset($data['start']) || isset($data['limit'])) { |
104
|
|
|
if ($data['start'] < 0) { |
105
|
|
|
$data['start'] = 0; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($data['limit'] < 1) { |
109
|
|
|
$data['limit'] = 20; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$query = $this->db->query($sql); |
116
|
|
|
|
117
|
|
|
return $query->rows; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getTotalLocations() |
121
|
|
|
{ |
122
|
|
|
$query = $this->db->query(" |
|
|
|
|
123
|
|
|
SELECT COUNT(*) AS total |
124
|
|
|
FROM location |
125
|
|
|
"); |
126
|
|
|
|
127
|
|
|
return $query->row['total']; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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.