add option parameter $states to __removeFromProcesses()

restricts removal to certain approval/review states
This commit is contained in:
Uwe Steinmann 2017-07-28 14:56:18 +02:00
parent 1ecb6236c0
commit d0ab0d0f9f

View File

@ -477,32 +477,42 @@ class SeedDMS_Core_User { /* {{{ */
/**
* Remove user from all processes
*
* This includes review, approval and workflow
* This method adds another log entry to the reviews and approvals
* which indicates the user has been deleted from the process. It will
* do so for each review/approval regardless of its current state. So even
* reviews/approvals already processed by the user will be added the log
* entry. Only if the last log entry was a removal already, it will not be
* added a second time.
*
* @param object $user the user doing the removal (needed for entry in
* review and approve log).
* @param array $states remove user only from reviews/approvals in one of the states
* @return boolean true on success or false in case of an error
*/
private function __removeFromProcesses($user) { /* {{{ */
private function __removeFromProcesses($user, $states = array()) { /* {{{ */
$db = $this->_dms->getDB();
$reviewStatus = $this->getReviewStatus();
foreach ($reviewStatus["indstatus"] as $ri) {
$queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ri["reviewID"] ."', '-2', 'Reviewer removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
return false;
if($ri['status'] != -2 && (!$states || in_array($ri['status'], $states))) {
$queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ri["reviewID"] ."', '-2', 'Reviewer removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
return false;
}
}
}
$approvalStatus = $this->getApprovalStatus();
foreach ($approvalStatus["indstatus"] as $ai) {
$queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ai["approveID"] ."', '-2', 'Approver removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
return false;
if($ai['status'] != -2 && (!$states || in_array($ai['status'], $states))) {
$queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $ai["approveID"] ."', '-2', 'Approver removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
$res=$db->getResult($queryStr);
if(!$res) {
return false;
}
}
}
return true;
@ -515,13 +525,14 @@ class SeedDMS_Core_User { /* {{{ */
*
* @param object $user the user doing the removal (needed for entry in
* review and approve log).
* @param array $states remove user only from reviews/approvals in one of the states
* @return boolean true on success or false in case of an error
*/
public function removeFromProcesses($user) { /* {{{ */
public function removeFromProcesses($user, $states=array()) { /* {{{ */
$db = $this->_dms->getDB();
$db->startTransaction();
if(!$this->__removeFromProcesses($user)) {
if(!$this->__removeFromProcesses($user, $states)) {
$db->rollbackTransaction();
return false;
}
@ -923,11 +934,14 @@ class SeedDMS_Core_User { /* {{{ */
/**
* Get a list of reviews
* This function returns a list of all reviews seperated by individual
* and group reviews. If the document id
*
* This function returns a list of all reviews and their latest log entry
* seperated by individuals and groups. If the document id
* is passed, then only this document will be checked for reviews. The
* same is true for the version of a document which limits the list
* further.
* further. If you do not limit on a version it will retrieve the status
* for each version, that includes even older versions which has been superseded
* by a new version.
*
* For a detailed description of the result array see
* {link SeedDMS_Core_User::getApprovalStatus} which does the same for
@ -1001,17 +1015,21 @@ class SeedDMS_Core_User { /* {{{ */
/**
* Get a list of approvals
* This function returns a list of all approvals seperated by individual
* and group approvals. If the document id
*
* This function returns a list of all approvals and their latest log entry
* seperated by individuals and groups. If the document id
* is passed, then only this document will be checked for approvals. The
* same is true for the version of a document which limits the list
* further.
* further. If you do not limit on a version it will retrieve the status
* for each version, that includes even older versions which has been superseded
* by a new version.
*
* The result array has two elements:
* - indstatus: which contains the approvals by individuals (users)
* - grpstatus: which contains the approvals by groups
*
* Each element is itself an array of approvals with the following elements:
* Each element is itself an array of approvals with the following elements
* (it is a combination of fields from tblDocumentApprovers and tblDocumentApproveLog):
* - approveID: unique id of approval
* - documentID: id of document, that needs to be approved
* - version: version of document, that needs to be approved