getComponent() public méthode

Retrieve a specific component.
public getComponent ( integer $idx ) : mixed
$idx integer The index of the object to retrieve.
Résultat mixed (boolean) False if the index does not exist. (Horde_Icalendar_*) The requested component.
Exemple #1
0
 public function testGeo()
 {
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/geo1.vcf'));
     $this->assertEquals(array('latitude' => -17.87, 'longitude' => 37.24), $ical->getComponent(0)->getAttribute('GEO'));
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/geo2.vcf'));
     $this->assertEquals(array('latitude' => 37.386013, 'longitude' => -122.082932), $ical->getComponent(0)->getAttribute('GEO'));
 }
Exemple #2
0
 public function testBug14132()
 {
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/bug14132.ics'));
     $params = $ical->getComponent(1)->getAttribute('DTSTART', true);
     $tz = $params[0]['TZID'];
     $start = $ical->getComponent(1)->getAttribute('DTSTART');
     $dtstart = new Horde_Date($start, $tz);
     $this->assertEquals((string) $dtstart, '2015-10-09 03:00:00');
 }
Exemple #3
0
 public function testIgnoringMultipleAttributeValues()
 {
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/multiple-summary.ics'));
     $result = $ical->getComponent(0)->getAttributeSingle('SUMMARY');
     $this->assertInternalType('string', $result);
     $this->assertEquals('Summary 1', $result);
 }
Exemple #4
0
 public function testFiles()
 {
     $test_files = glob(__DIR__ . '/fixtures/charset*.ics');
     foreach ($test_files as $file) {
         $ical = new Horde_Icalendar();
         $ical->parsevCalendar(file_get_contents($file));
         $this->assertEquals('möchen', $ical->getComponent(0)->getAttribute('SUMMARY'));
     }
 }
Exemple #5
0
 public function testRead()
 {
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/vfreebusy1.ics'));
     // Get the vFreeBusy component
     $vfb = $ical->getComponent(0);
     // Dump the type
     $this->assertEquals('vFreebusy', $vfb->getType());
     // Dump the vfreebusy component again (the duration should be
     // converted to start/end
     $this->assertStringEqualsFile(__DIR__ . '/fixtures/vfreebusy2.ics', $vfb->exportvCalendar());
     // Dump organizer name
     $this->assertEquals('GunnarWrobel', $vfb->getName());
     // Dump organizer mail
     $this->assertEquals('*****@*****.**', $vfb->getEmail());
     // Dump busy periods
     $this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000), $vfb->getBusyPeriods());
     // Decode the summary information
     $extra = $vfb->getExtraParams();
     $this->assertEquals('testtermin', base64_decode($extra[1164258000]['X-SUMMARY']));
     // Dump the free periods in between the two given time stamps
     $this->assertEquals(array(1164261600 => 1164268800), $vfb->getFreePeriods(1164261500, 1164268900));
     // Dump start of the free/busy information
     $this->assertEquals(1164236400, $vfb->getStart());
     // Dump end of the free/busy information
     $this->assertEquals(1169420400, $vfb->getEnd());
     // Free periods don't get added
     $vfb->addBusyPeriod('FREE', 1164261600, 1164268800);
     $this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000), $vfb->getBusyPeriods());
     // Add a busy period with start/end (11:00 / 12:00)
     $vfb->addBusyPeriod('BUSY', 1164279600, 1164283200);
     // Add a busy period with start/duration (14:00 / 2h)
     $vfb->addBusyPeriod('BUSY', 1164290400, null, 7200, array('X-SUMMARY' => 'dGVzdA=='));
     // Dump busy periods
     $this->assertEquals(array(1164258000 => 1164261600, 1164268800 => 1164276000, 1164279600 => 1164283200, 1164290400 => 1164297600), $vfb->getBusyPeriods());
     // Dump the extra parameters
     $this->assertEquals(array(1164258000 => array('X-UID' => 'MmZlNWU3NDRmMGFjNjZkNjRjZjFkZmFmYTE4NGFiZTQ=', 'X-SUMMARY' => 'dGVzdHRlcm1pbg=='), 1164268800 => array(), 1164279600 => array(), 1164290400 => array('X-SUMMARY' => 'dGVzdA==')), $vfb->getExtraParams());
     return $vfb;
 }
Exemple #6
0
 protected function toHash($vcard, $map = array())
 {
     $driver = new Turba_Driver();
     foreach ($map as $field => $config) {
         $driver->map[$field] = $config;
     }
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar($vcard);
     return $driver->toHash($ical->getComponent(0));
 }
Exemple #7
0
 /**
  * Replaces the contact identified by UID with the content represented in
  * the specified contentType.
  *
  * @param string $uid            Idenfity the contact to replace.
  * @param mixed  $content        The content of the contact.
  * @param string $contentType    What format is the data in? Currently
  *                               supports array, text/directory,
  *                               text/vcard, text/x-vcard and activesync.
  * @param string|array $sources  The source(s) where the contact will be
  *                               replaced.
  *
  * @return boolean  Success or failure.
  * @throws Turba_Exception
  */
 public function replace($uid, $content, $contentType, $sources = null)
 {
     if (empty($uid)) {
         throw new Turba_Exception(_("Invalid contact unique ID"));
     }
     $driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver');
     foreach ($this->_getSources($sources) as $source) {
         $sdriver = $driver->create($source);
         // Check permissions.
         if (!$sdriver->hasPermission(Horde_Perms::EDIT)) {
             continue;
         }
         $result = $sdriver->search(array('__uid' => $uid));
         if (!count($result)) {
             continue;
         } elseif (count($result) > 1) {
             throw new Turba_Exception(sprintf(_("Multiple contacts found with same unique ID %s."), $uid));
         }
         $object = $result->objects[0];
         switch ($contentType) {
             case 'activesync':
                 $content = $sdriver->fromASContact($content);
                 foreach ($content as $attribute => $value) {
                     if ($attribute != '__key') {
                         $object->setValue($attribute, $value);
                     }
                 }
                 return $object->store();
             case 'array':
                 break;
             case 'text/x-vcard':
             case 'text/vcard':
             case 'text/directory':
                 $iCal = new Horde_Icalendar();
                 if (!$iCal->parsevCalendar($content)) {
                     throw new Turba_Exception(_("There was an error importing the iCalendar data."));
                 }
                 switch ($iCal->getComponentCount()) {
                     case 0:
                         throw new Turba_Exception(_("No vCard data was found."));
                     case 1:
                         $content = $sdriver->toHash($iCal->getComponent(0));
                         break;
                     default:
                         throw new Turba_Exception(_("Only one vcard supported."));
                 }
                 break;
             default:
                 throw new Turba_Exception(sprintf(_("Unsupported Content-Type: %s"), $contentType));
         }
         foreach ($content as $attribute => $value) {
             if ($attribute != '__key') {
                 $object->setValue($attribute, $value);
             }
         }
         return $object->store();
     }
     throw new Turba_Exception(sprintf(_("Object %s not found."), $uid));
 }
Exemple #8
0
    public function testTimezone()
    {
        $date = new Horde_Date(array('year' => 2010, 'month' => 1, 'mday' => 1, 'hour' => 1, 'min' => 0, 'sec' => 0), 'UTC');
        $ical = new Horde_Icalendar();
        $event = Horde_Icalendar::newComponent('vevent', $ical);
        $event->setAttribute('UID', 'uid');
        $event->setAttribute('DTSTAMP', $date);
        $event->setAttribute('DTSTART', $date);
        $ical->addComponent($event);
        $this->assertEquals('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//The Horde Project//Horde iCalendar Library//EN
BEGIN:VEVENT
UID:uid
DTSTAMP:20100101T010000Z
DTSTART:20100101T010000Z
END:VEVENT
END:VCALENDAR
', $ical->exportVCalendar());
        $ical = new Horde_Icalendar();
        $event = Horde_Icalendar::newComponent('vevent', $ical);
        $event->setAttribute('UID', 'uid');
        $event->setAttribute('DTSTAMP', $date);
        $date->setTimezone('Europe/Berlin');
        $event->setAttribute('DTSTART', $date, array('TZID' => 'Europe/Berlin'));
        $ical->addComponent($event);
        $this->assertEquals('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//The Horde Project//Horde iCalendar Library//EN
BEGIN:VEVENT
UID:uid
DTSTAMP:20100101T010000Z
DTSTART;TZID=Europe/Berlin:20100101T020000
END:VEVENT
END:VCALENDAR
', $ical->exportVCalendar());
        $ical = new Horde_Icalendar();
        $tz = $ical->parsevCalendar('BEGIN:VCALENDAR
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19800406T010000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;UNTIL=19800406T00000Z
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=9;UNTIL=19950923T23000Z
TZNAME:CE-T
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CE-T
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
');
        $tz = $ical->getComponent(0);
        $ical = new Horde_Icalendar();
        $ical->addComponent($tz);
        $event = Horde_Icalendar::newComponent('vevent', $ical);
        $event->setAttribute('UID', 'uid');
        $event->setAttribute('DTSTAMP', $date);
        $date->setTimezone('Europe/Berlin');
        $event->setAttribute('DTSTART', $date, array('TZID' => 'Europe/Berlin'));
        $ical->addComponent($event);
        $ical->addComponent($tz);
        $event = Horde_Icalendar::newComponent('vevent', $ical);
        $event->setAttribute('UID', 'uid2');
        $event->setAttribute('DTSTAMP', $date);
        $date->setTimezone('Europe/Berlin');
        $start = clone $date;
        $start->mday++;
        $event->setAttribute('DTSTART', $start, array('TZID' => 'Europe/Berlin'));
        $ical->addComponent($event);
        $this->assertEquals('BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//The Horde Project//Horde iCalendar Library//EN
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19800406T010000
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;UNTIL=19800406T00000Z
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19800928T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=9;UNTIL=19950923T23000Z
TZNAME:CE-T
END:STANDARD
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T010000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CE-T
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:uid
DTSTAMP:20100101T010000Z
DTSTART;TZID=Europe/Berlin:20100101T020000
END:VEVENT
BEGIN:VEVENT
UID:uid2
DTSTAMP:20100101T010000Z
DTSTART;TZID=Europe/Berlin:20100102T020000
END:VEVENT
END:VCALENDAR
', $ical->exportVCalendar());
    }
Exemple #9
0
 public function testTimezone()
 {
     $date = new Horde_Date(array('year' => 2010, 'month' => 1, 'mday' => 1, 'hour' => 1, 'min' => 0, 'sec' => 0), 'UTC');
     $ical = new Horde_Icalendar();
     $event = Horde_Icalendar::newComponent('vevent', $ical);
     $event->setAttribute('UID', 'uid');
     $event->setAttribute('DTSTAMP', $date);
     $event->setAttribute('DTSTART', $date);
     $ical->addComponent($event);
     $this->assertStringEqualsFile(__DIR__ . '/fixtures/timezone1.ics', $ical->exportVCalendar());
     $ical = new Horde_Icalendar();
     $event = Horde_Icalendar::newComponent('vevent', $ical);
     $event->setAttribute('UID', 'uid');
     $event->setAttribute('DTSTAMP', $date);
     $date->setTimezone('Europe/Berlin');
     $event->setAttribute('DTSTART', $date, array('TZID' => 'Europe/Berlin'));
     $ical->addComponent($event);
     $this->assertStringEqualsFile(__DIR__ . '/fixtures/timezone2.ics', $ical->exportVCalendar());
     $ical = new Horde_Icalendar();
     $tz = $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/timezone3.ics'));
     $tz = $ical->getComponent(0);
     $ical = new Horde_Icalendar();
     $ical->addComponent($tz);
     $event = Horde_Icalendar::newComponent('vevent', $ical);
     $event->setAttribute('UID', 'uid');
     $event->setAttribute('DTSTAMP', $date);
     $date->setTimezone('Europe/Berlin');
     $event->setAttribute('DTSTART', $date, array('TZID' => 'Europe/Berlin'));
     $ical->addComponent($event);
     $ical->addComponent($tz);
     $event = Horde_Icalendar::newComponent('vevent', $ical);
     $event->setAttribute('UID', 'uid2');
     $event->setAttribute('DTSTAMP', $date);
     $date->setTimezone('Europe/Berlin');
     $start = clone $date;
     $start->mday++;
     $event->setAttribute('DTSTART', $start, array('TZID' => 'Europe/Berlin'));
     $ical->addComponent($event);
     $this->assertStringEqualsFile(__DIR__ . '/fixtures/timezone4.ics', $ical->exportVCalendar());
 }
Exemple #10
0
 public function testBug7423()
 {
     $ical = new Horde_Icalendar();
     $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/bug7423.ics'));
     $this->assertEquals(array('SUMMARY' => 'birthday'), $ical->getComponent(0)->toHash(true));
 }