예제 #1
0
 /**
  * As defined in Sabre_CalDAV_Backend_Abstract
  *
  * Creates a new calendar object from the given data.
  *
  * @param string $calendarId   The id of the calendar. Equals to the id of the user it belongs to.
  * @param string $objectUri    The uri that the new object should have.
  * @param string $calendarData The vobject data for the new calendar object.
  *
  * @return void
  */
 public function createCalendarObject($calendarId, $objectUri, $calendarData)
 {
     $vcalendar = Sabre_VObject_Reader::read($calendarData);
     $event = new Calendar2_Models_Calendar2();
     $event->fromVObject($vcalendar->vevent);
     $event->uri = $objectUri;
     $event->save();
 }
예제 #2
0
 /**
  * Saves the model.
  *
  * @param Calendar2_Models_Calendar2 $model  The model object
  * @param Array                      $params The request's parameters. All
  *                                           values taken from this array
  *                                           will be validated.
  *
  * @return int The id of the (new) model object.
  */
 private function _saveAction($model, $params)
 {
     $participants = array_key_exists('newParticipants', $params) ? $params['newParticipants'] : array();
     $location = trim($params['location']);
     $start = $params['start'];
     $end = $params['end'];
     $summary = trim($params['summary']);
     $description = trim($params['description']);
     $comments = trim($params['comments']);
     $visibility = $params['visibility'];
     $rrule = array_key_exists('rrule', $params) ? trim($params['rrule']) : null;
     $multiple = array_key_exists('multipleEvents', $params) ? $params['multipleEvents'] : 'true';
     if (!is_array($participants)) {
         throw new Zend_Controller_Action_Exception("Invalid newParticipants '{$participants}'", 400);
     }
     foreach ($participants as $p) {
         if (!Cleaner::validate('int', $p)) {
             //TODO: Check if the participant exists? Many db calls, little
             //      gain...
             throw new Zend_Controller_Action_Exception("Invalid participant {$p}", 400);
         }
     }
     if (!self::_validateTimestamp($start)) {
         throw new Zend_Controller_Action_Exception("Invalid start '{$start}'", 400);
     }
     if (!self::_validateTimestamp($end)) {
         throw new Zend_Controller_Action_Exception("Invalid end '{$end}'", 400);
     }
     if (!Cleaner::validate('int', $visibility) || !Calendar2_Models_Calendar2::isValidVisibility((int) $visibility)) {
         throw new Zend_Controller_Action_Exception("Invalid visibility '{$visibility}'", 400);
     }
     $visibility = (int) $visibility;
     if (!Cleaner::validate('int', $params['userId'])) {
         throw new Zend_Controller_Action_Exception("Invalid userId " . $params['userId'], 400);
     }
     $params['userId'] = (int) $params['userId'];
     if (!Cleaner::validate('boolean', $multiple)) {
         throw new Zend_Controller_Action_Exception("Invalid multiple '{$multiple}'", 400);
     }
     $multiple = 'true' == strtolower($multiple);
     $model->ownerId = $params['userId'];
     $model->setParticipants($participants);
     if ($model->id && ($model->location !== $location || $model->start !== $start || $model->end !== $end)) {
         $model->setParticipantsConfirmationStatuses(Calendar2_Models_Calendar2::STATUS_PENDING);
     }
     $model->summary = $summary;
     $model->description = $description;
     $model->location = $location;
     $model->comments = $comments;
     $model->visibility = $visibility;
     // Using Datetime would be much nicer here.
     // But Phprojekt doesn't really support Datetime yet.
     // (Dates will automatically be converted from Usertime to UTC)
     $model->start = $start;
     $model->end = $end;
     $model->rrule = $rrule;
     if ($multiple) {
         $model->save();
     } else {
         $model->saveSingleEvent();
     }
     return $model->id;
 }