/** * This function will return a folder by it's name (not ID) * * @author KnowledgeTree Team * @access public * @param KTAPI $ktapi * @param string $foldername * @param int $folderid * @return KTAPI_Folder */ function _get_folder_by_name($ktapi, $foldername, $folderid) { $foldername = trim($foldername); if (empty($foldername)) { return new PEAR_Error('A valid folder name must be specified.'); } $split = explode('/', $foldername); foreach ($split as $foldername) { if (empty($foldername)) { continue; } $foldername = KTUtil::replaceInvalidCharacters($foldername); $foldername = sanitizeForSQL($foldername); $sql = "SELECT id FROM folders WHERE\n\t\t\t\t\t(name='{$foldername}' and parent_id={$folderid}) OR\n\t\t\t\t\t(name='{$foldername}' and parent_id is null and {$folderid}=1)"; $row = DBUtil::getOneResult($sql); if (is_null($row) || PEAR::isError($row)) { return new KTAPI_Error(KTAPI_ERROR_FOLDER_INVALID, $row); } $folderid = $row['id']; } return KTAPI_Folder::get($ktapi, $folderid); }
/** * This is used to get a document based on document id. * * @author KnowledgeTree Team * @static * @access public * @param KTAPI $ktapi The ktapi object * @param int $documentid The document id * @return KTAPI_Document The document object */ function &get(&$ktapi, $documentid) { assert(!is_null($ktapi)); assert(is_a($ktapi, 'KTAPI')); assert(is_numeric($documentid)); $documentid += 0; $document =& Document::get($documentid); if (is_null($document) || PEAR::isError($document)) { return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID, $document); } $user = $ktapi->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); if (is_null($user) || PEAR::isError($user)) { return $user; } $folderid = $document->getParentID(); if (!is_null($folderid)) { $ktapi_folder =& KTAPI_Folder::get($ktapi, $folderid); } else { $ktapi_folder = null; } // We don't do any checks on this folder as it could possibly be deleted, and is not required right now. return new KTAPI_Document($ktapi, $ktapi_folder, $document); }
/** * Obtains the folder using a folder id. * * @author KnowledgeTree Team * @access public * @param integer $folderid The id of the folder * @return object $session SUCCESS - The KTAPI_Folder object | FAILURE - an error object */ public function &get_folder_by_id($folderid) { if (is_null($this->session)) { $error = new PEAR_Error('A session is not active'); return $error; } $folder = KTAPI_Folder::get($this, $folderid); return $folder; }