3
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 * Resources directory interface definition
|
|
5 *
|
|
6 * @author Thomas Bruederli <bruederli@kolabsys.com>
|
|
7 *
|
|
8 * Copyright (C) 2014, Kolab Systems AG <contact@kolabsys.com>
|
|
9 *
|
|
10 * This program is free software: you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU Affero General Public License as
|
|
12 * published by the Free Software Foundation, either version 3 of the
|
|
13 * License, or (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU Affero General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU Affero General Public License
|
|
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22 */
|
|
23
|
|
24
|
|
25 /**
|
|
26 * Interface definition for a resources directory driver classe
|
|
27 */
|
|
28 abstract class resources_driver
|
|
29 {
|
|
30 protected$cal;
|
|
31
|
|
32 /**
|
|
33 * Default constructor
|
|
34 */
|
|
35 function __construct($cal)
|
|
36 {
|
|
37 $this->cal = $cal;
|
|
38 }
|
|
39
|
|
40 /**
|
|
41 * Fetch resource objects to be displayed for booking
|
|
42 *
|
|
43 * @param string Search query (optional)
|
|
44 * @return array List of resource records available for booking
|
|
45 */
|
|
46 abstract public function load_resources($query = null);
|
|
47
|
|
48 /**
|
|
49 * Return properties of a single resource
|
|
50 *
|
|
51 * @param string Unique resource identifier
|
|
52 * @return array Resource object as hash array
|
|
53 */
|
|
54 abstract public function get_resource($id);
|
|
55
|
|
56 /**
|
|
57 * Return properties of a resource owner
|
|
58 *
|
|
59 * @param string Owner identifier
|
|
60 * @return array Resource object as hash array
|
|
61 */
|
|
62 public function get_resource_owner($id)
|
|
63 {
|
|
64 return null;
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * Get event data to display a resource's calendar
|
|
69 *
|
|
70 * The default implementation extracts the resource's email address
|
|
71 * and fetches free-busy data using the calendar backend driver.
|
|
72 *
|
|
73 * @param integer Event's new start (unix timestamp)
|
|
74 * @param integer Event's new end (unix timestamp)
|
|
75 * @return array A list of event objects (see calendar_driver specification)
|
|
76 */
|
|
77 public function get_resource_calendar($id, $start, $end)
|
|
78 {
|
|
79 $events = array();
|
|
80 $rec = $this->get_resource($id);
|
|
81 if ($rec && !empty($rec['email']) && $this->cal->driver) {
|
|
82 $fbtypemap = array(
|
|
83 calendar::FREEBUSY_BUSY => 'busy',
|
|
84 calendar::FREEBUSY_TENTATIVE => 'tentative',
|
|
85 calendar::FREEBUSY_OOF => 'outofoffice',
|
|
86 );
|
|
87
|
|
88 // if the backend has free-busy information
|
|
89 $fblist = $this->cal->driver->get_freebusy_list($rec['email'], $start, $end);
|
|
90 if (is_array($fblist)) {
|
|
91 foreach ($fblist as $slot) {
|
|
92 list($from, $to, $type) = $slot;
|
|
93 if ($type == calendar::FREEBUSY_FREE || $type == calendar::FREEBUSY_UNKNOWN) {
|
|
94 continue;
|
|
95 }
|
|
96 if ($from < $end && $to > $start) {
|
|
97 $event = array(
|
|
98 'id' => sha1($id . $from . $to),
|
|
99 'title' => $rec['name'],
|
|
100 'start' => new DateTime('@' . $from),
|
|
101 'end' => new DateTime('@' . $to),
|
|
102 'status' => $fbtypemap[$type],
|
|
103 'calendar' => '_resource',
|
|
104 );
|
|
105 $events[] = $event;
|
|
106 }
|
|
107 }
|
|
108 }
|
|
109 }
|
|
110
|
|
111 return $events;
|
|
112 }
|
|
113
|
|
114 }
|