From cdf2ed24601129c3667925710987b28ee746d153 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Thu, 27 Feb 2014 15:16:41 -0400 Subject: [PATCH] ProcessMaker "Category (endpoints)" - Se han implementado los siguientes Endpoints: GET /api/1.0/{workspace}/project/categories?filter={filter}&start={start}&limit={limit} --- .../src/BusinessModel/ProcessCategory.php | 236 ++++++++++++++++++ .../Api/ProcessMaker/ProcessCategory.php | 33 +++ workflow/engine/src/Services/api.ini | 1 + 3 files changed, 270 insertions(+) create mode 100644 workflow/engine/src/BusinessModel/ProcessCategory.php create mode 100644 workflow/engine/src/Services/Api/ProcessMaker/ProcessCategory.php diff --git a/workflow/engine/src/BusinessModel/ProcessCategory.php b/workflow/engine/src/BusinessModel/ProcessCategory.php new file mode 100644 index 000000000..b1009203d --- /dev/null +++ b/workflow/engine/src/BusinessModel/ProcessCategory.php @@ -0,0 +1,236 @@ + array("fieldName" => "CATEGORY_UID", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryUid"), + + "CAT_PARENT" => array("fieldName" => "CATEGORY_PARENT", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryParent"), + "CAT_NAME" => array("fieldName" => "CATEGORY_NAME", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processCategoryName"), + "CAT_ICON" => array("fieldName" => "CATEGORY_ICON", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCategoryIcon") + ); + + private $formatFieldNameInUppercase = true; + + private $arrayFieldNameForException = array( + "filter" => "FILTER", + "start" => "START", + "limit" => "LIMIT" + ); + + /** + * Constructor of the class + * + * return void + */ + public function __construct() + { + try { + foreach ($this->arrayFieldDefinition as $key => $value) { + $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Set the format of the fields name (uppercase, lowercase) + * + * @param bool $flag Value that set the format + * + * return void + */ + public function setFormatFieldNameInUppercase($flag) + { + try { + $this->formatFieldNameInUppercase = $flag; + + $this->setArrayFieldNameForException($this->arrayFieldNameForException); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Set exception messages for fields + * + * @param array $arrayData Data with the fields + * + * return void + */ + public function setArrayFieldNameForException($arrayData) + { + try { + foreach ($arrayData as $key => $value) { + $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get the name of the field according to the format + * + * @param string $fieldName Field name + * + * return string Return the field name according the format + */ + public function getFieldNameByFormatFieldName($fieldName) + { + try { + return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get criteria for Process Category + * + * return object + */ + public function getProcessCategoryCriteria() + { + try { + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_UID); + $criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_PARENT); + $criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_NAME); + $criteria->addSelectColumn(\ProcessCategoryPeer::CATEGORY_ICON); + $criteria->add(\ProcessCategoryPeer::CATEGORY_UID, "", \Criteria::NOT_EQUAL); + + return $criteria; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of a Process Category from a record + * + * @param array $record Record + * + * return array Return an array with data Process Category + */ + public function getProcessCategoryDataFromRecord($record) + { + try { + return array( + $this->getFieldNameByFormatFieldName("CAT_UID") => $record["CATEGORY_UID"], + $this->getFieldNameByFormatFieldName("CAT_NAME") => $record["CATEGORY_NAME"], + $this->getFieldNameByFormatFieldName("CAT_TOTAL_PROCESSES") => (int)($record["CATEGORY_TOTAL_PROCESSES"]) + ); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get all Process Categories + * + * @param array $arrayFilterData Data of the filters + * @param string $sortField Field name to sort + * @param string $sortDir Direction of sorting (ASC, DESC) + * @param int $start Start + * @param int $limit Limit + * + * return array Return an array with all Process Categories + */ + public function getCategories($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null) + { + try { + $arrayProcessCategory = array(); + + //Verify data + $process = new \BusinessModel\Process(); + + $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException); + + //Get data + if (!is_null($limit) && $limit . "" == "0") { + return $arrayProcessCategory; + } + + //Set variables + $process = new \Process(); + + $arrayTotalProcessesByCategory = $process->getAllProcessesByCategory(); + + //SQL + $criteria = $this->getProcessCategoryCriteria(); + + if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") { + $criteria->add(\ProcessCategoryPeer::CATEGORY_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE); + } + + //Number records total + $criteriaCount = clone $criteria; + + $criteriaCount->clearSelectColumns(); + $criteriaCount->addSelectColumn("COUNT(" . \ProcessCategoryPeer::CATEGORY_UID . ") AS NUM_REC"); + + $rsCriteriaCount = \ProcessCategoryPeer::doSelectRS($criteriaCount); + $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $rsCriteriaCount->next(); + $row = $rsCriteriaCount->getRow(); + + $numRecTotal = $row["NUM_REC"]; + + //SQL + if (!is_null($sortField) && trim($sortField) != "") { + $sortField = strtoupper($sortField); + $sortField = (isset($this->arrayFieldDefinition[$sortField]["fieldName"]))? $this->arrayFieldDefinition[$sortField]["fieldName"] : $sortField; + + switch ($sortField) { + case "CATEGORY_UID": + case "CATEGORY_PARENT": + case "CATEGORY_NAME": + case "CATEGORY_ICON": + $sortField = \ProcessCategoryPeer::TABLE_NAME . "." . $sortField; + break; + default: + $sortField = \ProcessCategoryPeer::CATEGORY_NAME; + break; + } + } else { + $sortField = \ProcessCategoryPeer::CATEGORY_NAME; + } + + if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") { + $criteria->addDescendingOrderByColumn($sortField); + } else { + $criteria->addAscendingOrderByColumn($sortField); + } + + if (!is_null($start)) { + $criteria->setOffset((int)($start)); + } + + if (!is_null($limit)) { + $criteria->setLimit((int)($limit)); + } + + $rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + while ($rsCriteria->next()) { + $row = $rsCriteria->getRow(); + + $row["CATEGORY_TOTAL_PROCESSES"] = (isset($arrayTotalProcessesByCategory[$row["CATEGORY_UID"]]))? $arrayTotalProcessesByCategory[$row["CATEGORY_UID"]] : 0; + + $arrayProcessCategory[] = $this->getProcessCategoryDataFromRecord($row); + } + + //Return + return $arrayProcessCategory; + } catch (\Exception $e) { + throw $e; + } + } +} + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/ProcessCategory.php b/workflow/engine/src/Services/Api/ProcessMaker/ProcessCategory.php new file mode 100644 index 000000000..2fb46ab2a --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/ProcessCategory.php @@ -0,0 +1,33 @@ +setFormatFieldNameInUppercase($this->formatFieldNameInUppercase); + + $response = $processCategory->getCategories(array("filter" => $filter), null, null, $start, $limit); + + return $response; + } 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 73371e62b..7bd9b6300 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -35,6 +35,7 @@ debug = 1 report-Table = "Services\Api\ProcessMaker\Project\ReportTable" sub-process= "Services\Api\ProcessMaker\Project\SubProcess" trigger-wizard = "Services\Api\ProcessMaker\Project\TriggerWizard" + category = "Services\Api\ProcessMaker\ProcessCategory" [alias: projects] project = "Services\Api\ProcessMaker\Project"