more documentation, better parameter checking, return false is sql fails

This commit is contained in:
Uwe Steinmann 2021-09-29 17:21:19 +02:00
parent 7366644d19
commit 335c2ffee5

View File

@ -3826,12 +3826,25 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return true; return true;
} /* }}} */ } /* }}} */
/**
* Add user as new reviewer
*
* @param object $user user in charge for the review
* @param object $requestUser user requesting the operation (usually the
* currently logged in user)
*
* @return integer|false if > 0 the id of the review log, if < 0 the error
* code, false in case of an sql error
*/
function addIndReviewer($user, $requestUser) { /* {{{ */ function addIndReviewer($user, $requestUser) { /* {{{ */
if(!$user || !$requestUser) if(!$user || !$requestUser)
return -1; return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$user->isType('user'))
return -1;
$userID = $user->getID(); $userID = $user->getID();
// Get the list of users and groups with read access to this document. // Get the list of users and groups with read access to this document.
@ -3871,18 +3884,33 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
"VALUES ('". $reviewID ."', '0', '', ".$db->getCurrentDatetime().", '". $requestUser->getID() ."')"; "VALUES ('". $reviewID ."', '0', '', ".$db->getCurrentDatetime().", '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr); $res = $db->getResult($queryStr);
if (is_bool($res) && !$res) { if (is_bool($res) && !$res) {
return -1; return false;
} }
// Add reviewer to event notification table. $reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID');
//$this->_document->addNotify($userID, true); $db->dropTemporaryTable('ttreviewid');
return $reviewLogID;
return 0;
} /* }}} */ } /* }}} */
/**
* Add group as new reviewer
*
* @param object $group group in charge for the review
* @param object $requestUser user requesting the operation (usually the
* currently logged in user)
*
* @return integer|false if > 0 the id of the review log, if < 0 the error
* code, false in case of an sql error
*/
function addGrpReviewer($group, $requestUser) { /* {{{ */ function addGrpReviewer($group, $requestUser) { /* {{{ */
if(!$group || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$group->isType('group'))
return -1;
$groupID = $group->getID(); $groupID = $group->getID();
// Get the list of users and groups with read access to this document. // Get the list of users and groups with read access to this document.
@ -3951,20 +3979,29 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* added, the review log id will be returned. * added, the review log id will be returned.
* *
* @see SeedDMS_Core_DocumentContent::setApprovalByInd() * @see SeedDMS_Core_DocumentContent::setApprovalByInd()
*
* @param object $user user doing the review * @param object $user user doing the review
* @param object $requestUser user asking for the review, this is mostly * @param object $requestUser user asking for the review, this is mostly
* the user currently logged in. * the user currently logged in.
* @param integer $status status of review * @param integer $status status of review
* @param string $comment comment for review * @param string $comment comment for review
* @return integer new review log id *
* @return integer|bool new review log id, error code 0 till -4,
* false in case of an sql error
*/ */
function setReviewByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */ function setReviewByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */
if(!$user || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
// Check to see if the user can be removed from the review list. if(!$user->isType('user'))
return -1;
// Check if the user is on the review list at all.
$reviewStatus = $user->getReviewStatus($this->_document->getID(), $this->_version); $reviewStatus = $user->getReviewStatus($this->_document->getID(), $this->_version);
if (is_bool($reviewStatus) && !$reviewStatus) { if (is_bool($reviewStatus) && !$reviewStatus) {
return -1; return false;
} }
if (count($reviewStatus["indstatus"])==0) { if (count($reviewStatus["indstatus"])==0) {
// User is not assigned to review this document. No action required. // User is not assigned to review this document. No action required.
@ -4001,13 +4038,17 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* *
* This method will not delete anything from the database, but will add * 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 * a new review log entry which sets the status to 0. This is only allowed
* if the current status is either 1 or -1. * if the current status is either 1 (reviewed) or -1 (rejected).
* *
* After calling this method SeedDMS_Core_DocumentCategory::verifyStatus() * After calling this method SeedDMS_Core_DocumentCategory::verifyStatus()
* should be called to recalculate the document status. * should be called to recalculate the document status.
* *
* @param SeedDMS_Core_User $user * @param integer $reviewid id of review
* @return int 0 if successful * @param SeedDMS_Core_User $requestUser user requesting the removal
* @param string $comment comment
*
* @return integer|bool true if successful, error code < 0,
* false in case of an sql error
*/ */
public function removeReview($reviewid, $requestUser, $comment='') { /* {{{ */ public function removeReview($reviewid, $requestUser, $comment='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
@ -4055,22 +4096,30 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* the user currently logged in. * the user currently logged in.
* @param integer $status status of review * @param integer $status status of review
* @param string $comment comment for review * @param string $comment comment for review
* @return integer new review log id *
* @return integer|bool new review log id, error code 0 till -4,
* false in case of an sql error
*/ */
function setReviewByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */ function setReviewByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */
if(!$group || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
// Check to see if the user can be removed from the review list. if(!$group->isType('group'))
return -1;
// Check if the group is on the review list at all.
$reviewStatus = $group->getReviewStatus($this->_document->getID(), $this->_version); $reviewStatus = $group->getReviewStatus($this->_document->getID(), $this->_version);
if (is_bool($reviewStatus) && !$reviewStatus) { if (is_bool($reviewStatus) && !$reviewStatus) {
return -1; return false;
} }
if (count($reviewStatus)==0) { if (count($reviewStatus)==0) {
// User is not assigned to review this document. No action required. // User is not assigned to review this document. No action required.
// Return an error. // Return an error.
return -3; return -3;
} }
if ($reviewStatus[0]["status"]==-2) { if ((int) $reviewStatus[0]["status"]==-2) {
// Group has been deleted from reviewers // Group has been deleted from reviewers
return -4; return -4;
} }
@ -4086,22 +4135,34 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$requestUser->getID() ."')"; $requestUser->getID() ."')";
$res=$db->getResult($queryStr); $res=$db->getResult($queryStr);
if (is_bool($res) && !$res) if (is_bool($res) && !$res)
return -1; return false;
else {
$reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID'); $reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID');
if($file) { if($file) {
SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID); SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID);
} }
return $reviewLogID; return $reviewLogID;
}
} /* }}} */ } /* }}} */
/**
* Add user as new approver
*
* @param object $user user in charge for the approval
* @param object $requestUser user requesting the operation (usually the
* currently logged in user)
*
* @return integer|false if > 0 the id of the approval log, if < 0 the error
* code, false in case of an sql error
*/
function addIndApprover($user, $requestUser) { /* {{{ */ function addIndApprover($user, $requestUser) { /* {{{ */
if(!$user || !$requestUser) if(!$user || !$requestUser)
return -1; return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$user->isType('user'))
return -1;
$userID = $user->getID(); $userID = $user->getID();
// Get the list of users and groups with read access to this document. // Get the list of users and groups with read access to this document.
@ -4141,16 +4202,33 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
"VALUES ('". $approveID ."', '0', '', ".$db->getCurrentDatetime().", '". $requestUser->getID() ."')"; "VALUES ('". $approveID ."', '0', '', ".$db->getCurrentDatetime().", '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr); $res = $db->getResult($queryStr);
if (is_bool($res) && !$res) { if (is_bool($res) && !$res) {
return -1; return false;
} }
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID'); $approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
$db->dropTemporaryTable('ttapproveid');
return $approveLogID; return $approveLogID;
} /* }}} */ } /* }}} */
/**
* Add group as new approver
*
* @param object $group group in charge for the approval
* @param object $requestUser user requesting the operation (usually the
* currently logged in user)
*
* @return integer|false if > 0 the id of the approval log, if < 0 the error
* code, false in case of an sql error
*/
function addGrpApprover($group, $requestUser) { /* {{{ */ function addGrpApprover($group, $requestUser) { /* {{{ */
if(!$group || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$group->isType('group'))
return -1;
$groupID = $group->getID(); $groupID = $group->getID();
// Get the list of users and groups with read access to this document. // Get the list of users and groups with read access to this document.
@ -4219,6 +4297,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* the function returns with an error. * the function returns with an error.
* *
* @see SeedDMS_Core_DocumentContent::setReviewByInd() * @see SeedDMS_Core_DocumentContent::setReviewByInd()
*
* @param object $user user in charge for doing the approval * @param object $user user in charge for doing the approval
* @param object $requestUser user actually calling this function * @param object $requestUser user actually calling this function
* @param integer $status the status of the approval, possible values are * @param integer $status the status of the approval, possible values are
@ -4228,15 +4307,23 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* -2=user is deleted (use {link * -2=user is deleted (use {link
* SeedDMS_Core_DocumentContent::delIndApprover} instead) * SeedDMS_Core_DocumentContent::delIndApprover} instead)
* @param string $comment approval comment * @param string $comment approval comment
* @return integer 0 on success, < 0 in case of an error *
* @return integer|bool new review log id, error code 0 till -4,
* false in case of an sql error
*/ */
function setApprovalByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */ function setApprovalByInd($user, $requestUser, $status, $comment, $file='') { /* {{{ */
if(!$user || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
// Check to see if the user can be removed from the approval list. if(!$user->isType('user'))
return -1;
// Check if the user is on the approval list at all.
$approvalStatus = $user->getApprovalStatus($this->_document->getID(), $this->_version); $approvalStatus = $user->getApprovalStatus($this->_document->getID(), $this->_version);
if (is_bool($approvalStatus) && !$approvalStatus) { if (is_bool($approvalStatus) && !$approvalStatus) {
return -1; return false;
} }
if (count($approvalStatus["indstatus"])==0) { if (count($approvalStatus["indstatus"])==0) {
// User is not assigned to approve this document. No action required. // User is not assigned to approve this document. No action required.
@ -4272,14 +4359,18 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
* Add another entry to approval log which resets the status * Add another entry to approval log which resets the status
* *
* This method will not delete anything from the database, but will add * 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 * a new approval log entry which sets the status to 0. This is only allowed
* if the current status is either 1 or -1. * if the current status is either 1 (approved) or -1 (rejected).
* *
* After calling this method SeedDMS_Core_DocumentCategory::verifyStatus() * After calling this method SeedDMS_Core_DocumentCategory::verifyStatus()
* should be called to recalculate the document status. * should be called to recalculate the document status.
* *
* @param SeedDMS_Core_User $user * @param integer $approveid id of approval
* @return int 0 if successful * @param SeedDMS_Core_User $requestUser user requesting the removal
* @param string $comment comment
*
* @return integer|bool true if successful, error code < 0,
* false in case of an sql error
*/ */
public function removeApproval($approveid, $requestUser, $comment='') { /* {{{ */ public function removeApproval($approveid, $requestUser, $comment='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
@ -4309,25 +4400,31 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$requestUser->getID() ."')"; $requestUser->getID() ."')";
$res=$db->getResult($queryStr); $res=$db->getResult($queryStr);
if (is_bool($res) && !$res) if (is_bool($res) && !$res)
return -1; return false;
return 0; return true;
} /* }}} */ } /* }}} */
/** /**
* Sets approval status of a document content for a group * Sets approval status of a document content for a group
*
* The functions behaves like * The functions behaves like
* {link SeedDMS_Core_DocumentContent::setApprovalByInd} but does it for * {link SeedDMS_Core_DocumentContent::setApprovalByInd} but does it for
* group instead of a user * a group instead of a user
*/ */
function setApprovalByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */ function setApprovalByGrp($group, $requestUser, $status, $comment, $file='') { /* {{{ */
if(!$group || !$requestUser)
return -1;
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
// Check to see if the user can be removed from the approval list. if(!$group->isType('group'))
return -1;
// Check if the group is on the approval list at all.
$approvalStatus = $group->getApprovalStatus($this->_document->getID(), $this->_version); $approvalStatus = $group->getApprovalStatus($this->_document->getID(), $this->_version);
if (is_bool($approvalStatus) && !$approvalStatus) { if (is_bool($approvalStatus) && !$approvalStatus) {
return -1; return false;
} }
if (count($approvalStatus)==0) { if (count($approvalStatus)==0) {
// User is not assigned to approve this document. No action required. // User is not assigned to approve this document. No action required.
@ -4362,10 +4459,13 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function delIndReviewer($user, $requestUser, $msg='') { /* {{{ */ function delIndReviewer($user, $requestUser, $msg='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$user->isType('user'))
return -1;
// Check to see if the user can be removed from the review list. // Check to see if the user can be removed from the review list.
$reviewStatus = $user->getReviewStatus($this->_document->getID(), $this->_version); $reviewStatus = $user->getReviewStatus($this->_document->getID(), $this->_version);
if (is_bool($reviewStatus) && !$reviewStatus) { if (is_bool($reviewStatus) && !$reviewStatus) {
return -1; return false;
} }
if (count($reviewStatus["indstatus"])==0) { if (count($reviewStatus["indstatus"])==0) {
// User is not assigned to review this document. No action required. // User is not assigned to review this document. No action required.
@ -4392,12 +4492,15 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function delGrpReviewer($group, $requestUser, $msg='') { /* {{{ */ function delGrpReviewer($group, $requestUser, $msg='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$group->isType('group'))
return -1;
$groupID = $group->getID(); $groupID = $group->getID();
// Check to see if the user can be removed from the review list. // Check to see if the user can be removed from the review list.
$reviewStatus = $group->getReviewStatus($this->_document->getID(), $this->_version); $reviewStatus = $group->getReviewStatus($this->_document->getID(), $this->_version);
if (is_bool($reviewStatus) && !$reviewStatus) { if (is_bool($reviewStatus) && !$reviewStatus) {
return -1; return false;
} }
if (count($reviewStatus)==0) { if (count($reviewStatus)==0) {
// User is not assigned to review this document. No action required. // User is not assigned to review this document. No action required.
@ -4423,12 +4526,15 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function delIndApprover($user, $requestUser, $msg='') { /* {{{ */ function delIndApprover($user, $requestUser, $msg='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$user->isType('user'))
return -1;
$userID = $user->getID(); $userID = $user->getID();
// Check to see if the user can be removed from the approval list. // Check if the user is on the approval list at all.
$approvalStatus = $user->getApprovalStatus($this->_document->getID(), $this->_version); $approvalStatus = $user->getApprovalStatus($this->_document->getID(), $this->_version);
if (is_bool($approvalStatus) && !$approvalStatus) { if (is_bool($approvalStatus) && !$approvalStatus) {
return -1; return false;
} }
if (count($approvalStatus["indstatus"])==0) { if (count($approvalStatus["indstatus"])==0) {
// User is not assigned to approve this document. No action required. // User is not assigned to approve this document. No action required.
@ -4455,12 +4561,15 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
function delGrpApprover($group, $requestUser, $msg='') { /* {{{ */ function delGrpApprover($group, $requestUser, $msg='') { /* {{{ */
$db = $this->_document->getDMS()->getDB(); $db = $this->_document->getDMS()->getDB();
if(!$group->isType('group'))
return -1;
$groupID = $group->getID(); $groupID = $group->getID();
// Check to see if the user can be removed from the approver list. // Check if the group is on the approval list at all.
$approvalStatus = $group->getApprovalStatus($this->_document->getID(), $this->_version); $approvalStatus = $group->getApprovalStatus($this->_document->getID(), $this->_version);
if (is_bool($approvalStatus) && !$approvalStatus) { if (is_bool($approvalStatus) && !$approvalStatus) {
return -1; return false;
} }
if (count($approvalStatus)==0) { if (count($approvalStatus)==0) {
// User is not assigned to approve this document. No action required. // User is not assigned to approve this document. No action required.