Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add classes for interfacing to events/calendar store.
- Loading branch information
Showing
3 changed files
with
221 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package OpenXchange | ||
*/ | ||
|
||
/** | ||
* Horde_OpenXchange_Events is the interface class for the events storage | ||
* of an Open-Xchange server. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package OpenXchange | ||
*/ | ||
class Horde_OpenXchange_Events extends Horde_OpenXchange_EventsAndTasks | ||
{ | ||
/** | ||
* The folder category. | ||
* | ||
* @var string | ||
*/ | ||
protected $_folderType = 'calendar'; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $params List of optional parameters: | ||
* - client: (Horde_Http_Client) An HTTP client. | ||
* - endpoint: (string) The URI of the OX API | ||
* endpoint. | ||
* - user: (string) Authentication user. | ||
* - password: (string) Authentication password. | ||
*/ | ||
public function __construct(array $params = array()) | ||
{ | ||
parent::__construct($params); | ||
$this->_columns += array( | ||
206 => 'recur_id', | ||
207 => 'recur_position', | ||
210 => 'recur_change_exceptions', | ||
211 => 'recur_delete_exceptions', | ||
400 => 'location', | ||
401 => 'allday', | ||
402 => 'status', | ||
408 => 'timezone', | ||
); | ||
} | ||
|
||
/** | ||
* Returns a list events. | ||
* | ||
* @param integer $folder A folder ID. If empty, returns events of all | ||
* visible calendars. | ||
* @param Horde_Date $start Start date, defaults to epoch. | ||
* @param Horde_Date $end End date, defaults to maximum date possible. | ||
* | ||
* @return array List of event hashes. | ||
* @throws Horde_OpenXchange_Exception. | ||
*/ | ||
public function listEvents($folder = null, $start = null, $end = null) | ||
{ | ||
return $this->_listObjects($folder, $start, $end); | ||
} | ||
|
||
/** | ||
* Returns an event. | ||
* | ||
* @param integer $folder A folder ID. | ||
* @param integer $id An event ID. | ||
* | ||
* @return array The event hash. | ||
* @throws Horde_OpenXchange_Exception. | ||
*/ | ||
public function getEvent($folder, $id) | ||
{ | ||
return $this->_getObject($folder, $id); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
framework/OpenXchange/lib/Horde/OpenXchange/EventsAndTasks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
/** | ||
* Copyright 2014 Horde LLC (http://www.horde.org/) | ||
* | ||
* See the enclosed file COPYING for license information (LGPL). If you | ||
* did not receive this file, see http://www.horde.org/licenses/lgpl21. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package OpenXchange | ||
*/ | ||
|
||
/** | ||
* Horde_OpenXchange_EventsAndTasks is the base class for the events and tasks | ||
* storage of an Open-Xchange server. | ||
* | ||
* @author Jan Schneider <jan@horde.org> | ||
* @category Horde | ||
* @copyright 2014 Horde LLC | ||
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 | ||
* @package OpenXchange | ||
*/ | ||
abstract class Horde_OpenXchange_EventsAndTasks extends Horde_OpenXchange_Base | ||
{ | ||
/** | ||
* Column IDs mapped to column names. | ||
* | ||
* @var array | ||
*/ | ||
protected $_columns = array( | ||
1 => 'id', | ||
100 => 'categories', | ||
101 => 'private', | ||
200 => 'title', | ||
201 => 'start', | ||
202 => 'end', | ||
203 => 'description', | ||
204 => 'alarm', | ||
209 => 'recur_type', | ||
212 => 'recur_days', | ||
213 => 'recur_day_in_month', | ||
214 => 'recur_month', | ||
215 => 'recur_interval', | ||
216 => 'recur_end', | ||
220 => 'attendees', | ||
222 => 'recur_count', | ||
223 => 'uid', | ||
224 => 'organizer', | ||
225 => 'sequence', | ||
226 => 'confirmations', | ||
); | ||
|
||
/** | ||
* Returns a list of events or tasks. | ||
* | ||
* @param integer $folder A folder ID. If empty, returns objects of all | ||
* visible resources. | ||
* @param Horde_Date $start Start date, defaults to epoch. | ||
* @param Horde_Date $end End date, defaults to maximum date possible. | ||
* | ||
* @return array List of object hashes. | ||
* @throws Horde_OpenXchange_Exception. | ||
*/ | ||
protected function _listObjects($folder = null, $start = null, $end = null) | ||
{ | ||
$this->_login(); | ||
|
||
$data = array( | ||
'session' => $this->_session, | ||
'columns' => implode(',', array_keys($this->_columns)), | ||
'start' => $start ? $start->timestamp() * 1000 : 0, | ||
'end' => $end ? $end->timestamp() * 1000 : PHP_INT_MAX, | ||
// Doesn't work for some reason. | ||
'recurrence_master' => true, | ||
); | ||
if ($folder) { | ||
$data['folder'] = $folder; | ||
} | ||
|
||
$response = $this->_request( | ||
'GET', | ||
$this->_folderType, | ||
array('action' => 'all'), | ||
$data | ||
); | ||
|
||
$events = array(); | ||
foreach ($response['data'] as $event) { | ||
$map = array(); | ||
foreach (array_values($this->_columns) as $key => $column) { | ||
$map[$column] = $event[$key]; | ||
} | ||
$events[] = $map; | ||
} | ||
|
||
return $events; | ||
} | ||
|
||
/** | ||
* Returns an event or task. | ||
* | ||
* @param integer $folder A folder ID. | ||
* @param integer $id An object ID. | ||
* | ||
* @return array The object hash. | ||
* @throws Horde_OpenXchange_Exception. | ||
*/ | ||
protected function _getObject($folder, $id) | ||
{ | ||
$this->_login(); | ||
|
||
$data = array( | ||
'session' => $this->_session, | ||
'id' => $id, | ||
'folder' => $folder, | ||
); | ||
|
||
$response = $this->_request( | ||
'GET', | ||
$this->_folderType, | ||
array('action' => 'get'), | ||
$data | ||
); | ||
|
||
return $response['data']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters