Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/drivers/kolab/kolab_invitation_calendar.php
Show All 17 Lines | |||||
* GNU Affero General Public License for more details. | * GNU Affero General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU Affero General Public License | * 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/>. | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
class kolab_invitation_calendar | class kolab_invitation_calendar | ||||
{ | { | ||||
public $id = '__invitation__'; | public $id = '__invitation__'; | ||||
public $ready = true; | public $ready = true; | ||||
public $alarms = false; | public $alarms = false; | ||||
public $rights = 'lrsv'; | public $rights = 'lrsv'; | ||||
public $editable = false; | public $editable = false; | ||||
public $attachments = false; | public $attachments = false; | ||||
public $subscriptions = false; | public $subscriptions = false; | ||||
public $partstats = array('unknown'); | public $partstats = ['unknown']; | ||||
public $categories = array(); | public $categories = []; | ||||
public $name = 'Invitations'; | public $name = 'Invitations'; | ||||
/** | /** | ||||
* Default constructor | * Default constructor | ||||
*/ | */ | ||||
public function __construct($id, $calendar) | public function __construct($id, $calendar) | ||||
{ | { | ||||
$this->cal = $calendar; | $this->cal = $calendar; | ||||
$this->id = $id; | $this->id = $id; | ||||
switch ($this->id) { | switch ($this->id) { | ||||
case kolab_driver::INVITATIONS_CALENDAR_PENDING: | case kolab_driver::INVITATIONS_CALENDAR_PENDING: | ||||
$this->partstats = array('NEEDS-ACTION'); | $this->partstats = ['NEEDS-ACTION']; | ||||
$this->name = $this->cal->gettext('invitationspending'); | $this->name = $this->cal->gettext('invitationspending'); | ||||
if (!empty($_REQUEST['_quickview'])) | |||||
if (!empty($_REQUEST['_quickview'])) { | |||||
$this->partstats[] = 'TENTATIVE'; | $this->partstats[] = 'TENTATIVE'; | ||||
} | |||||
break; | break; | ||||
case kolab_driver::INVITATIONS_CALENDAR_DECLINED: | case kolab_driver::INVITATIONS_CALENDAR_DECLINED: | ||||
$this->partstats = array('DECLINED'); | $this->partstats = ['DECLINED']; | ||||
$this->name = $this->cal->gettext('invitationsdeclined'); | $this->name = $this->cal->gettext('invitationsdeclined'); | ||||
break; | break; | ||||
} | } | ||||
// user-specific alarms settings win | // user-specific alarms settings win | ||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array()); | $prefs = $this->cal->rc->config->get('kolab_calendars', []); | ||||
if (isset($prefs[$this->id]['showalarms'])) | if (isset($prefs[$this->id]['showalarms'])) { | ||||
$this->alarms = $prefs[$this->id]['showalarms']; | $this->alarms = $prefs[$this->id]['showalarms']; | ||||
} | } | ||||
} | |||||
/** | /** | ||||
* Getter for a nice and human readable name for this calendar | * Getter for a nice and human readable name for this calendar | ||||
* | * | ||||
* @return string Name of this calendar | * @return string Name of this calendar | ||||
*/ | */ | ||||
public function get_name() | public function get_name() | ||||
{ | { | ||||
return $this->name; | return $this->name; | ||||
} | } | ||||
/** | /** | ||||
* Getter for the IMAP folder owner | * Getter for the IMAP folder owner | ||||
* | * | ||||
* @return string Name of the folder owner | * @return string Name of the folder owner | ||||
*/ | */ | ||||
public function get_owner() | public function get_owner() | ||||
{ | { | ||||
return $this->cal->rc->get_user_name(); | return $this->cal->rc->get_user_name(); | ||||
} | } | ||||
/** | /** | ||||
* | * | ||||
*/ | */ | ||||
public function get_title() | public function get_title() | ||||
{ | { | ||||
return $this->get_name(); | return $this->get_name(); | ||||
} | } | ||||
/** | /** | ||||
* Getter for the name of the namespace to which the IMAP folder belongs | * Getter for the name of the namespace to which the IMAP folder belongs | ||||
* | * | ||||
* @return string Name of the namespace (personal, other, shared) | * @return string Name of the namespace (personal, other, shared) | ||||
*/ | */ | ||||
public function get_namespace() | public function get_namespace() | ||||
{ | { | ||||
return 'x-special'; | return 'x-special'; | ||||
} | } | ||||
/** | /** | ||||
* Getter for the top-end calendar folder name (not the entire path) | * Getter for the top-end calendar folder name (not the entire path) | ||||
* | * | ||||
* @return string Name of this calendar | * @return string Name of this calendar | ||||
*/ | */ | ||||
public function get_foldername() | public function get_foldername() | ||||
{ | { | ||||
return $this->get_name(); | return $this->get_name(); | ||||
} | } | ||||
/** | /** | ||||
* Getter for the Cyrus mailbox identifier corresponding to this folder | * Getter for the Cyrus mailbox identifier corresponding to this folder | ||||
* | * | ||||
* @return string Mailbox ID | * @return string Mailbox ID | ||||
*/ | */ | ||||
public function get_mailbox_id() | public function get_mailbox_id() | ||||
{ | { | ||||
// this is a virtual collection and has no concrete mailbox ID | // this is a virtual collection and has no concrete mailbox ID | ||||
return null; | return null; | ||||
} | } | ||||
/** | /** | ||||
* Return color to display this calendar | * Return color to display this calendar | ||||
*/ | */ | ||||
public function get_color() | public function get_color() | ||||
{ | { | ||||
// calendar color is stored in local user prefs | // calendar color is stored in local user prefs | ||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array()); | $prefs = $this->cal->rc->config->get('kolab_calendars', []); | ||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color'])) | if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color'])) { | ||||
return $prefs[$this->id]['color']; | return $prefs[$this->id]['color']; | ||||
} | |||||
return 'ffffff'; | return 'ffffff'; | ||||
} | } | ||||
/** | /** | ||||
* Compose an URL for CalDAV access to this calendar (if configured) | * Compose an URL for CalDAV access to this calendar (if configured) | ||||
*/ | */ | ||||
public function get_caldav_url() | public function get_caldav_url() | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Check activation status of this folder | * Check activation status of this folder | ||||
* | * | ||||
* @return boolean True if enabled, false if not | * @return bool True if enabled, false if not | ||||
*/ | */ | ||||
public function is_active() | public function is_active() | ||||
{ | { | ||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array()); // read local prefs | $prefs = $this->cal->rc->config->get('kolab_calendars', []); // read local prefs | ||||
return (bool)$prefs[$this->id]['active']; | return !empty($prefs[$this->id]['active']); | ||||
} | } | ||||
/** | /** | ||||
* Update properties of this calendar folder | * Update properties of this calendar folder | ||||
* | * | ||||
* @see calendar_driver::edit_calendar() | * @see calendar_driver::edit_calendar() | ||||
*/ | */ | ||||
public function update(&$prop) | public function update(&$prop) | ||||
{ | { | ||||
// don't change anything. | // don't change anything. | ||||
// let kolab_driver save props in local prefs | // let kolab_driver save props in local prefs | ||||
return $prop['id']; | return $prop['id']; | ||||
} | } | ||||
/** | /** | ||||
* Getter for a single event object | * Getter for a single event object | ||||
*/ | */ | ||||
public function get_event($id) | public function get_event($id) | ||||
{ | { | ||||
// redirect call to kolab_driver::get_event() | // redirect call to kolab_driver::get_event() | ||||
$event = $this->cal->driver->get_event($id, calendar_driver::FILTER_WRITEABLE); | $event = $this->cal->driver->get_event($id, calendar_driver::FILTER_WRITEABLE); | ||||
if (is_array($event)) { | if (is_array($event)) { | ||||
$event = $this->_mod_event($event, $event['calendar']); | $event = $this->_mod_event($event, $event['calendar']); | ||||
} | } | ||||
return $event; | return $event; | ||||
} | } | ||||
/** | /** | ||||
* Create instances of a recurring event | * Create instances of a recurring event | ||||
* | * | ||||
* @see kolab_calendar::get_recurring_events() | * @see kolab_calendar::get_recurring_events() | ||||
*/ | */ | ||||
public function get_recurring_events($event, $start, $end = null, $event_id = null, $limit = null) | public function get_recurring_events($event, $start, $end = null, $event_id = null, $limit = null) | ||||
{ | { | ||||
// forward call to the actual storage folder | // forward call to the actual storage folder | ||||
if ($event['_folder_id']) { | if (!empty($event['_folder_id'])) { | ||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']); | $cal = $this->cal->driver->get_calendar($event['_folder_id']); | ||||
if ($cal && $cal->ready) { | if ($cal && $cal->ready) { | ||||
return $cal->get_recurring_events($event, $start, $end, $event_id, $limit); | return $cal->get_recurring_events($event, $start, $end, $event_id, $limit); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Get attachment body | * Get attachment body | ||||
* | * | ||||
* @see calendar_driver::get_attachment_body() | * @see calendar_driver::get_attachment_body() | ||||
*/ | */ | ||||
public function get_attachment_body($id, $event) | public function get_attachment_body($id, $event) | ||||
{ | { | ||||
// find the actual folder this event resides in | // find the actual folder this event resides in | ||||
if (!empty($event['_folder_id'])) { | if (!empty($event['_folder_id'])) { | ||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']); | $cal = $this->cal->driver->get_calendar($event['_folder_id']); | ||||
} | } | ||||
else { | else { | ||||
$cal = null; | $cal = null; | ||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | ||||
$cal = $this->_get_calendar($foldername); | $cal = $this->_get_calendar($foldername); | ||||
if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) { | if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($cal && $cal->storage) { | if ($cal && $cal->storage) { | ||||
return $cal->get_attachment_body($id, $event); | return $cal->get_attachment_body($id, $event); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* @param integer Event's new start (unix timestamp) | * @param int Event's new start (unix timestamp) | ||||
* @param integer Event's new end (unix timestamp) | * @param int Event's new end (unix timestamp) | ||||
* @param string Search query (optional) | * @param string Search query (optional) | ||||
* @param boolean Include virtual events (optional) | * @param bool Include virtual events (optional) | ||||
* @param array Additional parameters to query storage | * @param array Additional parameters to query storage | ||||
* | * | ||||
* @return array A list of event records | * @return array A list of event records | ||||
*/ | */ | ||||
public function list_events($start, $end, $search = null, $virtual = 1, $query = array()) | public function list_events($start, $end, $search = null, $virtual = 1, $query = []) | ||||
{ | { | ||||
// get email addresses of the current user | // get email addresses of the current user | ||||
$user_emails = $this->cal->get_user_emails(); | $user_emails = $this->cal->get_user_emails(); | ||||
$subquery = array(); | $subquery = []; | ||||
foreach ($user_emails as $email) { | foreach ($user_emails as $email) { | ||||
foreach ($this->partstats as $partstat) { | foreach ($this->partstats as $partstat) { | ||||
$subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)); | $subquery[] = ['tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)]; | ||||
} | } | ||||
} | } | ||||
$events = []; | |||||
// aggregate events from all calendar folders | // aggregate events from all calendar folders | ||||
$events = array(); | |||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | ||||
$cal = $this->_get_calendar($foldername); | $cal = $this->_get_calendar($foldername); | ||||
if (!$cal || $cal->get_namespace() == 'other') | if (!$cal || $cal->get_namespace() == 'other') { | ||||
continue; | continue; | ||||
} | |||||
foreach ($cal->list_events($start, $end, $search, 1, $query, array(array($subquery, 'OR'))) as $event) { | foreach ($cal->list_events($start, $end, $search, 1, $query, [[$subquery, 'OR']]) as $event) { | ||||
$match = false; | $match = false; | ||||
// post-filter events to match out partstats | // post-filter events to match out partstats | ||||
if (is_array($event['attendees'])) { | if (!empty($event['attendees'])) { | ||||
foreach ($event['attendees'] as $attendee) { | foreach ($event['attendees'] as $attendee) { | ||||
if (in_array($attendee['email'], $user_emails) && in_array($attendee['status'], $this->partstats)) { | if ( | ||||
in_array($attendee['email'], $user_emails) | |||||
&& in_array($attendee['status'], $this->partstats) | |||||
) { | |||||
$match = true; | $match = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($match) { | if ($match) { | ||||
$events[$event['id'] ?: $event['uid']] = $this->_mod_event($event, $cal->id); | $uid = !empty($event['id']) ? $event['id'] : $event['uid']; | ||||
$events[$uid] = $this->_mod_event($event, $cal->id); | |||||
} | } | ||||
} | } | ||||
// merge list of event categories (really?) | // merge list of event categories (really?) | ||||
$this->categories += $cal->categories; | $this->categories += $cal->categories; | ||||
} | } | ||||
return $events; | return $events; | ||||
} | } | ||||
/** | /** | ||||
* Get number of events in the given calendar | * Get number of events in the given calendar | ||||
* | * | ||||
* @param integer Date range start (unix timestamp) | * @param int Date range start (unix timestamp) | ||||
* @param integer Date range end (unix timestamp) | * @param int Date range end (unix timestamp) | ||||
* @param array Additional query to filter events | * @param array Additional query to filter events | ||||
* | * | ||||
* @return integer Count | * @return int Count | ||||
*/ | */ | ||||
public function count_events($start, $end = null, $filter = null) | public function count_events($start, $end = null, $filter = null) | ||||
{ | { | ||||
// get email addresses of the current user | // get email addresses of the current user | ||||
$user_emails = $this->cal->get_user_emails(); | $user_emails = $this->cal->get_user_emails(); | ||||
$subquery = array(); | $subquery = []; | ||||
foreach ($user_emails as $email) { | foreach ($user_emails as $email) { | ||||
foreach ($this->partstats as $partstat) { | foreach ($this->partstats as $partstat) { | ||||
$subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)); | $subquery[] = ['tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)]; | ||||
} | } | ||||
} | } | ||||
$filter = array( | $filter = [ | ||||
array('tags','!=','x-status:cancelled'), | ['tags', '!=', 'x-status:cancelled'], | ||||
array($subquery, 'OR') | [$subquery, 'OR'] | ||||
); | ]; | ||||
// aggregate counts from all calendar folders | // aggregate counts from all calendar folders | ||||
$count = 0; | $count = 0; | ||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { | ||||
$cal = $this->_get_calendar($foldername); | $cal = $this->_get_calendar($foldername); | ||||
if (!$cal || $cal->get_namespace() == 'other') | if (!$cal || $cal->get_namespace() == 'other') { | ||||
continue; | continue; | ||||
} | |||||
$count += $cal->count_events($start, $end, $filter); | $count += $cal->count_events($start, $end, $filter); | ||||
} | } | ||||
return $count; | return $count; | ||||
} | } | ||||
/** | /** | ||||
* Get calendar object instance (that maybe already initialized) | * Get calendar object instance (that maybe already initialized) | ||||
*/ | */ | ||||
private function _get_calendar($folder_name) | private function _get_calendar($folder_name) | ||||
{ | { | ||||
$id = kolab_storage::folder_id($folder_name, true); | $id = kolab_storage::folder_id($folder_name, true); | ||||
return $this->cal->driver->get_calendar($id); | return $this->cal->driver->get_calendar($id); | ||||
} | } | ||||
/** | /** | ||||
* Helper method to modify some event properties | * Helper method to modify some event properties | ||||
*/ | */ | ||||
private function _mod_event($event, $calendar_id = null) | private function _mod_event($event, $calendar_id = null) | ||||
{ | { | ||||
// set classes according to PARTSTAT | // set classes according to PARTSTAT | ||||
$event = kolab_driver::add_partstat_class($event, $this->partstats); | $event = kolab_driver::add_partstat_class($event, $this->partstats); | ||||
if (strpos($event['className'], 'fc-invitation-') !== false) { | if (strpos($event['className'], 'fc-invitation-') !== false) { | ||||
$event['calendar'] = $this->id; | $event['calendar'] = $this->id; | ||||
} | } | ||||
// add pointer to original calendar folder | // add pointer to original calendar folder | ||||
if ($calendar_id) { | if ($calendar_id) { | ||||
$event['_folder_id'] = $calendar_id; | $event['_folder_id'] = $calendar_id; | ||||
} | } | ||||
return $event; | return $event; | ||||
} | } | ||||
/** | /** | ||||
* Create a new event record | * Create a new event record | ||||
* | * | ||||
* @see kolab_calendar::insert_event() | * @see kolab_calendar::insert_event() | ||||
*/ | */ | ||||
public function insert_event($event) | public function insert_event($event) | ||||
{ | { | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Update a specific event record | * Update a specific event record | ||||
* | * | ||||
* @see kolab_calendar::update_event() | * @see kolab_calendar::update_event() | ||||
*/ | */ | ||||
public function update_event($event, $exception_id = null) | public function update_event($event, $exception_id = null) | ||||
{ | { | ||||
// forward call to the actual storage folder | // forward call to the actual storage folder | ||||
if ($event['_folder_id']) { | if (!empty($event['_folder_id'])) { | ||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']); | $cal = $this->cal->driver->get_calendar($event['_folder_id']); | ||||
if ($cal && $cal->ready) { | if ($cal && $cal->ready) { | ||||
return $cal->update_event($event, $exception_id); | return $cal->update_event($event, $exception_id); | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Delete an event record | * Delete an event record | ||||
* | * | ||||
* @see kolab_calendar::delete_event() | * @see kolab_calendar::delete_event() | ||||
*/ | */ | ||||
public function delete_event($event, $force = true) | public function delete_event($event, $force = true) | ||||
{ | { | ||||
// forward call to the actual storage folder | // forward call to the actual storage folder | ||||
if ($event['_folder_id']) { | if (!empty($event['_folder_id'])) { | ||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']); | $cal = $this->cal->driver->get_calendar($event['_folder_id']); | ||||
if ($cal && $cal->ready) { | if ($cal && $cal->ready) { | ||||
return $cal->delete_event($event, $force); | return $cal->delete_event($event, $force); | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Restore deleted event record | * Restore deleted event record | ||||
* | * | ||||
* @see kolab_calendar::restore_event() | * @see kolab_calendar::restore_event() | ||||
*/ | */ | ||||
public function restore_event($event) | public function restore_event($event) | ||||
{ | { | ||||
// forward call to the actual storage folder | // forward call to the actual storage folder | ||||
if ($event['_folder_id']) { | if (!empty($event['_folder_id'])) { | ||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']); | $cal = $this->cal->driver->get_calendar($event['_folder_id']); | ||||
if ($cal && $cal->ready) { | if ($cal && $cal->ready) { | ||||
return $cal->restore_event($event); | return $cal->restore_event($event); | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
} | } |