/**
  * 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();
 }
예제 #2
0
 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');
 }
 /**
  * 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());
 }
 /**
  * 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);
 }
 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";
     }
 }
예제 #10
0
 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);
 }
예제 #14
0
 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);
 }
예제 #15
0
 /**
  * @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 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');
 }
 /**
  * this is required for other applications needing demo data of this application
  * if this returns true, this demodata has been run already
  * 
  * @return boolean
  */
 public static function hasBeenRun()
 {
     $c = Calendar_Controller_Event::getInstance();
     $f = new Calendar_Model_EventFilter(array(array('field' => 'summary', 'operator' => 'equals', 'value' => 'Meeting for further education'), array('field' => 'summary', 'operator' => 'equals', 'value' => 'Fortbildungsveranstaltung')), 'OR');
     return $c->search($f)->count() > 0 ? true : false;
 }
 /**
  * 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;
 }
 /**
  * updates an attender status of a event
  *
  * @param  Calendar_Model_Event    $_event
  * @param  Calendar_Model_Attender $_attendee
  * @return Calendar_Model_Event    updated event
  */
 public function attenderStatusUpdate($_event, $_attendee)
 {
     if ($_event->recurid) {
         throw new Tinebase_Exception_UnexpectedValue('recur event instances must be saved as part of the base event');
     }
     $exceptions = $_event->exdate instanceof Tinebase_Record_RecordSet ? $_event->exdate : new Tinebase_Record_RecordSet('Calendar_Model_Event');
     $_event->exdate = $exceptions->getOriginalDtStart();
     // update base event status
     $attendeeFound = Calendar_Model_Attender::getAttendee($_event->attendee, $_attendee);
     if (!isset($attendeeFound)) {
         throw new Tinebase_Exception_UnexpectedValue('not an attendee');
     }
     $attendeeFound->displaycontainer_id = $_attendee->displaycontainer_id;
     Calendar_Controller_Event::getInstance()->attenderStatusUpdate($_event, $attendeeFound, $attendeeFound->status_authkey);
     // update exceptions
     foreach ($exceptions as $exception) {
         // do not attempt to set status of an deleted instance
         if ($exception->is_deleted) {
             continue;
         }
         $exceptionAttendee = Calendar_Model_Attender::getAttendee($exception->attendee, $_attendee);
         if (!$exception->getId()) {
             if (!$exceptionAttendee) {
                 // set user status to DECLINED
                 $exceptionAttendee = clone $attendeeFound;
                 $exceptionAttendee->status = Calendar_Model_Attender::STATUS_DECLINED;
             }
             $exceptionAttendee->displaycontainer_id = $_attendee->displaycontainer_id;
             Calendar_Controller_Event::getInstance()->attenderStatusCreateRecurException($exception, $exceptionAttendee, $exceptionAttendee->status_authkey);
         } else {
             if (!$exceptionAttendee) {
                 // we would need to find out the users authkey to decline him -> not allowed!?
                 if (!isset($attendeeFound)) {
                     throw new Tinebase_Exception_UnexpectedValue('not an attendee');
                 }
             }
             $exceptionAttendee->displaycontainer_id = $_attendee->displaycontainer_id;
             Calendar_Controller_Event::getInstance()->attenderStatusUpdate($exception, $exceptionAttendee, $exceptionAttendee->status_authkey);
         }
     }
     return $this->get($_event->getId());
 }
 /**
  * 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;
 }
 /**
  * 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());
 }
예제 #26
0
 public function setUp()
 {
     parent::setUp();
     $this->_controller = Calendar_Controller_Event::getInstance();
 }
 /**
  * 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());
 }
 /**
  * testAcceptInvitationForRecurringEventException
  * 
  * @see 0009022: can not accept invitation to recurring event exception
  * @see 0009510: is it allowed to have no main vevent in ics?
  */
 public function testAcceptInvitationForRecurringEventException()
 {
     Tinebase_Container::getInstance()->setGrants($this->objects['initialContainer'], new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array($this->_getAllCalendarGrants(), array('account_id' => 0, 'account_type' => 'anyone', Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_ADD => false, Tinebase_Model_Grants::GRANT_EDIT => false, Tinebase_Model_Grants::GRANT_DELETE => false, Tinebase_Model_Grants::GRANT_FREEBUSY => true, Tinebase_Model_Grants::GRANT_ADMIN => false))), true);
     $persistentEvent = Calendar_Controller_Event::getInstance()->create(new Calendar_Model_Event(array('container_id' => $this->objects['initialContainer']->getId(), 'rrule' => 'FREQ=WEEKLY;BYDAY=WE', 'dtstart' => new Tinebase_DateTime('20131016T120000'), 'dtend' => new Tinebase_DateTime('20131016T130000'), 'summary' => 'Meeting', 'attendee' => new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => Tinebase_Core::getUser()->contact_id, 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'status_authkey' => 'e4546f26cb37f69baf59135e7bd379bf94bba429'))), 'uid' => '3ef8b44333aea7c01aa5a9308e2cb014807c60b3')));
     // add pwulf as attender to create exception
     $exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
     $exception = Calendar_Model_Rrule::computeNextOccurrence($persistentEvent, $exceptions, new Tinebase_DateTime('20131017T140000'));
     $exception->attendee->addRecord(new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $this->_getPersonasContacts('pwulf')->getId())));
     $persistentException = Calendar_Controller_Event::getInstance()->createRecurException($exception);
     $persistentEvent = Calendar_Controller_Event::getInstance()->get($persistentEvent->getId());
     // pwulf tries to accept invitation
     Tinebase_Core::set(Tinebase_Core::USER, Tinebase_User::getInstance()->getFullUserByLoginName('pwulf'));
     $_SERVER['HTTP_USER_AGENT'] = 'Mac OS X/10.8.5 (12F45) CalendarAgent/57';
     // this ics only has an exdate vevent
     $vcalendarStream = self::getVCalendar(dirname(__FILE__) . '/../../Import/files/accept_exdate_invite.ics');
     $event = new Calendar_Frontend_WebDAV_Event($this->objects['initialContainer'], $persistentEvent);
     $event->put($vcalendarStream);
     $exdateWebDAVEvent = $event->getRecord()->exdate[0];
     $this->_assertCurrentUserAttender($exdateWebDAVEvent);
     $exdateCalEvent = Calendar_Controller_Event::getInstance()->get($persistentException->getId());
     $this->_assertCurrentUserAttender($exdateCalEvent);
 }
 /**
  * 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);
 }
 /**
  * (non-PHPdoc)
  * @see Syncroton_Data_IDataCalendar::setAttendeeStatus()
  */
 public function setAttendeeStatus(Syncroton_Model_MeetingResponse $response)
 {
     $event = $instance = $this->_contentController->get($response->requestId);
     $method = 'attenderStatusUpdate';
     if ($response->instanceId instanceof DateTime) {
         $instance = $event->exdate->filter('recurid', $event->uid . '-' . $response->instanceId->format(Tinebase_Record_Abstract::ISO8601LONG))->getFirstRecord();
         if (!$instance) {
             $exceptions = $event->exdate;
             $event->exdate = $exceptions->getOriginalDtStart();
             $instance = Calendar_Model_Rrule::computeNextOccurrence($event, $exceptions, new Tinebase_DateTime($response->instanceId));
         }
         $method = 'attenderStatusCreateRecurException';
     }
     $attendee = Calendar_Model_Attender::getOwnAttender($instance->attendee);
     if (!$attendee) {
         throw new Syncroton_Exception_Status_MeetingResponse("party crushing not allowed", Syncroton_Exception_Status_MeetingResponse::INVALID_REQUEST);
     }
     $attendee->status = $this->_meetingResponseAttendeeStatusMapping[$response->userResponse];
     Calendar_Controller_Event::getInstance()->{$method}($instance, $attendee, $attendee->status_authkey);
     // return id of calendar event
     return $response->requestId;
 }