Example #1
0
    public function createTaskByElement($elementUid, $elementType, $key)
    {
        try {
            if (isset($this->arrayElementTaskRelation[$elementUid])) {
                $taskUid = $this->arrayElementTaskRelation[$elementUid];
            } else {
                $taskPosX = 0;
                $taskPosY = 0;

                $flow = \BpmnFlow::findOneBy(array(
                    \BpmnFlowPeer::FLO_ELEMENT_ORIGIN      => $elementUid,
                    \BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => $elementType
                ));

                if (!is_null($flow)) {
                    $arrayFlowData = $flow->toArray();

                    $taskPosX = (int)($arrayFlowData["FLO_X1"]);
                    $taskPosY = (int)($arrayFlowData["FLO_Y1"]);
                } else {
                    $flow = \BpmnFlow::findOneBy(array(
                        \BpmnFlowPeer::FLO_ELEMENT_DEST      => $elementUid,
                        \BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => $elementType
                    ));

                    if (!is_null($flow)) {
                        $arrayFlowData = $flow->toArray();

                        $taskPosX = (int)($arrayFlowData["FLO_X2"]);
                        $taskPosY = (int)($arrayFlowData["FLO_Y2"]);
                    }
                }

                $prefix   = $this->arrayTaskAttribute[$key]["prefix"];
                $taskType = $this->arrayTaskAttribute[$key]["type"];

                $taskUid = $this->wp->addTask(array(
                    "TAS_UID"   => $prefix . substr(Util\Common::generateUID(), (32 - strlen($prefix)) * -1),
                    "TAS_TYPE"  => $taskType,
                    "TAS_TITLE" => $taskType,
                    "TAS_POSX"  => $taskPosX,
                    "TAS_POSY"  => $taskPosY
                ));

                if ($elementType == "bpmnEvent" &&
                    in_array($key, array("end-message-event", "start-message-event", "intermediate-catch-message-event"))
                ) {
                    if (in_array($key, array("start-message-event", "intermediate-catch-message-event"))) {
                        //Task - User
                        //Assign to admin
                        $task = new \Tasks();

                        $result = $task->assignUser($taskUid, "00000000000000000000000000000001", 1);
                    }
                }

                //Element-Task-Relation - Create
                $elementTaskRelation = new \ProcessMaker\BusinessModel\ElementTaskRelation();

                $arrayResult = $elementTaskRelation->create(
                    $this->wp->getUid(),
                    array(
                        "ELEMENT_UID"  => $elementUid,
                        "ELEMENT_TYPE" => $elementType,
                        "TAS_UID"      => $taskUid
                    )
                );

                //Array - Add element
                $this->arrayElementTaskRelation[$elementUid] = $taskUid;
            }

            //Return
            return $taskUid;
        } catch (\Exception $e) {
            throw $e;
        }
    }
 /**
  * Validate the data if they are invalid (INSERT and UPDATE)
  *
  * @param string $messageEventRelationUid Unique id of Message-Event-Relation
  * @param string $projectUid              Unique id of Project
  * @param array  $arrayData               Data
  *
  * return void Throw exception if data has an invalid value
  */
 public function throwExceptionIfDataIsInvalid($messageEventRelationUid, $projectUid, array $arrayData)
 {
     try {
         //Set variables
         $arrayMessageEventRelationData = $messageEventRelationUid == "" ? array() : $this->getMessageEventRelation($messageEventRelationUid, true);
         $flagInsert = $messageEventRelationUid == "" ? true : false;
         $arrayFinalData = array_merge($arrayMessageEventRelationData, $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_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
             $this->throwExceptionIfEventRelationIsRegistered($projectUid, $arrayFinalData["EVN_UID_THROW"], $arrayFinalData["EVN_UID_CATCH"], $messageEventRelationUid);
         }
         if (isset($arrayData["EVN_UID_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
             //Flow
             $bpmnFlow = \BpmnFlow::findOneBy(array(\BpmnFlowPeer::FLO_TYPE => "MESSAGE", \BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $arrayFinalData["EVN_UID_THROW"], \BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent", \BpmnFlowPeer::FLO_ELEMENT_DEST => $arrayFinalData["EVN_UID_CATCH"], \BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => "bpmnEvent"));
             if (is_null($bpmnFlow)) {
                 throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_RELATION_DOES_NOT_EXIST_MESSAGE_FLOW", array($this->arrayFieldNameForException["eventUidThrow"], $arrayFinalData["EVN_UID_THROW"], $this->arrayFieldNameForException["eventUidCatch"], $arrayFinalData["EVN_UID_CATCH"])));
             }
             //Check and validate Message Flow
             $bpmn = new \ProcessMaker\Project\Bpmn();
             $bpmn->throwExceptionFlowIfIsAnInvalidMessageFlow(array("FLO_TYPE" => "MESSAGE", "FLO_ELEMENT_ORIGIN" => $arrayFinalData["EVN_UID_THROW"], "FLO_ELEMENT_ORIGIN_TYPE" => "bpmnEvent", "FLO_ELEMENT_DEST" => $arrayFinalData["EVN_UID_CATCH"], "FLO_ELEMENT_DEST_TYPE" => "bpmnEvent"));
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }