コード例 #1
0
 public function testFileNotFound()
 {
     $filename = "foobar.ics";
     $this->expectException(new qCal_Exception_FileNotFound('File cannot be found: "' . $filename . '"'));
     $parser = new qCal_Parser();
     $parser->parseFile($filename);
 }
コード例 #2
0
ファイル: Ical.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * import the data
  *
  * @param  stream $_resource 
  * @param array $_clientRecordData
  * @return array : 
  *  'results'           => Tinebase_Record_RecordSet, // for dryrun only
  *  'totalcount'        => int,
  *  'failcount'         => int,
  *  'duplicatecount'    => int,
  */
 public function import($_resource = NULL, $_clientRecordData = array())
 {
     // force correct line ends
     require_once 'StreamFilter/StringReplace.php';
     $filter = stream_filter_append($_resource, 'str.replace', STREAM_FILTER_READ, array('search' => '/(?<!\\r)\\n/', 'replace' => "\r\n", 'searchIsRegExp' => TRUE));
     if (!$this->_options['importContainerId']) {
         throw new Tinebase_Exception_InvalidArgument('you need to define a importContainerId');
     }
     $icalData = stream_get_contents($_resource);
     $parser = new qCal_Parser();
     try {
         $ical = $parser->parse($icalData);
     } catch (Exception $e) {
         // rethrow a mal formated ics
         $isce = new Calendar_Exception_IcalParser();
         $isce->setParseError($e);
         throw $isce;
     }
     $events = $this->_importResult['results'] = $this->_getEvents($ical);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got ' . count($events) . ' events for import.');
     }
     //        print_r($events->toArray());
     // set container
     $events->container_id = $this->_options['importContainerId'];
     $cc = Calendar_Controller_Event::getInstance();
     $sendNotifications = $cc->sendNotifications(FALSE);
     // search uid's and remove already existing -> only in import cal?
     $existingEvents = $cc->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_options['importContainerId']), array('field' => 'uid', 'operator' => 'in', 'value' => array_unique($events->uid)))), NULL);
     // insert one by one in a single transaction
     $existingEvents->addIndices(array('uid'));
     foreach ($events as $event) {
         $existingEvent = $existingEvents->find('uid', $event->uid);
         try {
             if (!$existingEvent) {
                 $cc->create($event, FALSE);
                 $this->_importResult['totalcount'] += 1;
             } else {
                 if ($this->_options['forceUpdateExisting'] || $this->_options['updateExisting'] && $event->seq > $existingEvent->seq) {
                     $event->id = $existingEvent->getId();
                     $event->last_modified_time = clone $existingEvent->last_modified_time;
                     $cc->update($event, FALSE);
                     $this->_importResult['totalcount'] += 1;
                 } else {
                     $this->_importResult['duplicatecount'] += 1;
                 }
             }
         } catch (Exception $e) {
             $this->_importResult['failcount'] += 1;
         }
     }
     $cc->sendNotifications($sendNotifications);
     return $this->_importResult;
 }
コード例 #3
0
<?php

set_include_path(realpath("../lib") . PATH_SEPARATOR . get_include_path());
require_once "../tests/convenience.php";
/**
 * Parse an iCalendar file
 */
$filepath = realpath('../tests/files');
$parser = new qCal_Parser(array('searchpath' => $filepath));
// parse a file
$ical = $parser->parseFile('simple.ics');
// parse raw data
// $rawdata = file_get_contents($filepath . '/simple.ics');
// $ical->parse($rawdata);
/**
 * Render an iCal object as an icalendar file
 */
$iCalData = $ical->render();
// eventually we can use other renderers as well...
// $xCal = $ical->render(new qCal_Renderer_xCal()); // xCal is an implementation of icalendar in xml
// $hCal = $ical->render(new qCal_Renderer_hCal()); // hCal is a microformat (html version of icalendar format)
/**
 * Build an iCal object from scratch
 */
$calendar = new qCal(array('prodid' => '-//Some Calendar Company//Calendar Program v0.1//EN'));
$todo = new qCal_Component_Vtodo(array('class' => 'private', 'dtstart' => '20090909', 'description' => 'Eat some bacon!!', 'summary' => 'Eat bacon', 'priority' => 1));
$todo->attach(new qCal_Component_Valarm(array('action' => 'audio', 'trigger' => '20090423', 'attach' => 'http://www.example.com/foo.wav')));
$calendar->attach($todo);
// now you can render the calendar if you want, or just echo it out