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:  * Kronolith_Storage:: defines an API for storing free/busy information.
  4:  *
  5:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
  6:  * @author  Michael J Rubinsky <mrubinsk@horde.org>
  7:  * @package Kronolith
  8:  */
  9: class Kronolith_Storage_Sql extends Kronolith_Storage
 10: {
 11:     /**
 12:      * Handle for the current database connection, used for reading.
 13:      *
 14:      * @var Horde_Db_Adapter
 15:      */
 16:     protected $_db;
 17: 
 18:     /**
 19:      * Hash containing connection parameters.
 20:      *
 21:      * @var array
 22:      */
 23:     protected $_params = array();
 24: 
 25:     /**
 26:      * Constructs a new Kronolith_Storage SQL instance.
 27:      *
 28:      * @param string $user   The user the fb info belongs to.
 29:      * @param array $params  A hash containing connection parameters.
 30:      *
 31:      * @return Kronolith_Storage_Sql
 32:      */
 33:     public function __construct($user, array $params = array())
 34:     {
 35:         $this->_user = $user;
 36:         if (empty($params['db'])) {
 37:             throw new InvalidArgumentException('Missing required db parameter');
 38:         }
 39: 
 40:         $this->_db = $params['db'];
 41:         $this->_params = $params;
 42:         $this->_params['table'] = isset($params['table']) ? $params['table'] : 'kronolith_storage';
 43:     }
 44: 
 45:     /**
 46:      * Search for a user's free/busy information.
 47:      *
 48:      * @param string  $email        The email address to lookup
 49:      * @param boolean $private_only (optional) Only return free/busy
 50:      *                              information owned by this used.
 51:      *
 52:      * @return Horde_Icalendar_Vfreebusy
 53:      * @throws Kronolith_Exception
 54:      */
 55:     public function search($email, $private_only = false)
 56:     {
 57:         /* Build the SQL query. */
 58:         $query = sprintf('SELECT vfb_serialized FROM %s WHERE vfb_email = ? AND (vfb_owner = ?',
 59:                          $this->_params['table']);
 60:         $values = array($email, $this->_user);
 61: 
 62:         if ($private_only) {
 63:             $query .= ')';
 64:         } else {
 65:             $query .= " OR vfb_owner = '')";
 66:         }
 67: 
 68:         /* Execute the query. */
 69:         try {
 70:             $result = $this->_db->selectValue($query, $values);
 71:             if (empty($result)) {
 72:                 throw new Horde_Exception_NotFound();
 73:             }
 74:             return Horde_Serialize::unserialize($result, Horde_Serialize::BASIC);
 75:         } catch (Horde_Db_Exception $e) {
 76:             throw new Kronolith_Exception($e);
 77:         }
 78:     }
 79: 
 80:     /**
 81:      * Store the freebusy information for a given email address.
 82:      *
 83:      * @param string                     $email        The email address to store fb info for.
 84:      * @param Horde_Icalendar_Vfreebusy  $vfb          TODO
 85:      * @param boolean                    $private_only (optional) TODO
 86:      *
 87:      * @throws Kronolith_Exception
 88:      */
 89:     public function store($email, $vfb, $public = false)
 90:     {
 91:         /* Build the SQL query. */
 92:         $query = sprintf('INSERT INTO %s (vfb_owner, vfb_email, vfb_serialized) VALUES (?, ?, ?)',
 93:                          $this->_params['table']);
 94:         $values = array($public ? '' : $this->_user, $email, Horde_Serialize::serialize($vfb, Horde_Serialize::BASIC));
 95: 
 96:         /* Execute the query. */
 97:         try {
 98:             $result = $this->_db->insert($query, $values);
 99:         } catch (Horde_Db_Exception $e) {
100:             throw new Kronolith_Exception($e);
101:         }
102:     }
103: 
104: }
105: 
API documentation generated by ApiGen