seeddms-code/controllers/class.ReviewDocument.php

132 lines
4.0 KiB
PHP
Raw Normal View History

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>
* @copyright Copyright (C) 2010-2023 Uwe Steinmann
2015-06-01 05:16:21 +00:00
* @version Release: @package_version@
*/
/**
* 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>
* @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 {
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'];
$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") {
$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;
}
if($reviewLogID === false || 0 > $reviewLogID) {
$this->errormsg = "review_update_failed";
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) {
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;
foreach($docApprovalStatus as $dastat) {
if($dastat["status"] == 1) {
2015-06-01 05:16:21 +00:00
$approvalCT++;
}
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.
if($approvalCT < $approvalTotal) {
$this->newstatus = S_DRAFT_APP;
} else {
2015-06-01 05:16:21 +00:00
// Otherwise, change the status to released.
$this->newstatus = S_RELEASED;
2015-06-01 05:16:21 +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);
}
}
}
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;
} /* }}} */
2015-06-01 05:16:21 +00:00
}