Skip to content

Commit

Permalink
Add classes for interfacing to events/calendar store.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 18, 2014
1 parent 5c77a0f commit 26faf7f
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 2 deletions.
87 changes: 87 additions & 0 deletions framework/OpenXchange/lib/Horde/OpenXchange/Events.php
@@ -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 framework/OpenXchange/lib/Horde/OpenXchange/EventsAndTasks.php
@@ -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'];
}
}
8 changes: 6 additions & 2 deletions framework/OpenXchange/package.xml
Expand Up @@ -10,7 +10,7 @@
<email>jan@horde.org</email>
<active>yes</active>
</lead>
<date>2014-03-11</date>
<date>2014-03-18</date>
<version>
<release>1.0.0alpha1</release>
<api>1.0.0alpha1</api>
Expand All @@ -30,6 +30,8 @@
<dir name="OpenXchange">
<file name="Base.php" role="php" />
<file name="Contacts.php" role="php" />
<file name="Events.php" role="php" />
<file name="EventsAndTasks.php" role="php" />
<file name="Exception.php" role="php" />
</dir> <!-- /lib/Horde/OpenXchange -->
</dir> <!-- /lib/Horde -->
Expand Down Expand Up @@ -78,6 +80,8 @@
<filelist>
<install as="Horde/OpenXchange/Base.php" name="lib/Horde/OpenXchange/Base.php" />
<install as="Horde/OpenXchange/Contacts.php" name="lib/Horde/OpenXchange/Contacts.php" />
<install as="Horde/OpenXchange/Events.php" name="lib/Horde/OpenXchange/Events.php" />
<install as="Horde/OpenXchange/EventsAndTasks.php" name="lib/Horde/OpenXchange/EventsAndTasks.php" />
<install as="Horde/OpenXchange/Exception.php" name="lib/Horde/OpenXchange/Exception.php" />
</filelist>
</phprelease>
Expand All @@ -91,7 +95,7 @@
<release>alpha</release>
<api>alpha</api>
</stability>
<date>2014-03-11</date>
<date>2014-03-18</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* Initial release.
Expand Down

0 comments on commit 26faf7f

Please sign in to comment.