Exemple #1
0
 /**
  * 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;
     }
 }
Exemple #2
0
 /**
  * Create Steps for a Task
  *
  * @param string $taskUid    Unique id of Task
  * @param string $processUid Unique id of Process
  * @param array  $arrayData  Data
  *
  * return array Return data of the new Steps created
  */
 public function createAll($taskUid, $processUid, $arrayData)
 {
     try {
         $stepTrigger = new \ProcessMaker\BusinessModel\Step\Trigger();
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["STEP_UID"]);
         //Verify data
         $task = new \ProcessMaker\BusinessModel\Task();
         $this->throwExceptionIfNotExistsProcess($processUid);
         $task->throwExceptionIfNotExistsTask($processUid, $taskUid, $this->arrayParamException["taskUid"]);
         if (!isset($arrayData["STEP_TYPE_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->arrayParamException["stepTypeObj"])));
         }
         $arrayData["STEP_TYPE_OBJ"] = trim($arrayData["STEP_TYPE_OBJ"]);
         if ($arrayData["STEP_TYPE_OBJ"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->arrayParamException["stepTypeObj"])));
         }
         if (!isset($arrayData["STEP_UID_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->arrayParamException["stepUidObj"])));
         }
         $arrayData["STEP_UID_OBJ"] = trim($arrayData["STEP_UID_OBJ"]);
         if ($arrayData["STEP_UID_OBJ"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->arrayParamException["stepUidObj"])));
         }
         if (!isset($arrayData["STEP_MODE"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->arrayParamException["stepMode"])));
         }
         $arrayData["STEP_MODE"] = trim($arrayData["STEP_MODE"]);
         if ($arrayData["STEP_MODE"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->arrayParamException["stepMode"])));
         }
         $this->throwExceptionIfHaveInvalidValueInTypeObj($arrayData["STEP_TYPE_OBJ"]);
         $this->throwExceptionIfHaveInvalidValueInMode($arrayData["STEP_MODE"]);
         $msg = $this->existsObjectUid($arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"], $this->arrayParamException["stepUidObj"]);
         if ($msg != "") {
             throw new \Exception($msg);
         }
         if ($this->existsRecord($taskUid, $arrayData["STEP_TYPE_OBJ"], $arrayData["STEP_UID_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_RECORD_EXISTS_IN_TABLE", array($taskUid . ", " . $arrayData["STEP_TYPE_OBJ"] . ", " . $arrayData["STEP_UID_OBJ"], "STEP")));
         }
         //Create
         $step = new \Step();
         $stepUid = $step->create(array("PRO_UID" => $processUid, "TAS_UID" => $taskUid, "STEP_POSITION" => $arrayData["STEP_POSITION"]));
         if (!isset($arrayData["STEP_POSITION"]) || $arrayData["STEP_POSITION"] == "") {
             unset($arrayData["STEP_POSITION"]);
         }
         $arrayData = $this->updateAll($stepUid, $arrayData);
         //Return
         unset($arrayData["STEP_UID"]);
         $arrayData = array_merge(array("STEP_UID" => $stepUid), $arrayData);
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }