/** * Adds an individual folder hierarchy for an imap account. * * @param integer $accountId * @param integer $userId * @param string $name The name of the account to use as the folders name * * @return integer The total number of data inserted */ public function createFolderHierarchyForImapAccount($accountId, $userId, $name) { $accountId = (int) $accountId; $userId = (int) $userId; $name = trim((string) $name); if ($accountId == 0 || $userId == 0 || $name == "") { return 0; } $adapter = $this->getAdapter(); $adapter->beginTransaction(); $ids = array(); try { // root folder $parentId = $this->insert(array('name' => $name, 'is_child_allowed' => 0, 'is_locked' => 1, 'type' => 'root_remote', 'meta_info' => 'inbox', 'parent_id' => null)); $ids[] = $parentId; /** * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers */ require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersUsers.php'; $foldersUsers = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers(); $foldersUsers->addRelationship($ids, $userId, Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers::OWNER); $adapter->commit(); } catch (Exception $e) { $adapter->rollBack(); return array(); } // map all existing folders from the root hierarchy to the new account /** * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts */ require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersAccounts.php'; $foldersAccountsModel = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersAccounts(); return $foldersAccountsModel->mapFolderIdsToAccountId($ids, $accountId); }
/** * Returns false if the $folderEntity or any of its child folders is * not accessible by the user bound to this service. * * @param \Conjoon\Data\Entity\Mail\MailFolderEntity * @param bool $recurse * @return bool */ protected function checkFolderHierarchyAccessible(\Conjoon\Data\Entity\Mail\MailFolderEntity $folderEntity, $recurse = false) { /** * @refactor uses old implementation */ $OWNER_STR = \Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers::OWNER; $foldersUsers = new \Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers(); $checkNodeId = $folderEntity->getId(); $rel = $foldersUsers->getRelationShipForFolderAndUser($checkNodeId, $this->user->getId()); $isAccessible = $rel === $OWNER_STR; if ($isAccessible && $recurse) { $childFolders = $this->folderCommons->getChildFolderEntities($folderEntity); foreach ($childFolders as $childFolder) { $isAccessible = $this->checkFolderHierarchyAccessible($childFolder, $recurse); if (!$isAccessible) { break; } } } return $isAccessible; }