2015-06-01 05:16:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of ReviewDocument controller
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
2023-06-18 11:59:23 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
|
2015-06-01 05:16:21 +00:00
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-06-18 11:59:23 +00:00
|
|
|
* Class which does the busines logic for reviewing a document
|
2015-06-01 05:16:21 +00:00
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
2023-06-18 11:59:23 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
|
2015-06-01 05:16:21 +00:00
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Controller_ReviewDocument extends SeedDMS_Controller_Common {
|
|
|
|
|
2023-06-18 11:59:23 +00:00
|
|
|
public function run() { /* {{{ */
|
2015-06-01 05:16:21 +00:00
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
$settings = $this->params['settings'];
|
|
|
|
$content = $this->params['content'];
|
2023-06-18 11:59:23 +00:00
|
|
|
$reviewtype = $this->params['type'];
|
|
|
|
$reviewstatus = $this->params['status'];
|
|
|
|
$reviewcomment = $this->params['comment'];
|
|
|
|
$reviewfile = $this->params['file'];
|
|
|
|
$reviewgroup = $this->params['group'];
|
|
|
|
$overallStatus = $content->getStatus();
|
|
|
|
$this->oldstatus = $overallStatus['status'];
|
|
|
|
$this->newstatus = $this->oldstatus;
|
2015-06-01 05:16:21 +00:00
|
|
|
|
2015-06-01 15:34:52 +00:00
|
|
|
if(!$this->callHook('preReviewDocument', $content)) {
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-01 15:34:52 +00:00
|
|
|
$result = $this->callHook('reviewDocument', $content);
|
2015-06-01 05:16:21 +00:00
|
|
|
if($result === null) {
|
|
|
|
if ($reviewtype == "ind") {
|
2023-06-19 14:51:15 +00:00
|
|
|
$reviewLogID = $content->setReviewByInd($user, $user, $reviewstatus, $reviewcomment, $reviewfile);
|
|
|
|
} elseif($reviewtype == "grp") {
|
|
|
|
$reviewLogID = $content->setReviewByGrp($reviewgroup, $user, $reviewstatus, $reviewcomment, $reviewfile);
|
|
|
|
} else {
|
|
|
|
$this->errormsg = "review_wrong_type";
|
|
|
|
return false;
|
2023-06-18 11:59:23 +00:00
|
|
|
}
|
2023-06-19 14:51:15 +00:00
|
|
|
if($reviewLogID === false || 0 > $reviewLogID) {
|
|
|
|
$this->errormsg = "review_update_failed";
|
2023-06-18 11:59:23 +00:00
|
|
|
return false;
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 15:34:52 +00:00
|
|
|
$result = $this->callHook('reviewUpdateDocumentStatus', $content);
|
2015-06-01 05:16:21 +00:00
|
|
|
if($result === null) {
|
2023-06-19 14:51:15 +00:00
|
|
|
if($reviewstatus == -1) {
|
|
|
|
$this->newstatus = S_REJECTED;
|
|
|
|
if($content->setStatus(S_REJECTED, $reviewcomment, $user)) {
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, 'postReviewDocument')) {
|
|
|
|
$hookObj->postReviewDocument(null, $content, S_REJECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$docReviewStatus = $content->getReviewStatus();
|
|
|
|
if (is_bool($docReviewStatus) && !$docReviewStatus) {
|
|
|
|
$this->errormsg = "cannot_retrieve_review_snapshot";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$reviewCT = 0;
|
|
|
|
$reviewTotal = 0;
|
|
|
|
foreach ($docReviewStatus as $drstat) {
|
|
|
|
if ($drstat["status"] == 1) {
|
|
|
|
$reviewCT++;
|
|
|
|
}
|
|
|
|
if ($drstat["status"] != -2) {
|
|
|
|
$reviewTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If all reviews have been received and there are no rejections, retrieve a
|
|
|
|
// count of the approvals required for this document.
|
|
|
|
if ($reviewCT == $reviewTotal) {
|
|
|
|
$docApprovalStatus = $content->getApprovalStatus();
|
|
|
|
if (is_bool($docApprovalStatus) && !$docApprovalStatus) {
|
|
|
|
$this->errormsg = "cannot_retrieve_approval_snapshot";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$approvalCT = 0;
|
|
|
|
$approvalTotal = 0;
|
2023-06-19 14:51:15 +00:00
|
|
|
foreach($docApprovalStatus as $dastat) {
|
|
|
|
if($dastat["status"] == 1) {
|
2015-06-01 05:16:21 +00:00
|
|
|
$approvalCT++;
|
|
|
|
}
|
2023-06-19 14:51:15 +00:00
|
|
|
if($dastat["status"] != -2) {
|
2015-06-01 05:16:21 +00:00
|
|
|
$approvalTotal++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the approvals received is less than the approvals total, then
|
|
|
|
// change status to pending approval.
|
2023-06-19 14:51:15 +00:00
|
|
|
if($approvalCT < $approvalTotal) {
|
|
|
|
$this->newstatus = S_DRAFT_APP;
|
|
|
|
} else {
|
2015-06-01 05:16:21 +00:00
|
|
|
// Otherwise, change the status to released.
|
2023-06-19 14:51:15 +00:00
|
|
|
$this->newstatus = S_RELEASED;
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
2023-06-19 14:51:15 +00:00
|
|
|
if($content->setStatus($this->newstatus, getMLText("automatic_status_update"), $user)) {
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['reviewDocument'] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, 'postReviewDocument')) {
|
|
|
|
$hookObj->postReviewDocument(null, $content, $this->newstatus);
|
|
|
|
}
|
2023-06-18 11:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 15:34:52 +00:00
|
|
|
if(!$this->callHook('postReviewDocument', $content)) {
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2023-06-18 11:59:23 +00:00
|
|
|
} /* }}} */
|
2015-06-01 05:16:21 +00:00
|
|
|
}
|