Finalize recurring events: use patched Horde_Date_Recurrence class for recurrence computing; fix some misbehavior of the Kolab backend

This commit is contained in:
Thomas 2011-07-05 19:45:09 +02:00
parent c2daec1711
commit 8eb9cc25da
3 changed files with 32 additions and 33 deletions

View file

@ -323,7 +323,7 @@ class kolab_calendar
private function _get_recurring_events($event, $start, $end, $event_id = null) private function _get_recurring_events($event, $start, $end, $event_id = null)
{ {
// use Horde classes to compute recurring instances // use Horde classes to compute recurring instances
require_once 'Horde/Date/Recurrence.php'; require_once($this->cal->home . '/lib/Horde_Date_Recurrence.php');
$recurrence = new Horde_Date_Recurrence($event['start']); $recurrence = new Horde_Date_Recurrence($event['start']);
$recurrence->fromRRule20(calendar::to_rrule($event['recurrence'])); $recurrence->fromRRule20(calendar::to_rrule($event['recurrence']));
@ -415,7 +415,7 @@ class kolab_calendar
else if ($recurrence['type'] == 'yearday') else if ($recurrence['type'] == 'yearday')
$rrule['BYYEARDAY'] = $recurrence['daynumber']; $rrule['BYYEARDAY'] = $recurrence['daynumber'];
} }
if ($rec['month']) { if ($recurrence['month']) {
$monthmap = array_flip($this->month_map); $monthmap = array_flip($this->month_map);
$rrule['BYMONTH'] = strtolower($monthmap[$recurrence['month']]); $rrule['BYMONTH'] = strtolower($monthmap[$recurrence['month']]);
} }
@ -585,7 +585,7 @@ class kolab_calendar
$object['_attachments'] = array(); $object['_attachments'] = array();
if (!empty($event['attachments'])) { if (!empty($event['attachments'])) {
foreach ($event['attachments'] as $idx => $attachment) { foreach ($event['attachments'] as $idx => $attachment) {
// Roundcube ID has nothing to Horde ID, remove it // Roundcube ID has nothing to do with Horde ID, remove it
unset($attachment['id']); unset($attachment['id']);
$object['_attachments'][$attachment['name']] = $attachment; $object['_attachments'][$attachment['name']] = $attachment;
unset($event['attachments'][$idx]); unset($event['attachments'][$idx]);

View file

@ -369,7 +369,7 @@ class kolab_driver extends calendar_driver
} }
} }
$event['attachments'] = array_merge($old['attachments'], $attachments); $event['attachments'] = array_merge((array)$old['attachments'], $attachments);
// modify a recurring event, check submitted savemode to do the right things // modify a recurring event, check submitted savemode to do the right things
if ($old['recurrence'] || $old['recurrence_id']) { if ($old['recurrence'] || $old['recurrence_id']) {
@ -420,7 +420,7 @@ class kolab_driver extends calendar_driver
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::insert_event() // remove fixed weekday, will be re-set to the new weekday in kolab_calendar::insert_event()
if (strlen($event['recurrence']['BYDAY']) == 2) if (strlen($event['recurrence']['BYDAY']) == 2)
unset($event['recurrence']['BYDAY']); unset($event['recurrence']['BYDAY']);
if ($event['recurrence']['BYMONTH']) if ($master['recurrence']['BYMONTH'] == gmdate('n', $master['start']))
unset($event['recurrence']['BYMONTH']); unset($event['recurrence']['BYMONTH']);
$success = $storage->insert_event($event); $success = $storage->insert_event($event);
@ -448,7 +448,7 @@ class kolab_driver extends calendar_driver
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event() // remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event()
if (strlen($event['recurrence']['BYDAY']) == 2) if (strlen($event['recurrence']['BYDAY']) == 2)
unset($event['recurrence']['BYDAY']); unset($event['recurrence']['BYDAY']);
if ($event['recurrence']['BYMONTH']) if ($old['recurrence']['BYMONTH'] == gmdate('n', $old['start']))
unset($event['recurrence']['BYMONTH']); unset($event['recurrence']['BYMONTH']);
} }

View file

@ -5313,7 +5313,7 @@ class Horde_Date_Recurrence {
*/ */
function setRecurByMonth($months) function setRecurByMonth($months)
{ {
$this->recurMonths = $months; $this->recurMonths = (array)$months;
} }
/** /**
@ -5332,7 +5332,7 @@ class Horde_Date_Recurrence {
*/ */
function setRecurNthWeekday($nthDay) function setRecurNthWeekday($nthDay)
{ {
$this->recurNthDay = $nthDay; $this->recurNthDay = (int)$nthDay;
} }
/** /**
@ -5842,7 +5842,7 @@ class Horde_Date_Recurrence {
$weekday = $estart->dayOfWeek(); $weekday = $estart->dayOfWeek();
} }
// set month from recurrence rule (FEXME: support more than one month) // set month from recurrence rule (FIXME: support more than one month)
if ($this->recurMonths) { if ($this->recurMonths) {
$estart->month = $this->recurMonths[0]; $estart->month = $this->recurMonths[0];
} }
@ -6430,6 +6430,21 @@ class Horde_Date_Recurrence {
return false; return false;
} }
$month2number = array(
'january' => 1,
'february' => 2,
'march' => 3,
'april' => 4,
'may' => 5,
'june' => 6,
'july' => 7,
'august' => 8,
'september' => 9,
'october' => 10,
'november' => 11,
'december' => 12,
);
$this->setRecurInterval((int) $hash['interval']); $this->setRecurInterval((int) $hash['interval']);
$parse_day = false; $parse_day = false;
@ -6464,11 +6479,9 @@ class Horde_Date_Recurrence {
case 'weekday': case 'weekday':
$this->setRecurType(HORDE_DATE_RECUR_MONTHLY_WEEKDAY); $this->setRecurType(HORDE_DATE_RECUR_MONTHLY_WEEKDAY);
$nth_weekday = (int) $hash['daynumber']; $this->setRecurNthWeekday($hash['daynumber']);
$hash['daynumber'] = 1;
$parse_day = true; $parse_day = true;
$update_daynumber = true; $set_daymask = true;
$update_weekday = true;
break; break;
} }
break; break;
@ -6506,12 +6519,13 @@ class Horde_Date_Recurrence {
} }
$this->setRecurType(HORDE_DATE_RECUR_YEARLY_WEEKDAY); $this->setRecurType(HORDE_DATE_RECUR_YEARLY_WEEKDAY);
$nth_weekday = (int) $hash['daynumber']; $this->setRecurNthWeekday($hash['daynumber']);
$hash['daynumber'] = 1;
$parse_day = true; $parse_day = true;
$update_month = true; $set_daymask = true;
$update_daynumber = true;
$update_weekday = true; if ($hash['month'] && isset($month2number[$hash['month']])) {
$this->setRecurByMonth($month2number[$hash['month']]);
}
break; break;
} }
} }
@ -6580,21 +6594,6 @@ class Horde_Date_Recurrence {
if ($update_month || $update_daynumber || $update_weekday) { if ($update_month || $update_daynumber || $update_weekday) {
if ($update_month) { if ($update_month) {
$month2number = array(
'january' => 1,
'february' => 2,
'march' => 3,
'april' => 4,
'may' => 5,
'june' => 6,
'july' => 7,
'august' => 8,
'september' => 9,
'october' => 10,
'november' => 11,
'december' => 12,
);
if (isset($month2number[$hash['month']])) { if (isset($month2number[$hash['month']])) {
$this->start->month = $month2number[$hash['month']]; $this->start->month = $month2number[$hash['month']];
} }