add optional parameter $newuser to removeFromProcesses()

if set, the process will be transfered to a new user
This commit is contained in:
Uwe Steinmann 2019-11-28 09:16:23 +01:00
parent 2ec6534079
commit 3011f96372

View File

@ -899,7 +899,8 @@ class SeedDMS_Core_User { /* {{{ */
*
* This method adds another log entry to the reviews and approvals
* which indicates the user has been deleted from the process. By default it will
* do so for each review/approval regardless of its current state. So even
* do so for each review/approval regardless of its current state unless
* the user has been removed already (status=-2). 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.
@ -907,24 +908,42 @@ 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
* If passing array(0), the method will operate on reviews/approval which
* has not been touched.
* e.g. if passing array('review'=>array(0)), the method will operate on
* reviews which has not been touched yet.
* @return boolean true on success or false in case of an error
*/
private function __removeFromProcesses($user, $states = array()) { /* {{{ */
private function __removeFromProcesses($user, $states = array(), $newuser=null) { /* {{{ */
$db = $this->_dms->getDB();
$reviewStatus = $this->getReviewStatus();
// var_dump($newuser);
// print_r($reviewStatus);exit;
$db->startTransaction();
foreach ($reviewStatus["indstatus"] as $ri) {
if($ri['status'] != -2 && (!isset($states['review']) || in_array($ri['status'], $states['review']))) {
$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) {
$db->rollbackTransaction();
return false;
}
/* Only reviews not done already can be transferred to a new user */
if($newuser && $ri['status'] == 0) {
if($doc = $this->_dms->getDocument($ri['documentID'])) {
if($version = $doc->getContentByVersion($ri['version'])) {
$ret = $version->addIndReviewer($newuser, $user);
/* returns -3 if the user is already a reviewer */
if($ret != 0 && $ret != -3) {
$db->rollbackTransaction();
return false;
}
}
}
}
}
}
$db->commitTransaction();
$approvalStatus = $this->getApprovalStatus();
foreach ($approvalStatus["indstatus"] as $ai) {
@ -975,11 +994,11 @@ class SeedDMS_Core_User { /* {{{ */
* @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, $states=array()) { /* {{{ */
public function removeFromProcesses($user, $states=array(), $newuser=null) { /* {{{ */
$db = $this->_dms->getDB();
$db->startTransaction();
if(!$this->__removeFromProcesses($user, $states)) {
if(!$this->__removeFromProcesses($user, $states, $newuser)) {
$db->rollbackTransaction();
return false;
}