/** * Validate the data if they are invalid (INSERT and UPDATE) * * @param string $webEntryEventUid Unique id of WebEntry-Event * @param string $projectUid Unique id of Project * @param array $arrayData Data * * return void Throw exception if data has an invalid value */ public function throwExceptionIfDataIsInvalid($webEntryEventUid, $projectUid, array $arrayData) { try { //Set variables $arrayWebEntryEventData = $webEntryEventUid == "" ? array() : $this->getWebEntryEvent($webEntryEventUid, true); $flagInsert = $webEntryEventUid == "" ? true : false; $arrayFinalData = array_merge($arrayWebEntryEventData, $arrayData); //Verify data - Field definition $process = new \ProcessMaker\BusinessModel\Process(); $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert); //Verify data if (isset($arrayData["EVN_UID"])) { $this->throwExceptionIfEventIsRegistered($projectUid, $arrayData["EVN_UID"], $this->arrayFieldNameForException["eventUid"], $webEntryEventUid); } if (isset($arrayData["EVN_UID"])) { $obj = \BpmnEventPeer::retrieveByPK($arrayData["EVN_UID"]); if (is_null($obj)) { throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_EXIST", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"]))); } if ($obj->getEvnType() != "START" || $obj->getEvnType() == "START" && $obj->getEvnMarker() != "EMPTY") { throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_IS_START_EVENT", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"]))); } } if (isset($arrayData["WEE_TITLE"])) { $this->throwExceptionIfExistsTitle($projectUid, $arrayData["WEE_TITLE"], $this->arrayFieldNameForException["webEntryEventTitle"], $webEntryEventUid); } if (isset($arrayData["ACT_UID"])) { $bpmn = new \ProcessMaker\Project\Bpmn(); if (!$bpmn->activityExists($arrayData["ACT_UID"])) { throw new \Exception(\G::LoadTranslation("ID_ACTIVITY_DOES_NOT_EXIST", array($this->arrayFieldNameForException["activityUid"], $arrayData["ACT_UID"]))); } } if (isset($arrayData["EVN_UID"]) || isset($arrayData["ACT_UID"])) { $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\BpmnFlowPeer::FLO_UID); $criteria->add(\BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $arrayFinalData["EVN_UID"], \Criteria::EQUAL); $criteria->add(\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE, "bpmnEvent", \Criteria::EQUAL); $criteria->add(\BpmnFlowPeer::FLO_ELEMENT_DEST, $arrayFinalData["ACT_UID"], \Criteria::EQUAL); $criteria->add(\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE, "bpmnActivity", \Criteria::EQUAL); $rsCriteria = \BpmnFlowPeer::doSelectRS($criteria); if (!$rsCriteria->next()) { throw new \Exception(\G::LoadTranslation("ID_WEB_ENTRY_EVENT_FLOW_EVENT_TO_ACTIVITY_DOES_NOT_EXIST")); } } if (isset($arrayData["DYN_UID"])) { $dynaForm = new \ProcessMaker\BusinessModel\DynaForm(); $dynaForm->throwExceptionIfNotExistsDynaForm($arrayData["DYN_UID"], $projectUid, $this->arrayFieldNameForException["dynaFormUid"]); } if (isset($arrayData["USR_UID"])) { $process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); } } catch (\Exception $e) { throw $e; } }
/** * Validate the data if they are invalid (INSERT and UPDATE) * * @param string $webEntryUid Unique id of Web Entry * @param string $processUid Unique id of Process * @param array $arrayData Data * * return void Throw exception if data has an invalid value */ public function throwExceptionIfDataIsInvalid($webEntryUid, $processUid, array $arrayData) { try { //Set variables $arrayWebEntryData = $webEntryUid == "" ? array() : $this->getWebEntry($webEntryUid, true); $flagInsert = $webEntryUid == "" ? true : false; $arrayDataMain = array_merge($arrayWebEntryData, $arrayData); //Verify data - Field definition $process = new \ProcessMaker\BusinessModel\Process(); $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert); if ($arrayDataMain["WE_METHOD"] == "WS") { $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayUserFieldDefinition, $this->arrayFieldNameForException, $flagInsert); } //Verify data if (isset($arrayData["WE_TITLE"])) { $this->throwExceptionIfExistsTitle($processUid, $arrayData["WE_TITLE"], $this->arrayFieldNameForException["webEntryTitle"], $webEntryUid); } if (isset($arrayData["TAS_UID"])) { $task = new \ProcessMaker\BusinessModel\Task(); $task->throwExceptionIfNotExistsTask($processUid, $arrayData["TAS_UID"], $this->arrayFieldNameForException["taskUid"]); } if (isset($arrayData["DYN_UID"])) { $dynaForm = new \ProcessMaker\BusinessModel\DynaForm(); $dynaForm->throwExceptionIfNotExistsDynaForm($arrayData["DYN_UID"], $processUid, $this->arrayFieldNameForException["dynaFormUid"]); } if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["USR_UID"])) { $process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); } $task = new \Task(); $arrayTaskData = $task->load($arrayDataMain["TAS_UID"]); if (isset($arrayData["TAS_UID"])) { if ($arrayTaskData["TAS_START"] == "FALSE") { throw new \Exception(\G::LoadTranslation("ID_ACTIVITY_IS_NOT_INITIAL_ACTIVITY", array($arrayTaskData["TAS_TITLE"]))); } if ($arrayTaskData["TAS_ASSIGN_TYPE"] != "BALANCED") { throw new \Exception(\G::LoadTranslation("ID_WEB_ENTRY_ACTIVITY_DOES_NOT_HAVE_VALID_ASSIGNMENT_TYPE", array($arrayTaskData["TAS_TITLE"]))); } } if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["TAS_UID"])) { $task = new \Tasks(); if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) { throw new \Exception(\G::LoadTranslation("ID_ACTIVITY_DOES_NOT_HAVE_USERS", array($arrayTaskData["TAS_TITLE"]))); } } if (isset($arrayData["DYN_UID"])) { $dynaForm = new \Dynaform(); $arrayDynaFormData = $dynaForm->Load($arrayData["DYN_UID"]); $step = new \ProcessMaker\BusinessModel\Step(); if (!$step->existsRecord($arrayDataMain["TAS_UID"], "DYNAFORM", $arrayData["DYN_UID"])) { throw new \Exception(\G::LoadTranslation("ID_DYNAFORM_IS_NOT_ASSIGNED_TO_ACTIVITY", array($arrayDynaFormData["DYN_TITLE"], $arrayTaskData["TAS_TITLE"]))); } } if ($arrayDataMain["WE_METHOD"] == "WS" && isset($arrayData["USR_UID"])) { $user = new \Users(); $arrayUserData = $user->load($arrayData["USR_UID"]); //Verify if User is assigned to Task $projectUser = new \ProcessMaker\BusinessModel\ProjectUser(); if (!$projectUser->userIsAssignedToTask($arrayData["USR_UID"], $arrayDataMain["TAS_UID"])) { throw new \Exception(\G::LoadTranslation("ID_USER_DOES_NOT_HAVE_ACTIVITY_ASSIGNED", array($arrayUserData["USR_USERNAME"], $arrayTaskData["TAS_TITLE"]))); } } } catch (\Exception $e) { throw $e; } }
/** * Get Variables of a Process/Grid * * @param string $option Option (GRID, GRIDVARS, ALL) * @param string $processUid Unique id of Process * @param string $gridUid Unique id of Grid (DynaForm) * * return array Return an array with Variables of a Process/Grid */ public function getVariables($option, $processUid, $gridUid = "") { try { $arrayVariable = array(); //Verify data $this->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); //Get data switch ($option) { case "GRID": $arrayVar = self::getGridsVars($processUid); foreach ($arrayVar as $key => $value) { $arrayVariableAux = $this->getVariableDataFromRecord(array("name" => $value["sName"], "label" => "[ " . \G::LoadTranslation("ID_GRID") . " ]", "type" => "grid")); $arrayVariable[] = array_merge($arrayVariableAux, array($this->getFieldNameByFormatFieldName("GRID_UID") => $value["sXmlForm"])); } break; case "GRIDVARS": //Verify data $dynaForm = new \ProcessMaker\BusinessModel\DynaForm(); $dynaForm->throwExceptionIfNotExistsDynaForm($gridUid, $processUid, $this->arrayFieldNameForException["gridUid"]); $dynaForm->throwExceptionIfNotIsGridDynaForm($gridUid, $this->arrayFieldNameForException["gridUid"]); //Get data $fields = self::getVarsGrid($processUid, $gridUid); foreach ($fields as $field) { $arrayVariable[] = $this->getVariableDataFromRecord(array("name" => $field["sName"], "label" => $field["sLabel"], "type" => $field["sType"])); } break; default: //ALL $arrayVar = self::getDynaformsVars($processUid); foreach ($arrayVar as $key => $value) { $arrayVariable[] = $this->getVariableDataFromRecord(array("name" => $value["sName"], "label" => $value["sLabel"], "type" => $value["sType"], "source" => $value["sUid"])); } $arrayHtmlVariable = self::getHtmlFormVars($processUid); $arrayVariable = array_merge($arrayVariable, $arrayHtmlVariable); break; } //Return return $arrayVariable; } catch (\Exception $e) { throw $e; } }