/** * search tree nodes * * @param Tinebase_Model_Filter_FilterGroup|optional $_filter * @param Tinebase_Model_Pagination|optional $_pagination * @param bool $_getRelations * @param bool $_onlyIds * @param string|optional $_action * @return Tinebase_Record_RecordSet of Tinebase_Model_Tree_Node */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Record_Interface $_pagination = NULL, $_getRelations = FALSE, $_onlyIds = FALSE, $_action = 'get') { $path = $this->_checkFilterACL($_filter, $_action); if ($path->containerType === Tinebase_Model_Tree_Node_Path::TYPE_ROOT) { $result = $this->_getRootNodes(); } else { if ($path->containerType === Tinebase_Model_Container::TYPE_PERSONAL && !$path->containerOwner) { if (!file_exists($path->statpath)) { $this->_backend->mkdir($path->statpath); } $result = $this->_getOtherUserNodes(); } else { try { $result = $this->_backend->searchNodes($_filter, $_pagination); } catch (Tinebase_Exception_NotFound $tenf) { // create basic nodes like personal|shared|user root if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $path->statpath); } if ($path->name === Tinebase_Model_Container::TYPE_SHARED || $path->statpath === $this->_backend->getApplicationBasePath(Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName), Tinebase_Model_Container::TYPE_PERSONAL) . '/' . $this->_currentAccount->getId()) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating new path ' . $path->statpath); } $this->_backend->mkdir($path->statpath); $result = $this->_backend->searchNodes($_filter, $_pagination); } else { throw $tenf; } } $this->resolveContainerAndAddPath($result, $path); $this->_sortContainerNodes($result, $path, $_pagination); } } return $result; }
/** * fetches attachments for multiple records at once * * @param Tinebase_Record_RecordSet $records * * @todo maybe this should be improved */ public function getMultipleAttachmentsOfRecords($records) { if ($records instanceof Tinebase_Record_Abstract) { $records = new Tinebase_Record_RecordSet(get_class($records), array($records)); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Fetching attachments for ' . count($records) . ' record(s)'); } $parentNodes = new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node'); $recordNodeMapping = array(); $typeMap = array(); foreach ($records as $record) { $typeMap[get_class($record)][] = $record->getId(); $record->attachments = new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node'); } foreach ($typeMap as $className => $recordIds) { $classPathName = $this->_fsController->getApplicationBasePath($record->getApplication(), Tinebase_FileSystem::FOLDER_TYPE_RECORDS) . '/' . $className; // top folder for record attachments try { $classPathNode = $this->_fsController->stat($classPathName); } catch (Tinebase_Exception_NotFound $tenf) { continue; } // subfolders for all records attachments $searchFilter = new Tinebase_Model_Tree_Node_Filter(array(array('field' => 'parent_id', 'operator' => 'equals', 'value' => $classPathNode->getId()), array('field' => 'name', 'operator' => 'in', 'value' => $recordIds))); $recordNodes = $this->_fsController->searchNodes($searchFilter); if ($recordNodes->count() === 0) { // nothing to be done continue; } foreach ($recordNodes as $recordNode) { $recordNodeMapping[$recordNode->getId()] = $recordNode->name; } // get attachments $attachmentNodes = $this->_fsController->getTreeNodeChildren($recordNodes); // add attachments to records foreach ($attachmentNodes as $attachmentNode) { $record = $records->getById($recordNodeMapping[$attachmentNode->parent_id]); $record->attachments->addRecord($attachmentNode); } } }