1 | <?php |
---|
2 | class Psli_Map { |
---|
3 | /***********************************************************************/ |
---|
4 | /* Members *************************************************************/ |
---|
5 | private $id; // Unique id in table |
---|
6 | private $status; // Status of this map ==> true:open, enable - false:closed, disable |
---|
7 | private $category; // Id of the associated category |
---|
8 | private $title; |
---|
9 | private $lat; |
---|
10 | private $lon; |
---|
11 | private $zoom; |
---|
12 | private $data_changed; // Used to know if data were changed |
---|
13 | private $category_changed; // Used to know if category was changed |
---|
14 | |
---|
15 | /***********************************************************************/ |
---|
16 | /* Methods *************************************************************/ |
---|
17 | function getMaps() { |
---|
18 | $query = ' |
---|
19 | SELECT id |
---|
20 | FROM '.PSLI_MAPS_TABLE.' |
---|
21 | ORDER BY title;'; |
---|
22 | $result = pwg_query($query); |
---|
23 | $maps = array(); |
---|
24 | while ($row = pwg_db_fetch_assoc($result)) |
---|
25 | { |
---|
26 | $maps[] = new Psli_Map($row['id']); |
---|
27 | } |
---|
28 | return $maps; |
---|
29 | } |
---|
30 | |
---|
31 | function assignData ($template, $lat_name, $lon_name, $zoom_name, $title_name, $id_name) { |
---|
32 | $template->assign( |
---|
33 | array( |
---|
34 | $lat_name => $this->lat, |
---|
35 | $lon_name => $this->lon, |
---|
36 | $zoom_name => $this->zoom, |
---|
37 | $title_name => $this->title, |
---|
38 | $id_name => $this->id |
---|
39 | ) |
---|
40 | ); |
---|
41 | } |
---|
42 | |
---|
43 | function generateMapsList($template, $block) { |
---|
44 | $i = 0; |
---|
45 | $query = ' |
---|
46 | SELECT id, title |
---|
47 | FROM '.PSLI_MAPS_TABLE.' |
---|
48 | ORDER BY title;'; |
---|
49 | $result = pwg_query($query); |
---|
50 | $maps = array(); |
---|
51 | $maps_selecteds = array(); |
---|
52 | if (! $this->status) |
---|
53 | $maps_selecteds[0] = l10n('No selected map'); |
---|
54 | while ($row = pwg_db_fetch_assoc($result)) |
---|
55 | { |
---|
56 | $i ++; |
---|
57 | if ($row['id'] == $this->id) |
---|
58 | { |
---|
59 | $maps_selecteds[$row['id']] = $row['title']; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | $maps[$row['id']] = $row['title']; |
---|
64 | } |
---|
65 | } |
---|
66 | $template->assign($block.'_selected', $maps_selecteds); |
---|
67 | $template->assign($block, $maps); |
---|
68 | return $i; |
---|
69 | } |
---|
70 | |
---|
71 | function delete() { |
---|
72 | if ($this->status == true) |
---|
73 | { |
---|
74 | $query = 'DELETE FROM '.PSLI_ENTITIES_MAPS_TABLE.' WHERE id_map = '.$this->id.';'; |
---|
75 | pwg_query($query); |
---|
76 | $query = 'DELETE FROM '.PSLI_MAPS_TABLE.' WHERE id = '.$this->id.';'; |
---|
77 | pwg_query($query); |
---|
78 | $this->status = false; |
---|
79 | return true; |
---|
80 | } |
---|
81 | else |
---|
82 | return false; |
---|
83 | } |
---|
84 | |
---|
85 | function create() { |
---|
86 | if ($this->status == false) |
---|
87 | { |
---|
88 | $query = ' |
---|
89 | INSERT INTO '.PSLI_MAPS_TABLE.' |
---|
90 | (lat, lon, zoom, title) |
---|
91 | VALUES (0, 0, 2, "'.l10n("New Map").'");'; |
---|
92 | pwg_query($query); |
---|
93 | $this->id = pwg_db_insert_id(); |
---|
94 | $this->category = 0; |
---|
95 | $this->lat = 0; |
---|
96 | $this->lon = 0; |
---|
97 | $this->zoom = 2; |
---|
98 | $this->title = l10n("New Map"); |
---|
99 | $this->status = true; |
---|
100 | $this->category_changed = false; |
---|
101 | $this->data_changed = false; |
---|
102 | return true; |
---|
103 | } |
---|
104 | else |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | function open($open) { |
---|
109 | $query = ' |
---|
110 | SELECT id, id_category, lat, lon, zoom, title |
---|
111 | FROM '.PSLI_MAPS_TABLE.' |
---|
112 | WHERE id = '.$open.';'; |
---|
113 | $result = pwg_query($query); |
---|
114 | |
---|
115 | if (pwg_db_num_rows($result) > 0) |
---|
116 | { |
---|
117 | $row = pwg_db_fetch_assoc($result); |
---|
118 | $this->id = $row['id']; |
---|
119 | $this->category = $row['id_category']; |
---|
120 | $this->lat = $row['lat']; |
---|
121 | $this->lon = $row['lon']; |
---|
122 | $this->zoom = $row['zoom']; |
---|
123 | $this->title = $row['title']; |
---|
124 | $this->status = true; |
---|
125 | $this->category_changed = false; |
---|
126 | $this->data_changed = false; |
---|
127 | return true; |
---|
128 | } |
---|
129 | else |
---|
130 | return false; |
---|
131 | } |
---|
132 | |
---|
133 | function save() { |
---|
134 | if (($this->status == true) && ($this->data_changed == true)) |
---|
135 | { |
---|
136 | $query = ' |
---|
137 | UPDATE '.PSLI_MAPS_TABLE.' |
---|
138 | SET lat = '.$this->lat.', |
---|
139 | lon = '.$this->lon.', |
---|
140 | title = "'.addslashes($this->title).'", |
---|
141 | zoom = '.$this->zoom.' |
---|
142 | WHERE id = '.$this->id.';'; |
---|
143 | pwg_query($query); |
---|
144 | $this->data_changed = false; |
---|
145 | } |
---|
146 | if (($this->status == true) && ($this->category_changed == true)) |
---|
147 | { |
---|
148 | $query = ' |
---|
149 | UPDATE '.PSLI_MAPS_TABLE.' |
---|
150 | SET id_category = '.$this->category.' |
---|
151 | WHERE id = '.$this->id.';'; |
---|
152 | pwg_query($query); |
---|
153 | $this->category_changed = false; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | /***********************************************************************/ |
---|
158 | /* Setters ************************************************************/ |
---|
159 | function setCategory($value) { |
---|
160 | if (($this->status == true) && ($value != $this->category)) |
---|
161 | { |
---|
162 | $this->category = $value; |
---|
163 | $this->category_changed = true; |
---|
164 | } |
---|
165 | } |
---|
166 | function setTitle($value) { |
---|
167 | if (($this->status == true) && ($value != $this->title)) |
---|
168 | { |
---|
169 | $this->title = $value; |
---|
170 | $this->data_changed = true; |
---|
171 | } |
---|
172 | } |
---|
173 | function setLatitude($value) { |
---|
174 | if (($this->status == true) && ($value != $this->lat)) |
---|
175 | { |
---|
176 | $this->lat = $value; |
---|
177 | $this->data_changed = true; |
---|
178 | } |
---|
179 | } |
---|
180 | function setLongitude($value) { |
---|
181 | if (($this->status == true) && ($value != $this->lon)) |
---|
182 | { |
---|
183 | $this->lon = $value; |
---|
184 | $this->data_changed = true; |
---|
185 | } |
---|
186 | } |
---|
187 | function setZoom($value) { |
---|
188 | if (($this->status == true) && ($value != $this->zoom)) |
---|
189 | { |
---|
190 | $this->zoom = $value; |
---|
191 | $this->data_changed = true; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | /***********************************************************************/ |
---|
196 | /* Getters ************************************************************/ |
---|
197 | function getCategory() { |
---|
198 | return $this->category; |
---|
199 | } |
---|
200 | function getTitle() { |
---|
201 | return $this->title; |
---|
202 | } |
---|
203 | function getLatitude() { |
---|
204 | return $this->lat; |
---|
205 | } |
---|
206 | function getLongitude() { |
---|
207 | return $this->lon; |
---|
208 | } |
---|
209 | function getZoom() { |
---|
210 | return $this->zoom; |
---|
211 | } |
---|
212 | function getId() { |
---|
213 | return $this->id; |
---|
214 | } |
---|
215 | function isOpened() { |
---|
216 | return $this->status; |
---|
217 | } |
---|
218 | |
---|
219 | /***********************************************************************/ |
---|
220 | /* Constructor *********************************************************/ |
---|
221 | function __construct ($value = 0) { |
---|
222 | |
---|
223 | $this->category = 0; |
---|
224 | $this->lat = 0; |
---|
225 | $this->lon = 0; |
---|
226 | $this->zoom = 2; |
---|
227 | $this->title = l10n("New Map"); |
---|
228 | $this->status = false; |
---|
229 | $this->category_changed = false; |
---|
230 | $this->data_changed = false; |
---|
231 | if ($value != 0) |
---|
232 | $this->open($value); |
---|
233 | } |
---|
234 | } |
---|
235 | ?> |
---|