/**
  * testNextScheduledImport
  */
 public function testNextScheduledImport()
 {
     $cc = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())));
     $all = $cc->search($filter);
     $this->assertEquals(0, $all->count());
     $now = Tinebase_DateTime::now()->subHour(1);
     $record = $this->createScheduledImport();
     // assert setting timestamp to start value
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $record = $this->_uit->runNextScheduledImport();
     // assert updating timestamp after successful run
     $now->addHour(1);
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $all = $cc->search($filter);
     $seq = $all->getFirstRecord()->seq;
     // assert all events have been imported
     $this->assertEquals(7, $all->count());
     // this must not be run, the interval is not exceed
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals($seq, $all->getFirstRecord()->seq);
     // setting manual timestamp to force run again
     $record->timestamp = $record->timestamp->subHour(1)->subSecond(1);
     $this->_uit->update($record);
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals(7, $all->count());
 }
 protected function _createEventsForJmcblack()
 {
     // James McBlack
     $monday = clone $this->_monday;
     $tuesday = clone $this->_tuesday;
     $wednesday = clone $this->_wednesday;
     $thursday = clone $this->_thursday;
     $friday = clone $this->_friday;
     $saturday = clone $this->_saturday;
     $sunday = clone $this->_sunday;
     $lastMonday = clone $this->_lastMonday;
     $lastFriday = clone $this->_lastFriday;
     $lastSaturday = clone $this->_lastSaturday;
     $lastSunday = clone $this->_lastSunday;
     $cal = $this->_calendars['jmcblack'];
     $user = $this->_personas['jmcblack'];
     $defaultEventData = array('container_id' => $cal->getId(), 'class' => 'PRIVATE', Tinebase_Model_Grants::GRANT_EDIT => true, 'attendee' => array(array('quantity' => "1", 'role' => "REQ", 'status' => "ACCEPTED", 'transp' => "OPAQUE", 'user_id' => $user->toArray(), 'user_type' => "user")));
     $eventsData = array(array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Catherines Geburtstag' : 'Catherine\'s Birthday', 'description' => static::$_de ? '' : '', 'dtstart' => $thursday->format('d-m-Y') . ' 00:00:00', 'dtend' => $thursday->format('d-m-Y') . ' 23:59:00', 'is_all_day_event' => true, 'alarms' => array(array('alarm_time' => $tuesday->format('d-m-Y') . " 12:00:00", 'minutes_before' => 2880, 'model' => "Calendar_Model_Event", 'options' => json_encode(array("custom" => false, "recurid" => null, "minutes_before" => "2880")), 'sent_message' => "", 'sent_status' => "pending")), 'rrule' => array("bymonth" => $thursday->format('m'), "bymonthday" => $thursday->format('d'), "freq" => "YEARLY", "interval" => "1"), 'rrule_until' => '')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Alyssas Geburtstag' : 'Alyssa\'s Birthday', 'description' => static::$_de ? '' : '', 'dtstart' => $friday->format('d-m-Y') . ' 00:00:00', 'dtend' => $friday->format('d-m-Y') . ' 23:59:00', 'is_all_day_event' => true, 'alarms' => array(array('alarm_time' => $wednesday->format('d-m-Y') . " 12:00:00", 'minutes_before' => 2880, 'model' => "Calendar_Model_Event", 'options' => json_encode(array("custom" => false, "recurid" => null, "minutes_before" => "2880")), 'sent_message' => "", 'sent_status' => "pending")), 'rrule' => array("bymonth" => $friday->format('m'), "bymonthday" => $friday->format('d'), "freq" => "YEARLY", "interval" => "1"), 'rrule_until' => '')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Brendas\' Geburtstag' : 'Brenda\'s Birthday', 'description' => static::$_de ? '' : '', 'dtstart' => $thursday->format('d-m-Y') . ' 00:00:00', 'dtend' => $thursday->format('d-m-Y') . ' 23:59:00', 'is_all_day_event' => true, 'alarms' => array(array('alarm_time' => $tuesday->format('d-m-Y') . " 12:00:00", 'minutes_before' => 2880, 'model' => "Calendar_Model_Event", 'options' => json_encode(array("custom" => false, "recurid" => null, "minutes_before" => "2880")), 'sent_message' => "", 'sent_status' => "pending")), 'rrule' => array("bymonth" => $thursday->format('m'), "bymonthday" => $thursday->format('d'), "freq" => "YEARLY", "interval" => "1"), 'rrule_until' => '')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Automesse in Liverpool' : 'Auto fair in Liverpool', 'description' => static::$_de ? '' : '', 'dtstart' => $monday->format('d-m-Y') . ' 19:00:00', 'dtend' => $monday->format('d-m-Y') . ' 23:00:00')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Weinverkostung auf der Burg' : 'Wine tasting at the castle', 'description' => static::$_de ? '' : '', 'dtstart' => $saturday->format('d-m-Y') . ' 15:00:00', 'dtend' => $saturday->format('d-m-Y') . ' 16:00:00')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Eigentümerversammlung' : 'Owners\' meeting', 'description' => static::$_de ? '' : '', 'dtstart' => $tuesday->format('d-m-Y') . ' 17:00:00', 'dtend' => $tuesday->format('d-m-Y') . ' 18:00:00')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Datamining Konferenz' : 'Data mining conference', 'description' => static::$_de ? '' : '', 'dtstart' => $thursday->format('d-m-Y') . ' 17:00:00', 'dtend' => $thursday->format('d-m-Y') . ' 18:00:00')));
     foreach ($eventsData as $eData) {
         $event = new Calendar_Model_Event($eData);
         $this->_controller->create($event, false);
     }
     $cal = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => static::$_de ? 'Geschäftlich' : 'Business', 'type' => Tinebase_Model_Container::TYPE_PERSONAL, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'SQL', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'color' => '#00CCFF'), true));
     Tinebase_Container::getInstance()->addGrants($cal->getId(), 'user', $this->_personas['sclever']->getId(), $this->_secretaryGrants, true);
     Tinebase_Container::getInstance()->addGrants($cal->getId(), 'user', $this->_personas['rwright']->getId(), $this->_controllerGrants, true);
     $defaultEventData = array('container_id' => $cal->getId(), Tinebase_Model_Grants::GRANT_EDIT => true);
     $eventsData = array(array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Projektbesprechung Projekt Gamma mit Herrn Pearson' : 'Project Gamma Meeting with Mr. Pearson', 'description' => static::$_de ? '' : '', 'dtstart' => $monday->format('d-m-Y') . ' 09:00:00', 'dtend' => $monday->format('d-m-Y') . ' 10:30:00')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'MDH Pitch' : 'MDH Pitch', 'description' => static::$_de ? '' : '', 'dtstart' => $monday->format('d-m-Y') . ' 10:30:00', 'dtend' => $monday->format('d-m-Y') . ' 12:00:00')), array_merge_recursive($defaultEventData, array('summary' => static::$_de ? 'Mitarbeitergespräch mit Jack' : 'employee appraisal with Jack', 'description' => static::$_de ? '' : '', 'dtstart' => $monday->format('d-m-Y') . ' 10:30:00', 'dtend' => $monday->format('d-m-Y') . ' 12:00:00')));
     foreach ($eventsData as $eData) {
         $event = new Calendar_Model_Event($eData);
         $this->_controller->create($event, false);
     }
 }
 public function testImportOutlook12()
 {
     $importer = new Calendar_Import_Ical(array('importContainerId' => $this->_testCalendar->getId()));
     $importer->importFile(dirname(__FILE__) . '/files/outlook12.ics');
     $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId()))), NULL);
     $this->assertEquals(1, $events->count(), 'events where not imported');
 }
 /**
  * converts a tine20 event to an iTIP event
  * 
  * @param  Calendar_Model_Event $_event
  * @return Calendar_Model_Event 
  */
 protected function _toiTIP($_event)
 {
     if ($_event instanceof Tinebase_Record_RecordSet) {
         foreach ($_event as $idx => $event) {
             try {
                 $_event[$idx] = $this->_toiTIP($event);
             } catch (Tinebase_Exception_AccessDenied $ade) {
                 // if we don't have permissions for the exdates, this is likely a freebusy info only -> remove from set
                 $_event->removeRecord($event);
             } catch (Exception $e) {
                 $event->exdate = new Tinebase_Record_RecordSet('Calendar_Model_Event');
             }
         }
         return $_event;
     }
     // get exdates
     if ($_event->rrule) {
         $_event->exdate = $this->_eventController->getRecurExceptions($_event, TRUE);
     }
     // mark any exdates as deleted if the CU does not attend and is not organizer
     if ($_event->exdate instanceof Tinebase_Record_RecordSet && $_event->organizer != $this->_calendarUser->user_id) {
         foreach ($_event->exdate as $exdate) {
             $CUAttendee = Calendar_Model_Attender::getAttendee($exdate->attendee, $this->_calendarUser);
             if ($exdate->is_deleted == false && !$CUAttendee) {
                 $exdate->is_deleted = true;
             }
         }
     }
     return $_event;
 }
 /**
  * tear down tests
  */
 public function tearDown()
 {
     parent::tearDown();
     Calendar_Controller_Event::getInstance()->sendNotifications(false);
     Tinebase_Acl_Roles::getInstance()->resetClassCache();
     if (!$this->_transactionId) {
         if ($this->_backend != NULL) {
             $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()))), new Tinebase_Model_Pagination(array()));
             // delete alarms
             Tinebase_Alarm::getInstance()->deleteAlarmsOfRecord('Calendar_Model_Event', $events->getArrayOfIds());
             foreach ($events as $event) {
                 $this->_backend->delete($event->getId());
             }
         }
         foreach ($this->_testCalendars as $cal) {
             Tinebase_Container::getInstance()->deleteContainer($cal, true);
         }
     }
     $this->_testUserContact = NULL;
     $this->_testCalendar = NULL;
     $this->_testCalendars = NULL;
     $this->_personas = NULL;
     $this->_personasContacts = array();
     $this->_personasDefaultCals = array();
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     if (Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) {
         // account email addresses are empty with AD backend
         $this->markTestSkipped('skipped for ad backend');
     }
     Calendar_Controller_Event::getInstance()->sendNotifications(false);
     Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
 }
 /**
  * (non-PHPdoc)
  * @see tests/tine20/Calendar/Calendar_TestCase::setUp()
  */
 public function setUp()
 {
     parent::setUp();
     $smtpConfig = Tinebase_Config::getInstance()->getConfigAsArray(Tinebase_Config::SMTP);
     if (empty($smtpConfig)) {
         $this->markTestSkipped('No SMTP config found: this is needed to send notifications.');
     }
     $this->_eventController = Calendar_Controller_Event::getInstance();
     $this->_notificationController = Calendar_Controller_EventNotifications::getInstance();
     $this->_setupPreferences();
 }
 protected function setupCalendarContent()
 {
     $eventController = Calendar_Controller_Event::getInstance();
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $this->objects['initialContainer']->id, 'summary' => 'change socks', 'dtstart' => '1979-06-05 07:55:00', 'dtend' => '1979-06-05 08:00:00', 'rrule' => 'FREQ=DAILY;INTERVAL=2;UNTIL=2009-04-01 08:00:00', 'exdate' => '2009-03-31 07:00:00', 'originator_tz' => 'Europe/Berlin', 'rrule_until' => '2009-04-01 08:00:00', Tinebase_Model_Grants::GRANT_EDIT => true));
     $eventController->create($event);
     $event = new Calendar_Model_Event(array('uid' => Tinebase_Record_Abstract::generateUID(), 'container_id' => $this->objects['initialContainer']->id, 'summary' => 'change t-shirt', 'dtstart' => '1979-06-05 08:00:00', 'dtend' => '1979-06-05 08:05:00', 'rrule' => 'FREQ=DAILY;INTERVAL=2;UNTIL=2009-04-01 08:00:00', 'exdate' => '2009-03-31 07:00:00', 'originator_tz' => 'Europe/Berlin', 'rrule_until' => '2009-04-01 08:00:00', Tinebase_Model_Grants::GRANT_EDIT => true));
     $persistentEvent = $eventController->create($event);
     $exception = clone $persistentEvent;
     $exception->summary = 'use blue t-shirt today';
     $eventController->createRecurException($exception);
 }
 /**
  * export events
  *
  * @param string $filter JSON encoded string with items ids for multi export or item filter
  * @param string $options format or export definition id
  */
 public function exportEvents($filter, $options)
 {
     $decodedFilter = Zend_Json::decode($filter);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Export filter: ' . print_r($decodedFilter, TRUE));
     }
     if (!is_array($decodedFilter)) {
         $decodedFilter = array(array('field' => 'id', 'operator' => 'equals', 'value' => $decodedFilter));
     }
     $filter = new Calendar_Model_EventFilter($decodedFilter);
     parent::_export($filter, Zend_Json::decode($options), Calendar_Controller_Event::getInstance());
 }
 /**
  * testConvertAllDayEventWithExdate
  *
  * - exdate is the base event
  */
 public function testConvertAllDayEventWithExdate()
 {
     $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX, '10.10.2');
     $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_birthday.ics', 'r');
     $updateEvent = $converter->toTine20Model($vcalendarStream);
     $eventWithExdateOnBaseEvent = Calendar_Controller_MSEventFacade::getInstance()->create($updateEvent);
     $this->assertEquals(1, count($eventWithExdateOnBaseEvent->exdate));
     // refetch existing event here and pass it to converter
     $eventWithExdateOnBaseEvent = Calendar_Controller_Event::getInstance()->get($eventWithExdateOnBaseEvent->getId());
     $vcalendarStream2 = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_birthday2.ics', 'r');
     $updateEvent2 = $converter->toTine20Model($vcalendarStream2, $eventWithExdateOnBaseEvent);
     $this->assertEquals(1, count($updateEvent2->exdate), print_r($updateEvent2->toArray(), true));
     $this->assertEquals('2015-04-27 22:00:00', $updateEvent2->rrule_until);
 }
 /**
  * prepares an exception instance for persistence
  * 
  * @param  Calendar_Model_Event $_baseEvent
  * @param  Calendar_Model_Event $_exception
  * @return void
  * @throws Tinebase_Exception_InvalidArgument
  */
 protected function _prepareException(Calendar_Model_Event $_baseEvent, Calendar_Model_Event $_exception)
 {
     if (!$_baseEvent->uid) {
         throw new Tinebase_Exception_InvalidArgument('base event has no uid');
     }
     if ($_exception->is_deleted == false) {
         $_exception->container_id = $_baseEvent->container_id;
     }
     $_exception->uid = $_baseEvent->uid;
     $_exception->base_event_id = $_baseEvent->getId();
     $_exception->recurid = $_baseEvent->uid . '-' . $_exception->getOriginalDtStart()->format(Tinebase_Record_Abstract::ISO8601LONG);
     // NOTE: we always refetch the base event as it might be touched in the meantime
     $currBaseEvent = $this->_eventController->get($_baseEvent, null, false);
     $_exception->last_modified_time = $currBaseEvent->last_modified_time;
 }
 public function testGetEvent()
 {
     $user = Tinebase_User::getInstance()->getFullUsers('')->getFirstRecord();
     echo "getting month view for {$user->accountDisplayName}\n";
     $filterData = array(array('field' => 'container_id', 'operator' => 'in', 'value' => array('/personal/' . $user->getId(), '/shared')), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => '2010-03-01 00:00:00', 'until' => '2010-04-01 00:00:00')));
     $filter = new Calendar_Model_EventFilter($filterData);
     $eventIds = Calendar_Controller_Event::getInstance()->search($filter, NULL, FALSE, TRUE);
     foreach ($eventIds as $id) {
         $time_start = microtime(true);
         Calendar_Controller_Event::getInstance()->get($id);
         $time_end = microtime(true);
         $time = $time_end - $time_start;
         echo "getting event {$id} took {$time} seconds\n";
     }
 }
 public function setUp()
 {
     parent::setUp();
     /**
      * set up personas personal container grants:
      * 
      *  jsmith:    anyone freebusyGrant, readGrant, addGrant, editGrant, deleteGrant
      *  pwulf:     anyone readGrant, sclever addGrant, readGrant, editGrant, deleteGrant, privateGrant
      *  sclever:   testuser addGrant, readGrant, editGrant, deleteGrant, privateGrant
      *  jmcblack:  prim group of testuser readGrant, testuser privateGrant
      *  rwright:   testuser freebusyGrant, sclever has readGrant and editGrant
      */
     $this->_setupTestCalendars();
     $this->_uit = Calendar_Controller_Event::getInstance();
 }
 /**
  * testDownloadAttachment
  */
 public function testDownloadAttachment()
 {
     if (!Setup_Controller::getInstance()->isInstalled('Calendar')) {
         $this->markTestSkipped('Calendar not installed');
     }
     $event = new Calendar_Model_Event(array('summary' => 'Wakeup', 'dtstart' => '2009-03-25 06:00:00', 'dtend' => '2009-03-25 06:15:00'));
     $tempFile = $this->_getTempFile();
     $event->attachments = array(array('tempFile' => array('id' => $tempFile->getId())));
     $savedEvent = Calendar_Controller_Event::getInstance()->create($event);
     $this->assertTrue(isset($savedEvent->attachments) && count($savedEvent->attachments) === 1);
     // try to fetch attachment of event
     $node = $this->_getWebDAVTree()->getNodeForPath('/webdav/Calendar/records/Calendar_Model_Event/' . $savedEvent->getId() . '/' . $tempFile->name);
     $this->assertEquals('text/plain', $node->getContentType());
     $this->assertEquals(17, $node->getSize());
     return $savedEvent;
 }
 public function testCreateDemoCalendars()
 {
     ob_start();
     Calendar_Setup_DemoData::getInstance()->createDemoData(array('locale' => 'en'));
     ob_end_clean();
     $pwulf = Tinebase_User::getInstance()->getFullUserByLoginName('pwulf');
     $businessCalendar = Tinebase_Container::getInstance()->getContainerByName('Calendar', 'Business', Tinebase_Model_Container::TYPE_PERSONAL, $pwulf->getId());
     $sharedCalendar = Tinebase_Container::getInstance()->getContainerByName('Calendar', 'Shared Calendar', Tinebase_Model_Container::TYPE_SHARED);
     $cce = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $businessCalendar->getId())), 'AND');
     $businessEvents = $cce->search($filter);
     $cce->deleteByFilter($filter);
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $sharedCalendar->getId())), 'AND');
     $sharedEvents = $cce->search($filter);
     $cce->deleteByFilter($filter);
     $this->assertEquals($businessEvents->count(), 1);
     $this->assertEquals($sharedEvents->count(), 10);
 }
 /**
  * test update of events
  */
 public function testUpdateEvents()
 {
     $this->testImportEvents();
     $importedCalendar = $this->_getImportCalendar();
     $tine20Event = $this->_getEvent();
     $tine20Event->container_id = $importedCalendar->getId();
     Calendar_Controller_Event::getInstance()->create($tine20Event);
     $this->_getUit()->updateServerEvents();
     $this->_getUit()->updateAllCalendarData();
     $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => array($importedCalendar->getId())))));
     $this->assertEquals(4, count($events));
     $expectedEtags = array('"bcc36c611f0b60bfee64b4d42e44aa1d"', '"-1030341843%40citrixonlinecom"', '"aa3621a20e9045d8679075db57e881dd"', null);
     sort($expectedEtags);
     $currentEtags = $events->etag;
     sort($currentEtags);
     $this->assertEquals($expectedEtags, $currentEtags, 'etag mismatch');
     $updatedEvent = $events->filter('etag', '"aa3621a20e9045d8679075db57e881dd"')->getFirstRecord();
     $this->assertEquals('test update', $updatedEvent->summary);
 }
 public function testRecouseConfict()
 {
     $resource = $this->testCreateResource();
     $event = $this->_getEvent();
     $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $resource->id)));
     $persistentEvent = Calendar_Controller_Event::getInstance()->create($event);
     // we need to adopt conainer through backend, to bypass rights control
     $persistentEvent->container_id = $this->_personasDefaultCals['rwright']->getId();
     $persistentEvent->organizer = $this->_personasContacts['rwright']->getId();
     $this->_backend->update($persistentEvent);
     // try to search
     $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(array('field' => 'attender', 'operator' => 'in', 'value' => array(array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $resource->getId()))))), NULL, FALSE, FALSE);
     $this->assertEquals(1, count($events));
     $this->assertEquals($resource->getId(), $events[0]->attendee[0]->user_id);
     // now let's provoke a resource conflict
     $event = $this->_getEvent();
     $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $resource->id)));
     $this->setExpectedException('Calendar_Exception_AttendeeBusy');
     $conflictingEvent = Calendar_Controller_Event::getInstance()->create($event, TRUE);
 }
 /**
  * @return void
  */
 public function testEmailsToAttendeeWithGroups()
 {
     $event = $this->_getEvent();
     $persistentEvent = Calendar_Controller_Event::getInstance()->create($event);
     $primaryGroup = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup);
     $newAttendees = array(array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'firstName' => $this->_testUser->accountFirstName, 'lastName' => $this->_testUser->accountLastName, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $this->_testUser->accountEmailAddress), array('userType' => Calendar_Model_Attender::USERTYPE_GROUP, 'displayName' => $primaryGroup->name, 'partStat' => Calendar_Model_Attender::STATUS_NEEDSACTION, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => '*****@*****.**'));
     Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE);
     $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent);
     $attendees = clone $persistentEvent->attendee;
     Calendar_Model_Attender::resolveAttendee($attendees);
     $newAttendees = array();
     foreach ($attendees as $attendee) {
         $newAttendees[] = array('userType' => $attendee->user_type == 'group' ? Calendar_Model_Attender::USERTYPE_GROUP : Calendar_Model_Attender::USERTYPE_USER, 'partStat' => Calendar_Model_Attender::STATUS_TENTATIVE, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'email' => $attendee->user_type == 'group' ? $attendee->user_id->getId() : $attendee->user_id->email, 'displayName' => $attendee->user_type == 'group' ? $attendee->user_id->name : $attendee->user_id->n_fileas);
     }
     Calendar_Model_Attender::emailsToAttendee($persistentEvent, $newAttendees, TRUE);
     $persistentEvent = Calendar_Controller_Event::getInstance()->update($persistentEvent);
     //var_dump($persistentEvent->attendee->toArray());
     // there must be more than 2 attendees the user, the group + the groupmembers
     $this->assertGreaterThan(2, count($persistentEvent->attendee));
 }
 /**
  * testNextScheduledImport
  *
  * TODO this should run without the need for internet access to http://www.schulferien.org
  *      maybe we should put the file into the local filesystem
  */
 public function testNextScheduledImport()
 {
     $this->markTestSkipped('FIXME: use local ics file for this test / see TODO in doc block');
     $icsUri = 'http://www.schulferien.org/iCal/Ferien/icals/Ferien_Hamburg_2014.ics';
     $client = new Zend_Http_Client($icsUri);
     try {
         $client->request()->getBody();
     } catch (Exception $e) {
         $this->markTestSkipped('no access to ' . $icsUri);
     }
     $cc = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())));
     $all = $cc->search($filter);
     $this->assertEquals(0, $all->count());
     $now = Tinebase_DateTime::now()->subHour(1);
     $record = $this->createScheduledImport($icsUri);
     // assert setting timestamp to start value
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $record = $this->_uit->runNextScheduledImport();
     $this->assertTrue($record !== null, 'import did not run');
     // assert updating timestamp after successful run
     $now->addHour(1);
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $all = $cc->search($filter);
     $seq = $all->getFirstRecord()->seq;
     // assert all events have been imported
     $this->assertEquals(7, $all->count());
     // this must not be run, the interval is not exceed
     $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals($seq, $all->getFirstRecord()->seq);
     // setting manual timestamp to force run again
     $record->timestamp = $record->timestamp->subHour(1)->subSecond(1);
     $this->_uit->update($record);
     $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals(7, $all->count());
 }
 public function testEmailsToAttendeeWithMissingMail()
 {
     $contact = new Addressbook_Model_Contact(array('org_name' => 'unittestorg', 'email' => '', 'email_home' => ''));
     $persistentContact = Addressbook_Controller_Contact::getInstance()->create($contact, FALSE);
     $event = $this->_getEvent();
     $event->attendee->addRecord(new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $persistentContact->getId(), 'role' => Calendar_Model_Attender::ROLE_REQUIRED)));
     $persistentEvent = Calendar_Controller_Event::getInstance()->create($event);
     $clientAttendee = array();
     foreach ($persistentEvent->attendee as $attendee) {
         $clientAttendee[] = array('userType' => Calendar_Model_Attender::USERTYPE_USER, 'email' => $attendee->getEmail(), 'role' => $attendee->role);
     }
     Calendar_Model_Attender::emailsToAttendee($persistentEvent, $clientAttendee, TRUE);
     $userIds = $persistentEvent->attendee->user_id;
     foreach ($userIds as $idx => $id) {
         if ($id instanceof Tinebase_Record_Abstract) {
             $userIds[$idx] = $id->getId();
         }
     }
     $this->assertEquals(3, count($userIds));
     $this->assertTrue(in_array($this->_testUserContact->getId(), $userIds), 'testaccount missing');
     $this->assertTrue(in_array($this->_personasContacts['sclever']->getId(), $userIds), 'sclever missing');
     $this->assertTrue(in_array($persistentContact->getId(), $userIds), 'unittestorg missing');
 }
 /**
  * tests demo data creation for all applications having demodata prepared
  */
 public function testCreateAllDemoData()
 {
     $adbController = Addressbook_Controller_Contact::getInstance();
     $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'not', 'value' => 'user')));
     $existingContacts = $adbController->search($normalContactsFilter);
     // skip admin as it will be called before all tests
     $opts = new Zend_Console_Getopt('abp:', array('skipAdmin'));
     ob_start();
     $this->_cli->createAllDemoData($opts);
     ob_end_clean();
     // test addressbook contacts / admin user contacts
     $accountContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'user')));
     $normalContactsFilter = new Addressbook_Model_ContactFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'contact')));
     $normalContacts = $adbController->search($normalContactsFilter);
     $accountContacts = $adbController->search($accountContactsFilter);
     // shared should be 700
     $this->assertEquals(700 + $existingContacts->count(), $normalContacts->count(), 'NormalContacts');
     // internal contacts/accounts
     $this->assertEquals(6, $accountContacts->count(), 'AccountContacts');
     // test calendar entries
     $calController = Calendar_Controller_Event::getInstance();
     $allEventsFilter = new Calendar_Model_EventFilter(array());
     $allEvents = $calController->search($allEventsFilter);
     $this->assertEquals(49, $allEvents->count(), 'Events');
     // test crm leads
     $crmController = Crm_Controller_Lead::getInstance();
     $allLeadsFilter = new Crm_Model_LeadFilter(array());
     $allLeads = $crmController->search($allLeadsFilter);
     $this->assertEquals(1, $allLeads->count(), 'One shared lead should have been found');
     // test human resources
     $employeeController = HumanResources_Controller_Employee::getInstance();
     $allEmployeesFilter = new HumanResources_Model_EmployeeFilter(array());
     $allEmployees = $employeeController->search($allEmployeesFilter);
     $this->assertEquals(6, $allEmployees->count());
     // remove employees again
     $employeeController->delete($allEmployees->id);
 }
 public function setUp()
 {
     parent::setUp();
     $this->_controller = Calendar_Controller_Event::getInstance();
 }
 public function testUpdateEntriesIPhone()
 {
     $syncrotonFolder = $this->testCreateFolder();
     $syncrotonFolder2 = $this->testCreateFolder();
     //make $syncrotonFolder2 the default
     Tinebase_Core::getPreference('Calendar')->setValue(Calendar_Preference::DEFAULTCALENDAR, $syncrotonFolder2->serverId);
     $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), Tinebase_DateTime::now());
     list($serverId, $syncrotonEvent) = $this->testCreateEntry($syncrotonFolder);
     $event = Calendar_Controller_Event::getInstance()->get($serverId);
     unset($syncrotonEvent->recurrence);
     unset($syncrotonEvent->exceptions);
     unset($syncrotonEvent->attendees);
     // need to create new controller to set new sync timestamp for concurrency handling
     $syncTimestamp = Calendar_Controller_Event::getInstance()->get($serverId)->last_modified_time;
     $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), $syncTimestamp);
     $serverId = $controller->updateEntry($syncrotonFolder->serverId, $serverId, $syncrotonEvent);
     $syncrotonEvent = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder->serverId)), $serverId);
     $updatedEvent = Calendar_Controller_Event::getInstance()->get($serverId);
     $this->assertEmpty($syncrotonEvent->attendees, 'Events attendees found in folder which is not the default calendar');
     $this->assertNotEmpty($updatedEvent->attendee, 'attendee must be preserved');
     $this->assertEquals($event->attendee[0]->getId(), $updatedEvent->attendee[0]->getId(), 'attendee must be perserved');
     return;
     list($serverId, $syncrotonEvent) = $this->testCreateEntry($syncrotonFolder2);
     unset($syncrotonEvent->recurrence);
     unset($syncrotonEvent->exceptions);
     $syncrotonEvent->attendees[0]->name = Tinebase_Record_Abstract::generateUID();
     // need to create new controller to set new sync timestamp for concurrency handling
     $syncTimestamp = Calendar_Controller_Event::getInstance()->get($serverId)->last_modified_time;
     $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), $syncTimestamp);
     $serverId = $controller->updateEntry($syncrotonFolder2->serverId, $serverId, $syncrotonEvent);
     $syncrotonEvent = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder2->serverId)), $serverId);
     $this->assertNotEmpty($syncrotonEvent->attendees, 'Events attendees not found in default calendar');
 }
 /**
  * testOrganizerForeignIdFilterWithOrCondition
  */
 public function testOrganizerForeignIdFilterWithOrCondition()
 {
     $contact = $this->_addContact();
     $event = $this->_getEvent($contact);
     Calendar_Controller_Event::getInstance()->create($event);
     $filter = array(array('condition' => 'OR', 'filters' => array($this->_getOrganizerForeignIdFilter(), array('field' => 'id', 'operator' => 'in', 'value' => array($contact['id'])))));
     $result = $this->_uit->searchContacts($filter, array());
     $this->assertEquals(2, $result['totalcount'], 'expected 2 contacts');
 }
 /**
  * returns the changes happened since the provided syncToken which is the content sequence
  *
  * @param string $syncToken
  * @return array
  */
 public function getChanges($syncToken)
 {
     $result = parent::getChanges($syncToken);
     $newResult = array();
     $backend = Calendar_Controller_Event::getInstance()->getBackend();
     foreach ($result as $action => $value) {
         if (!is_array($value)) {
             $newResult[$action] = $value;
             continue;
         }
         $uids = $backend->getUidOfBaseEvents(array_keys($value));
         $newResult[$action] = array();
         foreach ($uids as $row) {
             $newResult[$action][$row[0]] = $row[0] . $this->_suffix;
         }
     }
     return $newResult;
 }
 /**
  * repair missing displaycontainer_id
  */
 public function update_7()
 {
     $allUser = $this->_db->query("SELECT " . $this->_db->quoteIdentifier('id') . "," . $this->_db->quoteIdentifier('contact_id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "accounts") . " WHERE " . $this->_db->quoteIdentifier("contact_id") . " IS NOT NULL")->fetchAll(Zend_Db::FETCH_ASSOC);
     $contactUserMap = array();
     foreach ($allUser as $id => $user) {
         $contactUserMap[$user['contact_id']] = $user['id'];
     }
     // find all user/groupmember attendees with missing displaycontainer
     $attendees = $this->_db->query("SELECT DISTINCT" . $this->_db->quoteIdentifier('user_type') . "," . $this->_db->quoteIdentifier('user_id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") . " WHERE " . $this->_db->quoteIdentifier("displaycontainer_id") . " IS  NULL" . "  AND " . $this->_db->quoteIdentifier("user_type") . $this->_db->quoteInto(" IN (?)", array('user', 'groupmemeber')) . "  AND " . $this->_db->quoteIdentifier("user_id") . $this->_db->quoteInto(" IN (?)", array_keys($contactUserMap)))->fetchAll(Zend_Db::FETCH_ASSOC);
     // find all user/groupmember attendees with missing displaycontainer
     $attendees = array_merge($attendees, $this->_db->query("SELECT DISTINCT" . $this->_db->quoteIdentifier('user_type') . "," . $this->_db->quoteIdentifier('user_id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") . " WHERE " . $this->_db->quoteIdentifier("displaycontainer_id") . " IS  NULL" . "  AND " . $this->_db->quoteIdentifier("user_type") . $this->_db->quoteInto(" IN (?)", array('resource')))->fetchAll(Zend_Db::FETCH_ASSOC));
     $resources = $this->_db->query("SELECT " . $this->_db->quoteIdentifier('id') . "," . $this->_db->quoteIdentifier('container_id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_resources"))->fetchAll(Zend_Db::FETCH_ASSOC);
     $resourceContainerMap = array();
     foreach ($resources as $resource) {
         $resourceContainerMap[$resource['id']] = $resource['container_id'];
     }
     foreach ($attendees as $attendee) {
         //find out displaycontainer
         if ($attendee['user_type'] != 'resource') {
             $userAccountId = $contactUserMap[$attendee['user_id']];
             try {
                 $attendee['displaycontainerId'] = Calendar_Controller_Event::getDefaultDisplayContainerId($userAccountId);
             } catch (Tinebase_Exception_NotFound $tenf) {
                 Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " Could not find user with id " . $attendee['user_id']);
                 continue;
             }
         } else {
             $attendee['displaycontainerId'] = $resourceContainerMap[$attendee['user_id']];
         }
         // update displaycontainer
         $this->_db->query("UPDATE" . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") . " SET " . $this->_db->quoteIdentifier("displaycontainer_id") . " = " . $this->_db->quote($attendee['displaycontainerId']) . " WHERE " . $this->_db->quoteIdentifier("user_type") . " = " . $this->_db->quote($attendee['user_type']) . "  AND " . $this->_db->quoteIdentifier("user_id") . " = " . $this->_db->quote($attendee['user_id']));
     }
     $this->setApplicationVersion('Calendar', '8.8');
 }
 /**
  * converts Tinebase_Record_RecordSet to external format
  * 
  * @param Tinebase_Record_RecordSet         $_records
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination         $_pagination
  *
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records = NULL, $_filter = NULL, $_pagination = NULL)
 {
     if (count($_records) == 0) {
         return array();
     }
     Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($_records);
     Tinebase_Tags::getInstance()->getMultipleTagsOfRecords($_records);
     if (Tinebase_Core::isFilesystemAvailable()) {
         Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($_records);
     }
     Calendar_Model_Attender::resolveAttendee($_records->attendee, TRUE, $_records);
     Calendar_Convert_Event_Json::resolveRrule($_records);
     Calendar_Controller_Event::getInstance()->getAlarms($_records);
     Calendar_Convert_Event_Json::resolveGrantsOfExternalOrganizers($_records);
     Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($_records, $_filter);
     $_records->sortByPagination($_pagination);
     Tinebase_Frontend_Json_Abstract::resolveContainersAndTags($_records, array('container_id'));
     $_records->setTimezone(Tinebase_Core::getUserTimezone());
     $_records->convertDates = true;
     $eventsData = $_records->toArray();
     foreach ($eventsData as $idx => $eventData) {
         if (!(isset($eventData[Tinebase_Model_Grants::GRANT_READ]) || array_key_exists(Tinebase_Model_Grants::GRANT_READ, $eventData)) || !$eventData[Tinebase_Model_Grants::GRANT_READ]) {
             $eventsData[$idx] = array_intersect_key($eventsData[$idx], array_flip(array('id', 'dtstart', 'dtend', 'transp', 'is_all_day_event')));
         }
     }
     return $eventsData;
 }
 /**
  * updated a recur series
  *
  * @param  array $recordData
  * @param  bool  $checkBusyConflicts
  * @noparamyet  JSONstring $returnPeriod NOT IMPLEMENTED YET
  * @return array 
  */
 public function updateRecurSeries($recordData, $checkBusyConflicts = FALSE)
 {
     $recurInstance = new Calendar_Model_Event(array(), TRUE);
     $recurInstance->setFromJsonInUsersTimezone($recordData);
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(print_r($recurInstance->toArray(), true));
     $baseEvent = Calendar_Controller_Event::getInstance()->updateRecurSeries($recurInstance, $checkBusyConflicts);
     return $this->getEvent($baseEvent->getId());
 }
 /**
  * testImportRruleNormalize
  * 
  * @see 0009856: ics import: recurring events one day earlier
  */
 public function testImportRruleNormalize()
 {
     $importer = new Calendar_Import_Ical(array('container_id' => $this->_getTestCalendar()->getId()));
     $importer->importFile(dirname(__FILE__) . '/files/ni-zsk.ics');
     // fetch first of may in 2014
     $from = new Tinebase_DateTime('2014-04-23 22:00:00');
     $until = new Tinebase_DateTime('2014-05-23 22:00:00');
     $events = Calendar_Controller_Event::getInstance()->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_getTestCalendar()->getId()), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => $from->toString(), 'until' => $until->toString())))), NULL);
     Calendar_Model_Rrule::mergeRecurrenceSet($events, $from, $until);
     $firstOfMay2014 = $events[1];
     $this->assertEquals('2014-04-30 22:00:00', $firstOfMay2014->dtstart);
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     Calendar_Controller_Event::getInstance()->sendNotifications(false);
     Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
 }