diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 822eea6c6..9345e56d2 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -4194,6 +4194,53 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */ return $approveLogID; } /* }}} */ + /** + * Add another entry to approval log which resets the status + * + * This method will not delete anything from the database, but will add + * a new review log entry which sets the status to 0. This is only allowed + * if the current status is either 1 or -1. + * + * After calling this method SeedDMS_Core_DocumentCategory::verifyStatus() + * should be called to recalculate the document status. + * + * @param SeedDMS_Core_User $user + * @return int 0 if successful + */ + public function removeApproval($approveid, $requestUser, $comment='') { /* {{{ */ + $db = $this->_document->getDMS()->getDB(); + + // Check to see if the user can be removed from the approval list. + $approvals = $this->getApprovalStatus(); + if (is_bool($approvals) && !$approvals) { + return -1; + } + $approvalStatus = null; + foreach($approvals as $approval) { + if($approval['approveID'] == $approveid) { + $approvalStatus = $approval; + break; + } + } + if(!$approvalStatus) + return -2; + + // The approval log entry may only be removed if the status is 1 or -1 + if ($approvalStatus["status"] != 1 && $approvalStatus["status"] != -1) + return -3; + + $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, + `comment`, `date`, `userID`) ". + "VALUES ('". $approvalStatus["approveID"] ."', '0', ".$db->qstr($comment).", ".$db->getCurrentDatetime().", '". + $requestUser->getID() ."')"; + $res=$db->getResult($queryStr); + if (is_bool($res) && !$res) + return -1; + + return 0; + } /* }}} */ + + /** * Sets approval status of a document content for a group * The functions behaves like diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index 24e70aa76..4df5e6bdf 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -31,6 +31,7 @@ - fix checking of email addresses by using filter_var instead of regex - add new method SeedDMS_Core_Document::hasCategory() - add new method SeedDMS_Core_DocumentContent::removeReview() +- add new method SeedDMS_Core_DocumentContent::removeApproval()