Example #1
0
 public static function fromArray($keyType, $valueType, array $array)
 {
     $map = new self($keyType, $valueType);
     foreach ($array as $key => $value) {
         $val = is_array($value) ? self::fromArray("?", "?", $value) : $value;
         $map->put($key, $val);
     }
     return $map;
 }
Example #2
0
 /**
  * Create a new Pattern instance from JSON file.
  *
  * @param  string $path
  * @return Raincolour\Containers\Pattern
  */
 public static function make($path)
 {
     $pattern = new self();
     $pattern->fromFile($path);
     $pattern->put('path', $path);
     $pattern->validate();
     $pattern->setTemplates();
     return $pattern;
 }
Example #3
0
 /**
  * Dynamically retrieve attributes on the model.
  *
  * @param  string $key
  *
  * @return mixed
  */
 public function __get($key)
 {
     $newCollection = new self();
     foreach ($this->items as $item) {
         if ($item instanceof self) {
             // This item is a collection.
             foreach ($item as $subItem) {
                 $newCollection->put($newCollection->count(), $subItem->{$key});
             }
         } elseif (is_object($item) && !$item instanceof self && $item->{$key} instanceof self) {
             // Next tap is a collection.
             foreach ($item->{$key} as $subItem) {
                 $newCollection->put($newCollection->count(), $subItem);
             }
         } else {
             // This item is an object.
             $newCollection->put($newCollection->count(), $item->{$key});
         }
     }
     return $newCollection;
 }
Example #4
0
 protected static function moveStatic($name1, $name2)
 {
     $self = new self();
     if ($self->exists($name)) {
         $content = $self->get($name1);
         $self->put($name2, $content);
         $self->delete($name1);
     } else {
         throw new \InvalidArgumentException("There is no file calls {$name}");
     }
 }
 /**
  * this function creates a Calendar_Model_Event and stores it in the database
  * 
  * @todo the header handling does not belong here. It should be moved to the DAV_Server class when supported
  * 
  * @param  Tinebase_Model_Container  $container
  * @param  stream|string             $vobjectData
  * @return Calendar_Frontend_WebDAV_Event
  */
 public static function create(Tinebase_Model_Container $container, $name, $vobjectData, $onlyCurrentUserOrganizer = false)
 {
     if (is_resource($vobjectData)) {
         $vobjectData = stream_get_contents($vobjectData);
     }
     // Converting to UTF-8, if needed
     $vobjectData = Sabre\DAV\StringUtil::ensureUTF8($vobjectData);
     #Sabre\CalDAV\ICalendarUtil::validateICalendarObject($vobjectData, array('VEVENT', 'VFREEBUSY'));
     list($backend, $version) = Calendar_Convert_Event_VCalendar_Factory::parseUserAgent($_SERVER['HTTP_USER_AGENT']);
     $converter = Calendar_Convert_Event_VCalendar_Factory::factory($backend, $version);
     try {
         $event = $converter->toTine20Model($vobjectData);
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e);
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData);
         throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage());
     }
     if (true === $onlyCurrentUserOrganizer) {
         if ($event->organizer && $event->organizer != Tinebase_Core::getUser()->contact_id) {
             return null;
         }
     }
     $event->container_id = $container->getId();
     $id = ($pos = strpos($name, '.')) === false ? $name : substr($name, 0, $pos);
     if (strlen($id) > 40) {
         $id = sha1($id);
     }
     $event->setId($id);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Event to create: " . print_r($event->toArray(), TRUE));
     }
     Calendar_Controller_MSEventFacade::getInstance()->assertEventFacadeParams($container);
     // check if there is already an existing event with this ID
     // this can happen when the invitation email is faster then the caldav update or
     // or when an event gets moved to another container
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'is_deleted', 'operator' => 'equals', 'value' => Tinebase_Model_Filter_Bool::VALUE_NOTSET), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $id), array('field' => 'uid', 'operator' => 'equals', 'value' => $id)))));
     $existingEvent = Calendar_Controller_MSEventFacade::getInstance()->search($filter, null, false, false, 'sync')->getFirstRecord();
     if ($existingEvent === null) {
         if (get_class($converter) == 'Calendar_Convert_Event_VCalendar_Generic') {
             if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . " update by generic client not allowed. See Calendar_Convert_Event_VCalendar_Factory for supported clients.");
             }
             throw new Sabre\DAV\Exception\Forbidden('write access denied for unknown client');
         }
         try {
             $event = Calendar_Controller_MSEventFacade::getInstance()->create($event);
         } catch (Zend_Db_Statement_Exception $zdse) {
             Tinebase_Exception::log($zdse, true);
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Might be a duplicate exception, try with new id');
             }
             unset($event->id);
             try {
                 $event = Calendar_Controller_MSEventFacade::getInstance()->create($event);
             } catch (Exception $e) {
                 Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e);
                 Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData);
                 Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . print_r($event->toArray(), true));
                 throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage());
             }
         } catch (Exception $e) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e);
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData);
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . print_r($event->toArray(), true));
             throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage());
         }
         $vevent = new self($container, $event);
     } else {
         if ($existingEvent->is_deleted) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' recovering already deleted event');
             }
             // @TODO have a undelete/recover workflow beginning in controller
             $existingEvent->is_deleted = 0;
             $existingEvent->deleted_by = NULL;
             $existingEvent->deleted_time = NULL;
             $be = new Calendar_Backend_Sql();
             $be->updateMultiple($existingEvent->getId(), array('is_deleted' => 0, 'deleted_by' => NULL, 'deleted_time' => NULL));
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' update existing event');
         }
         $vevent = new self($container, $existingEvent);
         $vevent->put($vobjectData);
     }
     return $vevent;
 }
Example #6
0
 static function fastPut($a_dir, $a_key, $a_data, $a_expire = null)
 {
     $c = new self($a_dir);
     return $c->put($a_key, $a_data, $a_expire);
 }
 /**
  * this function creates a Tasks_Model_Task and stores it in the database
  * 
  * @param  Tinebase_Model_Container  $container
  * @param  stream|string             $vobjectData
  */
 public static function create(Tinebase_Model_Container $container, $name, $vobjectData, $onlyCurrentUserOrganizer = 'unused')
 {
     if (is_resource($vobjectData)) {
         $vobjectData = stream_get_contents($vobjectData);
     }
     // Converting to UTF-8, if needed
     $vobjectData = Sabre\DAV\StringUtil::ensureUTF8($vobjectData);
     #Sabre_CalDAV_ICalendarUtil::validateICalendarObject($vobjectData, array('VTODO', 'VFREEBUSY'));
     list($backend, $version) = Tasks_Convert_Task_VCalendar_Factory::parseUserAgent($_SERVER['HTTP_USER_AGENT']);
     try {
         $task = Tasks_Convert_Task_VCalendar_Factory::factory($backend, $version)->toTine20Model($vobjectData);
     } catch (Exception $e) {
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e);
         Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData);
         throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage());
     }
     $task->container_id = $container->getId();
     $id = ($pos = strpos($name, '.')) === false ? $name : substr($name, 0, $pos);
     $task->setId($id);
     self::enforceEventParameters($task);
     // check if there is already an existing task with this ID
     // this can happen when the invitation email is faster then the caldav update or
     // or when an task gets moved to another container
     $filter = new Tasks_Model_TaskFilter(array(array('field' => 'is_deleted', 'operator' => 'equals', 'value' => Tinebase_Model_Filter_Bool::VALUE_NOTSET), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $id), array('field' => 'uid', 'operator' => 'equals', 'value' => $id)))));
     $existingEvent = Tasks_Controller_Task::getInstance()->search($filter, null, false, false, 'sync')->getFirstRecord();
     if ($existingEvent === null) {
         try {
             $task = Tasks_Controller_Task::getInstance()->create($task);
         } catch (Exception $e) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e);
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData);
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . print_r($task->toArray(), true));
             throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage());
         }
         $vevent = new self($container, $task);
     } else {
         if ($existingEvent->is_deleted) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' recovering already deleted task');
             }
             // @TODO have a undelete/recover workflow beginning in controller
             $existingEvent->is_deleted = 0;
             $existingEvent->deleted_by = NULL;
             $existingEvent->deleted_time = NULL;
             $be = new Tasks_Backend_Sql();
             $be->updateMultiple($existingEvent->getId(), array('is_deleted' => 0, 'deleted_by' => NULL, 'deleted_time' => NULL));
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' update existing task with id: ' . $existingEvent->getId());
         }
         $vevent = new self($container, $existingEvent);
         $vevent->put($vobjectData);
     }
     return $vevent;
 }
Example #8
0
 /**
  * this function creates a Calendar_Model_Event and stores it in the database
  * 
  * @todo the header handling does not belong here. It should be moved to the DAV_Server class when supported
  * 
  * @param  Tinebase_Model_Container  $container
  * @param  stream|string             $vobjectData
  */
 public static function create(Tinebase_Model_Container $container, $name, $vobjectData)
 {
     if (is_resource($vobjectData)) {
         $vobjectData = stream_get_contents($vobjectData);
     }
     // Converting to UTF-8, if needed
     $vobjectData = Sabre_DAV_StringUtil::ensureUTF8($vobjectData);
     Sabre_CalDAV_ICalendarUtil::validateICalendarObject($vobjectData, array('VEVENT', 'VFREEBUSY'));
     list($backend, $version) = Calendar_Convert_Event_VCalendar_Factory::parseUserAgent($_SERVER['HTTP_USER_AGENT']);
     $event = Calendar_Convert_Event_VCalendar_Factory::factory($backend, $version)->toTine20Model($vobjectData);
     $event->container_id = $container->getId();
     $id = ($pos = strpos($name, '.')) === false ? $name : substr($name, 0, $pos);
     $event->setId($id);
     self::enforceEventParameters($event);
     if ($event->exdate instanceof Tinebase_Record_RecordSet) {
         foreach ($event->exdate as $exdate) {
             if ($exdate->is_deleted == false && $exdate->organizer != $event->organizer) {
                 throw new Sabre_DAV_Exception_PreconditionFailed('Organizer for exdate must be the same like base event');
             }
         }
     }
     // check if there is already an existing event with this ID
     // this can happen when the invitation email is faster then the caldav update or
     // or when an event gets moved to another container
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'containerType', 'operator' => 'equals', 'value' => 'all'), array('field' => 'dtstart', 'operator' => 'equals', 'value' => $event->dtstart), array('field' => 'dtend', 'operator' => 'equals', 'value' => $event->dtend), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $id), array('field' => 'uid', 'operator' => 'equals', 'value' => $id)))));
     $existingEvent = Calendar_Controller_MSEventFacade::getInstance()->search($filter, null, false, false, 'sync')->getFirstRecord();
     if ($existingEvent === null) {
         $event = Calendar_Controller_MSEventFacade::getInstance()->create($event);
         $vevent = new self($container, $event);
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' update existing event');
         }
         $vevent = new self($container, $existingEvent);
         $vevent->put($vobjectData);
     }
     return $vevent;
 }