/**
  * Test whether splitting an recurring event saves the new event under a new UID.
  * See http://jira.opensource.mayflower.de/jira/browse/PHPROJEKT-298 for the ratio behind this.
  */
 public function testSplittingRecurrenceGivesNewUidAndUri()
 {
     $this->setRequestUrl('Calendar2/index/jsonSave/nodeId/1/id/0');
     $this->request->setParam('comments', '');
     $this->request->setParam('confirmationStatus', '2');
     $this->request->setParam('description', '');
     $this->request->setParam('end', '2011-12-01 09:00');
     $this->request->setParam('location', '');
     $this->request->setParam('ownerId', '2');
     $this->request->setParam('participants', '2');
     $this->request->setParam('rrule', 'FREQ=DAILY;INTERVAL=1;BYDAY=');
     $this->request->setParam('sendNotification', '0');
     $this->request->setParam('start', '2011-12-01 08:00');
     $this->request->setParam('summary', 'test');
     $this->request->setParam('visibility', '1');
     $response = $this->getResponse();
     $this->assertContains(IndexController::ADD_TRUE_TEXT, $response);
     $response = Zend_Json::decode(substr($response, 5, -1));
     $this->assertArrayHasKey('id', $response);
     $firstId = $response['id'];
     $this->_reset();
     $tzOffset = (int) Phprojekt_Auth_Proxy::getEffectiveUser()->getSetting('timeZone', '0');
     $hour = 8 - $tzOffset;
     $hour = sprintf('%02d', $hour);
     $this->setRequestUrl("Calendar2/index/jsonSave/nodeId/1/id/{$firstId}/occurrence/2011-12-03%20{$hour}:00:00");
     $this->request->setParam('comments', '');
     $this->request->setParam('confirmationStatus', '2');
     $this->request->setParam('description', '');
     $this->request->setParam('end', '2011-12-03 09:00:00');
     $this->request->setParam('location', '');
     $this->request->setParam('multipleEvents', 'true');
     $this->request->setParam('occurrence', '2011-12-03 08:00:00');
     $this->request->setParam('ownerId', '2');
     $this->request->setParam('participants', '2');
     $this->request->setParam('rrule', 'FREQ=DAILY;INTERVAL=1;BYDAY=');
     $this->request->setParam('sendNotification', '0');
     $this->request->setParam('start', '2011-12-03 08:00:00');
     $this->request->setParam('summary', 'something else');
     $this->request->setParam('visibility', '1');
     $response = $this->getResponse();
     $this->assertContains(IndexController::EDIT_TRUE_TEXT, $response);
     $response = Zend_Json::decode(substr($response, 5, -1));
     $this->assertArrayHasKey('id', $response);
     $secondId = $response['id'];
     $first = new Calendar2_Models_Calendar2();
     $first->find($firstId);
     $second = new Calendar2_Models_Calendar2();
     $second->find($secondId);
     $this->assertNotEquals($first->uid, $second->uid);
     $this->assertNotEquals($first->uri, $second->uri);
 }
 /**
  * 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();
 }
 /**
  * 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;
 }
Example #4
0
    /**
     * Test fromVObject with duration.
     */
    public function testFromVObjectWithDuration()
    {
        $calendarData = <<<HERE
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Pentabarf//Schedule//EN
BEGIN:VEVENT
DURATION:PT1H00M
LOCATION:Saal 1
SEQUENCE:0
URL:http://events.ccc.de/congress/2011/Fahrplan/events/4816.en.html
DTSTART;TZID=Europe/Berlin:20111229T160000
UID:4816@28C3@pentabarf.org
DTSTAMP:20111206T185008
CATEGORIES:Lecture
DESCRIPTION:Some
  Description
SUMMARY:the summary is
  here
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
HERE;
        $vcalendar = Sabre_VObject_Reader::read($calendarData);
        $model = new Calendar2_Models_Calendar2();
        $model->fromVObject($vcalendar->vevent);
        $this->assertEquals('Saal 1', $model->location);
        $this->assertEquals('Some Description', $model->description);
        $this->assertEquals('the summary is here', $model->summary);
        $reflection = new ReflectionClass($model);
        $data = $reflection->getProperty('_data');
        $data->setAccessible(true);
        $data = $data->getValue($model);
        // User timezone is utc in tests, so 1500 is correct
        $this->assertEquals('2011-12-29 15:00:00', $data['start']);
        $this->assertEquals('2011-12-29 16:00:00', $data['end']);
    }
Example #5
0
 private function _regenerateSearch()
 {
     $step = 100;
     $start = 0;
     $max = $this->_db->select()->from('calendar2', 'MAX(id)')->query()->fetchColumn();
     $model = new Calendar2_Models_Calendar2();
     $search = new Phprojekt_Search();
     while ($start <= $max) {
         if ($this->_debug) {
             Phprojekt::getInstance()->getLog()->debug($start . ' - ' . ($start + $step));
         }
         $events = $model->fetchAll("id >= {$start} AND id < " . ($start + $step));
         $start += $step;
         foreach ($events as $e) {
             $search->indexObjectItem($e);
         }
     }
 }