예제 #1
0
 public function saveProcess()
 {
     try {
         require_once 'classes/model/Task.php';
         G::LoadClass('processMap');
         $oProcessMap = new ProcessMap();
         if (!isset($_POST['PRO_UID'])) {
             if (Process::existsByProTitle($_POST['PRO_TITLE'])) {
                 $result = array('success' => false, 'msg' => 'Process Save Error', 'errors' => array('PRO_TITLE' => G::LoadTranslation('ID_PROCESSTITLE_ALREADY_EXISTS', SYS_LANG, $_POST)));
                 print G::json_encode($result);
                 exit(0);
             }
             $processData['USR_UID'] = $_SESSION['USER_LOGGED'];
             $processData['PRO_TITLE'] = $_POST['PRO_TITLE'];
             $processData['PRO_DESCRIPTION'] = $_POST['PRO_DESCRIPTION'];
             $processData['PRO_CATEGORY'] = $_POST['PRO_CATEGORY'];
             $sProUid = $oProcessMap->createProcess($processData);
             //call plugins
             $oData['PRO_UID'] = $sProUid;
             $oData['PRO_TEMPLATE'] = isset($_POST['PRO_TEMPLATE']) && $_POST['PRO_TEMPLATE'] != '' ? $_POST['form']['PRO_TEMPLATE'] : '';
             $oData['PROCESSMAP'] = $oProcessMap;
             $oPluginRegistry =& PMPluginRegistry::getSingleton();
             $oPluginRegistry->executeTriggers(PM_NEW_PROCESS_SAVE, $oData);
         } else {
             //$oProcessMap->updateProcess($_POST['form']);
             $sProUid = $_POST['PRO_UID'];
         }
         //Save Calendar ID for this process
         if (isset($_POST['PRO_CALENDAR'])) {
             G::LoadClass("calendar");
             $calendarObj = new Calendar();
             $calendarObj->assignCalendarTo($sProUid, $_POST['PRO_CALENDAR'], 'PROCESS');
         }
         $result->success = true;
         $result->PRO_UID = $sProUid;
         $result->msg = G::LoadTranslation('ID_CREATE_PROCESS_SUCCESS');
     } catch (Exception $e) {
         $result->success = false;
         $result->msg = $e->getMessage();
     }
     print G::json_encode($result);
 }
예제 #2
0
    public static function createFromStruct(array $projectData, $generateUid = true)
    {
        $projectData["prj_name"] = trim($projectData["prj_name"]);
        if ($projectData["prj_name"] == '') {
            throw new \Exception("`prj_name` is required but it is empty.");
        }
        if (\Process::existsByProTitle($projectData["prj_name"])) {
            throw new \Exception("Project with name: {$projectData["prj_name"]}, already exists.");
        }
        $activities = $projectData['diagrams']['0']['activities'];
        foreach ($activities as $value) {
            if (empty($value['act_type'])) {
                throw new \Exception("For activity: {$value['act_uid']} `act_type` is required but missing.");
            }
        }
        $events = $projectData['diagrams']['0']['events'];
        foreach ($events as $value) {
            if (empty($value['evn_type'])) {
                throw new \Exception("For event: {$value['evn_uid']} `evn_type` is required but missing.");
            }
            if (empty($value['evn_marker'])) {
                throw new \Exception("For event: {$value['evn_uid']} `evn_marker` is required but missing.");
            }
        }
        $bwp = new self;
        $result = array();
        $data = array();

        if ($generateUid) {
            $result[0]["old_uid"] = isset($projectData["prj_uid"]) ? $projectData["prj_uid"] : "";
            $projectData["prj_uid"] = Util\Common::generateUID();
            $result[0]["new_uid"] = $projectData["prj_uid"];
            $result[0]["object"] = "project";
        }

        $data["PRJ_UID"] = $projectData["prj_uid"];
        $data["PRJ_AUTHOR"] = $projectData["prj_author"];

        $bwp->create($data);

        $diagramData = $processData = array();

        if (array_key_exists("diagrams", $projectData) && is_array($projectData["diagrams"]) && count($projectData["diagrams"]) > 0) {
            $diagramData = array_change_key_case($projectData["diagrams"][0], CASE_UPPER);

            if ($generateUid) {
                $result[1]["old_uid"] = $diagramData["DIA_UID"];
                $diagramData["DIA_UID"] = Util\Common::generateUID();
                $result[1]["new_uid"] = $diagramData["DIA_UID"];
                $result[1]["object"] = "diagram";
            }
        }

        $bwp->addDiagram($diagramData);

        if (array_key_exists("process", $projectData) && is_array($projectData["process"])) {
            $processData = array_change_key_case($projectData["process"], CASE_UPPER);
            if ($generateUid) {
                $result[2]["old_uid"] = $processData["PRO_UID"];
                $processData["PRO_UID"] = Util\Common::generateUID();
                $result[2]["new_uid"] = $processData["PRO_UID"];
                $result[2]["object"] = "process";
            }
        }

        $bwp->addProcess($processData);

        $mappedUid = array_merge($result, self::updateFromStruct($bwp->prjUid, $projectData, $generateUid, true));

        return $generateUid ? $mappedUid : $bwp->getUid();
    }