/**
* Set the location of the specified event _id
*
* @see Kronolith_Geo_Base#setLocation()
* @throws Kronolith_Exception
*/
public function setLocation($event_id, $point)
{
/* First make sure it doesn't already exist */
$sql = 'SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ?';
try {
$count = $this->_db->selectValue($sql, array($event_id));
} catch (Horde_Db_Exception $e) {
throw new Kronolith_Exception($e);
}
/* Do we actually have data? If not, see if we are deleting an
* existing entry. */
if ((empty($point['lat']) || empty($point['lon'])) && $count) {
// Delete the record.
$this->deleteLocation($event_id);
return;
} elseif (empty($point['lat']) || empty($point['lon'])) {
return;
}
if (empty($point['zoom'])) {
$point['zoom'] = 0;
}
/* INSERT or UPDATE */
$params = array($point['lat'], $point['lon'], $point['zoom'], $event_id);
try {
if ($count) {
$sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ?, event_zoom = ? WHERE event_id = ?';
$this->_db->update($sql, $params);
} else {
$sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_zoom, event_id) VALUES(?, ?, ?, ?)';
$this->_db->insert($sql, $params);
}
} catch (Horde_Db_Exception $e) {
throw new Horde_Exception($e);
}
}