Ejemplo n.º 1
0
 /**
  * Appends a new folder to the folder with the specified $parentId.
  * If the folder is connected to an email-account, the new folder
  * will inherit the account-id from it's parent-folder. The new folder
  * will also inherit the meta-info-value of the parent folder
  *
  * Checks first if the
  *
  * @param integer $parentId
  * @param string $name
  * @param integer $userId
  */
 public function addFolder($parentId, $name, $userId)
 {
     if ((int) $parentId <= 0 || (int) $userId <= 0 || $name == "") {
         return -1;
     }
     if (!$this->doesFolderAllowChildren($parentId)) {
         return -1;
     }
     // check now if a folder with the same name already exists
     if ($this->getFolderIdForName($name, $parentId) != 0) {
         return -1;
     }
     $parentRow = $this->fetchRow($parentId)->toArray();
     if (!is_array($parentRow) || $parentRow['meta_info'] == null) {
         return -1;
     }
     $data = array('name' => $name, 'is_child_allowed' => 1, 'is_locked' => 0, 'type' => 'folder', 'parent_id' => $parentId, 'meta_info' => $parentRow['meta_info']);
     $id = (int) $this->insert($data);
     if ($id <= 0) {
         return -1;
     }
     // check if the parent folder is related to one ore more accounts
     /**
      * @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();
     $foldersAccountsModel->inheritFromParentIdForFolderId($parentId, $id);
     /**
      * @see Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers
      */
     require_once 'Conjoon/Modules/Groupware/Email/Folder/Model/FoldersUsers.php';
     $foldersUsersModel = new Conjoon_Modules_Groupware_Email_Folder_Model_FoldersUsers();
     $foldersUsersModel->inheritFromParentIdForFolderId($parentId, $id);
     return $id;
 }