Exemplo n.º 1
0
 /**
  * sets value
  *
  * @param mixed $_value
  */
 public function setValue($_value)
 {
     switch ($this->_operator) {
         case 'equals':
             $this->_value = array($_value);
             break;
         case 'in':
             $this->_value = $_value;
             break;
         case 'specialNode':
             switch ($_value) {
                 case 'all':
                     $this->_value = $_value;
                     break;
                 case 'allResources':
                     $this->_value = array();
                     $resources = Calendar_Controller_Resource::getInstance()->getAll();
                     foreach ($resources as $resource) {
                         $this->_value[] = array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $resource->getId());
                     }
                     break;
                 default:
                     throw new Tinebase_Exception_UnexpectedValue('specialNode not supported.');
                     break;
             }
     }
     if ($this->_value !== 'all' && !$this->_value instanceof Tinebase_Record_RecordSet) {
         $this->_value = new Tinebase_Record_RecordSet('Calendar_Model_Attender', $this->_value, TRUE);
     }
 }
Exemplo n.º 2
0
 /**
  * singleton
  *
  * @return Calendar_Controller_Resource
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Calendar_Controller_Resource();
     }
     return self::$_instance;
 }
Exemplo n.º 3
0
 public function testCreateResource()
 {
     $resource = new Calendar_Model_Resource(array('name' => 'Meeting Room', 'description' => 'Our main meeting room', 'email' => '*****@*****.**', 'is_location' => TRUE));
     $persitentResource = Calendar_Controller_Resource::getInstance()->create($resource);
     $this->_toCleanup->addRecord($persitentResource);
     $this->assertEquals($resource->name, $persitentResource->name);
     return $resource;
 }
 /**
  * update to 7.1
  * - add default grant for anyone to resources
  */
 public function update_0()
 {
     Calendar_Controller_Resource::getInstance()->doContainerACLChecks(FALSE);
     $resources = Calendar_Controller_Resource::getInstance()->getAll();
     foreach ($resources as $resource) {
         $grants = Tinebase_Container::getInstance()->getGrantsOfContainer($resource->container_id, TRUE);
         if (count($grants) === 0) {
             $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array('account_type' => 'anyone', 'account_id' => 0, 'readGrant' => TRUE)));
             $result = Tinebase_Container::getInstance()->setGrants($resource->container_id, $grants, TRUE, FALSE);
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Added anyone grant (READ) for resource ' . $resource->name);
             }
         }
     }
     $this->setApplicationVersion('Calendar', '7.1');
 }
 /**
  * repair dangling attendee records (no displaycontainer_id)
  *
  * @see https://forge.tine20.org/mantisbt/view.php?id=8172
  */
 public function repairDanglingDisplaycontainerEvents()
 {
     $filter = new Tinebase_Model_Filter_FilterGroup();
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'user_type', 'operator' => 'in', 'value' => array(Calendar_Model_Attender::USERTYPE_USER, Calendar_Model_Attender::USERTYPE_GROUPMEMBER, Calendar_Model_Attender::USERTYPE_RESOURCE))));
     $filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'displaycontainer_id', 'operator' => 'isnull', 'value' => null)));
     $danglingAttendee = $this->_attendeeBackend->search($filter);
     $danglingContactAttendee = $danglingAttendee->filter('user_type', '/' . Calendar_Model_Attender::USERTYPE_USER . '|' . Calendar_Model_Attender::USERTYPE_GROUPMEMBER . '/', TRUE);
     $danglingContactIds = array_unique($danglingContactAttendee->user_id);
     $danglingContacts = Addressbook_Controller_Contact::getInstance()->getMultiple($danglingContactIds, TRUE);
     $danglingResourceAttendee = $danglingAttendee->filter('user_type', Calendar_Model_Attender::USERTYPE_RESOURCE);
     $danglingResourceIds = array_unique($danglingResourceAttendee->user_id);
     Calendar_Controller_Resource::getInstance()->doContainerACLChecks(false);
     $danglingResources = Calendar_Controller_Resource::getInstance()->getMultiple($danglingResourceIds, TRUE);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Processing ' . count($danglingContactIds) . ' dangling contact ids...');
     }
     foreach ($danglingContactIds as $danglingContactId) {
         $danglingContact = $danglingContacts->getById($danglingContactId);
         if ($danglingContact && $danglingContact->account_id) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Get default display container for account ' . $danglingContact->account_id);
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($danglingContact->toArray(), true));
             }
             $displayCalId = Calendar_Controller_Event::getDefaultDisplayContainerId($danglingContact->account_id);
             if ($displayCalId) {
                 // finaly repair attendee records
                 $attendeeRecords = $danglingContactAttendee->filter('user_id', $danglingContactId);
                 $this->_attendeeBackend->updateMultiple($attendeeRecords->getId(), array('displaycontainer_id' => $displayCalId));
                 Tinebase_Core::getLogger()->NOTICE(__METHOD__ . '::' . __LINE__ . " repaired the following contact attendee " . print_r($attendeeRecords->toArray(), TRUE));
             }
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Processing ' . count($danglingResourceIds) . ' dangling resource ids...');
     }
     foreach ($danglingResourceIds as $danglingResourceId) {
         $resource = $danglingResources->getById($danglingResourceId);
         if ($resource && $resource->container_id) {
             $displayCalId = $resource->container_id;
             $attendeeRecords = $danglingResourceAttendee->filter('user_id', $danglingResourceId);
             $this->_attendeeBackend->updateMultiple($attendeeRecords->getId(), array('displaycontainer_id' => $displayCalId));
             Tinebase_Core::getLogger()->NOTICE(__METHOD__ . '::' . __LINE__ . " repaired the following resource attendee " . print_r($attendeeRecords->toArray(), TRUE));
         }
     }
 }
 /**
  * Enable by a preference which sends mails to every user who got permissions to edit the resource
  */
 public function testResourceNotificationForGrantedUsers($userIsAttendee = true, $suppress_notification = false)
 {
     // Enable feature, disabled by default!
     Calendar_Config::getInstance()->set(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS, true);
     $resource = $this->_getResource();
     $resource->email = Tinebase_Core::getUser()->accountEmailAddress;
     $resource->suppress_notification = $suppress_notification;
     $persistentResource = Calendar_Controller_Resource::getInstance()->create($resource);
     $event = $this->_getEvent(true);
     $event->attendee->addRecord($this->_createAttender($persistentResource->getId(), Calendar_Model_Attender::USERTYPE_RESOURCE));
     if (!$userIsAttendee) {
         // remove organizer attendee
         foreach ($event->attendee as $idx => $attender) {
             if ($attender->user_id === $event->organizer) {
                 $event->attendee->removeRecord($attender);
             }
         }
     }
     $grants = Tinebase_Container::getInstance()->getGrantsOfContainer($resource->container_id);
     $newGrants = array('account_id' => $this->_personas['sclever']->getId(), 'account_type' => 'user', Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_EDIT => true);
     Tinebase_Container::getInstance()->setGrants($resource->container_id, new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array_merge(array($newGrants), $grants->toArray())), TRUE);
     self::flushMailer();
     $persistentEvent = $this->_eventController->create($event);
     $messages = self::getMessages();
     Tinebase_Container::getInstance()->setGrants($resource->container_id, $grants);
     $this->assertContains('Resource "' . $persistentResource->name . '" was booked', print_r($messages, true));
     $this->assertContains('Meeting Room (Required, No response)', print_r($messages, true));
     if ($suppress_notification) {
         $this->assertEquals(2, count($messages), 'two mails should be send to current user (resource + attender)');
     } else {
         $this->assertEquals(4, count($messages), 'four mails should be send to current user (resource + attender + everybody who is allowed to edit this resource)');
         $this->assertEquals(count($event->attendee), count($persistentEvent->attendee));
     }
 }
Exemplo n.º 7
0
 /**
  * creates/updates a Resource
  *
  * @param   array   $recordData
  * @return  array   created/updated Resource
  */
 public function saveResource($recordData)
 {
     return $this->_save($recordData, Calendar_Controller_Resource::getInstance(), 'Resource');
 }
 /**
  * get notification subject and method
  * 
  * @param Calendar_Model_Event $_event
  * @param string $_notificationLevel
  * @param string $_action
  * @param array $_updates
  * @param string $timezone
  * @param Zend_Locale $locale
  * @param Zend_Translate $translate
  * @param atring $method
  * @param Calendar_Model_Attender
  * @return string
  * @throws Tinebase_Exception_UnexpectedValue
  */
 protected function _getSubject($_event, $_notificationLevel, $_action, $_updates, $timezone, $locale, $translate, &$method, Calendar_Model_Attender $attender)
 {
     $startDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtstart, $timezone, $locale);
     $endDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_event->dtend, $timezone, $locale);
     switch ($_action) {
         case 'alarm':
             $messageSubject = sprintf($translate->_('Alarm for event "%1$s" at %2$s'), $_event->summary, $startDateString);
             break;
         case 'created':
             $messageSubject = sprintf($translate->_('Event invitation "%1$s" at %2$s'), $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_REQUEST;
             break;
         case 'booked':
             if ($attender->user_type !== Calendar_Model_Attender::USERTYPE_RESOURCE) {
                 throw new Tinebase_Exception_UnexpectedValue('not a resource');
             }
             $resource = Calendar_Controller_Resource::getInstance()->get($attender->user_id);
             $messageSubject = sprintf($translate->_('Resource "%1$s" was booked for "%2$s" at %3$s'), $resource->name, $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_REQUEST;
             break;
         case 'deleted':
             $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been canceled'), $_event->summary, $startDateString);
             $method = Calendar_Model_iMIP::METHOD_CANCEL;
             break;
         case 'changed':
             switch ($_notificationLevel) {
                 case self::NOTIFICATION_LEVEL_EVENT_RESCHEDULE:
                     if (isset($_updates['dtstart']) || array_key_exists('dtstart', $_updates)) {
                         $oldStartDateString = Tinebase_Translation::dateToStringInTzAndLocaleFormat($_updates['dtstart'], $timezone, $locale);
                         $messageSubject = sprintf($translate->_('Event "%1$s" has been rescheduled from %2$s to %3$s'), $_event->summary, $oldStartDateString, $startDateString);
                         $method = Calendar_Model_iMIP::METHOD_REQUEST;
                         break;
                     }
                     // fallthrough if dtstart didn't change
                 // fallthrough if dtstart didn't change
                 case self::NOTIFICATION_LEVEL_EVENT_UPDATE:
                     $messageSubject = sprintf($translate->_('Event "%1$s" at %2$s has been updated'), $_event->summary, $startDateString);
                     $method = Calendar_Model_iMIP::METHOD_REQUEST;
                     break;
                 case self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE:
                     if (!empty($_updates['attendee']) && !empty($_updates['attendee']['toUpdate']) && count($_updates['attendee']['toUpdate']) == 1) {
                         // single attendee status update
                         $attender = $_updates['attendee']['toUpdate']->getFirstRecord();
                         switch ($attender->status) {
                             case Calendar_Model_Attender::STATUS_ACCEPTED:
                                 $messageSubject = sprintf($translate->_('%1$s accepted event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_DECLINED:
                                 $messageSubject = sprintf($translate->_('%1$s declined event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_TENTATIVE:
                                 $messageSubject = sprintf($translate->_('Tentative response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                             case Calendar_Model_Attender::STATUS_NEEDSACTION:
                                 $messageSubject = sprintf($translate->_('No response from %1$s for event "%2$s" at %3$s'), $attender->getName(), $_event->summary, $startDateString);
                                 break;
                         }
                     } else {
                         $messageSubject = sprintf($translate->_('Attendee changes for event "%1$s" at %2$s'), $_event->summary, $startDateString);
                     }
                     // we don't send iMIP parts to organizers with an account cause event is already up to date
                     if ($_event->organizer && !$_event->resolveOrganizer()->account_id) {
                         $method = Calendar_Model_iMIP::METHOD_REPLY;
                     }
                     break;
             }
             break;
         default:
             $messageSubject = 'unknown action';
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " unknown action '{$_action}'");
             }
             break;
     }
     if ($attender->user_type === Calendar_Model_Attender::USERTYPE_RESOURCE) {
         $messageSubject = '[' . $translate->_('Resource Management') . '] ' . $messageSubject;
     }
     return $messageSubject;
 }
 /**
  * testDeleteResource
  * 
  * @param Calendar_Model_Resource $resource
  */
 public function testDeleteResource($resource = null)
 {
     if ($resource === null) {
         $resource = $this->testCreateResource();
     }
     Calendar_Controller_Resource::getInstance()->delete($resource->getId());
     $this->assertEquals(0, count(Calendar_Controller_Resource::getInstance()->getMultiple(array($resource->getId()))));
     $this->setExpectedException('Tinebase_Exception_NotFound');
     Tinebase_Container::getInstance()->getContainerById($resource->container_id);
 }
 /**
  * test get free busy info with recurring event and dst
  *
  * @see 0009558: sometimes free/busy conflicts are not detected
  */
 public function testFreeBusyWithRecurSeriesAndRessourceInDST()
 {
     $event = $this->_getEvent();
     $resource = Calendar_Controller_Resource::getInstance()->create($this->_getResource());
     $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => $resource->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE)));
     $event->dtstart = new Tinebase_DateTime('2013-10-14 10:30:00');
     // this is UTC
     $event->dtend = new Tinebase_DateTime('2013-10-14 11:45:00');
     $event->rrule = 'FREQ=WEEKLY;INTERVAL=1;WKST=SU;BYDAY=MO';
     $persistentEvent = Calendar_Controller_Event::getInstance()->create($event);
     // check free busy in DST
     $newEvent = $this->_getEvent();
     $newEvent->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => $resource->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE)));
     $newEvent->dtstart = new Tinebase_DateTime('2014-01-20 12:30:00');
     $newEvent->dtend = new Tinebase_DateTime('2014-01-20 13:30:00');
     $this->setExpectedException('Calendar_Exception_AttendeeBusy');
     $savedEvent = Calendar_Controller_Event::getInstance()->create($newEvent, true);
 }
 /**
  * updates an attender
  * 
  * @param Calendar_Model_Attender  $attender
  * @param Calendar_Model_Attender  $currentAttender
  * @param Calendar_Model_Event     $event
  * @param bool                     $isRescheduled event got rescheduled reset all attendee status
  * @param Tinebase_Model_Container $calendar
  */
 protected function _updateAttender($attender, $currentAttender, $event, $isRescheduled, $calendar = NULL)
 {
     $userAccountId = $currentAttender->getUserAccountId();
     // update display calendar if attender has/is a useraccount
     if ($userAccountId) {
         if ($calendar->type == Tinebase_Model_Container::TYPE_PERSONAL && Tinebase_Container::getInstance()->hasGrant($userAccountId, $calendar, Tinebase_Model_Grants::GRANT_ADMIN)) {
             // if attender has admin grant to personal physical container, this phys. cal also gets displ. cal
             $attender->displaycontainer_id = $calendar->getId();
         } else {
             if ($userAccountId == Tinebase_Core::getUser()->getId() && Tinebase_Container::getInstance()->hasGrant($userAccountId, $attender->displaycontainer_id, Tinebase_Model_Grants::GRANT_ADMIN)) {
                 // allow user to set his own displ. cal
                 $attender->displaycontainer_id = $attender->displaycontainer_id;
             } else {
                 $attender->displaycontainer_id = $currentAttender->displaycontainer_id;
             }
         }
     }
     // reset status if user has no right and authkey is wrong
     if ($attender->displaycontainer_id) {
         if (!Tinebase_Core::getUser()->hasGrant($attender->displaycontainer_id, Tinebase_Model_Grants::GRANT_EDIT) && $attender->status_authkey != $currentAttender->status_authkey) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Wrong authkey, resetting status (' . $attender->status . ' -> ' . $currentAttender->status . ')');
             }
             $attender->status = $currentAttender->status;
         }
     }
     // reset all status but calUser on reschedule except resources (Resources might have a configured default value)
     if ($isRescheduled && !$attender->isSame($this->getCalendarUser())) {
         if ($attender->user_type === Calendar_Model_Attender::USERTYPE_RESOURCE) {
             //If resource has a default status reset to this
             $resource = Calendar_Controller_Resource::getInstance()->get($attender->user_id);
             $attender->status = isset($resource->status) ? $resource->status : Calendar_Model_Attender::STATUS_NEEDSACTION;
         } else {
             $attender->status = Calendar_Model_Attender::STATUS_NEEDSACTION;
         }
         $attender->transp = null;
     }
     // preserve old authkey
     $attender->status_authkey = $currentAttender->status_authkey;
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " Updating attender: " . print_r($attender->toArray(), TRUE));
     }
     Tinebase_Timemachine_ModificationLog::getInstance()->setRecordMetaData($attender, 'update', $currentAttender);
     Tinebase_Timemachine_ModificationLog::getInstance()->writeModLog($attender, $currentAttender, get_class($attender), $this->_getBackendType(), $attender->getId());
     $this->_backend->updateAttendee($attender);
     if ($attender->displaycontainer_id !== $currentAttender->displaycontainer_id) {
         $this->_increaseDisplayContainerContentSequence($currentAttender, $event, Tinebase_Model_ContainerContent::ACTION_DELETE);
         $this->_increaseDisplayContainerContentSequence($attender, $event, Tinebase_Model_ContainerContent::ACTION_CREATE);
     } else {
         $this->_increaseDisplayContainerContentSequence($attender, $event);
     }
 }
 /**
  * assert only resources with read grant are returned if the user has no manage right
  */
 public function testSearchResources()
 {
     $readableResoureData = $this->testSaveResource();
     $nonReadableResoureData = $this->testSaveResource(array());
     $filer = array(array('field' => 'name', 'operator' => 'in', 'value' => array($readableResoureData['name'], $nonReadableResoureData['name'])));
     $searchResultManager = $this->_uit->searchResources($filer, array());
     $this->assertEquals(2, count($searchResultManager['results']), 'with manage grants all records should be found');
     // steal manage right and reactivate container checks
     $roleManager = Tinebase_Acl_Roles::getInstance();
     $roleManager->deleteRoles(array($roleManager->getRoleByName('manager role')->getId(), $roleManager->getRoleByName('admin role')->getId()));
     Calendar_Controller_Resource::getInstance()->doContainerACLChecks(TRUE);
     $searchResult = $this->_uit->searchResources($filer, array());
     $this->assertEquals(1, count($searchResult['results']), 'without manage grants only one record should be found');
 }
 public function testCreateConflictResourceUnavailable()
 {
     $event = $this->_getEvent();
     // create & add resource
     $rt = new Calendar_Controller_ResourceTest();
     $rt->setUp();
     $resource = $rt->testCreateResource();
     $resource->busy_type = Calendar_Model_FreeBusy::FREEBUSY_BUSY_UNAVAILABLE;
     Calendar_Controller_Resource::getInstance()->update($resource);
     $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $resource->getId()))));
     $conflictEvent = clone $event;
     $this->_controller->create($event);
     try {
         $this->_controller->create($conflictEvent, TRUE);
         $this->fail('Calendar_Exception_AttendeeBusy was not thrown');
     } catch (Calendar_Exception_AttendeeBusy $abe) {
         $fb = $abe->getFreeBusyInfo();
         $this->assertEquals(Calendar_Model_FreeBusy::FREEBUSY_BUSY_UNAVAILABLE, $fb[0]->type);
     }
 }
 /**
  * creates a shared calendar
  */
 private function _createSharedCalendar()
 {
     // create shared calendar
     $this->sharedCalendar = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => static::$_de ? 'Gemeinsamer Kalender' : 'Shared Calendar', 'type' => Tinebase_Model_Container::TYPE_SHARED, 'owner_id' => Tinebase_Core::getUser(), 'backend' => 'SQL', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'color' => '#00FF00'), true));
     $group = Tinebase_Group::getInstance()->getDefaultGroup();
     Tinebase_Container::getInstance()->addGrants($this->sharedCalendar->getId(), 'group', $group->getId(), $this->_userGrants, true);
     if (isset($this->_personas['sclever'])) {
         Tinebase_Container::getInstance()->addGrants($this->sharedCalendar->getId(), 'user', $this->_personas['sclever']->getId(), $this->_secretaryGrants, true);
     }
     // create some resorces as well
     $this->_ressources = array();
     $this->_ressources[] = Calendar_Controller_Resource::getInstance()->create(new Calendar_Model_Resource(array('name' => static::$_de ? 'Besprechnungsraum Mars (1.OG)' : 'Meeting Room Mars (first floor)', 'description' => static::$_de ? 'Bis zu 10 Personen' : 'Up to 10 people', 'email' => '*****@*****.**', 'is_location' => TRUE)));
     $this->_ressources[] = Calendar_Controller_Resource::getInstance()->create(new Calendar_Model_Resource(array('name' => static::$_de ? 'Besprechnungsraum Venus (2.OG)' : 'Meeting Room Venus (second floor)', 'description' => static::$_de ? 'Bis zu 14 Personen' : 'Up to 14 people', 'email' => '*****@*****.**', 'is_location' => TRUE)));
 }
Exemplo n.º 15
0
 /**
  * resolves given attendee for json representation
  * 
  * @TODO move status_authkey cleanup elsewhere
  * 
  * @param Tinebase_Record_RecordSet|array   $_eventAttendee 
  * @param bool                              $_resolveDisplayContainers
  * @param Calendar_Model_Event|array        $_events
  */
 public static function resolveAttendee($_eventAttendee, $_resolveDisplayContainers = TRUE, $_events = NULL)
 {
     $eventAttendee = $_eventAttendee instanceof Tinebase_Record_RecordSet ? array($_eventAttendee) : $_eventAttendee;
     $events = $_events instanceof Tinebase_Record_Abstract ? array($_events) : $_events;
     // set containing all attendee
     $allAttendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender');
     $typeMap = array();
     // build type map
     foreach ($eventAttendee as $attendee) {
         foreach ($attendee as $attender) {
             $allAttendee->addRecord($attender);
             if ($attender->user_id instanceof Tinebase_Record_Abstract) {
                 // already resolved
                 continue;
             } elseif (array_key_exists($attender->user_type, self::$_resovedAttendeeCache) && array_key_exists($attender->user_id, self::$_resovedAttendeeCache[$attender->user_type])) {
                 // already in cache
                 $attender->user_id = self::$_resovedAttendeeCache[$attender->user_type][$attender->user_id];
             } else {
                 if (!array_key_exists($attender->user_type, $typeMap)) {
                     $typeMap[$attender->user_type] = array();
                 }
                 $typeMap[$attender->user_type][] = $attender->user_id;
             }
         }
     }
     // resolve display containers
     if ($_resolveDisplayContainers) {
         $displaycontainerIds = array_diff($allAttendee->displaycontainer_id, array(''));
         if (!empty($displaycontainerIds)) {
             Tinebase_Container::getInstance()->getGrantsOfRecords($allAttendee, Tinebase_Core::getUser(), 'displaycontainer_id');
         }
     }
     // get all user_id entries
     foreach ($typeMap as $type => $ids) {
         switch ($type) {
             case self::USERTYPE_USER:
             case self::USERTYPE_GROUPMEMBER:
                 $resolveCf = Addressbook_Controller_Contact::getInstance()->resolveCustomfields(FALSE);
                 $typeMap[$type] = Addressbook_Controller_Contact::getInstance()->getMultiple(array_unique($ids), TRUE);
                 Addressbook_Controller_Contact::getInstance()->resolveCustomfields($resolveCf);
                 break;
             case self::USERTYPE_GROUP:
             case Calendar_Model_AttenderFilter::USERTYPE_MEMBEROF:
                 // first fetch the groups, then the lists identified by list_id
                 $typeMap[$type] = Tinebase_Group::getInstance()->getMultiple(array_unique($ids));
                 $typeMap[self::USERTYPE_LIST] = Addressbook_Controller_List::getInstance()->getMultiple($typeMap[$type]->list_id, true);
                 break;
             case self::USERTYPE_RESOURCE:
                 $typeMap[$type] = Calendar_Controller_Resource::getInstance()->getMultiple(array_unique($ids));
                 break;
             default:
                 throw new Exception("type {$type} not supported");
                 break;
         }
     }
     // sort entries in
     foreach ($eventAttendee as $attendee) {
         foreach ($attendee as $attender) {
             if ($attender->user_id instanceof Tinebase_Record_Abstract) {
                 // allready resolved from cache
                 continue;
             }
             $idx = false;
             if ($attender->user_type == self::USERTYPE_GROUP) {
                 $attendeeTypeSet = $typeMap[$attender->user_type];
                 $idx = $attendeeTypeSet->getIndexById($attender->user_id);
                 if ($idx !== false) {
                     $group = $attendeeTypeSet[$idx];
                     $idx = false;
                     $attendeeTypeSet = $typeMap[self::USERTYPE_LIST];
                     $idx = $attendeeTypeSet->getIndexById($group->list_id);
                 }
             } else {
                 $attendeeTypeSet = $typeMap[$attender->user_type];
                 $idx = $attendeeTypeSet->getIndexById($attender->user_id);
             }
             if ($idx !== false) {
                 // copy to cache
                 if (!array_key_exists($attender->user_type, self::$_resovedAttendeeCache)) {
                     self::$_resovedAttendeeCache[$attender->user_type] = array();
                 }
                 self::$_resovedAttendeeCache[$attender->user_type][$attender->user_id] = $attendeeTypeSet[$idx];
                 $attender->user_id = $attendeeTypeSet[$idx];
             }
         }
     }
     foreach ($eventAttendee as $idx => $attendee) {
         $event = is_array($events) && array_key_exists($idx, $events) ? $events[$idx] : NULL;
         foreach ($attendee as $attender) {
             // keep authkey if user has editGrant to displaycontainer
             if (isset($attender['displaycontainer_id']) && !is_scalar($attender['displaycontainer_id']) && array_key_exists(Tinebase_Model_Grants::GRANT_EDIT, $attender['displaycontainer_id']['account_grants']) && $attender['displaycontainer_id']['account_grants'][Tinebase_Model_Grants::GRANT_EDIT]) {
                 continue;
             }
             // keep authkey if attender resource OR contact (no account) and user has editGrant for event
             if (in_array($attender->user_type, array(self::USERTYPE_USER, self::USERTYPE_RESOURCE)) && $attender->user_id instanceof Tinebase_Record_Abstract && (!$attender->user_id->has('account_id') || !$attender->user_id->account_id) && (!$event || $event->{Tinebase_Model_Grants::GRANT_EDIT})) {
                 continue;
             }
             $attender->status_authkey = NULL;
         }
     }
 }
 /**
  * gets tine cal recource by egw resource id
  * 
  * @param  int $_egwResourceId
  * @return string
  */
 protected function _getResourceId($_egwResourceId)
 {
     $select = $this->_egwDb->select()->from(array('resources' => 'egw_resources'))->where($this->_egwDb->quoteInto($this->_egwDb->quoteIdentifier('res_id') . ' = ?', $_egwResourceId));
     $egwResources = $this->_egwDb->fetchAll($select, NULL, Zend_Db::FETCH_ASSOC);
     if (count($egwResources) !== 1) {
         $this->_log->warn(__METHOD__ . '::' . __LINE__ . ' egw resource not found');
         return NULL;
     }
     $egwResource = $egwResources[0];
     // find tine resource
     $tineResources = Calendar_Controller_Resource::getInstance()->search(new Calendar_Model_ResourceFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => $egwResource['name']))));
     if (count($tineResources) === 0) {
         // migrate on the fly
         $this->_log->info(__METHOD__ . '::' . __LINE__ . " migrating resource {$egwResource['name']}");
         $resource = new Calendar_Model_Resource(array('name' => $egwResource['name'], 'description' => $egwResource['short_description'], 'email' => preg_replace('/[^A-Za-z0-9.\\-]/', '', $egwResource['name'])));
         $tineResource = Calendar_Controller_Resource::getInstance()->create($resource);
     } else {
         $tineResource = $tineResources->getFirstRecord();
     }
     return $tineResource->getId();
 }
 /**
  * creates/updates a Resource
  *
  * @param   array   $recordData
  * @return  array   created/updated Resource
  */
 public function saveResource($recordData)
 {
     $recordData['grants'] = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', $recordData['grants']);
     return $this->_save($recordData, Calendar_Controller_Resource::getInstance(), 'Resource');
 }
Exemplo n.º 18
0
 /**
  * creates a new attender
  * @todo add support for resources
  * 
  * @param Calendar_Model_Attender  $_attender
  * @param Tinebase_Model_Container $_calendar
  */
 protected function _createAttender($_attender, $_calendar)
 {
     // apply default user_type
     $_attender->user_type = $_attender->user_type ? $_attender->user_type : Calendar_Model_Attender::USERTYPE_USER;
     $userAccountId = $_attender->getUserAccountId();
     // reset status if not a contact or my account
     if ($_attender->user_type != Calendar_Model_Attender::USERTYPE_USER || $userAccountId && $userAccountId != Tinebase_Core::getUser()->getId()) {
         $_attender->status = Calendar_Model_Attender::STATUS_NEEDSACTION;
     }
     // generate auth key
     $_attender->status_authkey = Tinebase_Record_Abstract::generateUID();
     // attach to display calendar if attender has/is a useraccount
     if ($userAccountId) {
         if ($_calendar->type == Tinebase_Model_Container::TYPE_PERSONAL && Tinebase_Container::getInstance()->hasGrant($userAccountId, $_calendar, Tinebase_Model_Grants::GRANT_ADMIN)) {
             // if attender has admin grant to personal phisycal container, this phys. cal also gets displ. cal
             $_attender->displaycontainer_id = $_calendar->getId();
         } else {
             if ($_attender->displaycontainer_id && $userAccountId == Tinebase_Core::getUser()->getId() && Tinebase_Container::getInstance()->hasGrant($userAccountId, $_attender->displaycontainer_id, Tinebase_Model_Grants::GRANT_ADMIN)) {
                 // allow user to set his own displ. cal
                 $_attender->displaycontainer_id = $_attender->displaycontainer_id;
             } else {
                 $displayCalId = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, $userAccountId);
                 if ($displayCalId) {
                     $_attender->displaycontainer_id = $displayCalId;
                 }
             }
         }
     }
     if ($_attender->user_type === Calendar_Model_Attender::USERTYPE_RESOURCE) {
         $resource = Calendar_Controller_Resource::getInstance()->get($_attender->user_id);
         $_attender->displaycontainer_id = $resource->container_id;
     }
     $this->_backend->createAttendee($_attender);
 }