true:open, enable - false:closed, disable /* Data ****************************************************************/ protected $id; // Unique id in table protected $lat; protected $lon; protected $title; protected $idaction; protected $zoommin; protected $zoommax; protected $action; // 1: Zoom - 2: Category - 3: Picture protected $type; // 1: pin - 2: zone - 3:picture /* Maps ****************************************************************/ protected $maps; // Array of associated maps /***********************************************************************/ /* Methods *************************************************************/ /* getEntities Return all entities in database order by type (zone, pin, picture) and by title */ function getEntities() { $query = ' SELECT id FROM '.PSLI_ENTITIES_TABLE.' ORDER BY action, title;'; $result = pwg_query($query); $entities = array(); while ($row = pwg_db_fetch_assoc($result)) { $entities[] = new Psli_Entity($row['id']); } return $entities; } /* assignData Assign all data of this entity to template $template with data name $lat_name, $lon_name, $zoommin_name, $zoommax_name, $title_name, $actionid_name, $id_name */ function assignData ($template, $lat_name, $lon_name, $zoommin_name, $zoommax_name, $title_name, $actionid_name, $id_name) { $template->assign( array( $lat_name => $this->lat, $lon_name => $this->lon, $zoommin_name => $this->zoommin, $zoommax_name => $this->zoommax, $title_name => $this->title, $actionid_name => $this->idaction, $id_name => $this->id ) ); } /* isOpened Return true if entity is open */ function isOpened() { return $this->status; } /* generateEntityList($template, $block, $entitytype) Create an heml select option identified by $block in template $ template for each entity filtered by $entitytype in "pin", "zone", "picture", "all". Current Entity is selected. */ protected function generateList($template, $block, $entitytype) { $entities = array(); $entities_selecteds = array(); if (! $this->status) $entities_selecteds[0] = l10n('No selected entity'); switch ($entitytype) { case "pin": $query = ' SELECT id, title FROM '.PSLI_ENTITIES_TABLE.' WHERE type = 1 ORDER BY title;'; break; case "zone": $query = ' SELECT id, title FROM '.PSLI_ENTITIES_TABLE.' WHERE type = 2 ORDER BY title;'; break; case "picture": $query = ' SELECT id, title FROM '.PSLI_ENTITIES_TABLE.' WHERE type = 3 ORDER BY title;'; break; case "all": $query = ' SELECT id, title FROM '.PSLI_ENTITIES_TABLE.' ORDER BY title;'; break; } $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if ($row['id'] == $this->id) $entities_selecteds[$row['id']] = $row['title']; else $entities[$row['id']] = $row['title']; } $template->assign($block.'_selected', $entities_selecteds); $template->assign($block, $entities); } /* delete Delete entity from the database. */ function delete() { global $debug; $debug .= "PSLIDEBUG : delete"; if ($this->status == true) { $debug .= "PSLIDEBUG : delete"; $query = 'DELETE FROM '.PSLI_ENTITIES_MAPS_TABLE.' WHERE id_entity = '.$this->id.';'; pwg_query($query); $query = 'DELETE FROM '.PSLI_ENTITIES_TABLE.' WHERE id = '.$this->id.';'; pwg_query($query); $this->status = false; return true; } else return false; } /* save Save entity data to the database */ function save() { if (($this->status == true) && ($this->data_changed == true)) { $query = ' UPDATE '.PSLI_ENTITIES_TABLE.' SET lat = '.$this->lat.', lon = '.$this->lon.', zoommin = '.$this->zoommin.', zoommax = '.$this->zoommax.', action = '.$this->action.', id_action = '.$this->idaction.', title = "'.addslashes($this->title).'" WHERE id = '.$this->id.';'; pwg_query($query); $q = 'DELETE FROM '.PSLI_ENTITIES_MAPS_TABLE.' WHERE id_entity = '.$this->id.';'; pwg_query($q); foreach ($this->maps as $map) { $q = ' INSERT INTO '.PSLI_ENTITIES_MAPS_TABLE.' (id_entity, id_map) VALUES ('.$this->id.', '.$map.');'; pwg_query($q); } $this->data_changed = false; } } /* open Open entity identified by id $open */ function open ($open) { $query = ' SELECT id, lat, lon, zoomMin, zoomMax, action, id_action, title, type FROM '.PSLI_ENTITIES_TABLE.' WHERE id = '.$open.';'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $row = pwg_db_fetch_assoc($result); $this->id = $row['id']; $this->lat = $row['lat']; $this->lon = $row['lon']; $this->zoommin = $row['zoomMin']; $this->zoommax = $row['zoomMax']; $this->title = $row['title']; $this->action = $row['action']; $this->idaction = $row['id_action']; $this->type = $row['type']; $this->status = true; $this->data_changed = false; $query = ' SELECT id_map FROM '.PSLI_ENTITIES_MAPS_TABLE.' WHERE id_entity = '.$this->id.' ORDER BY id_map;' ; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { while ($row = pwg_db_fetch_assoc($result)) array_push($this->maps,$row['id_map']); } return true; } else return false; } /* create Create an entity with default value */ function create($typeentity) { if ($this->status == false) { switch ($typeentity) { case "pin": $query = ' INSERT INTO '.PSLI_ENTITIES_TABLE.' (lat, lon, title, id_action, action, zoomMin, zoomMax, type) VALUES (0, 0, "'.l10n("New Pin").'", 2, 1, 1, 20, 1);'; $this->type = 1; $this->action = 2; $this->title = l10n("New Pin"); break; case "zone": $query = ' INSERT INTO '.PSLI_ENTITIES_TABLE.' (lat, lon, title, id_action, action, zoomMin, zoomMax, type) VALUES (0, 0, "'.l10n("New Zone").'", 1, 1, 1, 20, 2);'; $this->type = 2; $this->action = 1; $this->title = l10n("New Zone"); break; case "picture": $query = ' INSERT INTO '.PSLI_ENTITIES_TABLE.' (lat, lon, title, id_action, action, zoomMin, zoomMax, type) VALUES (0, 0, "'.l10n("New Picture").'", 3, 1, 1, 20, 3);'; $this->type = 3; $this->action = 3; $this->title = l10n("New Picture"); break; } pwg_query($query); $this->id = pwg_db_insert_id(); $this->lat = 0; $this->lon = 0; $this->idaction = 1; $this->zoommin = 1; $this->zoommax = 20; $this->maps = Array(); $this->status = true; $this->data_changed = false; return true; } else return false; } /***********************************************************************/ /* Constructor *********************************************************/ function __construct ($openid = 0) { $this->id = 0; $this->lat = 0; $this->lon = 0; $this->zoom = 3; $this->title = l10n("New Entity"); $this->status = false; $this->maps = Array(); $this->data_changed = false; if ($openid != 0) $this->open($openid); } /***********************************************************************/ /* Getters ************************************************************/ function getType() { return $this->type; } function getActionId() { return $this->idaction; } function getAction() { return $this->action; } function getLatitude() { return $this->lat; } function getLongitude() { return $this->lon; } function getZoomMax() { return $this->zoommax; } function getZoomMin() { return $this->zoommin; } function getId() { return $this->id; } function getTitle() { return $this->title; } /***********************************************************************/ /* Setters ************************************************************/ function setAction($type, $value) { if (($this->status == true) && ($type != $this->action)) { $this->action = $type; $this->data_changed = true; } if (($this->status == true) && ($value != $this->idaction)) { $this->idaction = $value; $this->data_changed = true; } } function setZoomMax($value) { if (($this->status == true) && ($value != $this->zoommax)) { $this->zoommax = $value; $this->data_changed = true; } } function setZoomMin($value) { if (($this->status == true) && ($value != $this->zoommin)) { $this->zoommin = $value; $this->data_changed = true; } } function setLongitude($value) { if (($this->status == true) && ($value != $this->lon)) { $this->lon = $value; $this->data_changed = true; } } function setLatitude($value) { if (($this->status == true) && ($value != $this->lat)) { $this->lat = $value; $this->data_changed = true; } } function setTitle($value) { if (($this->status == true) && ($value != $this->title)) { $this->title = $value; $this->data_changed = true; } } /***********************************************************************/ /* Methods for associated maps *****************************************/ /* isMapAssociated Return true if map identified by $map is associated with this entity */ function isMapAssociated($map) { return in_array($map, $this->maps); } /* clearMaps Remove all associated maps */ function clearMaps () { $this->maps = Array(); $this->data_changed = true; } /* addMap Add an associated map identified by $map */ function addMap($map) { array_push($this->maps,$map); $this->data_changed = true; } } ?>