From 98dbed13a21ea69d746feb8112b6d156265723a0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Mar 2016 15:07:25 -0400 Subject: [PATCH] HOR-367 Create a PMFunction to get the identifier of a process element from name fix and obserbations fix in empty prouid --- workflow/engine/classes/class.pmFunctions.php | 60 ++++++++++- .../ProcessMaker/Util/ElementTranslation.php | 100 ++++++++++++++++++ 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 workflow/engine/src/ProcessMaker/Util/ElementTranslation.php diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index d45fcaa73..ab5b410be 100755 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -28,7 +28,7 @@ // // License: LGPL, see LICENSE //////////////////////////////////////////////////// - +use ProcessMaker\Util\ElementTranslation; if (! class_exists( 'PMScript' )) { G::LoadClass( 'pmScript' ); @@ -3168,3 +3168,61 @@ function PMFGetGroupName($grpUid, $lang = SYS_LANG) { return PMFGeti18nText($grpUid, 'GRP_TITLE', $lang); } +/** + * @method + * The identifier of the element found using the text. + * @name PMFGetUidFromText + * @label PMF Get Uid From Text + * @param string | $text | Text + * @param string | $category | Category + * @param string | $proUid | ProcessUid + * @param string | $lang | Languaje + * @return array + */ +function PMFGetUidFromText($text, $category, $proUid = null, $lang = SYS_LANG) +{ + $obj = new ElementTranslation(); + $uids = $obj->getUidFromTextI18n($text, $category, $proUid, $lang); + return $uids; +} + +/** + * @method + * Get UID of a Dynaform + * @name PMFGetDynaformUID + * @label PMF Get Dynafrom UID + * @param string | $dynaformName | Name Dynaform | Is the name of a Dynaform + * @param string | $proUid = null | Process ID | The process identifier to search the dynaform name. If not specified the current process is used. + * @return array | $result | array + */ +function PMFGetDynaformUID($dynaformName, $proUid = null) +{ + return PMFGetUidFromText($dynaformName, 'DYN_TITLE', $proUid); +} + +/** + * @method + * Get UID of a Group + * @name PMFGetGroupUID + * @label PMF Get Group UID + * @param string | $groupName | Name Group | Is the name of a Group + * @return array | $result | array + */ +function PMFGetGroupUID($groupName) +{ + return PMFGetUidFromText($groupName, 'GRP_TITLE'); +} + +/** + * @method + * Get UID of a Task + * @name PMFGetTaskUID + * @label PMF Get Task UID + * @param string | $taskName | Name Task | Is the name of a Task + * @param string | $proUid = null| Process ID | The process identifier to search the dynaform name. If not specified the current process is used. + * @return array | $result | array + */ +function PMFGetTaskUID($taskName, $proUid = null) +{ + return PMFGetUidFromText($taskName, 'TAS_TITLE', $proUid); +} \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Util/ElementTranslation.php b/workflow/engine/src/ProcessMaker/Util/ElementTranslation.php new file mode 100644 index 000000000..cfd3679b4 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Util/ElementTranslation.php @@ -0,0 +1,100 @@ + ['table' => 'APPLICATION', 'uid' => 'APP_UID', 'ownedByProcess' => true, 'className' => 'Application'], + 'APP_DOC_COMMENT' => ['table' => 'APPLICATION', 'uid' => 'APP_UID', 'ownedByProcess' => true, 'className' => 'Application'], + 'APP_DOC_FILENAME' => ['table' => 'APPLICATION', 'uid' => 'APP_UID', 'ownedByProcess' => true, 'className' => 'Application'], + 'APP_DOC_TITLE' => ['table' => 'APPLICATION', 'uid' => 'APP_UID', 'ownedByProcess' => true, 'className' => 'Application'], + 'APP_TITLE' => ['table' => 'APPLICATION', 'uid' => 'APP_UID', 'ownedByProcess' => true, 'className' => 'Application'], + 'PRO_TITLE' => ['table' => 'PROCESS', 'uid' => 'PRO_UID', 'ownedByProcess' => false, 'className' => 'Process'], + 'PRO_DESCRIPTION' => ['table'=>'PROCESS', 'uid'=>'PRO_UID', 'ownedByProcess'=>false, 'className'=>'Process'], + 'TAS_DEF_MESSAGE' => ['table' => 'TASK', 'uid' => 'TAS_UID', 'ownedByProcess' => true, 'className' => 'Task'], + 'TAS_TITLE' => ['table' => 'TASK', 'uid' => 'TAS_UID', 'ownedByProcess' => true, 'className' => 'Task'], + 'TAS_DEF_DESCRIPTION' => ['table'=>'TASK', 'uid'=>'TAS_UID', 'ownedByProcess'=>true, 'className'=>'Task'], + 'TAS_DEF_PROC_CODE' => ['table'=>'TASK', 'uid'=>'TAS_UID', 'ownedByProcess'=>true, 'className'=>'Task'], + 'TAS_DEF_SUBJECT_MESSAGE' => ['table'=>'TASK', 'uid'=>'TAS_UID', 'ownedByProcess'=>true, 'className'=>'Task'], + 'TAS_DEF_TITLE' => ['table'=>'TASK', 'uid'=>'TAS_UID', 'ownedByProcess'=>true, 'className'=>'Task'], + 'TAS_DESCRIPTION' => ['table'=>'TASK', 'uid'=>'TAS_UID', 'ownedByProcess'=>true, 'className'=>'Task'], + 'DYN_TITLE' => ['table'=>'DYNAFORM', 'uid'=>'DYN_UID', 'ownedByProcess'=>true, 'className'=>'Dynaform'], + 'DYN_DESCRIPTION' => ['table'=>'DYNAFORM', 'uid'=>'DYN_UID', 'ownedByProcess'=>true, 'className'=>'Dynaform'], + 'GRP_TITLE' => ['table'=>'GROUPWF', 'uid'=>'GRP_UID', 'ownedByProcess'=>false, 'className'=>'Groupwf'], + 'DEPO_TITLE' => ['table'=>'DEPARTMENT', 'uid'=>'DEP_UID', 'ownedByProcess'=>false, 'className'=>'Department'], + 'INP_DOC_DESCRIPTION' => ['table'=>'INPUT_DOCUMENT', 'uid'=>'INP_DOC_UID', 'ownedByProcess'=>true, 'className'=>'InputDocument'], + 'INP_DOC_TITLE' => ['table'=>'INPUT_DOCUMENT', 'uid'=>'INP_DOC_UID', 'ownedByProcess'=>true, 'className'=>'InputDocument'], + 'OUT_DOC_DESCRIPTION' => ['table'=>'OUTPUT_DOCUMENT', 'uid'=>'OUT_DOC_UID', 'ownedByProcess'=>true, 'className'=>'OutputDocument'], + 'OUT_DOC_FILENAME' => ['table'=>'OUTPUT_DOCUMENT', 'uid'=>'OUT_DOC_UID', 'ownedByProcess'=>true, 'className'=>'OutputDocument'], + 'OUT_DOC_TEMPLATE' => ['table'=>'OUTPUT_DOCUMENT', 'uid'=>'OUT_DOC_UID', 'ownedByProcess'=>true, 'className'=>'OutputDocument'], + 'OUT_DOC_TITLE' => ['table'=>'OUTPUT_DOCUMENT', 'uid'=>'OUT_DOC_UID', 'ownedByProcess'=>true, 'className'=>'OutputDocument'], + 'PER_NAME' => ['table'=>'RBAC_PERMISSIONS', 'uid'=>'PER_UID', 'ownedByProcess'=>false, 'className'=>'Permissions'], + 'ROL_NAME' => ['table'=>'RBAC_ROLES', 'uid'=>'ROL_UID', 'ownedByProcess'=>false, 'className'=>'Roles'], + ]; + + protected function getClassNameFrom($category) + { + return $this->map[$category]["className"]; + } + + protected function getTableFrom($category) + { + return $this->map[$category]["table"]; + } + + protected function getUidFieldFrom($category) + { + return $this->map[$category]["uid"]; + } + + protected function getProUidFrom($category) + { + return 'PRO_UID'; + } + + protected function isOwnedByProcess($category) + { + return $this->map[$category]["ownedByProcess"]; + } + + /** + * @param $text + * @param $category + * @param null $proUid + * @param string $lang + * @return array + */ + public function getUidFromTextI18n($text, $category, $proUid = null, $lang = SYS_LANG) + { + if (empty($text) || empty($category)){ + return array(); + } + $uids = array(); + $className = $this->getClassNameFrom($category) . 'Peer'; + $uidField = $this->getUidFieldFrom($category); + $proUidField = $this->getProUidFrom($category); + $ownedByProcess = $this->isOwnedByProcess($category); + require_once("classes/model/$className.php"); + $oCriteria = new \Criteria('workflow'); + if ($ownedByProcess) { + $oCriteria->addSelectColumn(\ContentPeer::CON_ID); + $oCriteria->addJoin(\ContentPeer::CON_ID, constant("$className::$uidField")); + if (!empty($proUid)) { + $oCriteria->add(constant("$className::$proUidField"), $proUid); + } + } else { + $oCriteria->addSelectColumn(\ContentPeer::CON_ID); + } + $oCriteria->add(\ContentPeer::CON_CATEGORY, $category); + $oCriteria->add(\ContentPeer::CON_VALUE, $text); + $oCriteria->add(\ContentPeer::CON_LANG, $lang); + $oDataset = \ContentPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + $oDataset->next(); + while ($row = $oDataset->getRow()) { + $uids[] = $row['CON_ID']; + $oDataset->next(); + } + return $uids; + } +}