コード例 #1
0
 public function testParserAcceptsRawData()
 {
     $data = file_get_contents(TESTFILE_PATH . DIRECTORY_SEPARATOR . 'simple.ics');
     $parser = new qCal_Parser(array());
     $ical = $parser->parse($data);
     $this->assertIsA($ical, 'qCal_Component_Vcalendar');
 }
コード例 #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;
 }