/** * Test that you can pass in name/value parts, property objects, or a combination, and that * the name portion is case insensitive */ public function testCalendarInitializeAcceptsMixedArray() { // name/value pairs $properties = array('prodid' => '// Test //', 'version' => '3.1'); $calendar = new qCal_Component_Vcalendar($properties); $prodid = $calendar->getProperty('prodid'); $this->assertEqual($prodid[0]->getValue(), '// Test //'); $version = $calendar->getProperty('version'); $this->assertEqual($version[0]->getValue(), '3.1'); // property objects $properties = array(new qCal_Property_Version('4.0'), new qCal_Property_Prodid('// Test //')); $calendar = new qCal_Component_Vcalendar($properties); $prodid = $calendar->getProperty('prodid'); $this->assertEqual($prodid[0]->getValue(), '// Test //'); $version = $calendar->getProperty('version'); $this->assertEqual($version[0]->getValue(), '4.0'); // combination of property objects and name/value $properties = array(new qCal_Property_Version('4.0'), 'prodid' => '// Test //'); $calendar = new qCal_Component_Vcalendar($properties); $prodid = $calendar->getProperty('prodid'); $this->assertEqual($prodid[0]->getValue(), '// Test //'); $version = $calendar->getProperty('version'); $this->assertEqual($version[0]->getValue(), '4.0'); // @todo what happens if the same property is passed in multiple times, and that isn't allowed? }
/** * An individual "VTIMEZONE" calendar component MUST be specified for * each unique "TZID" parameter value specified in the iCalendar object. * @todo Finish this when you are more sure how timezones will work */ public function testEachTzidParameterMustHaveCorrespondingVTimezone() { $cal = new qCal_Component_Vcalendar(); $todo1 = new qCal_Component_Vtodo(array('summary' => 'Make the monkey wash the cat', 'description' => 'Make the monkey wash the cat with a cloth. Make sure to also video-tape it.', new qCal_Property_Dtstart('20090815T050000', array('tzid' => 'US-Eastern')))); $todo2 = new qCal_Component_Vtodo(array('summary' => 'Make the cat wash the monkey', 'description' => 'Make the cat wash the monkey with a sponge. Make sure to audio-tape it.', new qCal_Property_Dtstart('20090816T050000', array('tzid' => 'US-Pacific')))); $this->expectException(new qCal_Exception_MissingComponent('TZID "US-Eastern" not defined')); $cal->attach($todo1); $cal->attach($todo2); // $cal->validate(); // $this->expectException(new qCal_Exception_MissingComponent('TZID "US-Pacific" not defined')); }
/** * Test that all components have access to their root component */ public function testComponentsHaveAccessToRootComponent() { $cal = new qCal_Component_Vcalendar(); $todo = new qCal_Component_Vtodo(); $alarm = new qCal_Component_Valarm(); $todo->attach($alarm); $cal->attach($todo); $this->assertIdentical($alarm->getRootComponent(), $cal); }
public function eventToIcal($_event) { if ($_event instanceof Tinebase_Record_RecordSet) { foreach ($_event as $event) { $this->eventToIcal($event); } return $this->_vcalendar; } // NOTE: we deliver events in originators tz $_event->setTimezone($_event->originator_tz); if (!in_array($_event->originator_tz, $this->_attachedTimezones)) { $this->_vcalendar->attach(self::getVtimezone($_event->originator_tz)); $this->_attachedTimezones[] = $_event->originator_tz; } if ($_event->is_all_day_event) { $dtstart = new qCal_Property_Dtstart($_event->dtstart->format('Ymd'), array('VALUE' => 'DATE')); $dtend = new qCal_Property_Dtend($_event->dtend->format('Ymd'), array('VALUE' => 'DATE')); } else { $dtstart = new qCal_Property_Dtstart(qCal_DateTime::factory($_event->dtstart->format('Ymd\\THis'), $_event->originator_tz), array('TZID' => $_event->originator_tz)); $dtend = new qCal_Property_Dtend(qCal_DateTime::factory($_event->dtend->format('Ymd\\THis'), $_event->originator_tz), array('TZID' => $_event->originator_tz)); } $vevent = new qCal_Component_Vevent(array('uid' => $_event->uid, 'sequence' => $_event->seq, 'summary' => $_event->summary, 'dtstart' => $dtstart, 'dtend' => $dtend)); foreach (self::$veventMap as $icalProp => $tineField) { if (isset($_event[$tineField])) { $vevent->addProperty($icalProp, $_event->{$tineField}); } } // rrule if ($_event->rrule) { $vevent->addProperty('rrule', preg_replace('/(UNTIL=)(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$1$2$3$4T$5$6$7Z', $_event->rrule)); if ($exdateArray = $_event->exdate) { // use multiple EXDATE for the moment, as apple ical uses them foreach ($_event->exdate as $exdate) { $exdates = new qCal_Property_Exdate(qCal_DateTime::factory($exdate->format('Ymd\\THis'), $_event->originator_tz), array('TZID' => $_event->originator_tz)); $vevent->addProperty($exdates); } // $exdates = new qCal_Property_Exdate(qCal_DateTime::factory(array_shift($exdateArray)->format('Ymd\THis'), $_event->originator_tz), array('TZID' => $_event->originator_tz)); // foreach($exdateArray as $exdate) { // $exdates->addValue(qCal_DateTime::factory($exdate->format('Ymd\THis'), $_event->originator_tz)); // } // // $vevent->addProperty($exdates); } } // recurid if ($_event->isRecurException()) { $originalDtStart = $_event->getOriginalDtStart(); $originalDtStart->setTimezone($_event->originator_tz); $vevent->addProperty(new qCal_Property_RecurrenceId(qCal_DateTime::factory($originalDtStart->format('Ymd\\THis'), $_event->originator_tz), array('TZID' => $_event->originator_tz))); } // organizer $organizerId = $_event->organizer instanceof Addressbook_Model_Contact ? array($_event->organizer->getId()) : array($_event->organizer); $organizer = Addressbook_Controller_Contact::getInstance()->getMultiple($organizerId, TRUE)->getFirstRecord(); if ($organizer && ($organizerEmail = $organizer->getPreferedEmailAddress())) { $vevent->addProperty(new qCal_Property_Organizer("mailto:{$organizerEmail}", array('CN' => $organizer->n_fileas))); } // attendee if ($_event->attendee) { Calendar_Model_Attender::resolveAttendee($_event->attendee, FALSE); foreach ($_event->attendee as $attender) { $attenderEmail = $attender->getEmail(); if ($attenderEmail) { $vevent->addProperty(new qCal_Property_Attendee("mailto:{$attenderEmail}", array('CN' => $attender->getName(), 'CUTYPE' => self::$cutypeMap[$attender->user_type], 'EMAIL' => $attenderEmail, 'PARTSTAT' => $attender->status, 'ROLE' => "{$attender->role}-PARTICIPANT", 'RSVP' => 'FALSE'))); } } } // alarms if ($_event->alarms) { foreach ($_event->alarms as $alarm) { $valarm = new qCal_Component_Valarm(array('ACTION' => 'DISPLAY', 'DESCRIPTION' => $_event->summary)); // qCal only support DURATION ;-( $diffSeconds = $_event->dtstart->php52compat_diff($alarm->alarm_time); $valarm->addProperty(new qCal_Property_Trigger($diffSeconds)); // if (is_numeric($alarm->minutes_before)) { // $valarm->addProperty(new qCal_Property_Trigger("-PT{$alarm->minutes_before}M")); // } else { // $valarm->addProperty(new qCal_Property_Trigger(qCal_DateTime::factory($alarm->alarm_time->format('Ymd\THis'), $_event->originator_tz)), array('TZID' => $_event->originator_tz)); // } $vevent->attach($valarm); } } // @todo status $this->_vcalendar->attach($vevent); return $this->_vcalendar; }
/** * convert a VCALENDAR into a Tinebase_Record_RecordSet of Calendar_Model_Event * * @param qCal_Component_Vcalendar $component * @return Tinebase_Record_RecordSet of Calendar_Model_Event */ protected function _getEvents(qCal_Component_Vcalendar $component) { $events = new Tinebase_Record_RecordSet('Calendar_Model_Event'); // do we have a generic timezone? if ($component->hasComponent('VTIMEZONE')) { $tz = array_value(0, $component->getComponent('VTIMEZONE')); $this->_defaultTimezoneId = array_value(0, $tz->getProperty('TZID'))->getValue(); } else { $this->_defaultTimezoneId = (string) Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); } foreach ($component->getChildren() as $children) { if (is_array($children)) { foreach ($children as $child) { if ($child->getName() === 'VEVENT') { $events->addRecord($this->_getEvent($child)); } } } else { if ($children->getName() === 'VEVENT') { $events->addRecord($this->_getEvent($children)); } } } return $events; }