PM-3632-A "REST endpoint GET /cases/{app_uid}/input-documents" SOLVED
This commit is contained in:
@@ -175,6 +175,137 @@ class InputDocument
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get criteria for AppDocument
|
||||
*
|
||||
* return object
|
||||
*/
|
||||
public function getAppDocumentCriteriaByData($applicationUid)
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_UID);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::DOC_VERSION);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::DOC_UID);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::USR_UID);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_TYPE);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_CREATE_DATE);
|
||||
$criteria->addSelectColumn(\AppDocumentPeer::APP_DOC_INDEX);
|
||||
|
||||
$sql = "
|
||||
SELECT MAX(APPDOC.DOC_VERSION)
|
||||
FROM " . \AppDocumentPeer::TABLE_NAME . " AS APPDOC
|
||||
WHERE APPDOC.APP_DOC_UID = " . \AppDocumentPeer::APP_DOC_UID . "
|
||||
";
|
||||
|
||||
$criteria->add(
|
||||
$criteria->getNewCriterion(\AppDocumentPeer::APP_UID, $applicationUid, \Criteria::EQUAL)->addAnd(
|
||||
$criteria->getNewCriterion(\AppDocumentPeer::APP_DOC_TYPE, array("INPUT", "ATTACHED"), \Criteria::IN))->addAnd(
|
||||
$criteria->getNewCriterion(\AppDocumentPeer::APP_DOC_STATUS, array("ACTIVE"), \Criteria::IN))->addAnd(
|
||||
$criteria->getNewCriterion(\AppDocumentPeer::DOC_VERSION, \AppDocumentPeer::DOC_VERSION . " IN ($sql)", \Criteria::CUSTOM))
|
||||
);
|
||||
|
||||
$criteria->addAscendingOrderByColumn(\AppDocumentPeer::APP_DOC_INDEX);
|
||||
|
||||
//Return
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a AppDocument from a record
|
||||
*
|
||||
* @param array $record Record
|
||||
*
|
||||
* return array Return an array with data AppDocument
|
||||
*/
|
||||
public function getAppDocumentDataFromRecord(array $record)
|
||||
{
|
||||
try {
|
||||
return array(
|
||||
"app_doc_uid" => $record["APP_DOC_UID"],
|
||||
"app_doc_filename" => $record["APP_DOC_FILENAME"],
|
||||
"doc_uid" => $record["DOC_UID"],
|
||||
"app_doc_version" => $record["DOC_VERSION"],
|
||||
"app_doc_create_date" => $record["APP_DOC_CREATE_DATE"],
|
||||
"app_doc_create_user" => $record["APP_DOC_CREATE_USER"],
|
||||
"app_doc_type" => $record["APP_DOC_TYPE"],
|
||||
"app_doc_index" => (int)($record["APP_DOC_INDEX"]),
|
||||
"app_doc_link" => $record["APP_DOC_LINK"]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is Supervisor
|
||||
*
|
||||
* @param string $applicationUid Unique id of Case
|
||||
* @param string $userUid Unique id of User
|
||||
*
|
||||
* return array Return data of input documents
|
||||
*/
|
||||
public function getCasesInputDocumentsBySupervisor($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
//Verify data Supervisor
|
||||
$application = \ApplicationPeer::retrieveByPK($applicationUid);
|
||||
|
||||
$flagSupervisor = 0;
|
||||
|
||||
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
||||
$arraySupervisor = $supervisor->getProcessSupervisors($application->getProUid());
|
||||
|
||||
foreach ($arraySupervisor as $value) {
|
||||
if($value["usr_uid"] == $userUid) {
|
||||
$flagSupervisor = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$user = new \Users();
|
||||
$appDocument = new \AppDocument();
|
||||
$configuraction = new \Configurations();
|
||||
|
||||
$confEnvSetting = $configuraction->getFormats();
|
||||
|
||||
$arrayInputDocument = array();
|
||||
|
||||
//Query
|
||||
$criteria = $this->getAppDocumentCriteriaByData($applicationUid);
|
||||
|
||||
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayUserData = $user->load($row["USR_UID"]);
|
||||
|
||||
$arrayAppDocument = $appDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
|
||||
|
||||
$row["APP_DOC_FILENAME"] = $arrayAppDocument["APP_DOC_FILENAME"];
|
||||
$row["APP_DOC_CREATE_USER"] = $configuraction->usersNameFormatBySetParameters($confEnvSetting["format"], $arrayUserData["USR_USERNAME"], $arrayUserData["USR_FIRSTNAME"], $arrayUserData["USR_LASTNAME"]);
|
||||
$row["APP_DOC_LINK"] = "cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
|
||||
|
||||
$arrayInputDocument[] = $this->getAppDocumentDataFromRecord($row);
|
||||
}
|
||||
|
||||
if (!empty($arrayInputDocument) && $flagSupervisor == 0) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_USER_IS_NOT_SUPERVISOR"));
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayInputDocument;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Cases InputDocument
|
||||
*
|
||||
@@ -186,33 +317,50 @@ class InputDocument
|
||||
public function getCasesInputDocuments($applicationUid, $userUid)
|
||||
{
|
||||
try {
|
||||
$sApplicationUID = $applicationUid;
|
||||
$sUserUID = $userUid;
|
||||
\G::LoadClass('case');
|
||||
$oCase = new \Cases();
|
||||
$fields = $oCase->loadCase( $sApplicationUID );
|
||||
$sProcessUID = $fields['PRO_UID'];
|
||||
$sTaskUID = '';
|
||||
$oCaseRest = new \ProcessMaker\BusinessModel\Cases();
|
||||
$oCaseRest->getAllUploadedDocumentsCriteria( $sProcessUID, $sApplicationUID, $sTaskUID, $sUserUID);
|
||||
$result = array ();
|
||||
global $_DBArray;
|
||||
foreach ($_DBArray['inputDocuments'] as $key => $row) {
|
||||
if (isset( $row['DOC_VERSION'] )) {
|
||||
$docrow = array ();
|
||||
$docrow['app_doc_uid'] = $row['APP_DOC_UID'];
|
||||
$docrow['app_doc_filename'] = $row['APP_DOC_FILENAME'];
|
||||
$docrow['doc_uid'] = $row['DOC_UID'];
|
||||
$docrow['app_doc_version'] = $row['DOC_VERSION'];
|
||||
$docrow['app_doc_create_date'] = $row['CREATE_DATE'];
|
||||
$docrow['app_doc_create_user'] = $row['CREATED_BY'];
|
||||
$docrow['app_doc_type'] = $row['TYPE'];
|
||||
$docrow['app_doc_index'] = $row['APP_DOC_INDEX'];
|
||||
$docrow['app_doc_link'] = 'cases/' . $row['DOWNLOAD_LINK'];
|
||||
$result[] = $docrow;
|
||||
}
|
||||
//Verify data inbox
|
||||
$case = new \ProcessMaker\BusinessModel\Cases();
|
||||
$arrayResult = $case->getStatusInfo($applicationUid, 0, $userUid);
|
||||
|
||||
$flagInbox = true;
|
||||
|
||||
if (empty($arrayResult) || !preg_match("/^(?:TO_DO|DRAFT)$/", $arrayResult["APP_STATUS"])) {
|
||||
$flagInbox = false;
|
||||
}
|
||||
return $result;
|
||||
|
||||
$user = new \Users();
|
||||
$appDocument = new \AppDocument();
|
||||
$configuraction = new \Configurations();
|
||||
|
||||
$confEnvSetting = $configuraction->getFormats();
|
||||
|
||||
$arrayInputDocument = array();
|
||||
|
||||
//Query
|
||||
$criteria = $this->getAppDocumentCriteriaByData($applicationUid);
|
||||
|
||||
if (!$flagInbox) {
|
||||
$criteria->add(\AppDocumentPeer::USR_UID, $userUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \AppDocumentPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$arrayUserData = $user->load($row["USR_UID"]);
|
||||
|
||||
$arrayAppDocument = $appDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
|
||||
|
||||
$row["APP_DOC_FILENAME"] = $arrayAppDocument["APP_DOC_FILENAME"];
|
||||
$row["APP_DOC_CREATE_USER"] = $configuraction->usersNameFormatBySetParameters($confEnvSetting["format"], $arrayUserData["USR_USERNAME"], $arrayUserData["USR_FIRSTNAME"], $arrayUserData["USR_LASTNAME"]);
|
||||
$row["APP_DOC_LINK"] = "cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
|
||||
|
||||
$arrayInputDocument[] = $this->getAppDocumentDataFromRecord($row);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayInputDocument;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,14 @@ class InputDocument extends Api
|
||||
try {
|
||||
$userUid = $this->getUserId();
|
||||
$inputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument();
|
||||
|
||||
$response = $inputDocument->getCasesInputDocuments($app_uid, $userUid);
|
||||
|
||||
if (empty($response)) {
|
||||
$response = $inputDocument->getCasesInputDocumentsBySupervisor($app_uid, $userUid);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
|
||||
Reference in New Issue
Block a user