File: EventsAndTasks.php

package info (click to toggle)
php-horde-openxchange 1.0.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 96 kB
  • sloc: php: 486; xml: 134; makefile: 2
file content (127 lines) | stat: -rw-r--r-- 3,493 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
 * Copyright 2014-2017 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-2017 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',
        20 => 'folder_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',
        221 => 'users',
        222 => 'recur_count',
        223 => 'uid',
    );

    /**
     * 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'];
    }
}