summaryrefslogtreecommitdiff
path: root/plugins/tasklist/drivers/tasklist_driver.php
blob: f810799660e50a6811ed9369307ec8227c931c80 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php

/**
 * Driver interface for the Tasklist plugin
 *
 * @version @package_version@
 * @author Thomas Bruederli <bruederli@kolabsys.com>
 *
 * Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

 /**
  * Struct of an internal task object how it is passed from/to the driver classes:
  *
  *  $task = array(
  *            'id' => 'Task ID used for editing',  // must be unique for the current user
  *     'parent_id' => 'ID of parent task',  // null if top-level task
  *           'uid' => 'Unique identifier of this task',
  *          'list' => 'Task list identifier to add the task to or where the task is stored',
  *       'changed' => <DateTime>,  // Last modification date/time of the record
  *         'title' => 'Event title/summary',
  *   'description' => 'Event description',
  *          'tags' => array(),      // List of tags for this task
  *          'date' => 'Due date',   // as string of format YYYY-MM-DD or null if no date is set
  *          'time' => 'Due time',   // as string of format hh::ii or null if no due time is set
  *     'startdate' => 'Start date'  // Delay start of the task until that date
  *     'starttime' => 'Start time'  // ...and time
  *    'categories' => 'Task category',
  *       'flagged' => 'Boolean value whether this record is flagged',
  *      'complete' => 'Float value representing the completeness state (range 0..1)',
  *   'sensitivity' => 0|1|2,   // Event sensitivity (0=public, 1=private, 2=confidential)
  *        'alarms' => '-15M:DISPLAY',  // Reminder settings inspired by valarm definition (e.g. display alert 15 minutes before due time)
  *     '_fromlist' => 'List identifier where the task was stored before',
  *  );
  */

/**
 * Driver interface for the Tasklist plugin
 */
abstract class tasklist_driver
{
    // features supported by the backend
    public $alarms = false;
    public $attachments = false;
    public $undelete = false; // task undelete action
    public $sortable = false;
    public $alarm_types = array('DISPLAY');
    public $last_error;

    /**
     * Get a list of available task lists from this source
     */
    abstract function get_lists();

    /**
     * Create a new list assigned to the current user
     *
     * @param array Hash array with list properties
     *        name: List name
     *       color: The color of the list
     *  showalarms: True if alarms are enabled
     * @return mixed ID of the new list on success, False on error
     */
    abstract function create_list($prop);

    /**
     * Update properties of an existing tasklist
     *
     * @param array Hash array with list properties
     *          id: List Identifier
     *        name: List name
     *       color: The color of the list
     *  showalarms: True if alarms are enabled (if supported)
     * @return boolean True on success, Fales on failure
     */
    abstract function edit_list($prop);

    /**
     * Set active/subscribed state of a list
     *
     * @param array Hash array with list properties
     *          id: List Identifier
     *      active: True if list is active, false if not
     * @return boolean True on success, Fales on failure
     */
    abstract function subscribe_list($prop);

    /**
     * Delete the given list with all its contents
     *
     * @param array Hash array with list properties
     *      id: list Identifier
     * @return boolean True on success, Fales on failure
     */
    abstract function remove_list($prop);

    /**
     * Get number of tasks matching the given filter
     *
     * @param array List of lists to count tasks of
     * @return array Hash array with counts grouped by status (all|flagged|completed|today|tomorrow|nodate)
     */
    abstract function count_tasks($lists = null);

    /**
     * Get all taks records matching the given filter
     *
     * @param array Hash array with filter criterias:
     *  - mask:  Bitmask representing the filter selection (check against tasklist::FILTER_MASK_* constants)
     *  - from:  Date range start as string (Y-m-d)
     *  - to:    Date range end as string (Y-m-d)
     *  - search: Search query string
     * @param array List of lists to get tasks from
     * @return array List of tasks records matchin the criteria
     */
    abstract function list_tasks($filter, $lists = null);

    /**
     * Get a list of pending alarms to be displayed to the user
     *
     * @param  integer Current time (unix timestamp)
     * @param  mixed   List of list IDs to show alarms for (either as array or comma-separated string)
     * @return array   A list of alarms, each encoded as hash array with task properties
     *         id: Task identifier
     *        uid: Unique identifier of this task
     *       date: Task due date
     *       time: Task due time
     *      title: Task title/summary
     */
    abstract function pending_alarms($time, $lists = null);

    /**
     * (User) feedback after showing an alarm notification
     * This should mark the alarm as 'shown' or snooze it for the given amount of time
     *
     * @param  string  Task identifier
     * @param  integer Suspend the alarm for this number of seconds
     */
    abstract function dismiss_alarm($id, $snooze = 0);

    /**
     * Return data of a specific task
     *
     * @param mixed  Hash array with task properties or task UID
     * @return array Hash array with task properties or false if not found
     */
    abstract public function get_task($prop);

    /**
     * Get decendents of the given task record
     *
     * @param mixed  Hash array with task properties or task UID
     * @param boolean True if all childrens children should be fetched
     * @return array List of all child task IDs
     */
    abstract public function get_childs($prop, $recursive = false);

    /**
     * Add a single task to the database
     *
     * @param array Hash array with task properties (see header of this file)
     * @return mixed New event ID on success, False on error
     */
    abstract function create_task($prop);

    /**
     * Update an task entry with the given data
     *
     * @param array Hash array with task properties (see header of this file)
     * @return boolean True on success, False on error
     */
    abstract function edit_task($prop);

    /**
     * Move a single task to another list
     *
     * @param array   Hash array with task properties:
     *      id: Task identifier
     *      list: New list identifier to move to
     *      _fromlist: Previous list identifier
     * @return boolean True on success, False on error
     */
    abstract function move_task($prop);

    /**
     * Remove a single task from the database
     *
     * @param array   Hash array with task properties:
     *      id: Task identifier
     * @param boolean Remove record irreversible (mark as deleted otherwise, if supported by the backend)
     * @return boolean True on success, False on error
     */
    abstract function delete_task($prop, $force = true);

    /**
     * Restores a single deleted task (if supported)
     *
     * @param array Hash array with task properties:
     *      id: Task identifier
     * @return boolean True on success, False on error
     */
    public function undelete_task($prop)
    {
        return false;
    }

    /**
     * Get attachment properties
     *
     * @param string $id    Attachment identifier
     * @param array  $task  Hash array with event properties:
     *         id: Task identifier
     *       list: List identifier
     *
     * @return array Hash array with attachment properties:
     *         id: Attachment identifier
     *       name: Attachment name
     *   mimetype: MIME content type of the attachment
     *       size: Attachment size
     */
    public function get_attachment($id, $task) { }

    /**
     * Get attachment body
     *
     * @param string $id    Attachment identifier
     * @param array  $task  Hash array with event properties:
     *         id: Task identifier
     *       list: List identifier
     *
     * @return string Attachment body
     */
    public function get_attachment_body($id, $task) { }

    /**
     * List availabale categories
     * The default implementation reads them from config/user prefs
     */
    public function list_categories()
    {
        $rcmail = rcmail::get_instance();
        return $rcmail->config->get('tasklist_categories', array());
    }

    /**
     * Build the edit/create form for lists.
     * This gives the drivers the opportunity to add more list properties
     *
     * @param array List with form fields to be rendered
     * @return string HTML content of the form
     */
    public function tasklist_edit_form($formfields)
    {
        $html = '';
        foreach ($formfields as $prop => $field) {
            $html .= html::div('form-section',
                html::label($field['id'], $field['label']) .
                $field['value']);
        }

        return $html;
    }

}