From 20da5ba2898c4fb49d7d676a701b79f8b8694dad Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Wed, 22 Jan 2014 17:18:33 -0400 Subject: [PATCH] ProcessMaker-MA "Web Entry (endpoints)" - Se han implementado los siguientes Endpoints: GET /api/1.0/{workspace}/project/{prj_uid}/web-entries GET /api/1.0/{workspace}/project/{prj_uid}/web-entry/{tas_uid}/{dyn_uid} DELETE /api/1.0/{workspace}/project/{prj_uid}/web-entry/{tas_uid}/{dyn_uid} --- workflow/engine/src/BusinessModel/Process.php | 37 +++ .../engine/src/BusinessModel/WebEntry.php | 226 ++++++++++++++++++ .../src/Services/Api/ProcessMaker/Project.php | 18 ++ .../Api/ProcessMaker/Project/WebEntry.php | 85 +++++++ workflow/engine/src/Services/api.ini | 1 + 5 files changed, 367 insertions(+) create mode 100644 workflow/engine/src/BusinessModel/WebEntry.php create mode 100644 workflow/engine/src/Services/Api/ProcessMaker/Project/WebEntry.php diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index 57365adc7..426964b25 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -593,5 +593,42 @@ class Process throw $e; } } + + /** + * Get all Web Entries of a Process + * + * @param string $processUid Unique id of Process + * + * return array Return an array with all Web Entries of a Process + */ + public function getWebEntries($processUid) + { + try { + $arrayWebEntry = array(); + + //Verify data + $process = new \Process(); + + if (!$process->exists($processUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + //Get data + $webEntry = new \BusinessModel\WebEntry(); + + $arrayWebEntryData = $webEntry->getData($processUid); + + foreach ($arrayWebEntryData as $index => $value) { + $row = $value; + + $arrayWebEntry[] = $webEntry->getWebEntryDataFromRecord($row); + } + + //Return + return $arrayWebEntry; + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/BusinessModel/WebEntry.php b/workflow/engine/src/BusinessModel/WebEntry.php new file mode 100644 index 000000000..a40345543 --- /dev/null +++ b/workflow/engine/src/BusinessModel/WebEntry.php @@ -0,0 +1,226 @@ +existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { + $flagPush = 1; + } + break; + case "UID": + if ($taskUid != "" && $dynaFormUid != "" && $weTaskUid == $taskUid && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { + $flagPush = 1; + $flagNext = 0; + } + break; + case "DYN_UID": + if ($dynaFormUid != "" && $weDynaFormUid == $dynaFormUid && $step->existsRecord($weTaskUid, "DYNAFORM", $weDynaFormUid)) { + $flagPush = 1; + $flagNext = 0; + } + break; + } + + if ($flagPush == 1) { + $arrayTaskData = $task->load($weTaskUid); + $arrayDynaFormData = $dynaForm->Load($weDynaFormUid); + + $arrayData[$weTaskUid . "/" . $weDynaFormUid] = array( + "processUid" => $processUid, + "taskUid" => $weTaskUid, + "taskTitle" => $arrayTaskData["TAS_TITLE"], + "dynaFormUid" => $weDynaFormUid, + "dynaFormTitle" => $arrayDynaFormData["DYN_TITLE"], + "fileName" => $weFileName, + "url" => $url . "/" . $weFileName . ".php" + ); + } + } + } + } + } + } + + return $arrayData; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Create Web Entry for a Process + * + * @param string $processUid Unique id of Process + * @param array $arrayData Data + * + * return array Return data of the new Web Entry created + */ + public function create($processUid, $arrayData) + { + try { + // + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Delete Web Entry + * + * @param string $processUid Unique id of Process + * @param string $taskUid Unique id of Task + * @param string $dynaFormUid Unique id of DynaForm + * + * return void + */ + public function delete($processUid, $taskUid, $dynaFormUid) + { + try { + //Verify data + $process = new \Process(); + + if (!$process->exists($processUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + $arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid); + + if (count($arrayWebEntryData) == 0) { + throw (new \Exception("The Web Entry doesn't exist")); + } + + //Delete + $webEntryPath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $processUid; + + unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . ".php"); + unlink($webEntryPath . PATH_SEP . $arrayWebEntryData[$taskUid . "/" . $dynaFormUid]["fileName"] . "Post.php"); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of a Web Entry from a record + * + * @param array $record Record + * + * return array Return an array with data of a Web Entry + */ + public function getWebEntryDataFromRecord($record) + { + try { + return array( + "tas_uid" => $record["taskUid"], + "tas_title" => $record["taskTitle"], + "dyn_uid" => $record["dynaFormUid"], + "dyn_title" => $record["dynaFormTitle"], + "url" => $record["url"] + ); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of a Web Entry + * + * @param string $processUid Unique id of Process + * @param string $taskUid Unique id of Task + * @param string $dynaFormUid Unique id of DynaForm + * + * return array Return an array with data of a Web Entry + */ + public function getWebEntry($processUid, $taskUid, $dynaFormUid) + { + try { + //Verify data + $process = new \Process(); + + if (!$process->exists($processUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + $arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid); + + if (count($arrayWebEntryData) == 0) { + throw (new \Exception("The Web Entry doesn't exist")); + } + + //Get data + //Return + return $this->getWebEntryDataFromRecord($arrayWebEntryData[$taskUid . "/" . $dynaFormUid]); + } catch (\Exception $e) { + throw $e; + } + } +} + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index b5ac779e2..a4f485708 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -182,5 +182,23 @@ class Project extends Api throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } + + /** + * @url GET /:projectUid/web-entries + * + * @param string $projectUid {@min 32}{@max 32} + */ + public function doGetWebEntries($projectUid) + { + try { + $process = new \BusinessModel\Process(); + + $response = $process->getWebEntries($projectUid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/WebEntry.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/WebEntry.php new file mode 100644 index 000000000..1e79de1e9 --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/WebEntry.php @@ -0,0 +1,85 @@ +getWebEntry($projectUid, $activityUid, $dynaFormUid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + ///** + // * @url POST /:projectUid/case-tracker/object + // * + // * @param string $projectUid {@min 32}{@max 32} + // * @param array $request_data + // * @param string $cto_type_obj {@from body}{@choice DYNAFORM,INPUT_DOCUMENT,OUTPUT_DOCUMENT}{@required true} + // * @param string $cto_uid_obj {@from body}{@min 32}{@max 32}{@required true} + // * @param string $cto_condition + // * @param int $cto_position {@from body}{@min 1} + // * + // * @status 201 + // */ + //public function doPostWebEntry( + // $projectUid, + // $request_data, + // $cto_type_obj = "DYNAFORM", + // $cto_uid_obj = "00000000000000000000000000000000", + // $cto_condition = "", + // $cto_position = 1 + //) { + // try { + // $caseTrackerObject = new \BusinessModel\WebEntry(); + // + // $arrayData = $caseTrackerObject->create($projectUid, $request_data); + // + // $response = $arrayData; + // + // return $response; + // } catch (\Exception $e) { + // throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + // } + //} + + /** + * @url DELETE /:projectUid/web-entry/:activityUid/:dynaFormUid + * + * @param string $dynaFormUid {@min 32}{@max 32} + * @param string $activityUid {@min 32}{@max 32} + * @param string $projectUid {@min 32}{@max 32} + */ + public function doDeleteWebEntry($dynaFormUid, $activityUid, $projectUid) + { + try { + $webEntry = new \BusinessModel\WebEntry(); + + $webEntry->delete($projectUid, $activityUid, $dynaFormUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } +} + diff --git a/workflow/engine/src/Services/api.ini b/workflow/engine/src/Services/api.ini index f947ceb21..c684256fa 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -29,6 +29,7 @@ debug = 1 case-tracker = "Services\Api\ProcessMaker\Project\CaseTracker" case-tracker-object = "Services\Api\ProcessMaker\Project\CaseTrackerObject" project-users = "Services\Api\ProcessMaker\Project\ProjectUsers" + web-entry = "Services\Api\ProcessMaker\Project\WebEntry" [alias: projects] project = "Services\Api\ProcessMaker\Project"