Overview

Packages

  • Kronolith
  • None

Classes

  • Kronolith
  • Kronolith_Ajax_Application
  • Kronolith_Ajax_Imple_ContactAutoCompleter
  • Kronolith_Ajax_Imple_Embed
  • Kronolith_Ajax_Imple_TagActions
  • Kronolith_Ajax_Imple_TagAutoCompleter
  • Kronolith_Api
  • Kronolith_Calendar
  • Kronolith_Calendar_External
  • Kronolith_Calendar_External_Tasks
  • Kronolith_Calendar_Holiday
  • Kronolith_Calendar_Internal
  • Kronolith_Calendar_Remote
  • Kronolith_Calendar_Resource
  • Kronolith_Calendars_Base
  • Kronolith_Calendars_Default
  • Kronolith_Calendars_Kolab
  • Kronolith_Day
  • Kronolith_Driver
  • Kronolith_Driver_Holidays
  • Kronolith_Driver_Horde
  • Kronolith_Driver_Ical
  • Kronolith_Driver_Kolab
  • Kronolith_Driver_Mock
  • Kronolith_Driver_Resource
  • Kronolith_Driver_Sql
  • Kronolith_Event
  • Kronolith_Event_Holidays
  • Kronolith_Event_Horde
  • Kronolith_Event_Ical
  • Kronolith_Event_Kolab
  • Kronolith_Event_Resource
  • Kronolith_Event_Sql
  • Kronolith_Exception
  • Kronolith_Factory_Calendars
  • Kronolith_Factory_Geo
  • Kronolith_Form_CreateCalendar
  • Kronolith_Form_CreateResource
  • Kronolith_Form_CreateResourceGroup
  • Kronolith_Form_DeleteCalendar
  • Kronolith_Form_DeleteResource
  • Kronolith_Form_DeleteResourceGroup
  • Kronolith_Form_EditCalendar
  • Kronolith_Form_EditRemoteCalendar
  • Kronolith_Form_EditResource
  • Kronolith_Form_EditResourceGroup
  • Kronolith_Form_SubscribeRemoteCalendar
  • Kronolith_Form_UnsubscribeRemoteCalendar
  • Kronolith_FreeBusy
  • Kronolith_FreeBusy_View
  • Kronolith_FreeBusy_View_Day
  • Kronolith_FreeBusy_View_Month
  • Kronolith_FreeBusy_View_Week
  • Kronolith_FreeBusy_View_Workweek
  • Kronolith_Geo_Base
  • Kronolith_Geo_Mysql
  • Kronolith_Geo_Sql
  • Kronolith_LoginTasks_SystemTask_Upgrade
  • Kronolith_LoginTasks_Task_PurgeEvents
  • Kronolith_Notification_Listener_AjaxStatus
  • Kronolith_Resource
  • Kronolith_Resource_Base
  • Kronolith_Resource_Group
  • Kronolith_Resource_Single
  • Kronolith_Storage
  • Kronolith_Storage_Kolab
  • Kronolith_Storage_Sql
  • Kronolith_Tagger
  • Kronolith_Test
  • Kronolith_View_Day
  • Kronolith_View_DeleteEvent
  • Kronolith_View_EditEvent
  • Kronolith_View_Event
  • Kronolith_View_ExportEvent
  • Kronolith_View_Month
  • Kronolith_View_Week
  • Kronolith_View_WorkWeek
  • Kronolith_View_Year
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * General SQL implementation for storing/searching geo location data for
  4:  * events.
  5:  *
  6:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author   Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @category Horde
 13:  * @package  Kronolith
 14:  */
 15: class Kronolith_Geo_Sql extends Kronolith_Geo_Base
 16: {
 17:     /**
 18:      * @var Horde_Db_Adapter
 19:      */
 20:     protected $_db;
 21: 
 22:     /**
 23:      * Set the location of the specified event _id
 24:      *
 25:      * @see Kronolith_Geo_Base#setLocation()
 26:      * @throws Kronolith_Exception
 27:      */
 28:     public function setLocation($event_id, $point)
 29:     {
 30:         /* First make sure it doesn't already exist */
 31:         $sql = 'SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ?';
 32:         try {
 33:             $count = $this->_db->selectValue($sql, array($event_id));
 34:         } catch (Horde_Db_Exception $e) {
 35:             throw new Kronolith_Exception($e);
 36:         }
 37: 
 38:         /* Do we actually have data? If not, see if we are deleting an
 39:          * existing entry. */
 40:         if ((empty($point['lat']) || empty($point['lon'])) && $count) {
 41:             // Delete the record.
 42:             $this->deleteLocation($event_id);
 43:             return;
 44:         } elseif (empty($point['lat']) || empty($point['lon'])) {
 45:             return;
 46:         }
 47: 
 48:         if (empty($point['zoom'])) {
 49:             $point['zoom'] = 0;
 50:         }
 51: 
 52:         /* INSERT or UPDATE */
 53:         $params = array($point['lat'], $point['lon'], $point['zoom'], $event_id);
 54:         if ($count) {
 55:             $sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ?, event_zoom = ? WHERE event_id = ?';
 56:         } else {
 57:             $sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_zoom, event_id) VALUES(?, ?, ?, ?)';
 58:         }
 59:         try {
 60:             $this->_db->execute($sql, $params);
 61:         } catch (Horde_Db_Exception $e) {
 62:             throw new Horde_Exception($e);
 63:         }
 64:     }
 65: 
 66:     /**
 67:      * Get the location of the provided event_id.
 68:      *
 69:      * @see Kronolith_Geo_Base#getLocation()
 70:      * @throws Kronolith_Exception
 71:      */
 72:     public function getLocation($event_id)
 73:     {
 74:         $sql = 'SELECT event_lat as lat, event_lon as lon, event_zoom as zoom FROM kronolith_events_geo WHERE event_id = ?';
 75:         try {
 76:             return $this->_db->selectOne($sql, array($event_id));
 77:         } catch (Horde_Db_Exception $e) {
 78:             throw new Kronolith_Exception($e);
 79:         }
 80:     }
 81: 
 82:     /**
 83:      * Deletes an entry from storage
 84:      *
 85:      * @see Kronolith_Geo_Base#removeLocation()
 86:      *
 87:      * @param string $event_id
 88:      *
 89:      * @throws Kronolith_Exception
 90:      */
 91:     public function deleteLocation($event_id)
 92:     {
 93:         $sql = 'DELETE FROM kronolith_events_geo WHERE event_id = ?';
 94:         try {
 95:             $this->_db->delete($sql, array($event_id));
 96:         } catch (Horde_Db_Exception $e) {
 97:             throw new Horde_Exception($e);
 98:         }
 99:     }
100: 
101:     /**
102:      * Search for events "close to" a given point.
103:      *
104:      * TODO: If all we really use the geodata for is distance, it really doesn't
105:      *       make sense to use the GIS extensions since the distance calculations
106:      *       are done with Euclidian geometry ONLY ... and therefore will give
107:      *       incorrect results when done on a geocentric coordinate system.
108:      *       They might be useful if we eventually want to do searches on
109:      *       MBRs
110:      *
111:      * @see kronolith/lib/Driver/Kronolith_Driver_Geo#search($criteria)
112:      * @throws Kronolith_Exception
113:      */
114:     public function search($criteria)
115:     {
116:         throw new Horde_Exception(_("Searching requires a GIS enabled database."));
117:     }
118: }
119: 
API documentation generated by ApiGen