mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 23:42:11 +00:00
add method countChildren()
This commit is contained in:
parent
291919c20e
commit
639355b1cf
|
@ -541,6 +541,73 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
|
|||
return $this->_documents;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Count all documents and subfolders of the folder
|
||||
*
|
||||
* This function also counts documents and folders of subfolders, so
|
||||
* basically it works like recursively counting children.
|
||||
*
|
||||
* This function does not check for access rights. Use
|
||||
* {@link SeedDMS_Core_DMS::filterAccess} for checking each document against
|
||||
* the currently logged in user and the access rights.
|
||||
*
|
||||
* FIXME: This function isn't complete! The idea is to return the documents
|
||||
* and folders if a maximum number isn't exceeded.
|
||||
*
|
||||
* @param string $orderby if set to 'n' the list is ordered by name, otherwise
|
||||
* it will be ordered by sequence
|
||||
* @return array array with two elements 'documents' and 'folders' holding
|
||||
* the counted number.
|
||||
*/
|
||||
function countChildren() { /* {{{ */
|
||||
$db = $this->_dms->getDB();
|
||||
|
||||
$pathPrefix="";
|
||||
$path = $this->getPath();
|
||||
foreach ($path as $f) {
|
||||
$pathPrefix .= ":".$f->getID();
|
||||
}
|
||||
if (strlen($pathPrefix)>1) {
|
||||
$pathPrefix .= ":";
|
||||
}
|
||||
|
||||
$queryStr = "SELECT count(id) as c FROM tblDocuments WHERE folderList like '".$pathPrefix. "%'";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if (is_bool($resArr) && !$resArr)
|
||||
return false;
|
||||
|
||||
$cdocs = $resArr[0]['c'];
|
||||
if($cdocs < 100) {
|
||||
$queryStr = "SELECT id FROM tblDocuments WHERE folderList like '".$pathPrefix. "%'";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if (is_bool($resArr) && !$resArr)
|
||||
return false;
|
||||
$documents = array();
|
||||
foreach ($resArr as $row) {
|
||||
array_push($documents, $this->_dms->getDocument($row["id"]));
|
||||
}
|
||||
}
|
||||
|
||||
$queryStr = "SELECT count(id) as c FROM tblFolders WHERE folderList like '".$pathPrefix. "%'";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if (is_bool($resArr) && !$resArr)
|
||||
return false;
|
||||
|
||||
$cfolders = $resArr[0]['c'];
|
||||
if($cfolders < 100) {
|
||||
$queryStr = "SELECT id FROM tblFolders WHERE folderList like '".$pathPrefix. "%'";
|
||||
$resArr = $db->getResultArray($queryStr);
|
||||
if (is_bool($resArr) && !$resArr)
|
||||
return false;
|
||||
$folders = array();
|
||||
foreach ($resArr as $row) {
|
||||
array_push($folders, $this->_dms->getFolder($row["id"]));
|
||||
}
|
||||
}
|
||||
|
||||
return array('document_count'=>$cdocs, 'folder_count'=>$cfolders);
|
||||
} /* }}} */
|
||||
|
||||
// $comment will be used for both document and version leaving empty the version_comment
|
||||
/**
|
||||
* Add a new document to the folder
|
||||
|
|
Loading…
Reference in New Issue
Block a user