public function html($property) { global $prefs; $options = array(); $attributes = ''; $sel = false; $label = ''; switch ($property) { case 'start[year]': return '<label for="' . $this->_formIDEncode($property) . '" class="hidden">' . _("Start Year") . '</label>' . '<input name="' . $property . '" value="' . $this->start->year . '" type="text"' . ' id="' . $this->_formIDEncode($property) . '" size="4" maxlength="4" />'; case 'start[month]': $sel = $this->start->month; for ($i = 1; $i < 13; ++$i) { $options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1)); } $label = _("Start Month"); break; case 'start[day]': $sel = $this->start->mday; for ($i = 1; $i < 32; ++$i) { $options[$i] = $i; } $label = _("Start Day"); break; case 'start_hour': $sel = $this->start->format($prefs->getValue('twentyFour') ? 'G' : 'g'); $hour_min = $prefs->getValue('twentyFour') ? 0 : 1; $hour_max = $prefs->getValue('twentyFour') ? 24 : 13; for ($i = $hour_min; $i < $hour_max; ++$i) { $options[$i] = $i; } $label = _("Start Hour"); break; case 'start_min': $sel = sprintf('%02d', $this->start->min); for ($i = 0; $i < 12; ++$i) { $min = sprintf('%02d', $i * 5); $options[$min] = $min; } $label = _("Start Minute"); break; case 'end[year]': return '<label for="' . $this->_formIDEncode($property) . '" class="hidden">' . _("End Year") . '</label>' . '<input name="' . $property . '" value="' . $this->end->year . '" type="text"' . ' id="' . $this->_formIDEncode($property) . '" size="4" maxlength="4" />'; case 'end[month]': $sel = $this->end ? $this->end->month : $this->start->month; for ($i = 1; $i < 13; ++$i) { $options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1)); } $label = _("End Month"); break; case 'end[day]': $sel = $this->end ? $this->end->mday : $this->start->mday; for ($i = 1; $i < 32; ++$i) { $options[$i] = $i; } $label = _("End Day"); break; case 'end_hour': $sel = $this->end ? $this->end->format($prefs->getValue('twentyFour') ? 'G' : 'g') : $this->start->format($prefs->getValue('twentyFour') ? 'G' : 'g') + 1; $hour_min = $prefs->getValue('twentyFour') ? 0 : 1; $hour_max = $prefs->getValue('twentyFour') ? 24 : 13; for ($i = $hour_min; $i < $hour_max; ++$i) { $options[$i] = $i; } $label = _("End Hour"); break; case 'end_min': $sel = $this->end ? $this->end->min : $this->start->min; $sel = sprintf('%02d', $sel); for ($i = 0; $i < 12; ++$i) { $min = sprintf('%02d', $i * 5); $options[$min] = $min; } $label = _("End Minute"); break; case 'dur_day': $dur = $this->getDuration(); return '<label for="' . $property . '" class="hidden">' . _("Duration Day") . '</label>' . '<input name="' . $property . '" value="' . $dur->day . '" type="text"' . ' id="' . $property . '" size="4" maxlength="4" />'; case 'dur_hour': $dur = $this->getDuration(); $sel = $dur->hour; for ($i = 0; $i < 24; ++$i) { $options[$i] = $i; } $label = _("Duration Hour"); break; case 'dur_min': $dur = $this->getDuration(); $sel = $dur->min; for ($i = 0; $i < 13; ++$i) { $min = sprintf('%02d', $i * 5); $options[$min] = $min; } $label = _("Duration Minute"); break; case 'recur_end[year]': if ($this->end) { $end = $this->recurs() && $this->recurrence->hasRecurEnd() ? $this->recurrence->recurEnd->year : $this->end->year; } else { $end = $this->start->year; } return '<label for="' . $this->_formIDEncode($property) . '" class="hidden">' . _("Recurrence End Year") . '</label>' . '<input name="' . $property . '" value="' . $end . '" type="text"' . ' id="' . $this->_formIDEncode($property) . '" size="4" maxlength="4" />'; case 'recur_end[month]': if ($this->end) { $sel = $this->recurs() && $this->recurrence->hasRecurEnd() ? $this->recurrence->recurEnd->month : $this->end->month; } else { $sel = $this->start->month; } for ($i = 1; $i < 13; ++$i) { $options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1)); } $label = _("Recurrence End Month"); break; case 'recur_end[day]': if ($this->end) { $sel = $this->recurs() && $this->recurrence->hasRecurEnd() ? $this->recurrence->recurEnd->mday : $this->end->mday; } else { $sel = $this->start->mday; } for ($i = 1; $i < 32; ++$i) { $options[$i] = $i; } $label = _("Recurrence End Day"); break; } if (!$this->_varRenderer) { $this->_varRenderer = Horde_Core_Ui_VarRenderer::factory('Html'); } return '<label for="' . $this->_formIDEncode($property) . '" class="hidden">' . $label . '</label>' . '<select name="' . $property . '"' . $attributes . ' id="' . $this->_formIDEncode($property) . '">' . $this->_varRenderer->selectOptions($options, $sel) . '</select>'; }
/** * Set recurrence information for this task * * @param Horde_Date_Recurrence $recurrence */ public function setRecurrence(Horde_Date_Recurrence $recurrence) { $r = Horde_ActiveSync::messageFactory('TaskRecurrence'); // Map the type fields switch ($recurrence->recurType) { case Horde_Date_Recurrence::RECUR_DAILY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; break; case Horde_Date_Recurrence::RECUR_WEEKLY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; $r->dayofweek = $recurrence->getRecurOnDays(); break; case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; $r->dayofmonth = $recurrence->start->mday; break; case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; $r->weekofmonth = ceil($recurrence->start->mday / 7); $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; break; case Horde_Date_Recurrence::RECUR_YEARLY_DATE: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; break; case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; $r->weekofmonth = ceil($recurrence->start->mday / 7); $r->monthofyear = $recurrence->start->month; break; } if (!empty($recurrence->recurInterval)) { $r->interval = $recurrence->recurInterval; } // AS messages can only have one or the other (or none), not both if ($recurrence->hasRecurCount()) { $r->occurrences = $recurrence->getRecurCount(); } elseif ($recurrence->hasRecurEnd()) { $r->until = $recurrence->getRecurEnd(); } // Set the start of the recurrence series. $r->start = clone $this->duedate; $this->_properties['recurrence'] = $r; }
/** * Set recurrence information for this appointment * * @param Horde_Date_Recurrence $recurrence The recurrence data. * @param integer $fdow The first day of the week. * (A Horde_ActiveSync_Message_Recurrence:: constant). @since 2.4.0 */ public function setRecurrence(Horde_Date_Recurrence $recurrence, $fdow = null) { $r = Horde_ActiveSync::messageFactory('Recurrence'); if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEENONE) { $r->firstdayofweek = $fdow; } /* Map the type fields */ switch ($recurrence->recurType) { case Horde_Date_Recurrence::RECUR_DAILY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; break; case Horde_Date_Recurrence::RECUR_WEEKLY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; $r->dayofweek = $recurrence->getRecurOnDays(); break; case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; break; case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; $r->weekofmonth = ceil($recurrence->start->mday / 7); $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; break; case Horde_Date_Recurrence::RECUR_YEARLY_DATE: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; $r->monthofyear = $recurrence->start->month; $r->dayofmonth = $recurrence->start->mday; break; case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; $r->weekofmonth = ceil($recurrence->start->mday / 7); $r->monthofyear = $recurrence->start->month; break; } if (!empty($recurrence->recurInterval)) { $r->interval = $recurrence->recurInterval; } /* AS messages can only have one or the other (or none), not both */ if ($recurrence->hasRecurCount()) { $r->occurrences = $recurrence->getRecurCount(); } elseif ($recurrence->hasRecurEnd()) { $r->until = $recurrence->getRecurEnd(); } // We don't support non-gregorian calendars. if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { $r->calendartype = Horde_ActiveSync_Message_Recurrence::CALENDAR_TYPE_GREGORIAN; } $this->_properties['recurrence'] = $r; }
/** */ public function testCompletions() { $r = new Horde_Date_Recurrence(new Horde_Date(1970, 1, 1)); $r->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); $r->addCompletion(1970, 1, 2); $this->assertTrue($r->hasCompletion(1970, 1, 2)); $this->assertEquals(1, count($r->getCompletions())); $r->addCompletion(1970, 1, 4); $this->assertEquals(2, count($r->getCompletions())); $r->deleteCompletion(1970, 1, 2); $this->assertEquals(1, count($r->getCompletions())); $this->assertFalse($r->hasCompletion(1970, 1, 2)); $r->addCompletion(1970, 1, 2); $r->addException(1970, 1, 1); $r->addException(1970, 1, 3); $next = $r->nextRecurrence(new Horde_Date($r->start)); $this->assertEquals(1, $next->mday); $this->assertTrue($r->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasCompletion($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $r->nextRecurrence($next); $this->assertTrue($r->hasCompletion($next->year, $next->month, $next->mday)); $r->setRecurEnd(new Horde_Date(1970, 1, 4)); $this->assertTrue($r->hasRecurEnd()); $this->assertFalse($r->hasActiveRecurrence()); $s = new Horde_Date_Recurrence(new Horde_Date(1970, 1, 1)); $s->fromKolab($r->toKolab()); $this->assertTrue($s->hasRecurEnd()); $next = $s->nextRecurrence(new Horde_Date($s->start)); $this->assertEquals(1, $next->mday); $this->assertTrue($s->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasCompletion($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasException($next->year, $next->month, $next->mday)); $next->mday++; $next = $s->nextRecurrence($next); $this->assertTrue($s->hasCompletion($next->year, $next->month, $next->mday)); $this->assertEquals(2, count($s->getCompletions())); $this->assertEquals(2, count($s->getExceptions())); $this->assertFalse($s->hasActiveRecurrence()); $this->assertEquals(2, count($s->getCompletions())); $s->deleteCompletion(1970, 1, 2); $this->assertEquals(1, count($s->getCompletions())); $s->deleteCompletion(1970, 1, 4); $this->assertEquals(0, count($s->getCompletions())); }