Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
Exemplo n.º 3
0
 /**
  * Assign User to Department
  *
  * @param string $departmentUid Unique id of Department
  * @param array  $arrayData     Data
  *
  * return array Return data of the User assigned to Department
  */
 public function assignUser($departmentUid, array $arrayData)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $validator = new \ProcessMaker\BusinessModel\Validator();
         $validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
         $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
         //Set data
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["DEP_UID"]);
         //Set variables
         $arrayUserFieldDefinition = array("DEP_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "departmentUid"), "USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid"));
         $arrayUserFieldNameForException = array("departmentUid" => strtolower("DEP_UID"), "userUid" => strtolower("USR_UID"));
         //Verify data
         $departmentUid = \ProcessMaker\BusinessModel\Validator::depUid($departmentUid);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayUserFieldDefinition, $arrayUserFieldNameForException, true);
         $process->throwExceptionIfNotExistsUser($arrayData["USR_UID"], $arrayUserFieldNameForException["userUid"]);
         //Assign User
         $department = new \Department();
         $department->load($departmentUid);
         $department->addUserToDepartment($departmentUid, $arrayData["USR_UID"], $department->getDepManager() == "" ? true : false, false);
         $department->updateDepartmentManager($departmentUid);
         //Return
         $arrayData = array_merge(array("DEP_UID" => $departmentUid), $arrayData);
         $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 4
0
 /**
  * Unassign User of the Role
  *
  * @param string $roleUid Unique id of Role
  * @param string $userUid Unique id of User
  *
  * return void
  */
 public function delete($roleUid, $userUid)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $role = new \ProcessMaker\BusinessModel\Role();
         $role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
         $process->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["userUid"]);
         $this->throwExceptionIfNotItsAssignedUserToRole($roleUid, $userUid, $this->arrayFieldNameForException["userUid"]);
         if ($userUid == "00000000000000000000000000000001") {
             throw new \Exception(\G::LoadTranslation("ID_ADMINISTRATOR_ROLE_CANT_CHANGED"));
         }
         //Delete
         $role = new \Roles();
         $role->deleteUserRole($roleUid, $userUid);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 5
0
 /**
  * Unassign User of the Group
  *
  * @param string $groupUid Unique id of Group
  * @param string $userUid  Unique id of User
  *
  * return void
  */
 public function delete($groupUid, $userUid)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $group = new \ProcessMaker\BusinessModel\Group();
         $group->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
         $process->throwExceptionIfNotExistsUser($userUid, $this->arrayFieldNameForException["userUid"]);
         $this->throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $this->arrayFieldNameForException["userUid"]);
         //Delete
         $group = new \Groups();
         $group->removeUserOfGroup($groupUid, $userUid);
     } catch (\Exception $e) {
         throw $e;
     }
 }