/** * rebuild paths for multiple records in an iteration * @see Tinebase_Record_Iterator / self::rebuildPaths() * * @param Tinebase_Record_RecordSet $records * @param Tinebase_Controller_Abstract $controller */ public function rebuildPathsIteration(Tinebase_Record_RecordSet $records, Tinebase_Controller_Record_Abstract $controller) { foreach ($records as $record) { try { $controller->buildPath($record, true); } catch (Exception $e) { Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' record path building failed: ' . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL . $record->toArray()); } } }
/** * appends sql to given select statement * * @param Zend_Db_Select $_select * @param Tinebase_Backend_Sql_Abstract $_backend */ public function appendFilterSql($_select, $_backend) { $db = Tinebase_Core::getDb(); if (!is_array($this->_foreignIdsP1)) { $this->_foreignIdsP1 = $this->_controllerP1->search($this->_filterGroupP1, new Tinebase_Model_Pagination(), FALSE, TRUE); } $filters = array(array('field' => 'contact_id', 'operator' => 'AND', 'value' => array(array('field' => 'id', 'operator' => 'in', 'value' => $this->_foreignIdsP1)))); $this->_filterGroup = new $this->_options['filtergroup']($filters); if (!is_array($this->_foreignIds)) { $this->_foreignIds = $this->_controller->search($this->_filterGroup, new Tinebase_Model_Pagination(), FALSE, TRUE); } $_select->where('bill_open_item.debitor_id' . ' IN (?)', empty($this->_foreignIds) ? array('') : $this->_foreignIds); }
/** * get records and resolve fields * * @return Tinebase_Record_RecordSet */ protected function _getRecords() { $pagination = !empty($this->_options['sortInfo']) ? new Tinebase_Model_Pagination($this->_options['sortInfo']) : new Tinebase_Model_Pagination(); if ($this->_recordIds === NULL) { // need to fetch record ids first because filtered fields can change during iteration step if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Getting record ids using filter: ' . print_r($this->_filter->toArray(), TRUE) . ' and pagination: ' . print_r($pagination->toArray(), true)); } $this->_recordIds = $this->_controller->search($this->_filter, $pagination, FALSE, TRUE, $this->_options['searchAction']); $this->_totalCount = count($this->_recordIds); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . $this->_totalCount . ' total records to process.'); } if (empty($this->_recordIds)) { return new Tinebase_Record_RecordSet($this->_filter->getModelName()); } } // get records by filter (ensure acl) $filterClassname = get_class($this->_filter); $recordIdsForIteration = array_splice($this->_recordIds, 0, $this->_options['limit']); $idFilter = new $filterClassname(array(array('field' => isset($this->_options['idProperty']) || array_key_exists('idProperty', $this->_options) ? $this->_options['idProperty'] : 'id', 'operator' => 'in', 'value' => $recordIdsForIteration))); $records = $this->_controller->search($idFilter, $pagination, $this->_options['getRelations']); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got ' . count($records) . ' for next iteration.'); } return $records; }
/** * get foreign controller * * @return Tinebase_Controller_Record_Abstract */ protected function _getController() { if ($this->_controller === NULL) { $this->_controller = Tinebase_Controller_Record_Abstract::getController($this->_options['related_model']); } return $this->_controller; }
/** * search for leads * * @param Tinebase_Model_Filter_FilterGroup $_filter * @param Tinebase_Record_Interface $_pagination * @param boolean $_getRelations * @param boolean $_onlyIds * @param string $_action for right/acl check * @return Tinebase_Record_RecordSet */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Record_Interface $_pagination = NULL, $_getRelations = FALSE, $_onlyIds = FALSE, $_action = 'get') { $leads = parent::search($_filter, $_pagination, $_getRelations, $_onlyIds, $_action); if ($_getRelations) { $leads->setByIndices('relations', Tinebase_Relations::getInstance()->getMultipleRelations($this->_modelName, $this->_backend->getType(), $leads->getId(), NULL, array('CUSTOMER', 'PARTNER', 'TASK', 'RESPONSIBLE', 'PRODUCT'), FALSE, $_getRelations)); } return $leads; }
protected function _importRecord(Tinebase_Record_Abstract $_record) { if ($_record->getId()) { return $this->_controllerToImport->update($_record, false); } else { return $this->_controllerToImport->create($_record, false); } }
/** * add one record * * @param Tinebase_Record_Interface $_record * @return Sales_Model_Contract */ public function create(Tinebase_Record_Interface $_record) { // add container $_record->container_id = self::getSharedContractsContainer()->getId(); // add number $numberBackend = new Sales_Backend_Number(); $number = $numberBackend->getNext(Sales_Model_Number::TYPE_CONTRACT, $this->_currentAccount->getId()); $_record->number = $number->number; return parent::create($_record); }
/** * get id's of all entries available on the server * * @param string $_folderId * @param int $_filterType * @return array */ public function getServerEntries($_folderId, $_filterType) { $filter = $this->_getContentFilter($_filterType); $this->_addContainerFilter($filter, $_folderId); if (!empty($this->_sortField)) { $pagination = new Tinebase_Model_Pagination(array('sort' => $this->_sortField)); } else { $pagination = null; } //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " assembled {$this->_contentFilterClass}: " . print_r($filter->toArray(), TRUE)); $result = $this->_contentController->search($filter, $pagination, false, true, 'sync'); return $result; }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::update() */ public function update(Tinebase_Record_Interface $_record) { parent::update($_record); // after update if ($this->mustUpdateReceiptAtOnce()) { try { $receiptPosition = Billing_Controller_ReceiptPosition::getInstance()->getByOrderPositionId($_record->getId()); $receipt = $receiptPosition->getForeignRecordBreakNull('receipt_id', Billing_Controller_Receipt::getInstance()); if ($receipt) { Billing_Controller_ReceiptPosition::getInstance()->updateReceipt($receipt); } } catch (Tinebase_Exception_NotFound $e) { // no receipt to be updated } } return $this->get($_record->getId()); }
/** * * @param string $folderId * @param int $filterType * @return Tinebase_Record_RecordSet */ public function getServerEntries($folderId, $filterType) { $maxFilterType = $this->getMaxFilterType(); if ($maxFilterType !== Syncroton_Command_Sync::FILTER_NOTHING) { if ($filterType === Syncroton_Command_Sync::FILTER_NOTHING || $maxFilterType < $filterType) { $filterType = $maxFilterType; } } $filter = $this->_getContentFilter($filterType); $this->_addContainerFilter($filter, $folderId); if (!empty($this->_sortField)) { $pagination = new Tinebase_Model_Pagination(array('sort' => $this->_sortField)); } else { $pagination = null; } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " Assembled {$this->_contentFilterClass}: " . print_r($filter->toArray(), TRUE)); } $result = $this->_contentController->search($filter, $pagination, false, true, 'sync'); return $result; }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied */ public function update(Tinebase_Record_Interface $_record) { $container = Tinebase_Container::getInstance()->getContainerById($_record->container_id); $container->name = $_record->name; Tinebase_Container::getInstance()->update($container); return parent::update($_record); }
/** * delete one record * - don't delete if it belongs to an user account * * @param Tinebase_Record_Interface $_record * @throws Addressbook_Exception_AccessDenied */ protected function _deleteRecord(Tinebase_Record_Interface $_record) { if (!empty($_record->account_id)) { throw new Addressbook_Exception_AccessDenied('It is not allowed to delete a contact linked to an user account!'); } parent::_deleteRecord($_record); }
/** * add related data / grants to record * * @param Tinebase_Record_Interface $record */ protected function _getRelatedData($record) { parent::_getRelatedData($record); if (empty($record->grants)) { // grants may have already been fetched $this->_getGrants($record); } }
/** * Deletes a set of records. * * @param array array of record identifiers * @return void */ public function delete($_ids) { parent::delete($_ids); // check if default account got deleted and set new default account if (in_array(Tinebase_Core::getPreference($this->_applicationName)->{Felamimail_Preference::DEFAULTACCOUNT}, (array) $_ids)) { $accounts = $this->search(); $defaultAccountId = count($accounts) > 0 ? $accounts->getFirstRecord()->getId() : ''; Tinebase_Core::getPreference($this->_applicationName)->{Felamimail_Preference::DEFAULTACCOUNT} = $defaultAccountId; } }
/** * get by id * * @param string $_id * @param int $_containerId * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied */ public function get($_id, $_containerId = NULL) { $record = parent::get($_id, $_containerId); $this->_doPrivateCleanup($record); return $record; }
/** * add related data to record * * @param Addressbook_Model_List $record */ protected function _getRelatedData($record) { $memberRoles = $this->_getMemberRoles($record); if (count($memberRoles) > 0) { $record->memberroles = $memberRoles; } parent::_getRelatedData($record); }
/** * get list of records * * @param Tinebase_Model_Filter_FilterGroup $_filter * @param Tinebase_Model_Pagination $_pagination * @param boolean $_getRelations * @param boolean $_onlyIds * @param string $_action for right/acl check * @return Tinebase_Record_RecordSet|array */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL, $_getRelations = FALSE, $_onlyIds = FALSE, $_action = 'get') { $_filter->setId('OuterFilter'); return parent::search($_filter, $_pagination, $_getRelations, $_onlyIds, $_action); }
/** * Deletes a set of records. * * If one of the records could not be deleted, no record is deleted * * @param array array of record identifiers * @return void * @throws Tinebase_Exception_NotFound|Tinebase_Exception */ public function delete($_ids) { $courses = $this->getMultiple($_ids); $groupsToDelete = array(); $usersToDelete = array(); foreach ($courses as $course) { $groupsToDelete[] = $course->group_id; $usersToDelete = array_merge($usersToDelete, $this->_groupController->getGroupMembers($course->group_id)); } Courses_Controller::getInstance()->suspendEvents(); $this->_userController->delete(array_unique($usersToDelete)); $this->_groupController->delete(array_unique($groupsToDelete)); Courses_Controller::getInstance()->resumeEvents(); parent::delete($_ids); }
/** * delete linked objects (notes, relations, ...) of record * * @param Tinebase_Record_Interface $_record */ protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record) { try { Tinebase_Container::getInstance()->deleteContainer($_record->container_id, true); } catch (Tinebase_Exception_NotFound $tenf) { Tinebase_Exception::log($tenf, false, $_record->toArray()); } return parent::_deleteLinkedObjects($_record); }
/** * delete linked objects / timesheets * * @param Tinebase_Record_Interface $_record */ protected function _deleteLinkedObjects(Tinebase_Record_Interface $_record) { // delete linked timesheets $timesheets = Timetracker_Controller_Timesheet::getInstance()->getTimesheetsByTimeaccountId($_record->getId()); Timetracker_Controller_Timesheet::getInstance()->delete($timesheets->getArrayOfIds()); // delete other linked objects parent::_deleteLinkedObjects($_record); }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::get() */ public function get($_id, $_containerId = NULL) { if (!$this->_checkACLContainer($this->_backend->getNodeContainer($_id), 'get')) { throw new Tinebase_Exception_AccessDenied('No permission to get node'); } $record = parent::get($_id); if ($record) { $record->notes = Tinebase_Notes::getInstance()->getNotesOfRecord('Tinebase_Model_Tree_Node', $record->getId()); } return $record; }
/** * add one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied */ public function create(Tinebase_Record_Interface $_record) { // check first if we already have a filter with this name for this account/application in the db $this->_sanitizeAccountId($_record); $existing = $this->search(new Tinebase_Model_PersistentFilterFilter(array('account_id' => $_record->account_id, 'application_id' => $_record->application_id, 'name' => $_record->name))); if (count($existing) > 0) { $_record->setId($existing->getFirstRecord()->getId()); $result = $this->update($_record); } else { $result = parent::create($_record); } return $result; }
/** * detach a single tag from records * * @param array $recordIds * @param string $dirtyTagId * @param string $appId * @param Tinebase_Controller_Record_Abstract $controller */ protected function _detachSingleTag($recordIds, $dirtyTagId, $appId, $controller) { $tag = $this->getTagsById($dirtyTagId, Tinebase_Model_TagRight::USE_RIGHT)->getFirstRecord(); if (empty($tag)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' No use right for tag, detaching not possible.'); return; } $tagId = $tag->getId(); $attachedIds = array(); $select = $this->_db->select()->from(array('tagging' => SQL_TABLE_PREFIX . 'tagging'), 'record_id')->where($this->_db->quoteIdentifier('application_id') . ' = ?', $appId)->where($this->_db->quoteIdentifier('tag_id') . ' = ? ', $tagId)->where($this->_db->quoteInto($this->_db->quoteIdentifier('record_id') . ' IN (?)', $recordIds)); Tinebase_Backend_Sql_Abstract::traitGroup($select); foreach ($this->_db->fetchAssoc($select) as $tagArray) { $attachedIds[] = $tagArray['record_id']; } if (empty($attachedIds)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' There are no records we could detach the tag(s) from'); return; } Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Detaching 1 Tag from ' . count($attachedIds) . ' records.'); foreach ($attachedIds as $recordId) { $this->_db->delete(SQL_TABLE_PREFIX . 'tagging', array($this->_db->quoteIdentifier('tag_id') . ' = ?' => $tagId, $this->_db->quoteIdentifier('record_id') . ' = ?' => $recordId, $this->_db->quoteIdentifier('application_id') . ' = ?' => $appId)); } $controller->concurrencyManagementAndModlogMultiple($attachedIds, array('tags' => array($tag->toArray())), array('tags' => array())); $this->_deleteOccurrence($tagId, count($attachedIds)); }
/** * update one record * * @param Tinebase_Record_Interface $_record * @param boolean $_duplicateCheck * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * */ public function update(Tinebase_Record_Interface $_record, $_duplicateCheck = TRUE) { $sharedSeenValue = $_record->shared_seen; $updatedRecord = parent::update($_record, $_duplicateCheck); if ($this->_checkSharedSeenSupport($_record)) { $updatedRecord->shared_seen_support = TRUE; if ($this->_setSharedSeenValue($_record, $sharedSeenValue)) { $updatedRecord->shared_seen = $sharedSeenValue; } else { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' Imap command failed when setting sharedseen value!'); $translate = Tinebase_Translation::getTranslation('Expressomail'); $message = $translate->_('Imap command failed when setting sharedseen value!'); throw new Expressomail_Exception_IMAPCommandFailed($message); } } Tinebase_Core::setupCache(); $cache = Tinebase_Core::getCache(); $cache->save($updatedRecord, $this->_createExpressomailModelAccountCacheId($updatedRecord->id), array('expressomailAccount')); return $updatedRecord; }
/** * fetch one tag identified by tagid * * @param int $_tagId * @return Tinebase_Model_FullTag */ public function get($_tagId) { $fullTag = parent::get($_tagId); $fullTag->rights = Tinebase_Tags::getInstance()->getRights($_tagId); $fullTag->contexts = Tinebase_Tags::getInstance()->getContexts($_tagId); return $fullTag; }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::update() */ public function update(Tinebase_Record_Interface $_record) { parent::update($_record); // after update if ($this->mustUpdateReceiptAtOnce($receiptPosition->getForeignRecord('receipt_id', Billing_Controller_Receipt::getInstance()))) { $this->updateReceipt($_record); } return $this->get($_record->getId()); }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::getMultiple() */ public function getMultiple($_ids, $_ignoreACL = FALSE) { $result = parent::getMultiple($_ids, $_ignoreACL); $this->_removeHiddenListMembers($result); return $result; }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * @throws Tinebase_Exception_Record_Validation */ public function update(Tinebase_Record_Interface $_task) { $this->_handleCompleted($_task); return parent::update($_task); }
/** * search for duplicates * * @param Tinebase_Controller_Record_Interface $_controller * @param Tinebase_Model_Filter_FilterGroup * @param string $_field * @return array with ids / field * * @todo add more options (like soundex, what do do with duplicates/delete/merge them, ...) */ protected function _searchDuplicates(Tinebase_Controller_Record_Abstract $_controller, $_filter, $_field) { $pagination = new Tinebase_Model_Pagination(array('start' => 0, 'limit' => 100)); $results = array(); $allRecords = array(); $totalCount = $_controller->searchCount($_filter); echo 'Searching ' . $totalCount . " record(s) for duplicates\n"; while ($pagination->start < $totalCount) { $records = $_controller->search($_filter, $pagination); foreach ($records as $record) { if (in_array($record->{$_field}, $allRecords)) { $allRecordsFlipped = array_flip($allRecords); $duplicateId = $allRecordsFlipped[$record->{$_field}]; $results[] = array('id' => $duplicateId, 'value' => $record->{$_field}); $results[] = array('id' => $record->getId(), 'value' => $record->{$_field}); } $allRecords[$record->getId()] = $record->{$_field}; } $pagination->start += 100; } return $results; }
/** * (non-PHPdoc) * @see Tinebase_Controller_Record_Abstract::create() */ public function create(Tinebase_Record_Interface $_record) { // if no explicit payment method given: // inherit payment method from order, or get default $order = $_record->getForeignRecord('order_id', Billing_Controller_Order::getInstance()); if (!$_record->__get('payment_method_id')) { $paymentMethodId = Billing_Controller_PaymentMethod::getInstance()->getPaymentMethodFromRecordOrDefault($order, 'payment_method_id')->getId(); $_record->__set('payment_method_id', $paymentMethodId); } $record = parent::create($_record); /*$type = $_record->__get('type'); switch($type){ case Billing_Model_Receipt::TYPE_INVOICE: case Billing_Model_Receipt::TYPE_CREDIT: $receipt = $this->get($record->getId()); Tinebase_Event::fireEvent(new Billing_Events_BillableReceiptCreated($receipt)); break; }*/ return $record; }