/**
  * appends sql to given select statement
  *
  * @param  Zend_Db_Select                    $_select
  * @param  Tinebase_Backend_Sql_Abstract     $_backend
  * 
  * @todo allow multiple role/status filters?
  */
 public function appendFilterSql($_select, $_backend)
 {
     if (!is_array($this->_foreignIds)) {
         $this->_getFilterData();
         $events = $this->_controller->search($this->_filterGroup);
         Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($events, $this->_filterGroup);
         $this->_getForeignIds($events);
     }
     // this is supposed to run in ContactFilter context
     $contactIdFilter = new Addressbook_Model_ContactIdFilter('id', 'in', $this->_foreignIds);
     $contactIdFilter->appendFilterSql($_select, $_backend);
 }
 /**
  * export records
  */
 protected function _exportRecords()
 {
     // to support rrule & sorting we can't do pagination in calendar exports
     $records = $this->_controller->search($this->_filter, NULL, $this->_getRelations, false, 'export');
     Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($records, $this->_filter);
     $this->_sortRecords($records);
     $this->_resolveRecords($records);
     foreach ($records as $idx => $record) {
         $this->processRecord($record, $idx);
     }
     $result = array();
     $this->_onAfterExportRecords($result);
 }
 /**
  * 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;
 }
Exemple #4
0
 /**
  * returns multiple records prepared for json transport
  *
  * @param Tinebase_Record_RecordSet $_records Tinebase_Record_Abstract
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination $_pagination needed for sorting
  * @return array data
  * 
  * @todo perhaps we need to resolveContainerTagsUsers() before  mergeAndRemoveNonMatchingRecurrences(), but i'm not sure about that
  * @todo use Calendar_Convert_Event_Json
  */
 protected function _multipleRecordsToJson(Tinebase_Record_RecordSet $_records, $_filter = NULL, $_pagination = NULL)
 {
     if ($_records->getRecordClassName() == 'Calendar_Model_Event') {
         if (is_null($_filter)) {
             throw new Tinebase_Exception_InvalidArgument('Required argument $_filter is missing');
         }
         Tinebase_Notes::getInstance()->getMultipleNotesOfRecords($_records);
         Calendar_Model_Attender::resolveAttendee($_records->attendee, TRUE, $_records);
         Calendar_Convert_Event_Json::resolveOrganizer($_records);
         Calendar_Convert_Event_Json::resolveRrule($_records);
         Calendar_Controller_Event::getInstance()->getAlarms($_records);
         Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($_records, $_filter);
         $_records->sortByPagination($_pagination);
         $eventsData = parent::_multipleRecordsToJson($_records);
         foreach ($eventsData as $eventData) {
             if (!array_key_exists(Tinebase_Model_Grants::GRANT_READ, $eventData) || !$eventData[Tinebase_Model_Grants::GRANT_READ]) {
                 $eventData['notes'] = array();
                 $eventData['tags'] = array();
             }
         }
         return $eventsData;
     }
     return parent::_multipleRecordsToJson($_records);
 }
 /**
  * print alarm acknowledgement report (when, ip, client, user, ...)
  * 
  * @param Zend_Console_Getopt $_opts
  */
 public function alarmAckReport(Zend_Console_Getopt $_opts)
 {
     $until = Tinebase_DateTime::now();
     $from = Tinebase_DateTime::now()->subDay(1);
     // get all events for today for current user
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'attender', 'operator' => 'in', 'value' => array(array('user_type' => 'user', 'user_id' => Tinebase_Core::getUser()->contact_id))), array('field' => 'attender_status', 'operator' => 'not', 'value' => Calendar_Model_Attender::STATUS_DECLINED), array('field' => 'period', 'operator' => 'within', 'value' => array("from" => $from, "until" => $until))));
     $events = Calendar_Controller_Event::getInstance()->search($filter);
     Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($events, $filter);
     Calendar_Controller_Event::getInstance()->getAlarms($events);
     echo "Reporting alarms for events of user " . Tinebase_Core::getUser()->accountLoginName . " (All times in UTC) from " . $from->toString() . ' until ' . $until->toString() . "...\n\n";
     // loop alarms and print alarm ack info
     foreach ($events as $event) {
         if (count($event->alarms) > 0) {
             $this->_printShortEvent($event);
             foreach ($event->alarms as $alarm) {
                 echo "  Alarm " . $alarm->alarm_time . "\n";
                 $ackTime = Calendar_Controller_Alarm::getAcknowledgeTime($alarm);
                 if (empty($ackTime)) {
                     echo "    not acknowledged!";
                 } else {
                     if (is_array($ackTime)) {
                         $ackTime = array_pop($ackTime);
                     }
                     echo "    acknowledged " . $ackTime->toString() . "\n    IP -> " . $alarm->getOption(Tinebase_Model_Alarm::OPTION_ACK_IP) . "\n    Client ->" . $alarm->getOption(Tinebase_Model_Alarm::OPTION_ACK_CLIENT) . "\n";
                 }
                 echo "\n";
             }
             echo "\n";
         }
     }
 }
 protected function _getEventsForPeriodAndCalendar($calendarId, $from, $until)
 {
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'period', 'operator' => 'within', 'value' => array("from" => $from, "until" => $until)), array('field' => 'container_id', 'operator' => 'equals', 'value' => $calendarId)));
     $events = Calendar_Controller_Event::getInstance()->search($filter);
     Calendar_Model_Rrule::mergeAndRemoveNonMatchingRecurrences($events, $filter);
     return $events;
 }