/** * test toArray() implementation */ public function testToArray() { $resultArray = $this->object->toArray(); for ($i = 0; $i < count($this->object); $i++) { $this->assertEquals($this->object[$i]->toArray(), $resultArray[$i]); } }
/** * get grants for records * * @param Tinebase_Record_RecordSet $records */ public function getGrantsForRecords(Tinebase_Record_RecordSet $records) { $recordIds = $records->getArrayOfIds(); if (empty($recordIds)) { return; } $select = $this->_getAclSelectByRecordIds($recordIds)->group(array('record_id', 'account_type', 'account_id')); Tinebase_Backend_Sql_Abstract::traitGroup($select); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $select); } $stmt = $this->_db->query($select); $grantsData = $stmt->fetchAll(Zend_Db::FETCH_ASSOC); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' grantsData: ' . print_r($grantsData, true)); } foreach ($grantsData as $grantData) { $givenGrants = explode(',', $grantData['account_grants']); foreach ($givenGrants as $grant) { $grantData[$grant] = TRUE; } $recordGrant = new $this->_modelName($grantData, true); unset($recordGrant->account_grant); $record = $records->getById($recordGrant->record_id); if (!$record->grants instanceof Tinebase_Record_RecordSet) { $record->grants = new Tinebase_Record_RecordSet($this->_modelName); } $record->grants->addRecord($recordGrant); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Records with grants: ' . print_r($records->toArray(), true)); } }
/** * convert Tinebase_Record_RecordSet to Sabre\VObject\Component * * @param Tinebase_Record_RecordSet $_records * @return Sabre\VObject\Component */ public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Events: ' . print_r($_records->toArray(), true)); } // required vcalendar fields $version = Tinebase_Application::getInstance()->getApplicationByName('Calendar')->version; $vcalendar = new \Sabre\VObject\Component\VCalendar(array('PRODID' => "-//tine20.com//Tine 2.0 Calendar V{$version}//EN", 'VERSION' => '2.0', 'CALSCALE' => 'GREGORIAN')); if (isset($this->_method)) { $vcalendar->add('METHOD', $this->_method); } $originatorTz = $_records->getFirstRecord() ? $_records->getFirstRecord()->originator_tz : NULL; if (empty($originatorTz)) { throw new Tinebase_Exception_Record_Validation('originator_tz needed for conversion to Sabre\\VObject\\Component'); } try { $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz)); } catch (Exception $e) { Tinebase_Exception::log($e); throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $originatorTz); } foreach ($_records as $_record) { $this->_convertCalendarModelEvent($vcalendar, $_record); if ($_record->exdate instanceof Tinebase_Record_RecordSet) { $_record->exdate->addIndices(array('is_deleted')); $eventExceptions = $_record->exdate->filter('is_deleted', false); foreach ($eventExceptions as $eventException) { $this->_convertCalendarModelEvent($vcalendar, $eventException, $_record); } } } $this->_afterFromTine20Model($vcalendar); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' card ' . $vcalendar->serialize()); } return $vcalendar; }
/** * get path of node * * @param Tinebase_Model_Tree_Node|string $node * @param boolean $getPathAsString * @return array|string */ public function getPathOfNode($node, $getPathAsString = FALSE) { $node = $node instanceof Tinebase_Model_Tree_Node ? $node : $this->get($node); $nodesPath = new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node', array($node)); while ($node->parent_id) { $node = $this->get($node->parent_id); $nodesPath->addRecord($node); } $result = $getPathAsString ? '/' . implode('/', array_reverse($nodesPath->name)) : array_reverse($nodesPath->toArray()); return $result; }
/** * updates dependent records on update the parent record * * @param Tinebase_Record_Interface $_record * @param Tinebase_Record_Interface $_oldRecord * @param string $_property * @param array $_fieldConfig */ protected function _updateDependentRecords(Tinebase_Record_Interface $_record, Tinebase_Record_Interface $_oldRecord, $_property, $_fieldConfig) { if (!(isset($_fieldConfig['dependentRecords']) || array_key_exists('dependentRecords', $_fieldConfig)) || !$_fieldConfig['dependentRecords']) { return; } if (!isset($_fieldConfig['refIdField'])) { throw new Tinebase_Exception_Record_DefinitionFailure('If a record is dependent, a refIdField has to be defined!'); } // don't handle dependent records on property if it is set to null or doesn't exist. if ($_record->{$_property} === NULL || !$_record->has($_property)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Skip updating dependent records (got NULL) on property ' . $_property . ' for ' . $this->_applicationName . ' ' . $this->_modelName . ' with id = "' . $_record->getId() . '"'); } return; } $ccn = $_fieldConfig['controllerClassName']; $controller = $ccn::getInstance(); $recordClassName = $_fieldConfig['recordClassName']; $filterClassName = $_fieldConfig['filterClassName']; $existing = new Tinebase_Record_RecordSet($recordClassName); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_record->{$_property}, TRUE)); } if (!empty($_record->{$_property}) && $_record->{$_property}) { // legacy - should be already done in frontend json - remove if all record properties are record sets before getting to controller if (is_array($_record->{$_property})) { $rs = new Tinebase_Record_RecordSet($recordClassName); foreach ($_record->{$_property} as $recordArray) { $rec = new $recordClassName(array(), true); $rec->setFromJsonInUsersTimezone($recordArray); $rs->addRecord($rec); } $_record->{$_property} = $rs; } $idProperty = $_record->{$_property}->getFirstRecord()->getIdProperty(); // legacy end $oldFilter = new $filterClassName(array(array('field' => $idProperty, 'operator' => 'in', 'value' => $_record->{$_property}->getId()))); $oldRecords = $controller->search($oldFilter); foreach ($_record->{$_property} as $record) { $record->{$_fieldConfig['refIdField']} = $_record->getId(); // update record if ID exists and has a length of 40 (it has a length of 10 if it is a timestamp) if ($record->getId() && strlen($record->getId()) == 40) { // do not try to update if the record hasn't changed $oldRecord = $oldRecords->getById($record->getId()); if ($oldRecord && !empty($oldRecord->diff($record)->diff)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating dependent record with id = "' . $record->getId() . '" on property ' . $_property . ' for ' . $this->_applicationName . ' ' . $this->_modelName); } $existing->addRecord($controller->update($record)); } else { $existing->addRecord($record); } // create if is not existing already } else { // try to find if it already exists (with corrupted id) if ($record->getId() == NULL) { $crc = $controller->create($record); $existing->addRecord($crc); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating dependent record with id = "' . $crc->getId() . '" on property ' . $_property . ' for ' . $this->_applicationName . ' ' . $this->_modelName); } } else { try { $prevRecord = $controller->get($record->getId()); if (!empty($prevRecord->diff($record)->diff)) { $existing->addRecord($controller->update($record)); } else { $existing->addRecord($record); } } catch (Tinebase_Exception_NotFound $e) { $record->id = NULL; $crc = $controller->create($record); $existing->addRecord($crc); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating dependent record with id = "' . $crc->getId() . '" on property ' . $_property . ' for ' . $this->_applicationName . ' ' . $this->_modelName); } } } } } } $filter = new $filterClassName(isset($_fieldConfig['addFilters']) ? $_fieldConfig['addFilters'] : array(), 'AND'); $filter->addFilter(new Tinebase_Model_Filter_Text($_fieldConfig['refIdField'], 'equals', $_record->getId())); // an empty array will remove all records on this property if (!empty($_record->{$_property})) { $filter->addFilter(new Tinebase_Model_Filter_Id('id', 'notin', $existing->getId())); } $deleteIds = $controller->search($filter, NULL, FALSE, TRUE); if (!empty($deleteIds)) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deleting dependent records with id = "' . print_r($deleteIds, 1) . '" on property ' . $_property . ' for ' . $this->_applicationName . ' ' . $this->_modelName); } $controller->delete($deleteIds); } $_record->{$_property} = $existing->toArray(); }
/** * get rules for account * * @param string $_accountId * @return Tinebase_Record_RecordSet of Felamimail_Model_Sieve_Rule */ public function getRules($_accountId) { $result = new Tinebase_Record_RecordSet('Felamimail_Model_Sieve_Rule'); $script = $this->_getSieveScript($_accountId); if ($script !== NULL) { foreach ($script->getRules() as $fsr) { $rule = new Felamimail_Model_Sieve_Rule(); $rule->setFromFSR($fsr); $result->addRecord($rule); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($result->toArray(), TRUE)); } } else { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Sieve script empty or could not parse it.'); } } return $result; }
/** * add/create shared tags if they don't exist * * @param array $_tags array of tag strings * @return Tinebase_Record_RecordSet with Tinebase_Model_Tag */ protected function _addSharedTags($_tags) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding tags: ' . print_r($_tags, TRUE)); } $result = new Tinebase_Record_RecordSet('Tinebase_Model_Tag'); foreach ($_tags as $tagData) { $tagData = is_array($tagData) ? $tagData : array('name' => $tagData); $tagName = trim($tagData['name']); // only check non-empty tags if (empty($tagName)) { continue; } $createTag = isset($this->_options['shared_tags']) && $this->_options['shared_tags'] == 'create'; $tagToAdd = $this->_getSingleTag($tagName, $tagData, $createTag); if ($tagToAdd) { $result->addRecord($tagToAdd); } } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($result->toArray(), TRUE)); } return $result; }
/** * returns existing nodes info as array * * @return array */ public function toArray() { $this->getExistingNodesInfo()->setTimezone(Tinebase_Core::getUserTimezone()); return array('existingnodesinfo' => $this->_existingNodes->toArray()); }
/** * assert status authkey with editGrant * assert stauts can be set with editGrant * assert stauts can't be set without editGrant */ public function testResourceAttendeeGrants() { $editableResoureData = $this->testSaveResource(); $nonEditableResoureData = $this->testSaveResource(array('readGrant')); $event = $this->_getEvent(TRUE); $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $editableResoureData['id'], 'status' => Calendar_Model_Attender::STATUS_ACCEPTED), array('user_type' => Calendar_Model_Attender::USERTYPE_RESOURCE, 'user_id' => $nonEditableResoureData['id'], 'status' => Calendar_Model_Attender::STATUS_ACCEPTED))); $persistentEventData = $this->_uit->saveEvent($event->toArray()); $attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', $persistentEventData['attendee']); $this->assertEquals(1, count($attendee->filter('status', Calendar_Model_Attender::STATUS_ACCEPTED)), 'one accepted'); $this->assertEquals(1, count($attendee->filter('status', Calendar_Model_Attender::STATUS_NEEDSACTION)), 'one needs action'); $this->assertEquals(1, count($attendee->filter('status_authkey', '/[a-z0-9]+/', TRUE)), 'one has authkey'); $attendee->status = Calendar_Model_Attender::STATUS_TENTATIVE; $persistentEventData['attendee'] = $attendee->toArray(); $updatedEventData = $this->_uit->saveEvent($persistentEventData); $attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', $updatedEventData['attendee']); $this->assertEquals(1, count($attendee->filter('status', Calendar_Model_Attender::STATUS_TENTATIVE)), 'one tentative'); }
protected function _inspectBeforeUpdate($_record, $_oldRecord) { // if empty, no changes have been made // @todo: lookforward: parts - parameter if (empty($_record->freedays)) { return; } $freeDays = new Tinebase_Record_RecordSet('HumanResources_Model_FreeDay'); $fc = HumanResources_Controller_FreeDay::getInstance(); $freetimeId = $_record->getId(); foreach ($_record->freedays as $freedayArray) { $freedayArray['freetime_id'] = $freetimeId; $freeday = new HumanResources_Model_FreeDay($freedayArray); if ($freeday->id) { $freeDays->addRecord($fc->update($freeday)); } else { $freeDays->addRecord($fc->create($freeday)); } } $filter = new HumanResources_Model_FreeDayFilter(array(), 'AND'); $filter->addFilter(new Tinebase_Model_Filter_Text('freetime_id', 'equals', $_record->getId())); $filter->addFilter(new Tinebase_Model_Filter_Id('id', 'notin', $freeDays->id)); $deleteFreedays = HumanResources_Controller_FreeDay::getInstance()->search($filter); // update first and last date $freeDays->sort('date', 'ASC'); $_record->firstday_date = $freeDays->getFirstRecord()->date; $freeDays->sort('date', 'DESC'); $_record->lastday_date = $freeDays->getFirstRecord()->date; $_record->days_count = $freeDays->count(); $fc->delete($deleteFreedays->id); $_record->freedays = $freeDays->toArray(); if ($_record->type == 'sickness') { $this->_handleOverwrittenVacation($_record); } }