Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/drivers/resources_driver.php
Show All 20 Lines | |||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
/** | /** | ||||
* Interface definition for a resources directory driver classe | * Interface definition for a resources directory driver classe | ||||
*/ | */ | ||||
abstract class resources_driver | abstract class resources_driver | ||||
{ | { | ||||
protected $cal; | protected $cal; | ||||
/** | /** | ||||
* Default constructor | * Default constructor | ||||
*/ | */ | ||||
function __construct($cal) | function __construct($cal) | ||||
{ | { | ||||
$this->cal = $cal; | $this->cal = $cal; | ||||
} | } | ||||
/** | /** | ||||
* Fetch resource objects to be displayed for booking | * Fetch resource objects to be displayed for booking | ||||
* | * | ||||
* @param string Search query (optional) | * @param string $query Search query (optional) | ||||
* | |||||
* @return array List of resource records available for booking | * @return array List of resource records available for booking | ||||
*/ | */ | ||||
abstract public function load_resources($query = null); | abstract public function load_resources($query = null); | ||||
/** | /** | ||||
* Return properties of a single resource | * Return properties of a single resource | ||||
* | * | ||||
* @param string Unique resource identifier | * @param string $id Unique resource identifier | ||||
* | |||||
* @return array Resource object as hash array | * @return array Resource object as hash array | ||||
*/ | */ | ||||
abstract public function get_resource($id); | abstract public function get_resource($id); | ||||
/** | /** | ||||
* Return properties of a resource owner | * Return properties of a resource owner | ||||
* | * | ||||
* @param string Owner identifier | * @param string $id Owner identifier | ||||
* | |||||
* @return array Resource object as hash array | * @return array Resource object as hash array | ||||
*/ | */ | ||||
public function get_resource_owner($id) | public function get_resource_owner($id) | ||||
{ | { | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Get event data to display a resource's calendar | * Get event data to display a resource's calendar | ||||
* | * | ||||
* The default implementation extracts the resource's email address | * The default implementation extracts the resource's email address | ||||
* and fetches free-busy data using the calendar backend driver. | * and fetches free-busy data using the calendar backend driver. | ||||
* | * | ||||
* @param integer Event's new start (unix timestamp) | * @param string $id Calendar identifier | ||||
* @param integer Event's new end (unix timestamp) | * @param int $start Event's new start (unix timestamp) | ||||
* @param int $end Event's new end (unix timestamp) | |||||
* | |||||
* @return array A list of event objects (see calendar_driver specification) | * @return array A list of event objects (see calendar_driver specification) | ||||
*/ | */ | ||||
public function get_resource_calendar($id, $start, $end) | public function get_resource_calendar($id, $start, $end) | ||||
{ | { | ||||
$events = array(); | $events = []; | ||||
$rec = $this->get_resource($id); | $rec = $this->get_resource($id); | ||||
if ($rec && !empty($rec['email']) && $this->cal->driver) { | |||||
$fbtypemap = array( | if ($rec && !empty($rec['email']) && !empty($this->cal->driver)) { | ||||
$fbtypemap = [ | |||||
calendar::FREEBUSY_BUSY => 'busy', | calendar::FREEBUSY_BUSY => 'busy', | ||||
calendar::FREEBUSY_TENTATIVE => 'tentative', | calendar::FREEBUSY_TENTATIVE => 'tentative', | ||||
calendar::FREEBUSY_OOF => 'outofoffice', | calendar::FREEBUSY_OOF => 'outofoffice', | ||||
); | ]; | ||||
// if the backend has free-busy information | // if the backend has free-busy information | ||||
$fblist = $this->cal->driver->get_freebusy_list($rec['email'], $start, $end); | $fblist = $this->cal->driver->get_freebusy_list($rec['email'], $start, $end); | ||||
if (is_array($fblist)) { | if (is_array($fblist)) { | ||||
foreach ($fblist as $slot) { | foreach ($fblist as $slot) { | ||||
list($from, $to, $type) = $slot; | list($from, $to, $type) = $slot; | ||||
if ($type == calendar::FREEBUSY_FREE || $type == calendar::FREEBUSY_UNKNOWN) { | if ($type == calendar::FREEBUSY_FREE || $type == calendar::FREEBUSY_UNKNOWN) { | ||||
continue; | continue; | ||||
} | } | ||||
if ($from < $end && $to > $start) { | if ($from < $end && $to > $start) { | ||||
$event = array( | $events[] = [ | ||||
'id' => sha1($id . $from . $to), | 'id' => sha1($id . $from . $to), | ||||
'title' => $rec['name'], | 'title' => $rec['name'], | ||||
'start' => new DateTime('@' . $from), | 'start' => new DateTime('@' . $from), | ||||
'end' => new DateTime('@' . $to), | 'end' => new DateTime('@' . $to), | ||||
'status' => $fbtypemap[$type], | 'status' => $fbtypemap[$type], | ||||
'calendar' => '_resource', | 'calendar' => '_resource', | ||||
); | ]; | ||||
$events[] = $event; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $events; | return $events; | ||||
} | } | ||||
} | } |