add new methods getMandatoryReviewers() and getMandatoryApprovers()

This commit is contained in:
Uwe Steinmann 2021-02-24 13:22:03 +01:00
parent 08ee240dc1
commit 20586c021d

View File

@ -33,13 +33,13 @@ function formatted_size($size_bytes) { /* {{{ */
* dd for %d
* This functions returns the converted format
*/
function getConvertDateFormat() {
function getConvertDateFormat() { /* {{{ */
global $settings;
if($settings->_dateformat) {
return str_replace(['y', 'Y', 'm', 'M', 'F', 'd', 'l', 'D'], ['yy', 'yyyy', 'mm', 'M', 'MM', 'dd', 'DD', 'D'], $settings->_dateformat);
} else
return 'yyyy-mm-dd';
}
} /* }}} */
function getReadableDate($timestamp=0) { /* {{{ */
global $settings;
@ -431,24 +431,24 @@ function _add_log_line($msg="") { /* {{{ */
}
} /* }}} */
function getFolderPathHTML($folder, $tagAll=false, $document=null) { /* {{{ */
$path = $folder->getPath();
$txtpath = "";
for ($i = 0; $i < count($path); $i++) {
if ($i +1 < count($path)) {
$txtpath .= "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
htmlspecialchars($path[$i]->getName())."</a> / ";
}
else {
$txtpath .= ($tagAll ? "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
htmlspecialchars($path[$i]->getName())."</a>" : htmlspecialchars($path[$i]->getName()));
}
function getFolderPathHTML($folder, $tagAll=false, $document=null) { /* {{{ */
$path = $folder->getPath();
$txtpath = "";
for ($i = 0; $i < count($path); $i++) {
if ($i +1 < count($path)) {
$txtpath .= "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
htmlspecialchars($path[$i]->getName())."</a> / ";
}
if($document)
$txtpath .= " / <a href=\"../out/out.ViewDocument.php?documentid=".$document->getId()."\">".htmlspecialchars($document->getName())."</a>";
else {
$txtpath .= ($tagAll ? "<a href=\"../out/out.ViewFolder.php?folderid=".$path[$i]->getID()."&showtree=".showtree()."\">".
htmlspecialchars($path[$i]->getName())."</a>" : htmlspecialchars($path[$i]->getName()));
}
}
if($document)
$txtpath .= " / <a href=\"../out/out.ViewDocument.php?documentid=".$document->getId()."\">".htmlspecialchars($document->getName())."</a>";
return $txtpath;
} /* }}} */
return $txtpath;
} /* }}} */
function showtree() { /* {{{ */
global $settings;
@ -776,6 +776,82 @@ function createNonce() { /* {{{ */
return base64_encode($bytes);
} /* }}} */
/**
* Returns the mandatory reviewers
*
* This function checks if the reviewers have at least read access
* on the folder containing the document.
*
* @param $folder folder where document is located
* @param $user user creating the new version or document
* @return array
*/
function getMandatoryReviewers($folder, $user) { /* {{{ */
global $settings;
/* Get a list of all users and groups with read access on the folder.
* Only those users and groups will be added as reviewers
*/
$docAccess = $folder->getReadAccessList($settings->_enableAdminRevApp, $settings->_enableOwnerRevApp);
$res=$user->getMandatoryReviewers();
$reviewers = array('i'=>[], 'g'=>[]);
foreach ($res as $r){
if ($r['reviewerUserID']!=0){
foreach ($docAccess["users"] as $usr)
if ($usr->getID()==$r['reviewerUserID']){
$reviewers["i"][] = $r['reviewerUserID'];
break;
}
} elseif ($r['reviewerGroupID']!=0){
foreach ($docAccess["groups"] as $grp)
if ($grp->getID()==$r['reviewerGroupID']){
$reviewers["g"][] = $r['reviewerGroupID'];
break;
}
}
}
return $reviewers;
} /* }}} */
/**
* Returns the mandatory approvers
*
* This function checks if the approvers have at least read access
* on the folder containing the document.
*
* @param $folder folder where document is located
* @param $user user creating the new version or document
* @return array
*/
function getMandatoryApprovers($folder, $user) { /* {{{ */
global $settings;
/* Get a list of all users and groups with read access on the folder.
* Only those users and groups will be added as approvers
*/
$docAccess = $folder->getReadAccessList($settings->_enableAdminRevApp, $settings->_enableOwnerRevApp);
$res=$user->getMandatoryApprovers();
$approvers = array('i'=>[], 'g'=>[]);
foreach ($res as $r){
if ($r['approverUserID']!=0){
foreach ($docAccess["users"] as $usr)
if ($usr->getID()==$r['approverUserID']){
$approvers["i"][] = $r['approverUserID'];
break;
}
}
else if ($r['approverGroupID']!=0){
foreach ($docAccess["groups"] as $grp)
if ($grp->getID()==$r['approverGroupID']){
$approvers["g"][] = $r['approverGroupID'];
break;
}
}
}
return $approvers;
} /* }}} */
/**
* Class for creating encrypted api keys
*