Add support for alarm notifications with local storage in DB
This commit is contained in:
parent
60635448fb
commit
f2666513bf
3 changed files with 69 additions and 4 deletions
14
plugins/calendar/drivers/kolab/SQL/mysql.sql
Normal file
14
plugins/calendar/drivers/kolab/SQL/mysql.sql
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/**
|
||||||
|
* Roundcube Calendar Kolab backend
|
||||||
|
*
|
||||||
|
* @version 0.3 beta
|
||||||
|
* @author Thomas Bruederli
|
||||||
|
* @licence GNU GPL
|
||||||
|
**/
|
||||||
|
|
||||||
|
CREATE TABLE `kolab_alarms` (
|
||||||
|
`event_id` VARCHAR(255) NOT NULL,
|
||||||
|
`notifyat` DATETIME DEFAULT NULL,
|
||||||
|
`dismissed` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
|
||||||
|
PRIMARY KEY(`event_id`)
|
||||||
|
) /*!40000 ENGINE=INNODB */;
|
|
@ -21,6 +21,7 @@ class kolab_calendar
|
||||||
public $ready = false;
|
public $ready = false;
|
||||||
public $readonly = true;
|
public $readonly = true;
|
||||||
|
|
||||||
|
private $rc;
|
||||||
private $cal;
|
private $cal;
|
||||||
private $storage;
|
private $storage;
|
||||||
private $events;
|
private $events;
|
||||||
|
@ -49,6 +50,7 @@ class kolab_calendar
|
||||||
public function __construct($imap_folder, $calendar)
|
public function __construct($imap_folder, $calendar)
|
||||||
{
|
{
|
||||||
$this->cal = $calendar;
|
$this->cal = $calendar;
|
||||||
|
$this->rc = $calendar->rc;
|
||||||
|
|
||||||
if (strlen($imap_folder))
|
if (strlen($imap_folder))
|
||||||
$this->imap_folder = $imap_folder;
|
$this->imap_folder = $imap_folder;
|
||||||
|
|
|
@ -258,8 +258,46 @@ class kolab_driver extends calendar_driver
|
||||||
*/
|
*/
|
||||||
public function pending_alarms($time, $calendars = null)
|
public function pending_alarms($time, $calendars = null)
|
||||||
{
|
{
|
||||||
// TBD.
|
$events = array();
|
||||||
return array();
|
foreach ($this->load_events($time, $time + 86400 * 365) as $e) {
|
||||||
|
// add to list if alarm is set
|
||||||
|
if ($e['alarm'] && ($notifyat = $e['start'] - $e['alarm'] * 60) <= $time) {
|
||||||
|
$id = $e['id'];
|
||||||
|
$events[$id] = $e;
|
||||||
|
$events[$id]['notifyat'] = $notifyat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get alarm information stored in local database
|
||||||
|
if (!empty($events)) {
|
||||||
|
$event_ids = array_keys($events);
|
||||||
|
array_walk($event_ids, array($this->rc->db, 'quote'));
|
||||||
|
$result = $this->rc->db->query(sprintf(
|
||||||
|
"SELECT * FROM kolab_alarms
|
||||||
|
WHERE event_id IN (%s)
|
||||||
|
AND notifyat <= %s",
|
||||||
|
join(',', $event_ids),
|
||||||
|
$this->rc->db->now()
|
||||||
|
));
|
||||||
|
|
||||||
|
while ($result && ($e = $this->rc->db->fetch_assoc($result))) {
|
||||||
|
$dbdata[$e['event_id']] = $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$alarms = array();
|
||||||
|
foreach ($events as $id => $e) {
|
||||||
|
// skip dismissed
|
||||||
|
if ($dbdata[$id]['dismissed'])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// snooze function may have shifted alarm time
|
||||||
|
$notifyat = $dbdata['notifyat'] ? strtotime($notifyat) : $e['notifyat'];
|
||||||
|
if ($notifyat <= $time)
|
||||||
|
$alarms[] = $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $alarms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,8 +307,19 @@ class kolab_driver extends calendar_driver
|
||||||
*/
|
*/
|
||||||
public function dismiss_alarm($event_id, $snooze = 0)
|
public function dismiss_alarm($event_id, $snooze = 0)
|
||||||
{
|
{
|
||||||
// TBD.
|
// set new notifyat time or unset if not snoozed
|
||||||
return false;
|
$notifyat = $snooze > 0 ? date('Y-m-d H:i:s', time() + $snooze) : null;
|
||||||
|
|
||||||
|
$query = $this->rc->db->query(
|
||||||
|
"UPDATE kolab_alarms
|
||||||
|
SET dismissed=?, notifyat=?
|
||||||
|
WHERE event_id=?",
|
||||||
|
$snooze > 0 ? 0 : 1,
|
||||||
|
$notifyat,
|
||||||
|
$event_id
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->rc->db->affected_rows($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue