예제 #1
0
 /**
  * @covers makinuk\ICalendar\ICalendar::saveToFile
  */
 public function testSaveToFile()
 {
     $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "icalOut.ics";
     if (file_exists($file)) {
         unlink($file);
     }
     $event = new ICalEvent();
     $event->setUId(1234)->setSummary("Summary")->setOrganizer(new ICalPerson("Mustafa AKIN", "*****@*****.**"))->setLocation("Istanbul")->setEndDate(strtotime("+26 hours"))->setStartDate(strtotime("+24 hours"))->setDescription("Description");
     $this->object->addEvent($event);
     $this->object->saveToFile($file);
     $this->assertFileExists($file);
 }
    private function apiArrayFromEvent(ICalEvent $event) {
        foreach ($this->fieldConfig as $aField => $fieldInfo) {
            $fieldName = isset($fieldInfo['label']) ? $fieldInfo['label'] : $aField;
            $attribute = $event->get_attribute($aField);

            if ($attribute) {
                if (isset($fieldInfo['section'])) {
                    $section = $fieldInfo['section'];
                    if (!isset($result[$section])) {
                        $result[$section] = array();
                    }
                    $result[$section][$fieldName] = $attribute;

                } else {
                    $result[$fieldName] = $attribute;
                }
            }
        }

        return $result;
    }
 public function set_attribute($attr, $value, $params = NULL)
 {
     switch ($attr) {
         case 'X-TRUMBA-CUSTOMFIELD':
             if (array_key_exists('NAME', $params)) {
                 $name = $params['NAME'];
                 unset($params['NAME']);
                 $this->TrumbaCustomFields[$name] = $value;
                 $this->set_attribute($name, $value, $params);
             }
             break;
         default:
             parent::set_attribute($attr, $value, $params);
             break;
     }
 }
예제 #4
0
 function occurrences(ICalEvent $event, TimeRange $range = null, $max = null)
 {
     $occurrences = array();
     $time = $event->get_start();
     $diff = $event->get_end() - $event->get_start();
     $limitType = $this->limitType;
     $limit = $this->limit;
     $count = 0;
     //    echo date('m/d/Y H:i:s', $time) . "<br>\n";
     $time = $this->nextIncrement($time, $this->type, $this->interval);
     while ($time <= $range->get_end()) {
         //      echo date('m/d/Y H:i:s', $time) . "<br>\n";
         if ($limitType == 'UNTIL' && $time > $limit) {
             break;
         }
         $occurrence_range = new TimeRange($time, $time + $diff);
         if ($occurrence_range->overlaps($range)) {
             if ($recurrence_exception = $event->getRecurrenceException($time)) {
                 $occurrence = clone $recurrence_exception;
             } else {
                 $occurrence = clone $event;
                 $occurrence->setRange($occurrence_range);
                 $occurrence->clear_rrules();
                 $recurrence_id = strftime("%Y%m%dT%H%M%S", $time);
                 if ($tzid = $occurrence->get_tzid()) {
                     $recurrence_id = sprintf("TZID=%s:%s", $tzid, $recurrence_id);
                 }
                 $occurrence->set_attribute('RECURRENCE-ID', $recurrence_id);
             }
             $occurrences[] = $occurrence;
         }
         if ($limitType == 'COUNT' && $count < $limit) {
             break;
         }
         if ($count > ICalRecurrenceRule::MAX_OCCURRENCES) {
             break;
         }
         if (!is_null($max) && count($occurrences) >= $max) {
             break;
         }
         $time = $this->nextIncrement($time, $this->type, $this->interval);
         $count++;
     }
     return $occurrences;
 }
예제 #5
0
  public function add_event(ICalEvent $event) {
    $uid = $event->get_uid();
    $this->events[$uid] = $event;

    // use event start times so we can return events in starting order
    $this->eventStartTimes[$uid] = $event->get_start();
  }
예제 #6
0
 public function add_event(ICalEvent $event) {
   $uid = $event->get_uid();
   $this->events[$uid] = $event;
 }
예제 #7
0
 protected function apiArrayFromEvent(ICalEvent $event, $version)
 {
     $standardAttributes = array('datetime', 'start', 'end', 'uid', 'summary', 'description', 'location', 'geo');
     $result = array('id' => $event->get_uid(), 'title' => $event->get_summary(), 'description' => nl2br($event->get_description()), 'start' => $event->get_start(), 'end' => $event->get_end(), 'allday' => $event->isAllDay(), 'location' => $event->get_location(), 'locationLabel' => '');
     // iCal GEO property -- subclass if event lat/lon comes from somewhere else
     $coords = $event->get_location_coordinates();
     if ($coords) {
         $result['latitude'] = $coords['lat'];
         $result['longitude'] = $coords['lon'];
     }
     foreach ($this->fieldConfig as $aField => $fieldInfo) {
         if (in_array($aField, $standardAttributes)) {
             continue;
         }
         // Handled these above
         $id = self::argVal($fieldInfo, 'id', $aField);
         $title = self::argVal($fieldInfo, 'label', $id);
         $section = self::argVal($fieldInfo, 'section', '');
         $type = self::argVal($fieldInfo, 'type', '');
         $value = $event->get_attribute($aField);
         if ($value) {
             if (self::argVal($fieldInfo, 'type', '') == 'category' && is_array($value)) {
                 $value = $this->apiArrayFromCategories($value);
             }
             if ($version < 2) {
                 $result[$title] = $value;
             } else {
                 if (!isset($result['fields'])) {
                     $result['fields'] = array();
                 }
                 $result['fields'][] = array('id' => $id, 'section' => $section, 'type' => $type, 'title' => $title, 'value' => $value);
             }
         }
     }
     return $result;
 }
예제 #8
0
 public function add_event(ICalEvent $event)
 {
     $uid = $event->get_uid();
     if (is_null($event->get_recurid())) {
         $this->events[$uid] = $event;
         // use event start times so we can return events in starting order
         $this->eventStartTimes[$uid] = $event->get_start();
         // Add any stored exceptions to the event.
         if (isset($this->recurrence_exceptions[$uid])) {
             foreach ($this->recurrence_exceptions[$uid] as $exception) {
                 $this->events[$uid]->addRecurenceException($exception);
             }
         }
     } else {
         // If the event already exists, add the exception to it.
         if (isset($this->events[$uid])) {
             $this->events[$uid]->addRecurenceException($event);
         } else {
             if (!isset($this->recurrence_exceptions[$uid])) {
                 $this->recurrence_exceptions[$uid] = array();
             }
             $this->recurrence_exceptions[$uid][] = $event;
         }
     }
 }
function formatDayTitle(ICalEvent $event) {
  $start = $event->get_start();
  $end = $event->get_end();
  if ($start != $end) {
    // all of acad calendar time units are in days so
    // we can end 23:59:00 instead of 00:00:00 next day
    $timeRange = new TimeRange($start, $end - 1);
    $dateTitle = $timeRange->format('l F j');
  } else {
    $dateTitle = date('l F j', $start);
  }
  return $dateTitle;
}