folder.inc
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· INC 代码 · 共 606 行 · 第 1/2 页
INC
606 行
$sTable = KTUtil::getTableName('documents');
$aQuery = array("SELECT id FROM {$sTable} WHERE folder_id = ? AND status_id = ?", array($iFolderID, LIVE));
$res = DBUtil::getResultArrayKey($aQuery,'id');
if (PEAR::isError($res)) {
return $res;
}
return implode(',', $res);
}
function &get($iFolderID) {
return KTEntityUtil::get('Folder', $iFolderID);
}
/**
* Checks if a folder with the same name and parent exists in the database already
*/
function exists() {
$sTable = KTUtil::getTableName('folders');
$sQuery = "SELECT count(*) as folder_count FROM $sTable WHERE name = ? AND parent_id = ?";/*ok*/
$aParams = array($this->sName, $this->iParentID);
$res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'folder_count');
if (PEAR::isError($res)) {
return false; // return $res
}
return ($res != 0); // handle pre-existing duplicates gracefully.
}
/**
* Checks if this folder is a symbolic link
*
* @return boolean
*/
function isSymbolicLink()
{
return !is_null($this->getLinkedFolderId());
}
/**
* Retrieves the folder this folder links to, if any.
*
* @return Folder
*/
function getLinkedFolder(){
if($this->isSymbolicLink()){
return Folder::get($this->getLinkedFolderId());
}
}
/**
* Returns the "Symbolic link" folder
*
* @return Folder the folder
*/
function getRealFolder(){
if (is_null($this->getLinkedFolderId()))
{
return Folder::get($this->getId());
}
$oFolder = Folder::get($this->getLinkedFolderId());
return $oFolder->getRealFolder();
}
/**
* Returns the ID of the "Symbolic link" folder
*
* @return int the ID
*/
function getRealFolderId(){
$oRealFolder = $this->getRealFolder();
return $oRealFolder->getId();
}
/**
* Returns the symbolic links linking to this folder
*
* @return Array array with folder IDs
*/
function getSymbolicLinks(){
$sQuery = 'SELECT * FROM folders ' .
'WHERE folders.linked_folder_id = '.$this->getId();
return DButil::getResultArray($sQuery);
}
/**
* Static function
* Get a list of Documents
*
* @param String Where clause (not required)
*
* @return Array array of Documents objects, false otherwise and set $_SESSION["errorMessage"]
*/
function getList($sWhereClause = null, $aOptions = null) {
return KTEntityUtil::getList2('Folder', $sWhereClause, $aOptions);
}
/**
* Static function.
* Get the full path for a folder
*
* @param Primary key of folder to generate path for
*
* @return String full path of folder
*/
function getFolderPath($iFolderID) {
global $default;
$oFolder = Folder::get($iFolderID);
$sPath = $default->documentRoot . "/" . $oFolder->getFullPath() . "/" . $oFolder->getName() . "/";
return $sPath;
}
/**
* Static function.
* Get the full path for a folder as an array
*
* @param int primary key of folder to generate path for
*
* @return array full path of folder as an array of folderIDs
*/
function getFolderPathNamesAsArray($iFolderID) {
global $default;
$oFolder = Folder::get($iFolderID);
$aPathArray = array();
if ($oFolder) {
if (strlen($oFolder->getFullPath()) > 0) {
if (strlen($oFolder->getFullPath()) > 1) {
$aPathArray = explode("/",$oFolder->getFullPath());
} else {
$aPathArray = array($oFolder->getFullPath());
}
//$aPathArray[count($aPathArray)] = $oFolder->getName();
} else {
$aPathArray = array($oFolder->getName());
}
}
return $aPathArray;
}
// {{{
function getPathArray() {
return Folder::getFolderPathNamesAsArray($this->getID());
}
// }}}
/**
* Static function.
* Get the full path for a folder as an array
*
* @param int primary key of folder to generate path for
*
* @return array full path of folder as an array of folderIDs
*/
function getFolderPathAsArray($iFolderID) {
global $default;
$oFolder = Folder::get($iFolderID);
if ($oFolder === false) {
return false;
}
if (strlen($oFolder->getParentFolderIDs()) > 0) {
if ($oFolder->iParentID == 0) {
$aPathArray = array();
} else if (strlen($oFolder->getParentFolderIDs()) > 1) {
$aPathArray = explode(",",$oFolder->getParentFolderIDs());
} else {
$aPathArray = array($oFolder->getParentFolderIDs());
}
$aPathArray[count($aPathArray)] = $oFolder->getID();
} else {
$aPathArray = array($oFolder->getID());
}
return $aPathArray;
}
/**
* Static function.
* Get the path for a folder that will be displated to the user
*
* @param Primary key of folder to generate path for
*
* @return String full path of folder
*/
function getFolderDisplayPath($iFolderID) {
global $default;
$aPathNamesArray = Folder::getFolderPathNamesAsArray($iFolderID);
foreach($aPathNamesArray as $k=>$v)
{
$aPathNamesArray[$k] = sanitizeForHTML($v);
}
if (count($aPathNamesArray) > 0) {
return implode(" » ", $aPathNamesArray);
} else {
return "";
}
}
/**
* Static function
* Get the primary key of the parent folder
*
* @param $iFolderID Primary key of folder to get parent for
*
* @return integer primary key of parent folder
*/
function getParentFolderID($iFolderID) {
if ($iFolderID != 0) {
$oFolder = Folder::get($iFolderID);
return $oFolder->getParentFolderID();
}
return 0;
}
/**
* Static function
* Checks if a given folder already exists using the folder name
*
* @param $sName Name of folder
* @param $iParentID Primary key of parent folder
*
* @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
*/
function folderExistsName($sName, $iParentID) {
$sQuery = "SELECT id, name FROM " . KTUtil::getTableName('folders') . " WHERE name = ? AND parent_id = ?";/*ok*/
$aParams = array($sName, $iParentID);
$res = DBUtil::getResultArray(array($sQuery, $aParams));
//var_dump($res);
if (count($res) != 0) {
// mysql is case-insensitive - check using php
foreach ($res as $folder){
$name = isset($folder['name']) ? $folder['name'] : '';
if($name == $sName){
return true;
}
}
return false;
}
return false;
}
/**
* Checks if a given folder already exists using the folder name
*
* @param $iFolderID Primary key of folder
*
* @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
*/
function folderExistsID($iFolderID) {
$oFolder = Folder::get($iFolderID);
if (PEAR::isError($oFolder)) {
return false; // no such folder, or bad ID
} else {
return true;
}
}
/**
* Get the folder name using the primary key
*
* @param int primary key of folder to get name for
*
* @return String name on success, false otherwise and set $_SESSION["errorMessage"]
*/
function getFolderName($iFolderID) {
$oFolder = Folder::get($iFolderID);
if (PEAR::isError($oFolder)) {
return false; // return $oFolder;
} else {
return $oFolder->getName();
}
}
function getByParentIDAndLookupID($iParentID, $iLookupID) {
return KTEntityUtil::getByDict('Folder', array(
'parent_id' => $iParentID,
'permission_lookup_id' => $iLookupID,
), array('multi' => true));
}
function getByParentId($iParentID) {
return KTEntityUtil::getByDict('Folder', array(
'parent_id' => $iParentID,
), array('multi' => true));
}
// STATIC
function &createFromArray($aOptions) {
return KTEntityUtil::createFromArray('Folder', $aOptions);
}
function clearAllCaches() {
$GLOBALS["_OBJECTCACHE"]['Folder'] = array();
return KTEntityUtil::clearAllCaches('Folder');
}
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?