Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsMap.php
Vai alla documentazione di questo file.
1 <?php
43 class gmapsMap extends propertyObject {
44 
45  public static $_tbl_map = "gmaps_map";
46  public static $_tbl_map_point = "gmaps_map_point";
47  public static $_tbl_map_polyline = "gmaps_map_polyline";
48  public static $_tbl_map_polygon = "gmaps_map_polygon";
49 
50  private $_controller;
51 
56 
61 
66 
75  function __construct($id, $instance) {
76 
77  $this->_controller = $instance;
78 
79  $this->_tbl_data = self::$_tbl_map;
80  parent::__construct($id);
81  $this->_points = array();
82  $this->_points_id = array();
83  $this->_polylines = array();
84  $this->_polylines_id = array();
85  $this->_polygons = array();
86  $this->_polygons_id = array();
87  $query = "SELECT point_id FROM ".self::$_tbl_map_point." WHERE map_id='".$this->id."'";
88  $a = $this->_db->selectquery($query);
89  if(count($a)) {
90  foreach($a as $b) {
91  $this->_points[] = new gmapsPoint($b['point_id'], $this->_controller);
92  $this->_points_id[] = $b['point_id'];
93  }
94  }
95  $query = "SELECT polyline_id FROM ".self::$_tbl_map_polyline." WHERE map_id='".$this->id."'";
96  $a = $this->_db->selectquery($query);
97  if(count($a)) {
98  foreach($a as $b) {
99  $this->_polylines[] = new gmapsPolyline($b['polyline_id'], $this->_controller);
100  $this->_polylines_id[] = $b['polyline_id'];
101  }
102  }
103  $query = "SELECT polygon_id FROM ".self::$_tbl_map_polygon." WHERE map_id='".$this->id."'";
104  $a = $this->_db->selectquery($query);
105  if(count($a)) {
106  foreach($a as $b) {
107  $this->_polygons[] = new gmapsPolygon($b['polygon_id'], $this->_controller);
108  $this->_polygons_id[] = $b['polygon_id'];
109  }
110  }
111  }
112 
120  public function setInstance($value) {
121 
122  if($this->_p['instance']!=$value && !in_array('instance', $this->_chgP)) $this->_chgP[] = 'instance';
123  $this->_p['instance'] = $value;
124  return true;
125 
126  }
127 
136  public static function deleteInstance($instance) {
137 
138  $db = db::instance();
139  $query = "DELETE FROM ".self::$_tbl_map." WHERE instance='$instance'";
140  $res = $db->actionquery($query);
141 
142  return $res;
143 
144  }
145 
152  public function points_id() {
153 
154  return $this->_points_id;
155 
156  }
157 
164  public function points() {
165 
166  return $this->_points;
167 
168  }
169 
176  public function polylines_id() {
177 
178  return $this->_polylines_id;
179 
180  }
181 
188  public function polylines() {
189 
190  return $this->_polylines;
191 
192  }
193 
200  public function polygons_id() {
201 
202  return $this->_polygons_id;
203 
204  }
205 
212  public function polygons() {
213 
214  return $this->_polygons;
215 
216  }
217 
218 
226  public function addPoints($point_ids) {
227 
228  if(!is_array($point_ids)) $points = array($point_ids);
229 
230  $values = array();
231  foreach($point_ids as $pid) {
232  $values[] = "('".$this->id."', '".$pid."')";
233  }
234 
235  $db = db::instance();
236  $query = "INSERT INTO ".self::$_tbl_map_point." (map_id, point_id) VALUES ".implode(',', $values).";";
237 
238  return $db->actionquery($query);
239  }
240 
248  public function addPolylines($polyline_ids) {
249 
250  if(!is_array($polyline_ids)) $points = array($polyline_ids);
251 
252  $values = array();
253  foreach($polyline_ids as $pid) {
254  $values[] = "('".$this->id."', '".$pid."')";
255  }
256 
257  $db = db::instance();
258  $query = "INSERT INTO ".self::$_tbl_map_polyline." (map_id, polyline_id) VALUES ".implode(',', $values).";";
259 
260  return $db->actionquery($query);
261  }
262 
270  public function addPolygons($polygon_ids) {
271 
272  if(!is_array($polygon_ids)) $points = array($polygon_ids);
273 
274  $values = array();
275  foreach($polygon_ids as $pid) {
276  $values[] = "('".$this->id."', '".$pid."')";
277  }
278 
279  $db = db::instance();
280  $query = "INSERT INTO ".self::$_tbl_map_polygon." (map_id, polygon_id) VALUES ".implode(',', $values).";";
281 
282  return $db->actionquery($query);
283  }
284 
285 
293  public function removePoints($point_ids) {
294 
295  if(!is_array($point_ids)) $points = array($point_ids);
296 
297  $values = array();
298  foreach($point_ids as $pid) {
299  $values[] = "point_id='".$pid."'";
300  }
301 
302  $db = db::instance();
303  $query = "DELETE FROM ".self::$_tbl_map_point." WHERE map_id='".$this->id."' AND (".implode(" OR ", $values).")";
304 
305  return $db->actionquery($query);
306  }
307 
315  public function removePolylines($polyline_ids) {
316 
317  if(!is_array($polyline_ids)) $points = array($polyline_ids);
318 
319  $values = array();
320  foreach($polyline_ids as $pid) {
321  $values[] = "polyline_id='".$pid."'";
322  }
323 
324  $db = db::instance();
325  $query = "DELETE FROM ".self::$_tbl_map_polyline." WHERE map_id='".$this->id."' AND (".implode(" OR ", $values).")";
326 
327  return $db->actionquery($query);
328  }
329 
337  public function removePolygons($polygon_ids) {
338 
339  if(!is_array($polygon_ids)) $points = array($polygon_ids);
340 
341  $values = array();
342  foreach($polygon_ids as $pid) {
343  $values[] = "polygon_id='".$pid."'";
344  }
345 
346  $db = db::instance();
347  $query = "DELETE FROM ".self::$_tbl_map_polygon." WHERE map_id='".$this->id."' AND (".implode(" OR ", $values).")";
348 
349  return $db->actionquery($query);
350  }
351 
352 
365  public static function get($instance, $opts=null) {
366 
367  $where = "instance='".$instance."'".((isset($opts['where']) && $opts['where']) ? " AND ".$opts['where'] : '');
368  $order = isset($opts['order']) ? $opts['order'] : 'name';
369  $limit = isset($opts['limit']) ? "LIMIT ".$opts['limit'] : '';
370 
371  $res = array();
372 
373  $db = db::instance();
374  $query = "SELECT id FROM ".self::$_tbl_map." WHERE $where ORDER BY $order $limit";
375  $a = $db->selectquery($query);
376  foreach($a as $b) {
377  $res[] = $b['id'];
378  }
379 
380  return $res;
381 
382  }
383 
391  public function form($redirect) {
392 
393  if(isset($_POST['submit'])) {
394  $gform = new Form('form_map', 'post', false, array('verifyToken'=>true));
395  $gform->save('dataform');
396  $req_error = $gform->arequired();
397  if(!$req_error) {
398  $this->name = cleanVar($_POST, 'name', 'string', '');
399  $this->description = cleanVarEditor($_POST, 'description', '');
400  $this->width = cleanVar($_POST, 'width', 'string', '');
401  $this->height = cleanVar($_POST, 'height', 'string', '');
402  $this->updateDbData();
403  header("Location: ".$redirect);
404  exit();
405  }
406  else {
407  exit(error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']));
408  }
409  }
410 
411  if($this->id) {
412  $title = _("Modifica mappa");
413  $submit = _("modifica");
414  }
415  else {
416  $title = _("Nuova mappa");
417  $submit= _("inserisci");
418  }
419  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
420 
421  $gform = new Form('form_map', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
422  $gform->load('dataform');
423  $required = "name,width,height";
424  $buffer = $gform->form('', false, $required, array('generateToken'=>true));
425  $buffer .= $gform->hidden('id', $this->id);
426 
427  $buffer .= $gform->cinput('name', 'text', $gform->retvar('name', htmlInput($this->name)), _("Nome"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'name'));
428  $buffer .= $gform->fcktextarea('description', $gform->retvar('description', htmlInputEditor($this->description)), _("Descrizione"), array('fck_toolbar'=>"Default", 'trnsl'=>true, 'field'=>'description'));
429  $buffer .= $gform->cinput('width', 'text', $gform->retvar('width', htmlInput($this->width)), array(_("Larghezza"), _("in px o percentuale<br />es: 500px, 98%")), array('required'=>true, 'maxlength'=>32, 'size'=>6));
430  $buffer .= $gform->cinput('height', 'text', $gform->retvar('height', htmlInput($this->height)), array(_("Altezza"), _("in px o percentuale<br />es: 500px, 98%")), array('required'=>true, 'maxlength'=>32, 'size'=>6));
431  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
432 
433  $buffer .= $gform->cform();
434 
435  $htmlsection->content = $buffer;
436 
437  return $htmlsection->render();
438 
439  }
440 
448  public function delete() {
449 
450  $db = db::instance();
451 
452  // delete point associations
453  $query = "DELETE FROM ".self::$_tbl_map_point." WHERE map_id='".$this->id."'";
454  $res = $db->actionquery($query);
455 
456  // delete polyline associations
457  $query = "DELETE FROM ".self::$_tbl_map_polyline." WHERE map_id='".$this->id."'";
458  $res = $db->actionquery($query);
459 
460  return $this->deleteDbData();
461 
462  }
463 
464 }
465 
466 ?>