add administration of recipients of documents

This commit is contained in:
Uwe Steinmann 2015-04-20 13:43:40 +02:00
parent 03bfa5f972
commit 8824aa4624
2 changed files with 412 additions and 1 deletions

View File

@ -2805,6 +2805,55 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return $this->_approvalStatus;
} /* }}} */
/**
* Get the current receipt status of the document content
* The receipt status is a list of receipts
*
* @return array list of receipts
*/
function getReceiptStatus() { /* {{{ */
$db = $this->_document->_dms->getDB();
if (!is_numeric($limit)) return false;
// Retrieve the current status of each assigned reviewer for the content
// represented by this object.
// FIXME: caching was turned off to make list of review log in ViewDocument
// possible
if (1 || !isset($this->_receiptStatus)) {
/* First get a list of all receipts for this document content */
$queryStr=
"SELECT receiptID FROM tblDocumentRecipients WHERE `version`='".$this->_version
."' AND `documentID` = '". $this->_document->getID() ."' ";
$recs = $db->getResultArray($queryStr);
if (is_bool($recs) && !$recs)
return false;
$this->_reviewStatus = array();
if($recs) {
foreach($recs as $rec) {
$queryStr=
"SELECT `tblDocumentRecipients`.*, `tblDocumentReceiptLog`.`receiptLogID`, ".
"`tblDocumentReceiptLog`.`date`, ".
"`tblDocumentReceiptLog`.`userID`, `tblUsers`.`fullName`, `tblGroups`.`name` AS `groupName` ".
"FROM `tblDocumentReviewers` ".
"LEFT JOIN `tblDocumentReceiptLog` USING (`reviewID`) ".
"LEFT JOIN `tblUsers` on `tblUsers`.`id` = `tblDocumentRecipients`.`required`".
"LEFT JOIN `tblGroups` on `tblGroups`.`id` = `tblDocumentRecipients`.`required`".
"WHERE `tblDocumentRecipients`.`reviewID` = '". $rec['reviewID'] ."' ".
"ORDER BY `tblDocumentReceiptLog`.`receiptLogID` DESC";
$res = $db->getResultArray($queryStr);
if (is_bool($res) && !$res) {
unset($this->_receiptStatus);
return false;
}
$this->_receiptStatus = array_merge($this->_receiptStatus, $res);
}
}
}
return $this->_receiptStatus;
} /* }}} */
function addIndReviewer($user, $requestUser, $listadmin=false) { /* {{{ */
$db = $this->_document->_dms->getDB();
@ -3253,6 +3302,222 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return 0;
} /* }}} */
function addIndRecipient($user, $requestUser, $listadmin=false) { /* {{{ */
$db = $this->_document->_dms->getDB();
$userID = $user->getID();
// Get the list of users and groups with read access to this document.
if($this->_document->getAccessMode($user) < M_READ) {
return -2;
}
// Check to see if the user has already been added to the receipt list.
$receiptStatus = $user->getReviewStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
$indstatus = false;
if (count($receiptStatus["indstatus"]) > 0) {
$indstatus = array_pop($receiptStatus["indstatus"]);
if($indstatus["status"]!=-2) {
// User is already on the list of recipients; return an error.
return -3;
}
}
// Add the user into the recipients database.
if (!$indstatus || ($indstatus && $indstatus["status"]!=-2)) {
$queryStr = "INSERT INTO `tblDocumentRecipients` (`documentID`, `version`, `type`, `required`) ".
"VALUES ('". $this->_document->getID() ."', '". $this->_version ."', '0', '". $userID ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
$receiptID = $db->getInsertID();
}
else {
$receiptID = isset($indstatus["receiptID"]) ? $ $indstatus["receiptID"] : NULL;
}
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $receiptID ."', '0', '', CURRENT_TIMESTAMP, '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
// Add recipient to event notification table.
//$this->_document->addNotify($userID, true);
return 0;
} /* }}} */
function addGrpRecipient($group, $requestUser) { /* {{{ */
$db = $this->_document->_dms->getDB();
$groupID = $group->getID();
// Get the list of users and groups with read access to this document.
if (!isset($this->_readAccessList)) {
// TODO: error checking.
$this->_readAccessList = $this->_document->getReadAccessList();
}
$approved = false;
foreach ($this->_readAccessList["groups"] as $appGroup) {
if ($groupID == $appGroup->getID()) {
$approved = true;
break;
}
}
if (!$approved) {
return -2;
}
// Check to see if the group has already been added to the review list.
$receiptStatus = $group->getReceiptStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
if (count($receiptStatus) > 0 && $receiptStatus[0]["status"]!=-2) {
// Group is already on the list of recipients; return an error.
return -3;
}
// Add the group into the recipients database.
if (!isset($receiptStatus[0]["status"]) || (isset($receiptStatus[0]["status"]) && $receiptStatus[0]["status"]!=-2)) {
$queryStr = "INSERT INTO `tblDocumentRecipients` (`documentID`, `version`, `type`, `required`) ".
"VALUES ('". $this->_document->getID() ."', '". $this->_version ."', '1', '". $groupID ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
$receiptID = $db->getInsertID();
}
else {
$receiptID = isset($receiptStatus[0]["receiptID"])?$receiptStatus[0]["receiptID"]:NULL;
}
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $receiptID ."', '0', '', CURRENT_TIMESTAMP, '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
// Add reviewer to event notification table.
//$this->_document->addNotify($groupID, false);
return 0;
} /* }}} */
/**
* Add a receipt to the document content
*
* This method will add an entry to the table tblDocumentReceiptLog.
* It will first check if the user is ment to receipt the document version.
* It not the return value is -3.
* Next it will check if the users has been removed from the list of
* recipients. In that case -4 will be returned.
* If the given receipt has been set by the user before, it cannot
* be set again and 0 will be returned. Іf the review could be succesfully
* added, the review log id will be returned.
*
* @see SeedDMS_Core_DocumentContent::setApprovalByInd()
* @param object $user user doing the receipt
* @param object $requestUser user asking for the receipt, this is mostly
* @param integer $status the status of the receipt, possible values are
* 0=unprocessed (maybe used to reset a status)
* 1=received,
* -2=user is deleted (use {link
* SeedDMS_Core_DocumentContent::delIndRecipient} instead)
* the user currently logged in.
* @return integer new receipt log id
*/
function setReceiptByInd($user, $requestUser, $status, $comment) { /* {{{ */
$db = $this->_document->_dms->getDB();
// Check to see if the user can be removed from the review list.
$receiptStatus = $user->getReceiptStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
if (count($receiptStatus["indstatus"])==0) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return -3;
}
$indstatus = array_pop($receiptStatus["indstatus"]);
if ($indstatus["status"]==-2) {
// User has been deleted from recipients
return -4;
}
// Check if the status is really different from the current status
if ($indstatus["status"] == $status)
return 0;
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`,
`comment`, `date`, `userID`) ".
"VALUES ('". $indstatus["receiptID"] ."', '".
(int) $status ."', ".$db->qstr($comment).", CURRENT_TIMESTAMP, '".
$requestUser->getID() ."')";
$res=$db->getResult($queryStr);
if (is_bool($res) && !$res)
return -1;
else {
$receiptLogID = $db->getInsertID();
return $receiptLogID;
}
} /* }}} */
/**
* Add a receipt to the document content
*
* This method is similar to
* {@see SeedDMS_Core_DocumentContent::setReceiptByInd()} but adds a receipt
* for a group instead of a user.
*
* @param object $group group doing the receipt
* @param object $requestUser user asking for the receipt, this is mostly
* the user currently logged in.
* @return integer new receipt log id
*/
function setReceiptByGrp($group, $requestUser, $status, $comment) { /* {{{ */
$db = $this->_document->_dms->getDB();
// Check to see if the user can be removed from the recipient list.
$receiptStatus = $group->getReceiptStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
if (count($receiptStatus)==0) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return -3;
}
if ($receiptStatus[0]["status"]==-2) {
// Group has been deleted from recipients
return -4;
}
// Check if the status is really different from the current status
if ($receiptStatus[0]["status"] == $status)
return 0;
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`recipientsID`, `status`,
`comment`, `date`, `userID`) ".
"VALUES ('". $receiptStatus[0]["recipientsID"] ."', '".
(int) $status ."', ".$db->qstr($comment).", CURRENT_TIMESTAMP, '".
$requestUser->getID() ."')";
$res=$db->getResult($queryStr);
if (is_bool($res) && !$res)
return -1;
else {
$receiptLogID = $db->getInsertID();
return $receiptLogID;
}
} /* }}} */
function delIndReviewer($user, $requestUser) { /* {{{ */
$db = $this->_document->_dms->getDB();
@ -3379,6 +3644,69 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return 0;
} /* }}} */
function delIndRecipient($user, $requestUser) { /* {{{ */
$db = $this->_document->_dms->getDB();
$userID = $user->getID();
// Check to see if the user can be removed from the recipient list.
$receiptStatus = $user->getReceiptStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
if (count($receiptStatus["indstatus"])==0) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return -3;
}
$indstatus = array_pop($receiptStatus["indstatus"]);
if ($indstatus["status"]!=0) {
// User has already submitted a receipt or has already been deleted;
// return an error.
return -3;
}
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $indstatus["receiptID"] ."', '-2', '', CURRENT_TIMESTAMP, '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
return 0;
} /* }}} */
function delGrpRecipient($group, $requestUser) { /* {{{ */
$db = $this->_document->_dms->getDB();
$groupID = $group->getID();
// Check to see if the user can be removed from the recipient list.
$receiptStatus = $group->getReceiptStatus($this->_document->getID(), $this->_version);
if (is_bool($receiptStatus) && !$receiptStatus) {
return -1;
}
if (count($receiptStatus)==0) {
// User is not assigned to receipt this document. No action required.
// Return an error.
return -3;
}
if ($receiptStatus[0]["status"]!=0) {
// User has already submitted a receipt or has already been deleted;
// return an error.
return -3;
}
$queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
"VALUES ('". $receiptStatus[0]["receiptID"] ."', '-2', '', CURRENT_TIMESTAMP, '". $requestUser->getID() ."')";
$res = $db->getResult($queryStr);
if (is_bool($res) && !$res) {
return -1;
}
return 0;
} /* }}} */
/**
* Set state of workflow assigned to the document content
*

View File

@ -885,7 +885,7 @@ class SeedDMS_Core_User {
* Get a list of reviews
* This function returns a list of all reviews seperated by individual
* and group reviews. If the document id
* is passed, then only this document will be checked for approvals. The
* is passed, then only this document will be checked for reviews. The
* same is true for the version of a document which limits the list
* further.
*
@ -1088,6 +1088,89 @@ class SeedDMS_Core_User {
return $status;
} /* }}} */
/**
* Get a list of receipts
* This function returns a list of all receipts seperated by individual
* and group receipts. If the document id
* is passed, then only this document will be checked for receipts. The
* same is true for the version of a document which limits the list
* further.
*
* For a detaile description of the result array see
* {link SeedDMS_Core_User::getApprovalStatus} which does the same for
* approvals.
*
* @param int $documentID optional document id for which to retrieve the
* receipt
* @param int $version optional version of the document
* @return array list of all receipts
*/
function getReceiptStatus($documentID=null, $version=null) { /* {{{ */
$db = $this->_dms->getDB();
/*
if (!$db->createTemporaryTable("ttreviewid")) {
return false;
}
*/
$status = array("indstatus"=>array(), "grpstatus"=>array());
// See if the user is assigned as an individual recipient.
$queryStr = "SELECT `tblDocumentRecipients`.*, `tblDocumentReceiptLog`.`status`, ".
"`tblDocumentReceiptLog`.`comment`, `tblDocumentReceiptLog`.`date`, ".
"`tblDocumentReceiptLog`.`userID` ".
"FROM `tblDocumentRecipients` ".
"LEFT JOIN `tblDocumentReceiptLog` USING (`recipientID`) ".
"WHERE `tblDocumentRecipients`.`type`='0' ".
($documentID==null ? "" : "AND `tblDocumentRecipients`.`documentID` = '". (int) $documentID ."' ").
($version==null ? "" : "AND `tblDocumentRecipients`.`version` = '". (int) $version ."' ").
"AND `tblDocumentRecipients`.`required`='". $this->_id ."' ".
"ORDER BY `tblDocumentReceiptLog`.`reviewLogID` DESC";
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr === false)
return false;
if (count($resArr)>0) {
foreach ($resArr as $res) {
if(isset($status["indstatus"][$res['documentID']])) {
if($status["indstatus"][$res['documentID']]['date'] < $res['date']) {
$status["indstatus"][$res['documentID']] = $res;
}
} else {
$status["indstatus"][$res['documentID']] = $res;
}
}
}
// See if the user is the member of a group that has been assigned to
// receipt the document version.
$queryStr = "SELECT `tblDocumentRecipients`.*, `tblDocumentReceiptLog`.`status`, ".
"`tblDocumentReceiptLog`.`comment`, `tblDocumentReceiptLog`.`date`, ".
"`tblDocumentReceiptLog`.`userID` ".
"FROM `tblDocumentRecipients` ".
"LEFT JOIN `tblDocumentReceiptLog` USING (`reviewID`) ".
"LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`groupID` = `tblDocumentRecipients`.`required` ".
"WHERE `tblDocumentRecipients`.`type`='1' ".
($documentID==null ? "" : "AND `tblDocumentRecipients`.`documentID` = '". (int) $documentID ."' ").
($version==null ? "" : "AND `tblDocumentRecipients`.`version` = '". (int) $version ."' ").
"AND `tblGroupMembers`.`userID`='". $this->_id ."' ".
"ORDER BY `tblDocumentReceiptLog`.`reviewLogID` DESC";
$resArr = $db->getResultArray($queryStr);
if (is_bool($resArr) && $resArr === false)
return false;
if (count($resArr)>0) {
foreach ($resArr as $res) {
if(isset($status["grpstatus"][$res['documentID']])) {
if($status["grpstatus"][$res['documentID']]['date'] < $res['date']) {
$status["grpstatus"][$res['documentID']] = $res;
}
} else {
$status["grpstatus"][$res['documentID']] = $res;
}
}
}
return $status;
} /* }}} */
/**
* Get a list of documents with a workflow
*