From 3f2e24f80d6f3c1dea3e887797e4ecfdcb0d4c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Neugebauer?= Date: Sat, 28 Oct 2017 14:28:12 +0200 Subject: [PATCH] inc.ClassFolder.php --- SeedDMS_Core/Core/inc.ClassDMS.php | 2 +- SeedDMS_Core/Core/inc.ClassDocument.php | 89 +++-- SeedDMS_Core/Core/inc.ClassFolder.php | 465 ++++++++++++++---------- 3 files changed, 332 insertions(+), 224 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDMS.php b/SeedDMS_Core/Core/inc.ClassDMS.php index 704255ce6..f683eb086 100644 --- a/SeedDMS_Core/Core/inc.ClassDMS.php +++ b/SeedDMS_Core/Core/inc.ClassDMS.php @@ -561,7 +561,7 @@ class SeedDMS_Core_DMS { * If user authentication was done externally, this function can * be used to tell the dms who is currently logged in. * - * @return object $user + * @return SeedDMS_Core_User $user * */ function getLoggedInUser() { /* {{{ */ diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 017ed1571..37ec40bdb 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -186,7 +186,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ protected $_sequence; /** - * @var object temp. storage for latestcontent + * @var SeedDMS_Core_DocumentContent temp. storage for latestcontent */ protected $_latestContent; @@ -200,7 +200,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ */ protected $_folder; - /** @var SeedDMS_Core_UserAccess[] */ + /** @var array of SeedDMS_Core_UserAccess and SeedDMS_Core_GroupAccess */ protected $_accessList; function __construct($id, $name, $comment, $date, $expires, $ownerID, $folderID, $inheritAccess, $defaultAccess, $locked, $keywords, $sequence) { /* {{{ */ @@ -557,7 +557,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * will not have read access anymore. * * @param integer $mode access mode - * @param boolean $noclean set to true if notifier list shall not be clean up + * @param bool|string $noclean set to true if notifier list shall not be clean up * @return bool */ function setDefaultAccess($mode, $noclean="false") { /* {{{ */ @@ -802,7 +802,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * * @param int $mode access mode (defaults to M_ANY) * @param int|string $op operation (defaults to O_EQ) - * @return bool|SeedDMS_Core_UserAccess[] + * @return bool|array */ function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */ $db = $this->_dms->getDB(); @@ -970,7 +970,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $accessList = $this->getAccessList(); if (!$accessList) return false; - foreach ($accessList["users"] as $userAccess) { + /** @var SeedDMS_Core_UserAccess $userAccess */ + foreach ($accessList["users"] as $userAccess) { if ($userAccess->getUserID() == $user->getID()) { $mode = $userAccess->getMode(); if ($user->isGuest()) { @@ -983,7 +984,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ /* Get the highest right defined by a group */ if($accessList['groups']) { $mode = 0; - foreach ($accessList["groups"] as $groupAccess) { + /** @var SeedDMS_Core_GroupAccess $groupAccess */ + foreach ($accessList["groups"] as $groupAccess) { if ($user->isMemberOfGroup($groupAccess->getGroup())) { if ($groupAccess->getMode() > $mode) $mode = $groupAccess->getMode(); @@ -1014,7 +1016,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * The function takes inherited access rights into account. * For a list of possible access rights see @file inc.AccessUtils.php * - * @param $group object instance of class SeedDMS_Core_Group + * @param SeedDMS_Core_Group $group object instance of class SeedDMS_Core_Group * @return integer access mode */ function getGroupAccessMode($group) { /* {{{ */ @@ -1026,7 +1028,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ if (!$accessList) return false; - foreach ($accessList["groups"] as $groupAccess) { + /** @var SeedDMS_Core_GroupAccess $groupAccess */ + foreach ($accessList["groups"] as $groupAccess) { if ($groupAccess->getGroupID() == $group->getID()) { $foundInACL = true; if ($groupAccess->getMode() > $highestPrivileged) @@ -1043,7 +1046,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return $this->getDefaultAccess(); } /* }}} */ - /** + /** * Returns a list of all notifications * * The returned list has two elements called 'users' and 'groups'. Each one @@ -1051,8 +1054,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * SeedDMS_Core_Group. * * @param integer $type type of notification (not yet used) - * @return array list of notifications - */ + * @return array|bool + */ function getNotifyList($type=0) { /* {{{ */ if (empty($this->_notifyList)) { $db = $this->_dms->getDB(); @@ -1092,7 +1095,9 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ /* Make a copy of both notifier lists because removeNotify will empty * $this->_notifyList and the second foreach will not work anymore. */ + /** @var SeedDMS_Core_User[] $nusers */ $nusers = $this->_notifyList["users"]; + /** @var SeedDMS_Core_Group[] $ngroups */ $ngroups = $this->_notifyList["groups"]; foreach ($nusers as $u) { if ($this->getAccessMode($u) < M_READ) { @@ -1172,7 +1177,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ // that the current group has not been explicitly excluded. $acl = $this->getAccessList(M_NONE, O_EQ); $found = false; - foreach ($acl["groups"] as $group) { + /** @var SeedDMS_Core_GroupAccess $group */ + foreach ($acl["groups"] as $group) { if ($group->getGroupID() == $userOrGroupID) { $found = true; break; @@ -1190,7 +1196,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return -4; } $found = false; - foreach ($acl["groups"] as $group) { + /** @var SeedDMS_Core_GroupAccess $group */ + foreach ($acl["groups"] as $group) { if ($group->getGroupID() == $userOrGroupID) { $found = true; break; @@ -1240,6 +1247,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $db = $this->_dms->getDB(); /* Verify that user / group exists. */ + /** @var SeedDMS_Core_Group|SeedDMS_Core_User $obj */ $obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID)); if (!is_object($obj)) { return -1; @@ -1315,8 +1323,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * @param array $attributes list of version attributes. The element key * must be the id of the attribute definition. * @param object $workflow - * @return bool/array false in case of an error or a result set - */ + * @return bool|SeedDMS_Core_AddContentResultSet + */ function addContent($comment, $user, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers=array(), $approvers=array(), $version=0, $attributes=array(), $workflow=null) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1365,7 +1373,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $this->_content = null; $this->_latestContent = null; - $content = $this->getLatestContent($contentID); + $content = $this->getLatestContent($contentID); /** @todo: Parameter not defined in Funktion */ $docResultSet = new SeedDMS_Core_AddContentResultSet($content); $docResultSet->setDMS($this->_dms); @@ -1402,7 +1410,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ // and submit comments, if appropriate. Reviewers can also recommend that // a document be rejected. $pendingReview=false; - $reviewRes = array(); + /** @noinspection PhpUnusedLocalVariableInspection */ + $reviewRes = array(); /** @todo unused variable */ foreach (array("i", "g") as $i){ if (isset($reviewers[$i])) { foreach ($reviewers[$i] as $reviewerID) { @@ -1420,7 +1429,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ // Add approvers to the database. Approvers must also review the document // and make a recommendation on its release as an approved version. $pendingApproval=false; - $approveRes = array(); + /** @noinspection PhpUnusedLocalVariableInspection */ + $approveRes = array(); /** @todo unused variable */ foreach (array("i", "g") as $i){ if (isset($approvers[$i])) { foreach ($approvers[$i] as $approverID) { @@ -1458,7 +1468,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return false; } - $docResultSet->setStatus($status,$comment,$user); + /** @noinspection PhpMethodParametersCountMismatchInspection */ + $docResultSet->setStatus($status,$comment,$user); /** @todo parameter count wrong */ $db->commitTransaction(); return $docResultSet; @@ -1496,7 +1507,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ if ((int) $version<1) { $queryStr = "SELECT MAX(`version`) as m from `tblDocumentContent` where `document` = ".$this->_id; $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && !$res) + if (is_bool($resArr) && !$res) /** @todo undefined variable */ return false; $version = $resArr[0]['m']; @@ -1551,21 +1562,22 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * out. Access rights based on the document status are calculated for the * currently logged in user. * - * @return array list of objects of class SeedDMS_Core_DocumentContent - */ + * @return bool|SeedDMS_Core_DocumentContent[] + */ function getContent() { /* {{{ */ $db = $this->_dms->getDB(); if (!isset($this->_content)) { $queryStr = "SELECT * FROM `tblDocumentContent` WHERE `document` = ".$this->_id." ORDER BY `version`"; $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && !$res) + if (is_bool($resArr) && !$res) /** @todo undefined variable */ return false; $this->_content = array(); $classname = $this->_dms->getClassname('documentcontent'); $user = $this->_dms->getLoggedInUser(); foreach ($resArr as $row) { + /** @var SeedDMS_Core_DocumentContent $content */ $content = new $classname($row["id"], $this, $row["version"], $row["comment"], $row["date"], $row["createdBy"], $row["dir"], $row["orgFileName"], $row["fileType"], $row["mimeType"], $row['fileSize'], $row['checksum']); if($user) { if($content->getAccessMode($user) >= M_READ) @@ -1587,7 +1599,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * currently logged in user. * * @param integer $version version number of content element - * @return object/boolean object of class {@link SeedDMS_Core_DocumentContent} + * @return SeedDMS_Core_DocumentContent|boolean object of class {@link SeedDMS_Core_DocumentContent} * or false */ function getContentByVersion($version) { /* {{{ */ @@ -1604,13 +1616,14 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $db = $this->_dms->getDB(); $queryStr = "SELECT * FROM `tblDocumentContent` WHERE `document` = ".$this->_id." AND `version` = " . (int) $version; $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && !$res) + if (is_bool($resArr) && !$res) /** @todo undefined variable */ return false; if (count($resArr) != 1) return false; $resArr = $resArr[0]; $classname = $this->_dms->getClassname('documentcontent'); + /** @var SeedDMS_Core_DocumentContent $content */ if($content = new $classname($resArr["id"], $this, $resArr["version"], $resArr["comment"], $resArr["date"], $resArr["createdBy"], $resArr["dir"], $resArr["orgFileName"], $resArr["fileType"], $resArr["mimeType"], $resArr['fileSize'], $resArr['checksum'])) { $user = $this->_dms->getLoggedInUser(); /* A user with write access on the document may always see the version */ @@ -1623,6 +1636,9 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ } } /* }}} */ + /** + * @return bool|null|SeedDMS_Core_DocumentContent + */ function __getLatestContent() { /* {{{ */ if (!$this->_latestContent) { $db = $this->_dms->getDB(); @@ -1651,20 +1667,21 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * Access rights based on the document status are calculated for the * currently logged in user. * - * @return object object of class {@link SeedDMS_Core_DocumentContent} + * @return bool|SeedDMS_Core_DocumentContent object of class {@link SeedDMS_Core_DocumentContent} */ function getLatestContent() { /* {{{ */ if (!$this->_latestContent) { $db = $this->_dms->getDB(); $queryStr = "SELECT * FROM `tblDocumentContent` WHERE `document` = ".$this->_id." ORDER BY `version` DESC"; $resArr = $db->getResultArray($queryStr); - if (is_bool($resArr) && !$res) + if (is_bool($resArr) && !$res) /** @todo: $res not defined */ return false; $classname = $this->_dms->getClassname('documentcontent'); $user = $this->_dms->getLoggedInUser(); foreach ($resArr as $row) { if (!$this->_latestContent) { + /** @var SeedDMS_Core_DocumentContent $content */ $content = new $classname($row["id"], $this, $row["version"], $row["comment"], $row["date"], $row["createdBy"], $row["dir"], $row["orgFileName"], $row["fileType"], $row["mimeType"], $row['fileSize'], $row['checksum']); if($user) { /* If the user may even write the document, then also allow to see all content. @@ -1686,7 +1703,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ /** * Remove version of document * - * @param interger $version version number of content + * @param SeedDMS_Core_DocumentContent $version version number of content * @return boolean true if successful, otherwise false */ private function _removeContent($version) { /* {{{ */ @@ -1813,11 +1830,12 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return true; } /* }}} */ - /** - * Call callback onPreRemoveDocument before deleting content - * - * @param integer $version version number of content - */ + /** + * Call callback onPreRemoveDocument before deleting content + * + * @param SeedDMS_Core_DocumentContent $version version number of content + * @return bool|mixed + */ function removeContent($version) { /* {{{ */ /* Check if 'onPreRemoveDocument' callback is set */ if(isset($this->_dms->callbacks['onPreRemoveContent'])) { @@ -1847,7 +1865,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ * Return a certain document link * * @param integer $linkID id of link - * @return object instance of SeedDMS_Core_DocumentLink or false in case of + * @return SeedDMS_Core_DocumentLink|bool of SeedDMS_Core_DocumentLink or false in case of * an error. */ function getDocumentLink($linkID) { /* {{{ */ @@ -1866,7 +1884,8 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $link = new SeedDMS_Core_DocumentLink($resArr["id"], $document, $target, $resArr["userID"], $resArr["public"]); $user = $this->_dms->getLoggedInUser(); if($link->getAccessMode($user, $document, $target) >= M_READ) - return $file; + /** @noinspection PhpUndefinedVariableInspection */ + return $file; /** @todo variable not defined */ return null; } /* }}} */ diff --git a/SeedDMS_Core/Core/inc.ClassFolder.php b/SeedDMS_Core/Core/inc.ClassFolder.php index e2c7e2bf8..ffb348642 100644 --- a/SeedDMS_Core/Core/inc.ClassFolder.php +++ b/SeedDMS_Core/Core/inc.ClassFolder.php @@ -73,6 +73,48 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { */ protected $_sequence; + /** + * @var + */ + protected $_date; + + /** + * @var SeedDMS_Core_Folder + */ + protected $_parent; + + /** + * @var SeedDMS_Core_User + */ + protected $_owner; + + /** + * @var SeedDMS_Core_Folder[] + */ + protected $_subFolders; + + /** + * @var SeedDMS_Core_Document[] + */ + protected $_documents; + + /** + * @var SeedDMS_Core_UserAccess[]|SeedDMS_Core_GroupAccess[] + */ + protected $_accessList; + + /** + * SeedDMS_Core_Folder constructor. + * @param $id + * @param $name + * @param $parentID + * @param $comment + * @param $date + * @param $ownerID + * @param $inheritAccess + * @param $defaultAccess + * @param $sequence + */ function __construct($id, $name, $parentID, $comment, $date, $ownerID, $inheritAccess, $defaultAccess, $sequence) { /* {{{ */ parent::__construct($id); $this->_id = $id; @@ -87,14 +129,15 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $this->_notifyList = array(); } /* }}} */ - /** - * Return an array of database fields which used for searching - * a term entered in the database search form - * - * @param array $searchin integer list of search scopes (2=name, 3=comment, - * 4=attributes) - * @return array list of database fields - */ + /** + * Return an array of database fields which used for searching + * a term entered in the database search form + * + * @param SeedDMS_Core_DMS $dms + * @param array $searchin integer list of search scopes (2=name, 3=comment, + * 4=attributes) + * @return array list of database fields + */ public static function getSearchFields($dms, $searchin) { /* {{{ */ $db = $dms->getDB(); @@ -125,6 +168,11 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $sql; } /* }}} */ + /** + * @param $id + * @param SeedDMS_Core_DMS $dms + * @return bool|SeedDMS_Core_Folder + */ public static function getInstance($id, $dms) { /* {{{ */ $db = $dms->getDB(); @@ -137,23 +185,25 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $resArr = $resArr[0]; $classname = $dms->getClassname('folder'); + /** @var SeedDMS_Core_Folder $folder */ $folder = new $classname($resArr["id"], $resArr["name"], $resArr["parent"], $resArr["comment"], $resArr["date"], $resArr["owner"], $resArr["inheritAccess"], $resArr["defaultAccess"], $resArr["sequence"]); $folder->setDMS($dms); return $folder; } /* }}} */ - /* + /** * Get the name of the folder. * * @return string name of folder */ public function getName() { return $this->_name; } - /* - * Set the name of the folder. - * - * @param string $newName set a new name of the folder - */ + /** + * Set the name of the folder. + * + * @param string $newName set a new name of the folder + * @return bool + */ public function setName($newName) { /* {{{ */ $db = $this->_dms->getDB(); @@ -166,8 +216,15 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ + /** + * @return string + */ public function getComment() { return $this->_comment; } + /** + * @param $newComment + * @return bool + */ public function setComment($newComment) { /* {{{ */ $db = $this->_dms->getDB(); @@ -215,8 +272,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /** * Returns the parent * - * @return object parent folder or false if there is no parent folder - */ + * @return bool|SeedDMS_Core_Folder + */ public function getParent() { /* {{{ */ if ($this->_id == $this->_dms->rootFolderID || empty($this->_parentID)) { return false; @@ -228,15 +285,15 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->_parent; } /* }}} */ - /** - * Check if the folder is subfolder - * - * This function checks if the passed folder is a subfolder of the current - * folder. - * - * @param object $subFolder potential sub folder - * @return boolean true if passes folder is a subfolder - */ + /** + * Check if the folder is subfolder + * + * This function checks if the passed folder is a subfolder of the current + * folder. + * + * @param SeedDMS_Core_Folder $subfolder + * @return bool true if passes folder is a subfolder + */ function isSubFolder($subfolder) { /* {{{ */ $target_path = $subfolder->getPath(); foreach($target_path as $next_folder) { @@ -252,7 +309,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * This function moves a folder from one parent folder into another parent * folder. It will fail if the root folder is moved. * - * @param object $newParent new parent folder + * @param SeedDMS_Core_Folder $newParent new parent folder * @return boolean true if operation was successful otherwise false */ public function setParent($newParent) { /* {{{ */ @@ -306,7 +363,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { foreach ($resArr as $row) { $newPath = preg_replace("/^.*:".$this->_id.":(.*$)/", $pathPrefix."\\1", $row["folderList"]); $queryStr="UPDATE `tblDocuments` SET `folderList` = '".$newPath."' WHERE `tblDocuments`.`id` = '".$row["id"]."'"; - $res = $db->getResult($queryStr); + /** @noinspection PhpUnusedLocalVariableInspection */ + $res = $db->getResult($queryStr); } /* Update path in folderList for all documents */ @@ -318,7 +376,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { foreach ($resArr as $row) { $newPath = preg_replace("/^.*:".$this->_id.":(.*$)/", $pathPrefix."\\1", $row["folderList"]); $queryStr="UPDATE `tblFolders` SET `folderList` = '".$newPath."' WHERE `tblFolders`.`id` = '".$row["id"]."'"; - $res = $db->getResult($queryStr); + /** @noinspection PhpUnusedLocalVariableInspection */ + $res = $db->getResult($queryStr); } return true; @@ -338,7 +397,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /** * Set the owner * - * @param object new owner of the folder + * @param SeedDMS_Core_User $newOwner of the folder * @return boolean true if successful otherwise false */ function setOwner($newOwner) { /* {{{ */ @@ -353,6 +412,9 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ + /** + * @return bool|int + */ function getDefaultAccess() { /* {{{ */ if ($this->inheritsAccess()) { $res = $this->getParent(); @@ -363,15 +425,16 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->_defaultAccess; } /* }}} */ - /** - * Set default access mode - * - * This method sets the default access mode and also removes all notifiers which - * will not have read access anymore. - * - * @param integer $mode access mode - * @param boolean $noclean set to true if notifier list shall not be clean up - */ + /** + * Set default access mode + * + * This method sets the default access mode and also removes all notifiers which + * will not have read access anymore. + * + * @param integer $mode access mode + * @param boolean $noclean set to true if notifier list shall not be clean up + * @return bool + */ function setDefaultAccess($mode, $noclean=false) { /* {{{ */ $db = $this->_dms->getDB(); @@ -443,7 +506,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { function hasSubFolders() { /* {{{ */ $db = $this->_dms->getDB(); if (isset($this->_subFolders)) { - return count($this->subFolders); + /** @noinspection PhpUndefinedFieldInspection */ + return count($this->subFolders); /** @todo not $this->_subFolders? */ } $queryStr = "SELECT count(*) as c FROM `tblFolders` WHERE `parent` = " . $this->_id; $resArr = $db->getResultArray($queryStr); @@ -462,8 +526,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * @param string $orderby if set to 'n' the list is ordered by name, otherwise * it will be ordered by sequence * @param string $dir direction of sorting (asc or desc) - * @return array list of folder objects or false in case of an error - */ + * @return SeedDMS_Core_Folder[]|bool + */ function getSubFolders($orderby="", $dir="asc") { /* {{{ */ $db = $this->_dms->getDB(); @@ -497,8 +561,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * @param integer $sequence position of folder in list of sub folders. * @param array $attributes list of document attributes. The element key * must be the id of the attribute definition. - * @return object object of type SeedDMS_Core_Folder or false in case of - * an error. + * @return bool|SeedDMS_Core_Folder + * an error. */ function addSubFolder($name, $comment, $owner, $sequence, $attributes=array()) { /* {{{ */ $db = $this->_dms->getDB(); @@ -540,7 +604,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /* Check if 'onPostAddSubFolder' callback is set */ if(isset($this->_dms->callbacks['onPostAddSubFolder'])) { foreach($this->_dms->callbacks['onPostAddSubFolder'] as $callback) { - if(!call_user_func($callback[0], $callback[1], $newFolder)) { + /** @noinspection PhpStatementHasEmptyBodyInspection */ + if(!call_user_func($callback[0], $callback[1], $newFolder)) { } } } @@ -618,7 +683,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { function hasDocuments() { /* {{{ */ $db = $this->_dms->getDB(); if (isset($this->_documents)) { - return count($this->documents); + /** @noinspection PhpUndefinedFieldInspection */ + return count($this->documents); /** @todo not $this->_documents? */ } $queryStr = "SELECT count(*) as c FROM `tblDocuments` WHERE `folder` = " . $this->_id; $resArr = $db->getResultArray($queryStr); @@ -628,16 +694,18 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $resArr[0]['c']; } /* }}} */ - /** - * Check if folder has document with given name - * - * @return boolean true if document exists, false if not or in case - * of an error - */ + /** + * Check if folder has document with given name + * + * @param string $name + * @return bool true if document exists, false if not or in case + * of an error + */ function hasDocumentByName($name) { /* {{{ */ $db = $this->_dms->getDB(); if (isset($this->_documents)) { - return count($this->documents); + /** @noinspection PhpUndefinedFieldInspection */ /** @todo not $this->_documents? */ + return count($this->documents); } $queryStr = "SELECT count(*) as c FROM `tblDocuments` WHERE `folder` = " . $this->_id . " AND `name` = ".$db->qstr($name); $resArr = $db->getResultArray($queryStr); @@ -656,8 +724,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * @param string $orderby if set to 'n' the list is ordered by name, otherwise * it will be ordered by sequence * @param string $dir direction of sorting (asc or desc) - * @return array list of documents or false in case of an error - */ + * @return SeedDMS_Core_Document[]|bool + */ function getDocuments($orderby="", $dir="asc") { /* {{{ */ $db = $this->_dms->getDB(); @@ -682,29 +750,30 @@ 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 checks for access rights up the given limit. If more - * documents or folders are found, the returned value will be the number - * of objects available and the precise flag in the return array will be - * set to false. This number should not be revelead to the - * user, because it allows to gain information about the existens of - * objects without access right. - * Setting the parameter $limit to 0 will turn off access right checking - * which is reasonable if the $user is an administrator. - * - * @param string $orderby if set to 'n' the list is ordered by name, otherwise - * it will be ordered by sequence - * @param integer $limit maximum number of folders and documents that will - * be precisly counted by taken the access rights into account - * @return array array with four elements 'document_count', 'folder_count' - * 'document_precise', 'folder_precise' holding - * the counted number and a flag if the number is precise. - */ + /** + * 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 checks for access rights up the given limit. If more + * documents or folders are found, the returned value will be the number + * of objects available and the precise flag in the return array will be + * set to false. This number should not be revelead to the + * user, because it allows to gain information about the existens of + * objects without access right. + * Setting the parameter $limit to 0 will turn off access right checking + * which is reasonable if the $user is an administrator. + * + * @param SeedDMS_Core_User $user + * @param integer $limit maximum number of folders and documents that will + * be precisly counted by taken the access rights into account + * @return array|bool with four elements 'document_count', 'folder_count' + * 'document_precise', 'folder_precise' holding + * the counted number and a flag if the number is precise. + * @internal param string $orderby if set to 'n' the list is ordered by name, otherwise + * it will be ordered by sequence + */ function countChildren($user, $limit=10000) { /* {{{ */ $db = $this->_dms->getDB(); @@ -771,38 +840,38 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { } /* }}} */ // $comment will be used for both document and version leaving empty the version_comment - /** - * Add a new document to the folder - * This function will add a new document and its content from a given file. - * It does not check for access rights on the folder. The new documents - * default access right is read only and the access right is inherited. - * - * @param string $name name of new document - * @param string $comment comment of new document - * @param integer $expires expiration date as a unix timestamp or 0 for no - * expiration date - * @param object $owner owner of the new document - * @param string $keywords keywords of new document - * @param array $categories list of category ids - * @param string $tmpFile the path of the file containing the content - * @param string $orgFileName the original file name - * @param string $fileType usually the extension of the filename - * @param string $mimeType mime type of the content - * @param float $sequence position of new document within the folder - * @param array $reviewers list of users who must review this document - * @param array $approvers list of users who must approve this document - * @param string $reqversion version number of the content - * @param string $version_comment comment of the content. If left empty - * the $comment will be used. - * @param array $attributes list of document attributes. The element key - * must be the id of the attribute definition. - * @param array $version_attributes list of document version attributes. - * The element key must be the id of the attribute definition. - * @param object $workflow - * @return array/boolean false in case of error, otherwise an array - * containing two elements. The first one is the new document, the - * second one is the result set returned when inserting the content. - */ + /** + * Add a new document to the folder + * This function will add a new document and its content from a given file. + * It does not check for access rights on the folder. The new documents + * default access right is read only and the access right is inherited. + * + * @param string $name name of new document + * @param string $comment comment of new document + * @param integer $expires expiration date as a unix timestamp or 0 for no + * expiration date + * @param object $owner owner of the new document + * @param SeedDMS_Core_User $keywords keywords of new document + * @param array $categories list of category ids + * @param string $tmpFile the path of the file containing the content + * @param string $orgFileName the original file name + * @param string $fileType usually the extension of the filename + * @param string $mimeType mime type of the content + * @param float $sequence position of new document within the folder + * @param array $reviewers list of users who must review this document + * @param array $approvers list of users who must approve this document + * @param int|string $reqversion version number of the content + * @param string $version_comment comment of the content. If left empty + * the $comment will be used. + * @param array $attributes list of document attributes. The element key + * must be the id of the attribute definition. + * @param array $version_attributes list of document version attributes. + * The element key must be the id of the attribute definition. + * @param SeedDMS_Core_Workflow $workflow + * @return array|bool false in case of error, otherwise an array + * containing two elements. The first one is the new document, the + * second one is the result set returned when inserting the content. + */ function addDocument($name, $comment, $expires, $owner, $keywords, $categories, $tmpFile, $orgFileName, $fileType, $mimeType, $sequence, $reviewers=array(), $approvers=array(),$reqversion=0,$version_comment="", $attributes=array(), $version_attributes=array(), $workflow=null) { /* {{{ */ $db = $this->_dms->getDB(); @@ -859,7 +928,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /* Check if 'onPostAddDocument' callback is set */ if(isset($this->_dms->callbacks['onPostAddDocument'])) { foreach($this->_dms->callbacks['onPostAddDocument'] as $callback) { - if(!call_user_func($callback[0], $callback[1], $document)) { + /** @noinspection PhpStatementHasEmptyBodyInspection */ + if(!call_user_func($callback[0], $callback[1], $document)) { } } } @@ -923,7 +993,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /* Check if 'onPostRemoveFolder' callback is set */ if(isset($this->_dms->callbacks['onPostRemoveFolder'])) { foreach($this->_dms->callbacks['onPostRemoveFolder'] as $callback) { - if(!call_user_func($callback[0], $callback[1], $this->_id)) { + /** @noinspection PhpStatementHasEmptyBodyInspection */ + if(!call_user_func($callback[0], $callback[1], $this->_id)) { } } } @@ -939,7 +1010,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * @return boolean true on success, false in case of an error */ function remove() { /* {{{ */ - $db = $this->_dms->getDB(); + /** @noinspection PhpUnusedLocalVariableInspection */ + $db = $this->_dms->getDB(); // Do not delete the root folder. if ($this->_id == $this->_dms->rootFolderID || !isset($this->_parentID) || ($this->_parentID == null) || ($this->_parentID == "") || ($this->_parentID == 0)) { @@ -969,24 +1041,24 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->removeFromDatabase(); } /* }}} */ - /** - * Returns a list of access privileges - * - * If the folder inherits the access privileges from the parent folder - * those will be returned. - * $mode and $op can be set to restrict the list of returned access - * privileges. If $mode is set to M_ANY no restriction will apply - * regardless of the value of $op. The returned array contains a list - * of {@link SeedDMS_Core_UserAccess} and - * {@link SeedDMS_Core_GroupAccess} objects. Even if the document - * has no access list the returned array contains the two elements - * 'users' and 'groups' which are than empty. The methode returns false - * if the function fails. - * - * @param integer $mode access mode (defaults to M_ANY) - * @param integer $op operation (defaults to O_EQ) - * @return array multi dimensional array - */ + /** + * Returns a list of access privileges + * + * If the folder inherits the access privileges from the parent folder + * those will be returned. + * $mode and $op can be set to restrict the list of returned access + * privileges. If $mode is set to M_ANY no restriction will apply + * regardless of the value of $op. The returned array contains a list + * of {@link SeedDMS_Core_UserAccess} and + * {@link SeedDMS_Core_GroupAccess} objects. Even if the document + * has no access list the returned array contains the two elements + * 'users' and 'groups' which are than empty. The methode returns false + * if the function fails. + * + * @param int $mode access mode (defaults to M_ANY) + * @param int|string $op operation (defaults to O_EQ) + * @return bool|SeedDMS_Core_GroupAccess|SeedDMS_Core_UserAccess + */ function getAccessList($mode = M_ANY, $op = O_EQ) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1043,16 +1115,17 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ - /** - * Add access right to folder - * This function may change in the future. Instead of passing the a flag - * and a user/group id a user or group object will be expected. - * - * @param integer $mode access mode - * @param integer $userOrGroupID id of user or group - * @param integer $isUser set to 1 if $userOrGroupID is the id of a - * user - */ + /** + * Add access right to folder + * This function may change in the future. Instead of passing the a flag + * and a user/group id a user or group object will be expected. + * + * @param integer $mode access mode + * @param integer $userOrGroupID id of user or group + * @param integer $isUser set to 1 if $userOrGroupID is the id of a + * user + * @return bool + */ function addAccess($mode, $userOrGroupID, $isUser) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1073,16 +1146,17 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ - /** - * Change access right of folder - * This function may change in the future. Instead of passing the a flag - * and a user/group id a user or group object will be expected. - * - * @param integer $newMode access mode - * @param integer $userOrGroupID id of user or group - * @param integer $isUser set to 1 if $userOrGroupID is the id of a - * user - */ + /** + * Change access right of folder + * This function may change in the future. Instead of passing the a flag + * and a user/group id a user or group object will be expected. + * + * @param integer $newMode access mode + * @param integer $userOrGroupID id of user or group + * @param integer $isUser set to 1 if $userOrGroupID is the id of a + * user + * @return bool + */ function changeAccess($newMode, $userOrGroupID, $isUser) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1102,6 +1176,11 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ + /** + * @param $userOrGroupID + * @param $isUser + * @return bool + */ function removeAccess($userOrGroupID, $isUser) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1158,7 +1237,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $accessList = $this->getAccessList(); if (!$accessList) return false; - foreach ($accessList["users"] as $userAccess) { + /** @var SeedDMS_Core_UserAccess $userAccess */ + foreach ($accessList["users"] as $userAccess) { if ($userAccess->getUserID() == $user->getID()) { $mode = $userAccess->getMode(); if ($user->isGuest()) { @@ -1171,7 +1251,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /* Get the highest right defined by a group */ if($accessList['groups']) { $mode = 0; - foreach ($accessList["groups"] as $groupAccess) { + /** @var SeedDMS_Core_GroupAccess $groupAccess */ + foreach ($accessList["groups"] as $groupAccess) { if ($user->isMemberOfGroup($groupAccess->getGroup())) { if ($groupAccess->getMode() > $mode) $mode = $groupAccess->getMode(); @@ -1198,7 +1279,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { * applied to get the access mode is the same as describe at * {@link getAccessMode} * - * @param object $group group for which access shall be checked + * @param SeedDMS_Core_Group $group group for which access shall be checked * @return integer access mode */ function getGroupAccessMode($group) { /* {{{ */ @@ -1208,7 +1289,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { if (!$accessList) return false; - foreach ($accessList["groups"] as $groupAccess) { + /** @var SeedDMS_Core_GroupAccess $groupAccess */ + foreach ($accessList["groups"] as $groupAccess) { if ($groupAccess->getGroupID() == $group->getID()) { $foundInACL = true; if ($groupAccess->getMode() > $highestPrivileged) @@ -1224,13 +1306,14 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->getDefaultAccess(); } /* }}} */ - /** + /** @noinspection PhpUnusedParameterInspection */ + /** * Get a list of all notification * This function returns all users and groups that have registerd a * notification for the folder * * @param integer $type type of notification (not yet used) - * @return array array with a the elements 'users' and 'groups' which + * @return SeedDMS_Core_User[]|SeedDMS_Core_Group[]|bool array with a the elements 'users' and 'groups' which * contain a list of users and groups. */ function getNotifyList($type=0) { /* {{{ */ @@ -1272,6 +1355,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { /* Make a copy of both notifier lists because removeNotify will empty * $this->_notifyList and the second foreach will not work anymore. */ + /** @var SeedDMS_Core_User[] $nusers */ $nusers = $this->_notifyList["users"]; $ngroups = $this->_notifyList["groups"]; foreach ($nusers as $u) { @@ -1279,6 +1363,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $this->removeNotify($u->getID(), true); } } + + /** @var SeedDMS_Core_Group[] $ngroups */ foreach ($ngroups as $g) { if ($this->getGroupAccessMode($g) < M_READ) { $this->removeNotify($g->getID(), false); @@ -1286,7 +1372,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { } } /* }}} */ - /* + /** * Add a user/group to the notification list * This function does not check if the currently logged in user * is allowed to add a notification. This must be checked by the calling @@ -1307,6 +1393,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { $userOrGroup = ($isUser) ? "`userID`" : "`groupID`"; /* Verify that user / group exists */ + /** @var SeedDMS_Core_User|SeedDMS_Core_Group $obj */ $obj = ($isUser ? $this->_dms->getUser($userOrGroupID) : $this->_dms->getGroup($userOrGroupID)); if (!is_object($obj)) { return -1; @@ -1356,7 +1443,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { // that the current group has not been explicitly excluded. $acl = $this->getAccessList(M_NONE, O_EQ); $found = false; - foreach ($acl["groups"] as $group) { + /** @var SeedDMS_Core_GroupAccess $group */ + foreach ($acl["groups"] as $group) { if ($group->getGroupID() == $userOrGroupID) { $found = true; break; @@ -1374,7 +1462,8 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return -4; } $found = false; - foreach ($acl["groups"] as $group) { + /** @var SeedDMS_Core_GroupAccess $group */ + foreach ($acl["groups"] as $group) { if ($group->getGroupID() == $userOrGroupID) { $found = true; break; @@ -1407,21 +1496,21 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return 0; } /* }}} */ - /* - * Removes notify for a user or group to folder - * This function does not check if the currently logged in user - * is allowed to remove a notification. This must be checked by the calling - * application. - * - * @param integer $userOrGroupID - * @param boolean $isUser true if $userOrGroupID is a user id otherwise false - * @param $type type of notification (0 will delete all) Not used yet! - * @return integer error code - * -1: Invalid User/Group ID. - * -3: User is not subscribed. - * -4: Database / internal error. - * 0: Update successful. - */ + /** + * Removes notify for a user or group to folder + * This function does not check if the currently logged in user + * is allowed to remove a notification. This must be checked by the calling + * application. + * + * @param integer $userOrGroupID + * @param boolean $isUser true if $userOrGroupID is a user id otherwise false + * @param int $type type of notification (0 will delete all) Not used yet! + * @return int error code + * -1: Invalid User/Group ID. + * -3: User is not subscribed. + * -4: Database / internal error. + * 0: Update successful. + */ function removeNotify($userOrGroupID, $isUser, $type=0) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1494,17 +1583,16 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return $this->getReadAccessList(0, 0); } /* }}} */ - /** - * Returns a list of groups and users with read access on the folder - * The list will not include any guest users, - * administrators and the owner of the folder unless $listadmin resp. - * $listowner is set to true. - * - * @param boolean $listadmin if set to true any admin will be listed too - * @param boolean $listowner if set to true the owner will be listed too - * - * @return array list of users and groups - */ + /** + * Returns a list of groups and users with read access on the folder + * The list will not include any guest users, + * administrators and the owner of the folder unless $listadmin resp. + * $listowner is set to true. + * + * @param bool|int $listadmin if set to true any admin will be listed too + * @param bool|int $listowner if set to true the owner will be listed too + * @return array list of users and groups + */ function getReadAccessList($listadmin=0, $listowner=0) { /* {{{ */ $db = $this->_dms->getDB(); @@ -1530,9 +1618,12 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { // to the folder. $tmpList = $this->getAccessList(M_NONE, O_LTEQ); } + /** @var SeedDMS_Core_GroupAccess $groupAccess */ foreach ($tmpList["groups"] as $groupAccess) { $groupIDs .= (strlen($groupIDs)==0 ? "" : ", ") . $groupAccess->getGroupID(); } + + /** @var SeedDMS_Core_UserAccess $userAccess */ foreach ($tmpList["users"] as $userAccess) { $user = $userAccess->getUser(); if (!$listadmin && $user->isAdmin()) continue; @@ -1671,6 +1762,4 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object { return true; } /* }}} */ -} - -?> +} \ No newline at end of file