Esempio n. 1
0
 public function delete($processUid, $checkCases = 1)
 {
     $response = array();
     try {
         $process = new \ProcessMaker\BusinessModel\Process();
         $result = $process->deleteProcess($processUid, $checkCases && $checkCases == 1 ? true : false);
         //Response
         $response["success"] = true;
         $response["message"] = "Process was deleted successfully";
     } catch (\Exception $e) {
         throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
     }
     return $response;
 }
 /**
  * Create Case Tracker Object for a Process
  *
  * @param string $processUid Unique id of Process
  * @param array  $arrayData  Data
  *
  * return array Return data of the new Case Tracker Object created
  */
 public function create($processUid, $arrayData)
 {
     try {
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         unset($arrayData["CTO_UID"]);
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, "prj_uid");
         if (!isset($arrayData["CTO_TYPE_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array(strtolower("CTO_TYPE_OBJ"))));
         }
         if (!isset($arrayData["CTO_UID_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array(strtolower("CTO_UID_OBJ"))));
         }
         $step = new \ProcessMaker\BusinessModel\Step();
         $msg = $step->existsObjectUid($arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"], strtolower("CTO_UID_OBJ"));
         if ($msg != "") {
             throw new \Exception($msg);
         }
         if ($this->existsRecord($processUid, $arrayData["CTO_TYPE_OBJ"], $arrayData["CTO_UID_OBJ"])) {
             throw new \Exception(\G::LoadTranslation("ID_RECORD_EXISTS_IN_TABLE", array($processUid . ", " . $arrayData["CTO_TYPE_OBJ"] . ", " . $arrayData["CTO_UID_OBJ"], "CASE_TRACKER_OBJECT")));
         }
         $ctoPosition = $arrayData["CTO_POSITION"];
         $criteria = new \Criteria("workflow");
         $criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid);
         $arrayData["CTO_POSITION"] = \CaseTrackerObjectPeer::doCount($criteria) + 1;
         //Create
         $caseTrackerObject = new \CaseTrackerObject();
         $arrayData["PRO_UID"] = $processUid;
         $caseTrackerObjectUid = $caseTrackerObject->create($arrayData);
         $arrayData["CTO_POSITION"] = $ctoPosition;
         $arrayData["CTO_UID"] = $caseTrackerObjectUid;
         $arrayDataUpdate = array_change_key_case($arrayData, CASE_LOWER);
         $this->update($caseTrackerObjectUid, $arrayDataUpdate);
         //Return
         unset($arrayData["PRO_UID"]);
         $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         unset($arrayData["cto_uid"]);
         return array_merge(array("cto_uid" => $caseTrackerObjectUid), $arrayData);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * Return an assignee list of an activity
  *
  * @param string $processUid
  * @param string $taskUid
  * @param string $option
  * @param int    $taskUserType
  * @param array  $arrayFilterData
  * @param int    $start
  * @param int    $limit
  * @param string $type
  *
  * return array
  */
 public function getTaskAssignees($processUid, $taskUid, $option, $taskUserType, $arrayFilterData = null, $start = null, $limit = null, $type = null)
 {
     try {
         $arrayAssignee = array();
         $numRecTotal = 0;
         $startbk = $start;
         $limitbk = $limit;
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), array("start" => "start", "limit" => "limit"));
         $arrayFieldDefinition = array("OPTION" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ASSIGNEE", "AVAILABLE"), "fieldNameAux" => "option"), "TASK_USER_TYPE" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(1, 2), "fieldNameAux" => "taskUserType"));
         $process->throwExceptionIfDataNotMetFieldDefinition(array("OPTION" => $option, "TASK_USER_TYPE" => $taskUserType), $arrayFieldDefinition, array("option" => "option", "taskUserType" => "taskUserType"), false);
         //Set variables
         $filterName = "filter";
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"])) {
             $arrayAux = array("" => "filter", "LEFT" => "lfilter", "RIGHT" => "rfilter");
             $filterName = $arrayAux[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
         }
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             //Return
             return array("total" => $numRecTotal, "start" => (int) (!is_null($startbk) ? $startbk : 0), "limit" => (int) (!is_null($limitbk) ? $limitbk : 0), $filterName => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arrayAssignee);
         }
         //Verify data
         $process->throwExceptionIfNotExistsProcess($processUid, "prj_uid");
         $this->throwExceptionIfNotExistsTask($processUid, $taskUid, "act_uid");
         //Set variables
         $numRecTotalGroup = 0;
         $numRecTotalUser = 0;
         switch ($option) {
             case "ASSIGNEE":
                 break;
             case "AVAILABLE":
                 $task = new \Tasks();
                 $arrayGroupUid = array();
                 foreach ($task->getGroupsOfTask($taskUid, $taskUserType) as $value) {
                     $arrayGroupUid[] = $value['GRP_UID'];
                 }
                 $arrayUserUid = array();
                 foreach ($task->getUsersOfTask($taskUid, $taskUserType) as $value) {
                     $arrayUserUid[] = $value['USR_UID'];
                 }
                 break;
         }
         //Groups
         //Query
         if (empty($type) || $type == "group") {
             $criteriaGroup = new \Criteria("workflow");
             $criteriaGroup->addSelectColumn(\GroupwfPeer::GRP_UID);
             $criteriaGroup->addAsColumn("GRP_TITLE", \ContentPeer::CON_VALUE);
             switch ($option) {
                 case "ASSIGNEE":
                     $criteriaGroup->addJoin(\TaskUserPeer::USR_UID, \GroupwfPeer::GRP_UID, \Criteria::LEFT_JOIN);
                     $criteriaGroup->add(\TaskUserPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
                     $criteriaGroup->add(\TaskUserPeer::TU_TYPE, $taskUserType, \Criteria::EQUAL);
                     $criteriaGroup->add(\TaskUserPeer::TU_RELATION, 2, \Criteria::EQUAL);
                     break;
                 case "AVAILABLE":
                     $criteriaGroup->add(\GroupwfPeer::GRP_UID, $arrayGroupUid, \Criteria::NOT_IN);
                     break;
             }
             $criteriaGroup->addJoin(\GroupwfPeer::GRP_UID, \ContentPeer::CON_ID, \Criteria::LEFT_JOIN);
             $criteriaGroup->add(\ContentPeer::CON_CATEGORY, "GRP_TITLE", \Criteria::EQUAL);
             $criteriaGroup->add(\ContentPeer::CON_LANG, SYS_LANG, \Criteria::EQUAL);
             if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
                 $arraySearch = array("" => "%" . $arrayFilterData["filter"] . "%", "LEFT" => $arrayFilterData["filter"] . "%", "RIGHT" => "%" . $arrayFilterData["filter"]);
                 $search = $arraySearch[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
                 $criteriaGroup->add(\ContentPeer::CON_VALUE, $search, \Criteria::LIKE);
             }
             $criteriaGroup->add(\GroupwfPeer::GRP_STATUS, "ACTIVE", \Criteria::EQUAL);
             //Number records total
             $criteriaCount = clone $criteriaGroup;
             $criteriaCount->clearSelectColumns();
             $criteriaCount->addSelectColumn("COUNT(" . \GroupwfPeer::GRP_UID . ") AS NUM_REC");
             switch ($option) {
                 case "ASSIGNEE":
                     $rsCriteriaCount = \TaskUserPeer::doSelectRS($criteriaCount);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaCount = \GroupwfPeer::doSelectRS($criteriaCount);
                     break;
             }
             $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $result = $rsCriteriaCount->next();
             $row = $rsCriteriaCount->getRow();
             $numRecTotalGroup = (int) $row["NUM_REC"];
             $numRecTotal = $numRecTotal + $numRecTotalGroup;
         }
         //Users
         //Query
         if (empty($type) || $type == "user") {
             $criteriaUser = new \Criteria("workflow");
             $criteriaUser->addSelectColumn(\UsersPeer::USR_UID);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_USERNAME);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_LASTNAME);
             switch ($option) {
                 case "ASSIGNEE":
                     $criteriaUser->addJoin(\TaskUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::LEFT_JOIN);
                     $criteriaUser->add(\TaskUserPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
                     $criteriaUser->add(\TaskUserPeer::TU_TYPE, $taskUserType, \Criteria::EQUAL);
                     $criteriaUser->add(\TaskUserPeer::TU_RELATION, 1, \Criteria::EQUAL);
                     break;
                 case "AVAILABLE":
                     $criteriaUser->add(\UsersPeer::USR_UID, $arrayUserUid, \Criteria::NOT_IN);
                     break;
             }
             if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
                 $arraySearch = array("" => "%" . $arrayFilterData["filter"] . "%", "LEFT" => $arrayFilterData["filter"] . "%", "RIGHT" => "%" . $arrayFilterData["filter"]);
                 $search = $arraySearch[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
                 $criteriaUser->add($criteriaUser->getNewCriterion(\UsersPeer::USR_USERNAME, $search, \Criteria::LIKE)->addOr($criteriaUser->getNewCriterion(\UsersPeer::USR_FIRSTNAME, $search, \Criteria::LIKE))->addOr($criteriaUser->getNewCriterion(\UsersPeer::USR_LASTNAME, $search, \Criteria::LIKE)));
             }
             $criteriaUser->add(\UsersPeer::USR_STATUS, "ACTIVE", \Criteria::EQUAL);
             //Number records total
             $criteriaCount = clone $criteriaUser;
             $criteriaCount->clearSelectColumns();
             $criteriaCount->addSelectColumn("COUNT(" . \UsersPeer::USR_UID . ") AS NUM_REC");
             switch ($option) {
                 case "ASSIGNEE":
                     $rsCriteriaCount = \TaskUserPeer::doSelectRS($criteriaCount);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaCount = \UsersPeer::doSelectRS($criteriaCount);
                     break;
             }
             $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $result = $rsCriteriaCount->next();
             $row = $rsCriteriaCount->getRow();
             $numRecTotalUser = (int) $row["NUM_REC"];
             $numRecTotal = $numRecTotal + $numRecTotalUser;
         }
         //Groups
         //Query
         if (empty($type) || $type == "group") {
             $criteriaGroup->addAscendingOrderByColumn("GRP_TITLE");
             if (!is_null($start)) {
                 $criteriaGroup->setOffset((int) $start);
             }
             if (!is_null($limit)) {
                 $criteriaGroup->setLimit((int) $limit);
             }
             switch ($option) {
                 case "ASSIGNEE":
                     $rsCriteriaGroup = \TaskUserPeer::doSelectRS($criteriaGroup);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaGroup = \GroupwfPeer::doSelectRS($criteriaGroup);
                     break;
             }
             $rsCriteriaGroup->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $numRecGroup = 0;
             while ($rsCriteriaGroup->next()) {
                 $row = $rsCriteriaGroup->getRow();
                 $criteria2 = new \Criteria("workflow");
                 $criteria2->addSelectColumn("COUNT(" . \GroupUserPeer::GRP_UID . ") AS NUM_MEM");
                 $criteria2->add(\GroupUserPeer::GRP_UID, $row["GRP_UID"], \Criteria::EQUAL);
                 $rsCriteria2 = \GroupUserPeer::doSelectRS($criteria2);
                 $rsCriteria2->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 $result = $rsCriteria2->next();
                 $row2 = $rsCriteria2->getRow();
                 $row["GRP_TITLE"] = $row["GRP_TITLE"] . " (" . $row2["NUM_MEM"] . " " . \G::LoadTranslation((int) $row2["NUM_MEM"] == 1 ? "ID_USER" : "ID_USERS") . ")";
                 $arrayAssignee[] = $this->getTaskAssigneeDataFromRecord(array($row["GRP_UID"], $row["GRP_TITLE"], "", $row["GRP_TITLE"], "group"), $taskUserType);
                 $numRecGroup++;
             }
         }
         //Users
         //Query
         if (empty($type) || $type == "user") {
             $flagUser = true;
             if ($numRecTotalGroup > 0) {
                 if ($numRecGroup > 0) {
                     if (!is_null($limit)) {
                         if ($numRecGroup < (int) $limit) {
                             $start = 0;
                             $limit = $limit - $numRecGroup;
                         } else {
                             $flagUser = false;
                         }
                     } else {
                         $start = 0;
                     }
                 } else {
                     $start = (int) $start - $numRecTotalGroup;
                 }
             }
             if ($flagUser) {
                 //Users
                 //Query
                 $criteriaUser->addAscendingOrderByColumn(\UsersPeer::USR_FIRSTNAME);
                 if (!is_null($start)) {
                     $criteriaUser->setOffset((int) $start);
                 }
                 if (!is_null($limit)) {
                     $criteriaUser->setLimit((int) $limit);
                 }
                 switch ($option) {
                     case "ASSIGNEE":
                         $rsCriteriaUser = \TaskUserPeer::doSelectRS($criteriaUser);
                         break;
                     case "AVAILABLE":
                         $rsCriteriaUser = \UsersPeer::doSelectRS($criteriaUser);
                         break;
                 }
                 $rsCriteriaUser->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 while ($rsCriteriaUser->next()) {
                     $row = $rsCriteriaUser->getRow();
                     $arrayAssignee[] = $this->getTaskAssigneeDataFromRecord(array($row["USR_UID"], $row["USR_FIRSTNAME"], $row["USR_LASTNAME"], $row["USR_USERNAME"], "user"), $taskUserType);
                 }
             }
         }
         //Return
         return array("total" => $numRecTotal, "start" => (int) (!is_null($startbk) ? $startbk : 0), "limit" => (int) (!is_null($limitbk) ? $limitbk : 0), $filterName => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arrayAssignee);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 4
0
    /**
     * @url GET /:prj_uid/trigger-wizards
     *
     * @param string $prj_uid {@min 32}{@max 32}
     */
    public function doGetTriggerWizards($prj_uid)
    {
        try {
            $process = new \ProcessMaker\BusinessModel\Process();
            $process->setFormatFieldNameInUppercase(false);
            $process->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name"));

            $response = $process->getLibraries($prj_uid);

            return $response;
        } catch (\Exception $e) {
            throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
        }
    }
Esempio n. 5
0
    /**
     * Get all Message-Applications
     *
     * @param array  $arrayFilterData Data of the filters
     * @param string $sortField       Field name to sort
     * @param string $sortDir         Direction of sorting (ASC, DESC)
     * @param int    $start           Start
     * @param int    $limit           Limit
     *
     * return array Return an array with all Message-Applications
     */
    public function getMessageApplications($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
    {
        try {
            $arrayMessageApplication = array();

            //Verify data
            $process = new \ProcessMaker\BusinessModel\Process();

            $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);

            //Get data
            if (!is_null($limit) && $limit . "" == "0") {
                return $arrayMessageApplication;
            }

            //SQL
            $criteria = $this->getMessageApplicationCriteria();

            $criteria->addSelectColumn(\BpmnEventPeer::EVN_UID);
            $criteria->addSelectColumn(\BpmnEventPeer::EVN_TYPE);
            $criteria->addSelectColumn(\BpmnEventPeer::EVN_MARKER);
            $criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_USR_UID);
            $criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_VARIABLES);
            $criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_CORRELATION);
            $criteria->addSelectColumn(\ElementTaskRelationPeer::TAS_UID);

            $arrayEventType   = array("START", "INTERMEDIATE");
            $arrayEventMarker = array("MESSAGECATCH");

            $criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \BpmnEventPeer::EVN_UID, \Criteria::INNER_JOIN);
            $criteria->add(\BpmnEventPeer::EVN_TYPE, $arrayEventType, \Criteria::IN);
            $criteria->add(\BpmnEventPeer::EVN_MARKER, $arrayEventMarker, \Criteria::IN);

            $criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \MessageEventDefinitionPeer::EVN_UID, \Criteria::INNER_JOIN);

            $criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \ElementTaskRelationPeer::ELEMENT_UID, \Criteria::INNER_JOIN);
            $criteria->add(\ElementTaskRelationPeer::ELEMENT_TYPE, "bpmnEvent", \Criteria::EQUAL);

            if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["messageApplicationStatus"]) && trim($arrayFilterData["messageApplicationStatus"]) != "") {
                $criteria->add(\MessageApplicationPeer::MSGAPP_STATUS, $arrayFilterData["messageApplicationStatus"], \Criteria::EQUAL);
            }

            //Number records total
            $criteriaCount = clone $criteria;

            $criteriaCount->clearSelectColumns();
            $criteriaCount->addSelectColumn("COUNT(" . \MessageApplicationPeer::MSGAPP_UID . ") AS NUM_REC");

            $rsCriteriaCount = \MessageApplicationPeer::doSelectRS($criteriaCount);
            $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);

            $rsCriteriaCount->next();
            $row = $rsCriteriaCount->getRow();

            $numRecTotal = $row["NUM_REC"];

            //SQL
            if (!is_null($sortField) && trim($sortField) != "") {
                $sortField = strtoupper($sortField);

                if (in_array($sortField, array("MSGAPP_THROW_DATE", "MSGAPP_CATCH_DATE", "MSGAPP_STATUS"))) {
                    $sortField = \MessageApplicationPeer::TABLE_NAME . "." . $sortField;
                } else {
                    $sortField = \MessageApplicationPeer::MSGAPP_THROW_DATE;
                }
            } else {
                $sortField = \MessageApplicationPeer::MSGAPP_THROW_DATE;
            }

            if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
                $criteria->addDescendingOrderByColumn($sortField);
            } else {
                $criteria->addAscendingOrderByColumn($sortField);
            }

            if (!is_null($start)) {
                $criteria->setOffset((int)($start));
            }

            if (!is_null($limit)) {
                $criteria->setLimit((int)($limit));
            }

            $rsCriteria = \MessageApplicationPeer::doSelectRS($criteria);
            $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);

            while ($rsCriteria->next()) {
                $row = $rsCriteria->getRow();

                $row["MSGAPP_VARIABLES"] = unserialize($row["MSGAPP_VARIABLES"]);
                $row["MSGED_VARIABLES"]  = unserialize($row["MSGED_VARIABLES"]);

                $arrayMessageApplication[] = $row;
            }

            //Return
            return array(
                "total"  => $numRecTotal,
                "start"  => (int)((!is_null($start))? $start : 0),
                "limit"  => (int)((!is_null($limit))? $limit : 0),
                "filter" => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["messageApplicationStatus"]))? $arrayFilterData["messageApplicationStatus"] : "",
                "data"   => $arrayMessageApplication
            );
        } catch (\Exception $e) {
            throw $e;
        }
    }
Esempio n. 6
0
 /**
  * Get all Users of a Group
  *
  * @param string $option          Option (USERS, AVAILABLE-USERS)
  * @param string $groupUid        Unique id of Group
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Users of a Group
  */
 public function getUsers($option, $groupUid, $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayUser = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $this->throwExceptionIfNotExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]);
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayUser;
         }
         //SQL
         switch ($option) {
             case "SUPERVISOR":
                 $flagPermission = true;
                 //Criteria for Supervisor
                 $criteria = $this->getUserCriteria($groupUid, $arrayFilterData);
                 break;
             case "USERS":
                 //Criteria
                 $criteria = $this->getUserCriteria($groupUid, $arrayFilterData);
                 break;
             case "AVAILABLE-USERS":
                 //Get Uids
                 $arrayUid = array();
                 $criteria = $this->getUserCriteria($groupUid);
                 $rsCriteria = \UsersPeer::doSelectRS($criteria);
                 $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 while ($rsCriteria->next()) {
                     $row = $rsCriteria->getRow();
                     $arrayUid[] = $row["USR_UID"];
                 }
                 //Criteria
                 $criteria = $this->getUserCriteria("", $arrayFilterData, $arrayUid);
                 break;
         }
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             if (in_array($sortField, array("USR_UID", "USR_USERNAME", "USR_FIRSTNAME", "USR_LASTNAME", "USR_EMAIL", "USR_STATUS"))) {
                 $sortField = \UsersPeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \UsersPeer::USR_USERNAME;
             }
         } else {
             $sortField = \UsersPeer::USR_USERNAME;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \UsersPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         if (isset($flagPermission) && $flagPermission) {
             \G::LoadSystem('rbac');
             while ($rsCriteria->next()) {
                 $row = $rsCriteria->getRow();
                 $aPermissions = $this->loadUserRolePermission("PROCESSMAKER", $row['USR_UID']);
                 $bInclude = false;
                 foreach ($aPermissions as $aPermission) {
                     if ($aPermission['PER_CODE'] == 'PM_SUPERVISOR') {
                         $bInclude = true;
                     }
                 }
                 if ($bInclude) {
                     $arrayUser[] = $this->getUserDataFromRecord($row);
                 }
             }
         } else {
             while ($rsCriteria->next()) {
                 $row = $rsCriteria->getRow();
                 $arrayUser[] = $this->getUserDataFromRecord($row);
             }
         }
         //Return
         return $arrayUser;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 7
0
    /**

     * Get all Users

     *

     * @param array  $arrayFilterData Data of the filters

     * @param string $sortField       Field name to sort

     * @param string $sortDir         Direction of sorting (ASC, DESC)

     * @param int    $start           Start

     * @param int    $limit           Limit

     *

     * return array Return an array with all Users

     */

    public function getUsers($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)

    {

        try {

            $arrayUser = array();



            $numRecTotal = 0;



            //Verify data

            $process = new \ProcessMaker\BusinessModel\Process();



            $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), array("start" => "start", "limit" => "limit"));



            //Set variables

            $filterName = "filter";



            if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"])) {

                $arrayAux = array(

                    ""      => "filter",

                    "LEFT"  => "lfilter",

                    "RIGHT" => "rfilter"

                );



                $filterName = $arrayAux[(isset($arrayFilterData["filterOption"]))? $arrayFilterData["filterOption"] : ""];

            }



            //Get data

            if (!is_null($limit) && $limit . "" == "0") {

                //Return

                return array(

                    "total"     => $numRecTotal,

                    "start"     => (int)((!is_null($start))? $start : 0),

                    "limit"     => (int)((!is_null($limit))? $limit : 0),

                    $filterName => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "",

                    "data"      => $arrayUser

                );

            }



            //Query

            $criteria = $this->getUserCriteria();



            if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {

                $arraySearch = array(

                    ""      => "%" . $arrayFilterData["filter"] . "%",

                    "LEFT"  => $arrayFilterData["filter"] . "%",

                    "RIGHT" => "%" . $arrayFilterData["filter"]

                );



                $search = $arraySearch[(isset($arrayFilterData["filterOption"]))? $arrayFilterData["filterOption"] : ""];



                $criteria->add(

                    $criteria->getNewCriterion(\UsersPeer::USR_USERNAME,  $search, \Criteria::LIKE)->addOr(

                    $criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, $search, \Criteria::LIKE))->addOr(

                    $criteria->getNewCriterion(\UsersPeer::USR_LASTNAME,  $search, \Criteria::LIKE))

                );

            }



            $criteria->add(\UsersPeer::USR_STATUS, "ACTIVE", \Criteria::EQUAL);



            //Number records total

            $criteriaCount = clone $criteria;



            $criteriaCount->clearSelectColumns();

            $criteriaCount->addSelectColumn("COUNT(" . \UsersPeer::USR_UID . ") AS NUM_REC");



            $rsCriteriaCount = \UsersPeer::doSelectRS($criteriaCount);

            $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);



            $result = $rsCriteriaCount->next();

            $row = $rsCriteriaCount->getRow();



            $numRecTotal = (int)($row["NUM_REC"]);



            //Query

            if (!is_null($sortField) && trim($sortField) != "") {

                $sortField = strtoupper($sortField);



                if (in_array(\UsersPeer::TABLE_NAME . "." . $sortField, $criteria->getSelectColumns())) {

                    $sortField = \UsersPeer::TABLE_NAME . "." . $sortField;

                } else {

                    $sortField = \UsersPeer::USR_FIRSTNAME;

                }

            } else {

                $sortField = \UsersPeer::USR_FIRSTNAME;

            }



            if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {

                $criteria->addDescendingOrderByColumn($sortField);

            } else {

                $criteria->addAscendingOrderByColumn($sortField);

            }



            if (!is_null($start)) {

                $criteria->setOffset((int)($start));

            }



            if (!is_null($limit)) {

                $criteria->setLimit((int)($limit));

            }



            $rsCriteria = \UsersPeer::doSelectRS($criteria);

            $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);



            while ($rsCriteria->next()) {

                $row = $rsCriteria->getRow();



                $arrayUser[] = $this->getUserDataFromRecord($row);

            }



            //Return

            return array(

                "total"     => $numRecTotal,

                "start"     => (int)((!is_null($start))? $start : 0),

                "limit"     => (int)((!is_null($limit))? $limit : 0),

                $filterName => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "",

                "data"      => $arrayUser

            );

        } catch (\Exception $e) {

            throw $e;

        }

    }
Esempio n. 8
0
 /**
  * Get all Roles
  *
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Roles
  */
 public function getRoles(array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayRole = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayRole;
         }
         //Set variables
         $content = new \Content();
         $role = new \Roles();
         $arrayContentByRole = $content->getAllContentsByRole();
         //SQL
         $criteria = $this->getRoleCriteria();
         $criteria->addAsColumn("ROL_TOTAL_USERS", "(SELECT COUNT(" . \UsersRolesPeer::ROL_UID . ") FROM " . \UsersRolesPeer::TABLE_NAME . " WHERE " . \UsersRolesPeer::ROL_UID . " = " . \RolesPeer::ROL_UID . ")");
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add(\RolesPeer::ROL_CODE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
         }
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             if (in_array($sortField, array("ROL_UID", "ROL_PARENT", "ROL_STATUS", "ROL_SYSTEM", "ROL_CREATE_DATE", "ROL_UPDATE_DATE"))) {
                 $sortField = \RolesPeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \RolesPeer::ROL_CODE;
             }
         } else {
             $sortField = \RolesPeer::ROL_CODE;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \RolesPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $roleUid = $row["ROL_UID"];
             if (isset($arrayContentByRole[$roleUid])) {
                 $roleName = $arrayContentByRole[$roleUid];
             } else {
                 $rowAux = $role->load($roleUid);
                 $roleName = $rowAux["ROL_NAME"];
             }
             $row["ROL_NAME"] = $roleName;
             $arrayRole[] = $this->getRoleDataFromRecord($row);
         }
         //Return
         return $arrayRole;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 9
0
 /**
  * Get all Email Servers
  *
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Email Servers
  */
 public function getEmailServers($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayEmailServer = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayEmailServer;
         }
         //SQL
         $criteria = $this->getEmailServerCriteria();
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add($criteria->getNewCriterion(\EmailServerPeer::MESS_ENGINE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr($criteria->getNewCriterion(\EmailServerPeer::MESS_SERVER, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr($criteria->getNewCriterion(\EmailServerPeer::MESS_ACCOUNT, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr($criteria->getNewCriterion(\EmailServerPeer::MESS_FROM_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr($criteria->getNewCriterion(\EmailServerPeer::SMTPSECURE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)));
         }
         //Number records total
         $criteriaCount = clone $criteria;
         $criteriaCount->clearSelectColumns();
         $criteriaCount->addSelectColumn("COUNT(" . \EmailServerPeer::MESS_UID . ") AS NUM_REC");
         $rsCriteriaCount = \EmailServerPeer::doSelectRS($criteriaCount);
         $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $rsCriteriaCount->next();
         $row = $rsCriteriaCount->getRow();
         $numRecTotal = $row["NUM_REC"];
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             if (in_array($sortField, array("MESS_ENGINE", "MESS_SERVER", "MESS_ACCOUNT", "MESS_FROM_NAME", "SMTPSECURE"))) {
                 $sortField = \EmailServerPeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \EmailServerPeer::MESS_ENGINE;
             }
         } else {
             $sortField = \EmailServerPeer::MESS_ENGINE;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \EmailServerPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $passwd = $row["MESS_PASSWORD"];
             $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT");
             $auxPass = explode("hash:", $passwdDec);
             if (count($auxPass) > 1) {
                 if (count($auxPass) == 2) {
                     $passwd = $auxPass[1];
                 } else {
                     array_shift($auxPass);
                     $passwd = implode("", $auxPass);
                 }
             }
             $row["MESS_PASSWORD"] = $passwd;
             $arrayEmailServer[] = $this->getEmailServerDataFromRecord($row);
         }
         //Return
         return array("total" => $numRecTotal, "start" => (int) (!is_null($start) ? $start : 0), "limit" => (int) (!is_null($limit) ? $limit : 0), "filter" => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arrayEmailServer);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 10
0
 /**
  * Get Supervisors
  *
  * @param string $processUid
  * @param string $option
  * @param array  $arrayFilterData
  * @param int    $start
  * @param int    $limit
  * @param string $type
  *
  * @return array
  */
 public function getProcessSupervisors($processUid, $option, $arrayFilterData = null, $start = null, $limit = null, $type = null)
 {
     try {
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersRoles.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "UsersRolesPeer.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Roles.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RolesPeer.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RolesPermissions.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "RolesPermissionsPeer.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Permissions.php";
         require_once PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "PermissionsPeer.php";
         $arraySupervisor = array();
         $numRecTotal = 0;
         $startbk = $start;
         $limitbk = $limit;
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), array("start" => "start", "limit" => "limit"));
         //Set variables
         $filterName = "filter";
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"])) {
             $arrayAux = array("" => "filter", "LEFT" => "lfilter", "RIGHT" => "rfilter");
             $filterName = $arrayAux[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
         }
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             //Return
             return array("total" => $numRecTotal, "start" => (int) (!is_null($startbk) ? $startbk : 0), "limit" => (int) (!is_null($limitbk) ? $limitbk : 0), $filterName => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arraySupervisor);
         }
         //Verify data
         $process->throwExceptionIfNotExistsProcess($processUid, "prj_uid");
         //Set variables
         $numRecTotalGroup = 0;
         $numRecTotalUser = 0;
         $delimiter = \DBAdapter::getStringDelimiter();
         switch ($option) {
             case "ASSIGNED":
                 break;
             case "AVAILABLE":
                 $arrayGroupUid = array();
                 $arrayUserUid = array();
                 $criteria = new \Criteria("workflow");
                 $criteria->addSelectColumn(\ProcessUserPeer::USR_UID);
                 $criteria->addSelectColumn(\ProcessUserPeer::PU_TYPE);
                 $criteria->add(\ProcessUserPeer::PRO_UID, $processUid, \Criteria::EQUAL);
                 $criteria->add(\ProcessUserPeer::PU_TYPE, "%SUPERVISOR%", \Criteria::LIKE);
                 $rsCriteria = \ProcessUserPeer::doSelectRS($criteria);
                 $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 while ($rsCriteria->next()) {
                     $row = $rsCriteria->getRow();
                     if ($row["PU_TYPE"] == "SUPERVISOR") {
                         $arrayUserUid[] = $row["USR_UID"];
                     } else {
                         $arrayGroupUid[] = $row["USR_UID"];
                     }
                 }
                 $arrayRbacSystemData = array("SYS_UID" => "PROCESSMAKER", "SYS_CODE" => "00000000000000000000000000000002");
                 break;
         }
         //Groups
         //Query
         if (empty($type) || $type == "group") {
             $criteriaGroup = new \Criteria("workflow");
             $criteriaGroup->addSelectColumn(\GroupwfPeer::GRP_UID);
             $criteriaGroup->addAsColumn("GRP_TITLE", \ContentPeer::CON_VALUE);
             switch ($option) {
                 case "ASSIGNED":
                     $criteriaGroup->addSelectColumn(\ProcessUserPeer::PU_UID);
                     $arrayCondition = array();
                     $arrayCondition[] = array(\ProcessUserPeer::USR_UID, \GroupwfPeer::GRP_UID, \Criteria::EQUAL);
                     $arrayCondition[] = array(\GroupwfPeer::GRP_STATUS, $delimiter . "ACTIVE" . $delimiter, \Criteria::EQUAL);
                     $criteriaGroup->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
                     $arrayCondition = array();
                     $arrayCondition[] = array(\GroupwfPeer::GRP_UID, \ContentPeer::CON_ID, \Criteria::EQUAL);
                     $arrayCondition[] = array(\ContentPeer::CON_CATEGORY, $delimiter . "GRP_TITLE" . $delimiter, \Criteria::EQUAL);
                     $arrayCondition[] = array(\ContentPeer::CON_LANG, $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
                     $criteriaGroup->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
                     $criteriaGroup->add(\ProcessUserPeer::PU_TYPE, "GROUP_SUPERVISOR", \Criteria::EQUAL);
                     $criteriaGroup->add(\ProcessUserPeer::PRO_UID, $processUid, \Criteria::EQUAL);
                     break;
                 case "AVAILABLE":
                     $sql = "\n                        SELECT DISTINCT " . \GroupUserPeer::GRP_UID . "\n                        FROM   " . \GroupUserPeer::TABLE_NAME . ", " . \UsersPeer::TABLE_NAME . ",\n                               " . \UsersRolesPeer::TABLE_NAME . ", " . \RolesPermissionsPeer::TABLE_NAME . ", " . \PermissionsPeer::TABLE_NAME . "\n                        WHERE  " . \GroupUserPeer::GRP_UID . " = " . \GroupwfPeer::GRP_UID . " AND\n                               " . \GroupUserPeer::USR_UID . " = " . \UsersPeer::USR_UID . " AND " . \UsersPeer::USR_STATUS . " = " . $delimiter . "ACTIVE" . $delimiter . " AND\n                               " . \UsersPeer::USR_UID . " = " . \UsersRolesPeer::USR_UID . " AND\n                               " . \UsersRolesPeer::ROL_UID . " = " . \RolesPermissionsPeer::ROL_UID . " AND\n                               " . \RolesPermissionsPeer::PER_UID . " = " . \PermissionsPeer::PER_UID . " AND\n                               " . \PermissionsPeer::PER_CODE . " = " . $delimiter . "PM_SUPERVISOR" . $delimiter . " AND\n                               " . \PermissionsPeer::PER_SYSTEM . " = " . $delimiter . $arrayRbacSystemData["SYS_CODE"] . $delimiter . "\n                        ";
                     $arrayCondition = array();
                     $arrayCondition[] = array(\GroupwfPeer::GRP_UID, \ContentPeer::CON_ID, \Criteria::EQUAL);
                     $arrayCondition[] = array(\ContentPeer::CON_CATEGORY, $delimiter . "GRP_TITLE" . $delimiter, \Criteria::EQUAL);
                     $arrayCondition[] = array(\ContentPeer::CON_LANG, $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL);
                     $criteriaGroup->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
                     $criteriaGroup->add($criteriaGroup->getNewCriterion(\GroupwfPeer::GRP_UID, $arrayGroupUid, \Criteria::NOT_IN)->addAnd($criteriaGroup->getNewCriterion(\GroupwfPeer::GRP_STATUS, "ACTIVE", \Criteria::EQUAL))->addAnd($criteriaGroup->getNewCriterion(\GroupwfPeer::GRP_UID, \GroupwfPeer::GRP_UID . " IN ({$sql})", \Criteria::CUSTOM)));
                     break;
             }
             if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
                 $arraySearch = array("" => "%" . $arrayFilterData["filter"] . "%", "LEFT" => $arrayFilterData["filter"] . "%", "RIGHT" => "%" . $arrayFilterData["filter"]);
                 $search = $arraySearch[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
                 $criteriaGroup->add(\ContentPeer::CON_VALUE, $search, \Criteria::LIKE);
             }
             //Number records total
             $criteriaCount = clone $criteriaGroup;
             $criteriaCount->clearSelectColumns();
             $criteriaCount->addSelectColumn("COUNT(" . \GroupwfPeer::GRP_UID . ") AS NUM_REC");
             switch ($option) {
                 case "ASSIGNED":
                     $rsCriteriaCount = \ProcessUserPeer::doSelectRS($criteriaCount);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaCount = \GroupwfPeer::doSelectRS($criteriaCount);
                     break;
             }
             $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $result = $rsCriteriaCount->next();
             $row = $rsCriteriaCount->getRow();
             $numRecTotalGroup = (int) $row["NUM_REC"];
             $numRecTotal = $numRecTotal + $numRecTotalGroup;
         }
         //Users
         //Query
         if (empty($type) || $type == "user") {
             $criteriaUser = new \Criteria("workflow");
             $criteriaUser->addSelectColumn(\UsersPeer::USR_UID);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_USERNAME);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_FIRSTNAME);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_LASTNAME);
             $criteriaUser->addSelectColumn(\UsersPeer::USR_EMAIL);
             switch ($option) {
                 case "ASSIGNED":
                     $criteriaUser->addSelectColumn(\ProcessUserPeer::PU_UID);
                     $arrayCondition = array();
                     $arrayCondition[] = array(\ProcessUserPeer::USR_UID, \UsersPeer::USR_UID, \Criteria::EQUAL);
                     $arrayCondition[] = array(\UsersPeer::USR_STATUS, $delimiter . "ACTIVE" . $delimiter, \Criteria::EQUAL);
                     $criteriaUser->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN);
                     $criteriaUser->add(\ProcessUserPeer::PU_TYPE, "SUPERVISOR", \Criteria::EQUAL);
                     $criteriaUser->add(\ProcessUserPeer::PRO_UID, $processUid, \Criteria::EQUAL);
                     break;
                 case "AVAILABLE":
                     $sql = "\n                        SELECT DISTINCT " . \UsersRolesPeer::USR_UID . "\n                        FROM   " . \UsersRolesPeer::TABLE_NAME . ", " . \RolesPermissionsPeer::TABLE_NAME . ", " . \PermissionsPeer::TABLE_NAME . "\n                        WHERE  " . \UsersRolesPeer::USR_UID . " = " . \UsersPeer::USR_UID . " AND\n                               " . \UsersRolesPeer::ROL_UID . " = " . \RolesPermissionsPeer::ROL_UID . " AND\n                               " . \RolesPermissionsPeer::PER_UID . " = " . \PermissionsPeer::PER_UID . " AND\n                               " . \PermissionsPeer::PER_CODE . " = " . $delimiter . "PM_SUPERVISOR" . $delimiter . " AND\n                               " . \PermissionsPeer::PER_SYSTEM . " = " . $delimiter . $arrayRbacSystemData["SYS_CODE"] . $delimiter . "\n                        ";
                     $criteriaUser->add($criteriaUser->getNewCriterion(\UsersPeer::USR_UID, $arrayUserUid, \Criteria::NOT_IN)->addAnd($criteriaUser->getNewCriterion(\UsersPeer::USR_STATUS, "ACTIVE", \Criteria::EQUAL))->addAnd($criteriaUser->getNewCriterion(\UsersPeer::USR_UID, \UsersPeer::USR_UID . " IN ({$sql})", \Criteria::CUSTOM)));
                     break;
             }
             if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
                 $arraySearch = array("" => "%" . $arrayFilterData["filter"] . "%", "LEFT" => $arrayFilterData["filter"] . "%", "RIGHT" => "%" . $arrayFilterData["filter"]);
                 $search = $arraySearch[isset($arrayFilterData["filterOption"]) ? $arrayFilterData["filterOption"] : ""];
                 $criteriaUser->add($criteriaUser->getNewCriterion(\UsersPeer::USR_USERNAME, $search, \Criteria::LIKE)->addOr($criteriaUser->getNewCriterion(\UsersPeer::USR_FIRSTNAME, $search, \Criteria::LIKE))->addOr($criteriaUser->getNewCriterion(\UsersPeer::USR_LASTNAME, $search, \Criteria::LIKE)));
             }
             //Number records total
             $criteriaCount = clone $criteriaUser;
             $criteriaCount->clearSelectColumns();
             $criteriaCount->addSelectColumn("COUNT(" . \UsersPeer::USR_UID . ") AS NUM_REC");
             switch ($option) {
                 case "ASSIGNED":
                     $rsCriteriaCount = \ProcessUserPeer::doSelectRS($criteriaCount);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaCount = \UsersPeer::doSelectRS($criteriaCount);
                     break;
             }
             $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $result = $rsCriteriaCount->next();
             $row = $rsCriteriaCount->getRow();
             $numRecTotalUser = (int) $row["NUM_REC"];
             $numRecTotal = $numRecTotal + $numRecTotalUser;
         }
         //Groups
         //Query
         if (empty($type) || $type == "group") {
             $criteriaGroup->addAscendingOrderByColumn("GRP_TITLE");
             if (!is_null($start)) {
                 $criteriaGroup->setOffset((int) $start);
             }
             if (!is_null($limit)) {
                 $criteriaGroup->setLimit((int) $limit);
             }
             switch ($option) {
                 case "ASSIGNED":
                     $rsCriteriaGroup = \ProcessUserPeer::doSelectRS($criteriaGroup);
                     break;
                 case "AVAILABLE":
                     $rsCriteriaGroup = \GroupwfPeer::doSelectRS($criteriaGroup);
                     break;
             }
             $rsCriteriaGroup->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             $numRecGroup = 0;
             while ($rsCriteriaGroup->next()) {
                 $row = $rsCriteriaGroup->getRow();
                 switch ($option) {
                     case "ASSIGNED":
                         $arraySupervisor[] = array("pu_uid" => $row["PU_UID"], "pu_type" => "GROUP_SUPERVISOR", "grp_uid" => $row["GRP_UID"], "grp_name" => $row["GRP_TITLE"]);
                         break;
                     case "AVAILABLE":
                         $arraySupervisor[] = array("grp_uid" => $row["GRP_UID"], "grp_name" => $row["GRP_TITLE"], "obj_type" => "group");
                         break;
                 }
                 $numRecGroup++;
             }
         }
         //Users
         //Query
         if (empty($type) || $type == "user") {
             $flagUser = true;
             if ($numRecTotalGroup > 0) {
                 if ($numRecGroup > 0) {
                     if (!is_null($limit)) {
                         if ($numRecGroup < (int) $limit) {
                             $start = 0;
                             $limit = $limit - $numRecGroup;
                         } else {
                             $flagUser = false;
                         }
                     } else {
                         $start = 0;
                     }
                 } else {
                     $start = (int) $start - $numRecTotalGroup;
                 }
             }
             if ($flagUser) {
                 //Users
                 //Query
                 $criteriaUser->addAscendingOrderByColumn(\UsersPeer::USR_FIRSTNAME);
                 if (!is_null($start)) {
                     $criteriaUser->setOffset((int) $start);
                 }
                 if (!is_null($limit)) {
                     $criteriaUser->setLimit((int) $limit);
                 }
                 switch ($option) {
                     case "ASSIGNED":
                         $rsCriteriaUser = \ProcessUserPeer::doSelectRS($criteriaUser);
                         break;
                     case "AVAILABLE":
                         $rsCriteriaUser = \UsersPeer::doSelectRS($criteriaUser);
                         break;
                 }
                 $rsCriteriaUser->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 while ($rsCriteriaUser->next()) {
                     $row = $rsCriteriaUser->getRow();
                     switch ($option) {
                         case "ASSIGNED":
                             $arraySupervisor[] = array("pu_uid" => $row["PU_UID"], "pu_type" => "SUPERVISOR", "usr_uid" => $row["USR_UID"], "usr_firstname" => $row["USR_FIRSTNAME"], "usr_lastname" => $row["USR_LASTNAME"], "usr_username" => $row["USR_USERNAME"], "usr_email" => $row["USR_EMAIL"]);
                             break;
                         case "AVAILABLE":
                             $arraySupervisor[] = array("usr_uid" => $row["USR_UID"], "usr_firstname" => $row["USR_FIRSTNAME"], "usr_lastname" => $row["USR_LASTNAME"], "usr_username" => $row["USR_USERNAME"], "usr_email" => $row["USR_EMAIL"], "obj_type" => "user");
                             break;
                     }
                 }
             }
         }
         //Return
         return array("total" => $numRecTotal, "start" => (int) (!is_null($startbk) ? $startbk : 0), "limit" => (int) (!is_null($limitbk) ? $limitbk : 0), $filterName => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arraySupervisor);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 11
0
 /**
  * Get data of a WebEntry-Event by unique id of Event
  *
  * @param string $projectUid    Unique id of Project
  * @param string $eventUid      Unique id of Event
  * @param bool   $flagGetRecord Value that set the getting
  *
  * return array Return an array with data of a WebEntry-Event by unique id of Event
  */
 public function getWebEntryEventByEvent($projectUid, $eventUid, $flagGetRecord = false)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         if (!$this->existsEvent($projectUid, $eventUid)) {
             throw new \Exception(\G::LoadTranslation("ID_WEB_ENTRY_EVENT_DOES_NOT_IS_REGISTERED", array($this->arrayFieldNameForException["eventUid"], $eventUid)));
         }
         //Get data
         $criteria = $this->getWebEntryEventCriteria();
         $criteria->add(\WebEntryEventPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
         $criteria->add(\WebEntryEventPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
         $rsCriteria = \WebEntryEventPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $rsCriteria->next();
         $row = $rsCriteria->getRow();
         //Return
         return !$flagGetRecord ? $this->getWebEntryEventDataFromRecord($row) : $row;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 12
0
 /**
  * Get all records by execute SQL suggest
  *
  * @param string $processUid    Unique id of Process
  * @param string $variableName  Variable name
  * @param array  $arrayVariable The variables
  *
  * return array Return an array with all records
  */
 public function executeSqlSuggest($processUid, $variableName, array $arrayVariable = array())
 {
     try {
         $arrayRecord = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));
         //Set data
         \G::LoadClass('pmDynaform');
         $pmDynaform = new \pmDynaform();
         $field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $variableName);
         $variableDbConnectionUid = $field !== null ? $field->dbConnection : "";
         $variableSql = $field !== null ? $field->sql : "";
         //Get data
         $_SESSION["PROCESS"] = $processUid;
         $cnn = \Propel::getConnection($variableDbConnectionUid . "" != "" ? $variableDbConnectionUid : "workflow");
         $stmt = $cnn->createStatement();
         $replaceFields = G::replaceDataField($variableSql, $arrayVariable);
         $filter = "";
         if (isset($arrayVariable["filter"])) {
             $filter = $arrayVariable["filter"];
         }
         $start = 0;
         if (isset($arrayVariable["start"])) {
             $start = $arrayVariable["start"];
         }
         $limit = "";
         if (isset($arrayVariable["limit"])) {
             $limit = $arrayVariable["limit"];
         }
         $parser = new \PHPSQLParser($replaceFields);
         $filter = str_replace("'", "''", $filter);
         $replaceFields = $this->queryModified($parser->parsed, $filter, "*searchtype*", $start, $limit);
         $rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
         while ($rs->next()) {
             $row = $rs->getRow();
             $arrayRecord[] = array(strtolower("VALUE") => $row[0], strtolower("TEXT") => isset($row[1]) ? $row[1] : $row[0]);
         }
         //Return
         return $arrayRecord;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 13
0
    /**
     * Get all records by execute SQL suggest
     *
     * @param string $processUid    Unique id of Process
     * @param string $variableName  Variable name
     * @param array  $arrayVariable The variables
     *
     * return array Return an array with all records
     */
    public function executeSqlSuggest($processUid, $variableName, array $arrayVariable = array())
    {
        try {
            $arrayRecord = array();

            //Verify data
            $process = new \ProcessMaker\BusinessModel\Process();

            $process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));

            //Set data
            $variableDbConnectionUid = "";
            $variableSql = "";
            $sqlLimit = "";
            $variableSqlLimit = "";
            $sqlConditionLike = "";

            $criteria = new \Criteria("workflow");

            $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DBCONNECTION);
            $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_SQL);
            $criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
            $criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);

            $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);

            $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
            if ($rsCriteria->next()) {
                $row = $rsCriteria->getRow();

                $variableDbConnectionUid = $row["VAR_DBCONNECTION"];
                $variableSql = $row["VAR_SQL"];
            } else {
                throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_DOES_NOT_EXIST", array(strtolower("VAR_NAME"), $variableName)));
            }

            //Verify data
            $this->throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, $arrayVariable);

            //Get data
            $_SESSION["PROCESS"] = $processUid;

            foreach ($arrayVariable as $keyRequest => $valueRequest) {
                $keyRequest = strtoupper($keyRequest);

                if ($keyRequest == 'LIMIT') {
                    if (strpos($variableSql, 'LIMIT')) {
                        $variableSqlLimit = explode("LIMIT", $variableSql);
                        $sqlLimit = " LIMIT " . $variableSqlLimit[1];
                        $variableSql = $variableSqlLimit[0];
                    } else {
                        $sqlLimit = " LIMIT ". 0 . ", " . $valueRequest;
                    }
                } else {
                    if (strpos($variableSql, 'WHERE')) {
                        $sqlConditionLike = " AND " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
                    } else {
                        $sqlConditionLike = " WHERE " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
                    }
                }
            }

            $sqlQuery = $variableSql . $sqlConditionLike . $sqlLimit;

            $cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
            $stmt = $cnn->createStatement();
            $replaceFields = G::replaceDataField($sqlQuery, $arrayVariable);

            $rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);

            while ($rs->next()) {
                $row = $rs->getRow();

                $arrayRecord[] = array(
                    strtolower("VALUE") => $row[0],
                    strtolower("TEXT")  => $row[1]
                );
            }

            //Return
            return $arrayRecord;
        } catch (\Exception $e) {
            throw $e;
        }
    }
Esempio n. 14
0
 /**
  * Get all Calendars
  *
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Calendars
  */
 public function getCalendars($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayCalendar = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayCalendar;
         }
         //Set variables
         $calendar = new \CalendarDefinition();
         $arrayTotalUsersByCalendar = $calendar->getAllCounterByCalendar("USER");
         $arrayTotalProcessesByCalendar = $calendar->getAllCounterByCalendar("PROCESS");
         $arrayTotalTasksByCalendar = $calendar->getAllCounterByCalendar("TASK");
         //SQL
         $criteria = $this->getCalendarCriteria();
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add($criteria->getNewCriterion(\CalendarDefinitionPeer::CALENDAR_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr($criteria->getNewCriterion(\CalendarDefinitionPeer::CALENDAR_DESCRIPTION, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)));
         }
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             $sortField = isset($this->arrayFieldDefinition[$sortField]["fieldName"]) ? $this->arrayFieldDefinition[$sortField]["fieldName"] : $sortField;
             switch ($sortField) {
                 case "CALENDAR_UID":
                 case "CALENDAR_NAME":
                 case "CALENDAR_DESCRIPTION":
                 case "CALENDAR_WORK_DAYS":
                 case "CALENDAR_STATUS":
                 case "CALENDAR_CREATE_DATE":
                 case "CALENDAR_UPDATE_DATE":
                     $sortField = \CalendarDefinitionPeer::TABLE_NAME . "." . $sortField;
                     break;
                 default:
                     $sortField = \CalendarDefinitionPeer::CALENDAR_NAME;
                     break;
             }
         } else {
             $sortField = \CalendarDefinitionPeer::CALENDAR_NAME;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \CalendarDefinitionPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $row["CALENDAR_TOTAL_USERS"] = isset($arrayTotalUsersByCalendar[$row["CALENDAR_UID"]]) ? $arrayTotalUsersByCalendar[$row["CALENDAR_UID"]] : 0;
             $row["CALENDAR_TOTAL_PROCESSES"] = isset($arrayTotalProcessesByCalendar[$row["CALENDAR_UID"]]) ? $arrayTotalProcessesByCalendar[$row["CALENDAR_UID"]] : 0;
             $row["CALENDAR_TOTAL_TASKS"] = isset($arrayTotalTasksByCalendar[$row["CALENDAR_UID"]]) ? $arrayTotalTasksByCalendar[$row["CALENDAR_UID"]] : 0;
             $arrayCalendar[] = $this->getCalendarDataFromRecord($row);
         }
         //Return
         return $arrayCalendar;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 15
0
 /**
  * Get all Permissions of a Role
  *
  * @param string $roleUid         Unique id of Role
  * @param string $option          Option (PERMISSIONS, AVAILABLE-PERMISSIONS)
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Permissions of a Role
  */
 public function getPermissions($roleUid, $option, array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayPermission = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $role = new \ProcessMaker\BusinessModel\Role();
         $role->throwExceptionIfNotExistsRole($roleUid, $this->arrayFieldNameForException["roleUid"]);
         $process->throwExceptionIfDataNotMetFieldDefinition(array("OPTION" => $option), array("OPTION" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("PERMISSIONS", "AVAILABLE-PERMISSIONS"), "fieldNameAux" => "option")), array("option" => "\$option"), true);
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayPermission;
         }
         //Set variables
         $rolePermission = new \RolesPermissions();
         //SQL
         switch ($option) {
             case "PERMISSIONS":
                 //Criteria
                 $criteria = $this->getPermissionCriteria($roleUid);
                 break;
             case "AVAILABLE-PERMISSIONS":
                 //Get Uids
                 $arrayUid = array();
                 $criteria = $this->getPermissionCriteria($roleUid);
                 $rsCriteria = \PermissionsPeer::doSelectRS($criteria);
                 $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                 while ($rsCriteria->next()) {
                     $row = $rsCriteria->getRow();
                     $arrayUid[] = $row["PER_UID"];
                 }
                 //Criteria
                 $criteria = $this->getPermissionCriteria("", $arrayUid);
                 break;
         }
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add(\PermissionsPeer::PER_CODE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
         }
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             if (in_array($sortField, array("PER_UID", "PER_CODE"))) {
                 $sortField = \PermissionsPeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \PermissionsPeer::PER_CODE;
             }
         } else {
             $sortField = \PermissionsPeer::PER_CODE;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \PermissionsPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $rolePermission->setPerUid($row["PER_UID"]);
             $row["PER_NAME"] = $rolePermission->getPermissionName();
             $arrayPermission[] = $this->getPermissionDataFromRecord($row);
         }
         //Return
         return $arrayPermission;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 16
0
    /**

     * Validate the data if they are invalid (INSERT and UPDATE)

     *

     * @param string $userUid   Unique id of User

     * @param array  $arrayData Data

     *

     * return void Throw exception if data has an invalid value

     */

    public function throwExceptionIfDataIsInvalid($userUid, array $arrayData)

    {

        try {

            //Set variables

            $arrayUserData = ($userUid == "")? array() : $this->getUser($userUid, true);

            $flagInsert = ($userUid == "")? true : false;



            $arrayFinalData = array_merge($arrayUserData, $arrayData);



            //Verify data - Field definition.

            $process = new \ProcessMaker\BusinessModel\Process();



            $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);



            //Verify data

            if (isset($arrayData["USR_USERNAME"])) {

                $this->throwExceptionIfExistsName($arrayData["USR_USERNAME"], $this->arrayFieldNameForException["usrUsername"], $userUid);

            }



            if (isset($arrayData["USR_EMAIL"])) {

                if (!filter_var($arrayData["USR_EMAIL"], FILTER_VALIDATE_EMAIL)) {

                    throw new \Exception($this->arrayFieldNameForException["usrEmail"] . ": " . \G::LoadTranslation("ID_INCORRECT_EMAIL"));

                }

            }



            if (isset($arrayData["USR_NEW_PASS"])) {

                $this->throwExceptionIfPasswordIsInvalid($arrayData["USR_NEW_PASS"], $this->arrayFieldNameForException["usrNewPass"]);

            }



            if (isset($arrayData["USR_REPLACED_BY"]) && $arrayData["USR_REPLACED_BY"] != "") {

                $obj = \UsersPeer::retrieveByPK($arrayData["USR_REPLACED_BY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_USER_DOES_NOT_EXIST", array($this->arrayFieldNameForException["usrReplacedBy"], $arrayData["USR_REPLACED_BY"])));

                }

            }



            if (isset($arrayData["USR_DUE_DATE"])) {

                $arrayUserDueDate = explode("-", $arrayData["USR_DUE_DATE"]);



                if (ctype_digit($arrayUserDueDate[0])) {

                    if (!checkdate($arrayUserDueDate[1], $arrayUserDueDate[2], $arrayUserDueDate[0])) {

                        throw new \Exception($this->arrayFieldNameForException["usrDueDate"] . ": " . \G::LoadTranslation("ID_MSG_ERROR_DUE_DATE"));

                    }

                } else {

                    throw new \Exception($this->arrayFieldNameForException["usrDueDate"] . ": " . \G::LoadTranslation("ID_MSG_ERROR_DUE_DATE"));

                }

            }



            if (isset($arrayData["USR_ROLE"])) {

                require_once (PATH_RBAC_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "Roles.php");



                $criteria = new \Criteria("rbac");



                $criteria->add(\RolesPeer::ROL_CODE, $arrayData["USR_ROLE"]);

                $rsCriteria = \RolesPeer::doSelectRS($criteria);



                if (!$rsCriteria->next()) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrRole"])));

                }

            }



            if (isset($arrayData["USR_COUNTRY"]) && $arrayData["USR_COUNTRY"] != "") {

                $obj = \IsoCountryPeer::retrieveByPK($arrayData["USR_COUNTRY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }

            }



            if (isset($arrayData["USR_CITY"]) && $arrayData["USR_CITY"] != "") {

                if (!isset($arrayFinalData["USR_COUNTRY"]) || $arrayFinalData["USR_COUNTRY"] == "") {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }



                $obj = \IsoSubdivisionPeer::retrieveByPK($arrayFinalData["USR_COUNTRY"], $arrayData["USR_CITY"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCity"])));

                }

            }



            if (isset($arrayData["USR_LOCATION"]) && $arrayData["USR_LOCATION"] != "") {

                if (!isset($arrayFinalData["USR_COUNTRY"]) || $arrayFinalData["USR_COUNTRY"] == "") {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrCountry"])));

                }



                $obj = \IsoLocationPeer::retrieveByPK($arrayFinalData["USR_COUNTRY"], $arrayData["USR_LOCATION"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($this->arrayFieldNameForException["usrLocation"])));

                }

            }



            if (isset($arrayData["USR_CALENDAR"]) && $arrayData["USR_CALENDAR"] != "") {

                $obj = \CalendarDefinitionPeer::retrieveByPK($arrayData["USR_CALENDAR"]);



                if (is_null($obj)) {

                    throw new \Exception(\G::LoadTranslation("ID_CALENDAR_DOES_NOT_EXIST", array($this->arrayFieldNameForException["usrCalendar"], $arrayData["USR_CALENDAR"])));

                }

            }



            if (isset($arrayData["DEP_UID"]) && $arrayData["DEP_UID"] != "") {

                $department = new \Department();



                if (!$department->existsDepartment($arrayData["DEP_UID"])) {

                    throw new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($this->arrayFieldNameForException["depUid"], $arrayData["DEP_UID"])));

                }

            }

        } catch (\Exception $e) {

            throw $e;

        }

    }
Esempio n. 17
0
 /**
  * Get all Web Entries
  *
  * @param string $processUid Unique id of Process
  *
  * return array Return an array with all Web Entries
  */
 public function getWebEntries($processUid)
 {
     try {
         $arrayWebEntry = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
         //Get data
         $criteria = $this->getWebEntryCriteria();
         $criteria->add(\WebEntryPeer::PRO_UID, $processUid, \Criteria::EQUAL);
         $criteria->addAscendingOrderByColumn("WE_TITLE");
         $rsCriteria = \WebEntryPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $arrayWebEntry[] = $this->getWebEntryDataFromRecord($row);
         }
         //Return
         return $arrayWebEntry;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 18
0
    public function update($data)
    {
        if (isset($data["PRJ_NAME"])) {
            $process = new \ProcessMaker\BusinessModel\Process();

            $process->throwExceptionIfExistsTitle($data["PRJ_NAME"], strtolower("PRJ_NAME"), $this->prjUid);
        }

        if (array_key_exists("PRJ_CREATE_DATE", $data) && empty($data["PRJ_CREATE_DATE"])) {
            unset($data["PRJ_UPDATE_DATE"]);
        }

        if (array_key_exists("PRJ_UPDATE_DATE", $data)) {
            unset($data["PRJ_UPDATE_DATE"]);
        }

        $this->project->fromArray($data, BasePeer::TYPE_FIELDNAME);
        $this->project->setPrjUpdateDate(date("Y-m-d H:i:s"));
        $this->project->save();

        if (isset($data["PRJ_NAME"])) {
            $this->updateDiagram(array("DIA_NAME" => $data["PRJ_NAME"]));
        }
    }
Esempio n. 19
0
 /**
  * Create a Dynaform based on a PMTable
  *
  * @param string $processUid Unique id of Process
  * @param array  $arrayData  Data
  *
  * return array Return data of the new DynaForm created
  */
 public function createBasedPmTable($processUid, $arrayData)
 {
     try {
         $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER);
         unset($arrayData["DYN_UID"]);
         unset($arrayData["COPY_IMPORT"]);
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
         if ($arrayData["DYN_TYPE"] == "grid") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array($this->arrayFieldNameForException["dynaFormType"], "xmlform")));
         }
         if (!isset($arrayData["PMTABLE"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("PMTABLE"))));
         }
         if (!isset($arrayData["PMTABLE"]["TAB_UID"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"))));
         }
         $arrayData["PMTABLE"]["TAB_UID"] = trim($arrayData["PMTABLE"]["TAB_UID"]);
         if ($arrayData["PMTABLE"]["TAB_UID"] == "") {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"))));
         }
         if (!isset($arrayData["PMTABLE"]["FIELDS"])) {
             throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"))));
         }
         if (count($arrayData["PMTABLE"]["FIELDS"]) == 0) {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"))));
         }
         $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
         $process->throwExceptionIfNotExistsPmTable($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"));
         //Validate PMTABLE.FIELDS
         //Valid Keys
         $flagValidFieldKey = 1;
         foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) {
             if (!isset($value["FLD_NAME"]) || !isset($value["PRO_VARIABLE"])) {
                 $flagValidFieldKey = 0;
                 break;
             }
         }
         if ($flagValidFieldKey == 0) {
             throw new \Exception(\G::LoadTranslation("ID_ATTRIBUTE_HAS_INVALID_ELEMENT_KEY", array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"))));
         }
         //Is Primary Key
         $arrayFieldPk = $process->getPmTablePrimaryKeyFields($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID"));
         $flagValidFieldPk = 1;
         $invalidFieldPk = "";
         $arrayFieldPkAux = array();
         foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) {
             $arrayFieldPkAux[] = $value["FLD_NAME"];
             if (!in_array($value["FLD_NAME"], $arrayFieldPk)) {
                 $flagValidFieldPk = 0;
                 $invalidFieldPk = $value["FLD_NAME"];
                 break;
             }
         }
         if ($flagValidFieldPk == 0) {
             throw new \Exception(\G::LoadTranslation("ID_PMTABLE_FIELD_IS_NOT_PRIMARY_KEY", array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS.FLD_NAME"), $invalidFieldPk)));
         }
         //All Primary Keys
         $flagAllFieldPk = 1;
         $missingFieldPk = "";
         foreach ($arrayFieldPk as $key => $value) {
             if (!in_array($value, $arrayFieldPkAux)) {
                 $flagAllFieldPk = 0;
                 $missingFieldPk = $value;
                 break;
             }
         }
         if ($flagAllFieldPk == 0) {
             throw new \Exception(\G::LoadTranslation("ID_PMTABLE_PRIMARY_KEY_FIELD_IS_MISSING_IN_ATTRIBUTE", array($missingFieldPk, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"))));
         }
         //Total of Primary Keys
         $n1 = count($arrayFieldPk);
         $n2 = count($arrayFieldPkAux);
         if ($n1 != $n2) {
             throw new \Exception(\G::LoadTranslation("ID_PMTABLE_TOTAL_PRIMARY_KEY_FIELDS_IS_NOT_EQUAL_IN_ATTRIBUTE", array($n1, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"), $n2)));
         }
         //Set data
         $tableUid = $arrayData["PMTABLE"]["TAB_UID"];
         $arrayFields = $arrayData["PMTABLE"]["FIELDS"];
         unset($arrayData["PMTABLE"]);
         //Create
         $dynaForm = new \Dynaform();
         $arrayData["PRO_UID"] = $processUid;
         $arrayData["DYN_TYPE"] = "xmlform";
         $arrayData["FIELDS"] = $arrayFields;
         $dynaForm->createFromPMTable($arrayData, $tableUid);
         $dynaFormUid = $dynaForm->getDynUid();
         //Return
         unset($arrayData["PRO_UID"]);
         unset($arrayData["FIELDS"]);
         $arrayData = array_merge(array("DYN_UID" => $dynaFormUid), $arrayData);
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * Create Element-Task-Relation for a Project
  *
  * @param string $projectUid Unique id of Project
  * @param array  $arrayData  Data
  *
  * return array Return data of the new Element-Task-Relation created
  */
 public function create($projectUid, 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["ETR_UID"]);
         unset($arrayData["PRJ_UID"]);
         //Verify data
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         $this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
         //Create
         $cnn = \Propel::getConnection("workflow");
         try {
             $elementTaskRelation = new \ElementTaskRelation();
             $elementTaskRelationUid = \ProcessMaker\Util\Common::generateUID();
             $elementTaskRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
             $elementTaskRelation->setEtrUid($elementTaskRelationUid);
             $elementTaskRelation->setPrjUid($projectUid);
             if ($elementTaskRelation->validate()) {
                 $cnn->begin();
                 $result = $elementTaskRelation->save();
                 $cnn->commit();
                 //Return
                 return $this->getElementTaskRelation($elementTaskRelationUid);
             } else {
                 $msg = "";
                 foreach ($elementTaskRelation->getValidationFailures() as $validationFailure) {
                     $msg = $msg . ($msg != "" ? "\n" : "") . $validationFailure->getMessage();
                 }
                 throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . ($msg != "" ? "\n" . $msg : ""));
             }
         } catch (\Exception $e) {
             $cnn->rollback();
             throw $e;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 21
0
 /**
  * Get all Message-Type-Variable
  *
  * @param string $messageTypeUid  {@min 32}{@max 32}
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Message-Type-Variable
  */
 public function getMessageTypeVariables($messageTypeUid, $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayMessage = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $messageType = new \ProcessMaker\BusinessModel\MessageType();
         $messageType->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayMessage;
         }
         //SQL
         $criteria = $this->getMessageTypeVariableCriteria();
         $criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add($criteria->getNewCriterion(\MessageTypeVariablePeer::MSGTV_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE));
         }
         //Number records total
         $criteriaCount = clone $criteria;
         $criteriaCount->clearSelectColumns();
         $criteriaCount->addSelectColumn("COUNT(" . \MessageTypeVariablePeer::MSGTV_UID . ") AS NUM_REC");
         $rsCriteriaCount = \MessageTypeVariablePeer::doSelectRS($criteriaCount);
         $rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $rsCriteriaCount->next();
         $row = $rsCriteriaCount->getRow();
         $numRecTotal = $row["NUM_REC"];
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             if (in_array($sortField, array("MSGTV_NAME"))) {
                 $sortField = \MessageTypeVariablePeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \MessageTypeVariablePeer::MSGTV_NAME;
             }
         } else {
             $sortField = \MessageTypeVariablePeer::MSGTV_NAME;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \MessageTypeVariablePeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $arrayMessage[] = $this->getMessageTypeVariableDataFromRecord($row);
         }
         //Return
         return array("total" => $numRecTotal, "start" => (int) (!is_null($start) ? $start : 0), "limit" => (int) (!is_null($limit) ? $limit : 0), "filter" => !is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) ? $arrayFilterData["filter"] : "", "data" => $arrayMessage);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 22
0
 /**
  * Get all Categories
  *
  * @param array  $arrayFilterData Data of the filters
  * @param string $sortField       Field name to sort
  * @param string $sortDir         Direction of sorting (ASC, DESC)
  * @param int    $start           Start
  * @param int    $limit           Limit
  *
  * return array Return an array with all Categories
  */
 public function getCategories(array $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
 {
     try {
         $arrayCategory = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
         //Get data
         if (!is_null($limit) && $limit . "" == "0") {
             return $arrayCategory;
         }
         //Set variables
         $process = new \Process();
         $arrayTotalProcessesByCategory = $process->getAllProcessesByCategory();
         //SQL
         $criteria = $this->getCategoryCriteria();
         if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
             $criteria->add(\ProcessCategoryPeer::CATEGORY_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE);
         }
         //SQL
         if (!is_null($sortField) && trim($sortField) != "") {
             $sortField = strtoupper($sortField);
             $sortField = isset($this->arrayFieldDefinition[$sortField]["fieldName"]) ? $this->arrayFieldDefinition[$sortField]["fieldName"] : $sortField;
             if (in_array($sortField, array("CATEGORY_UID", "CATEGORY_PARENT", "CATEGORY_NAME", "CATEGORY_ICON"))) {
                 $sortField = \ProcessCategoryPeer::TABLE_NAME . "." . $sortField;
             } else {
                 $sortField = \ProcessCategoryPeer::CATEGORY_NAME;
             }
         } else {
             $sortField = \ProcessCategoryPeer::CATEGORY_NAME;
         }
         if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
             $criteria->addDescendingOrderByColumn($sortField);
         } else {
             $criteria->addAscendingOrderByColumn($sortField);
         }
         if (!is_null($start)) {
             $criteria->setOffset((int) $start);
         }
         if (!is_null($limit)) {
             $criteria->setLimit((int) $limit);
         }
         $rsCriteria = \ProcessCategoryPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $row["CATEGORY_TOTAL_PROCESSES"] = isset($arrayTotalProcessesByCategory[$row["CATEGORY_UID"]]) ? (int) $arrayTotalProcessesByCategory[$row["CATEGORY_UID"]] : 0;
             $arrayCategory[] = $this->getCategoryDataFromRecord($row);
         }
         //Return
         return $arrayCategory;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 23
0
    /**
     * Save Data for Email-Event
     * @var string $prj_uid. Uid for Process
     * @var string $arrayData. Data for Trigger
     *     
     * return array
     */
    public function save($prj_uid = '', $arrayData = array())
    {
        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);

            //Verify data
            $process->throwExceptionIfNotExistsProcess($prj_uid, "projectUid");

            //Create
            $db = \Propel::getConnection("workflow");

            try {
                $emailEvent = new \EmailEvent();
                
                $emailEvent->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
                
                $emailEventUid = \ProcessMaker\Util\Common::generateUID();

                $emailEvent->setEmailEventUid($emailEventUid);
                $emailEvent->setPrjUid($prj_uid);

                $db->begin();
                $result = $emailEvent->save();
                $db->commit();
                
                return $this->getEmailEvent($emailEventUid);
            } catch (\Exception $e) {
                $db->rollback();
                throw $e;
            }
        } catch (\Exception $e) {
            throw $e;
        }    
    }
Esempio n. 24
0
 /**
  * Get data of a Timer-Event by unique id of Event
  *
  * @param string $projectUid    Unique id of Project
  * @param string $eventUid      Unique id of Event
  * @param bool   $flagGetRecord Value that set the getting
  *
  * return array Return an array with data of a Timer-Event by unique id of Event
  */
 public function getTimerEventByEvent($projectUid, $eventUid, $flagGetRecord = false)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $bpmnEvent = \BpmnEventPeer::retrieveByPK($eventUid);
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         if (is_null($bpmnEvent)) {
             throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_EXIST", array($this->arrayFieldNameForException["eventUid"], $eventUid)));
         }
         if ($bpmnEvent->getPrjUid() != $projectUid) {
             throw new \Exception(\G::LoadTranslation("ID_EVENT_EVENT_NOT_BELONG_TO_PROJECT", array($this->arrayFieldNameForException["eventUid"], $eventUid, $this->arrayFieldNameForException["projectUid"], $projectUid)));
         }
         //Get data
         if (!$this->existsEvent($projectUid, $eventUid)) {
             //Return
             return array();
         }
         $criteria = $this->getTimerEventCriteria();
         $criteria->add(\TimerEventPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
         $criteria->add(\TimerEventPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
         $rsCriteria = \TimerEventPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $result = $rsCriteria->next();
         $row = $rsCriteria->getRow();
         $row["TMREVN_CONFIGURATION_DATA"] = unserialize($row["TMREVN_CONFIGURATION_DATA"]);
         //Return
         return !$flagGetRecord ? $this->getTimerEventDataFromRecord($row) : $row;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 25
0
 /**
  * Get all Case Tracker Objects of a Process
  *
  * @param string $processUid Unique id of Process
  *
  * return array Return an array with all Case Tracker Objects of a Process
  */
 public function getCaseTrackerObjects($processUid)
 {
     try {
         $arrayCaseTrackerObject = array();
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($processUid, "prj_uid");
         $dynaform = new \Dynaform();
         $inputDocument = new \InputDocument();
         $outputDocument = new \OutputDocument();
         $arrayCaseTrackerObject = array();
         $criteria = new \Criteria("workflow");
         $criteria->add(\CaseTrackerObjectPeer::PRO_UID, $processUid, \Criteria::EQUAL);
         $rsCriteria = \CaseTrackerObjectPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         while ($rsCriteria->next()) {
             $row = $rsCriteria->getRow();
             $titleObj = "";
             $descriptionObj = "";
             switch ($row["CTO_TYPE_OBJ"]) {
                 case "DYNAFORM":
                     $arrayData = $dynaform->load($row["CTO_UID_OBJ"]);
                     $titleObj = $arrayData["DYN_TITLE"];
                     $descriptionObj = $arrayData["DYN_DESCRIPTION"];
                     break;
                 case "INPUT_DOCUMENT":
                     $arrayData = $inputDocument->getByUid($row["CTO_UID_OBJ"]);
                     $titleObj = $arrayData["INP_DOC_TITLE"];
                     $descriptionObj = $arrayData["INP_DOC_DESCRIPTION"];
                     break;
                 case "OUTPUT_DOCUMENT":
                     $arrayData = $outputDocument->getByUid($row["CTO_UID_OBJ"]);
                     $titleObj = $arrayData["OUT_DOC_TITLE"];
                     $descriptionObj = $arrayData["OUT_DOC_DESCRIPTION"];
                     break;
             }
             $arrayCaseTrackerObject[] = array("cto_uid" => $row["CTO_UID"], "cto_type_obj" => $row["CTO_TYPE_OBJ"], "cto_uid_obj" => $row["CTO_UID_OBJ"], "cto_condition" => $row["CTO_CONDITION"], "cto_position" => (int) $row["CTO_POSITION"], "obj_title" => $titleObj, "obj_description" => $descriptionObj);
         }
         $arrayCaseTrackerObject = \ProcessMaker\Util\ArrayUtil::sort($arrayCaseTrackerObject, array("cto_position"), SORT_ASC);
         return $arrayCaseTrackerObject;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 26
0
 /**
  * Get data of a Script-Task by unique id of Activity
  *
  * @param string $projectUid  Unique id of Project
  * @param string $activityUid Unique id of Event
  *
  * return array Return an array with data of a Script-Task by unique id of Activity
  */
 public function getScriptTaskByActivity($projectUid, $activityUid)
 {
     try {
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
         //---
         $obj = \BpmnActivityPeer::retrieveByPK($activityUid);
         if (is_null($obj)) {
             throw new \Exception(\G::LoadTranslation("ID_SCRIPT_TASK_DOES_NOT_ACTIVITY", array($this->arrayFieldNameForException["actUid"], $activityUid)));
         }
         //---
         $criteria = new \Criteria("workflow");
         $criteria->addSelectColumn(\BpmnActivityPeer::ACT_UID);
         $criteria->add(\BpmnActivityPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
         $criteria->add(\BpmnActivityPeer::ACT_UID, $activityUid, \Criteria::EQUAL);
         $rsCriteria = \BpmnActivityPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         if (!$rsCriteria->next()) {
             throw new \Exception(\G::LoadTranslation("ID_SCRIPT_TASK_ACTIVITY_NOT_BELONG_TO_PROJECT", array($arrayData["ACT_UID"], $projectUid)));
         }
         //---
         $criteria = $this->getScriptTaskCriteria();
         $criteria->add(\ScriptTaskPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
         $criteria->add(\ScriptTaskPeer::ACT_UID, $activityUid, \Criteria::EQUAL);
         $rsCriteria = \ScriptTaskPeer::doSelectRS($criteria);
         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         //Return
         return $rsCriteria->next() ? $this->getScriptTaskDataFromRecord($rsCriteria->getRow()) : array();
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 27
0
 /**
  * Update InputDocument
  *
  * @param string $inputDocumentUid Unique id of InputDocument
  * @param array  $arrayData        Data
  *
  * return array Return data of the InputDocument updated
  */
 public function update($inputDocumentUid, $arrayData)
 {
     try {
         $arrayData = array_change_key_case($arrayData, CASE_UPPER);
         //Verify data
         $this->throwExceptionIfNotExistsInputDocument($inputDocumentUid, "", $this->arrayFieldNameForException["inputDocumentUid"]);
         //Load InputDocument
         $inputDocument = new \InputDocument();
         $arrayInputDocumentData = $inputDocument->load($inputDocumentUid);
         $processUid = $arrayInputDocumentData["PRO_UID"];
         //Verify data
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false);
         if (isset($arrayData["INP_DOC_TITLE"])) {
             $this->throwExceptionIfExistsTitle($processUid, $arrayData["INP_DOC_TITLE"], $this->arrayFieldNameForException["inputDocumentTitle"], $inputDocumentUid);
         }
         //Update
         $arrayData["INP_DOC_UID"] = $inputDocumentUid;
         $result = $inputDocument->update($arrayData);
         \G::LoadClass('pmDynaform');
         $pmDynaform = new \pmDynaform();
         $pmDynaform->synchronizeInputDocument($processUid, $arrayData);
         //Return
         unset($arrayData["INP_DOC_UID"]);
         if (!$this->formatFieldNameInUppercase) {
             $arrayData = array_change_key_case($arrayData, CASE_LOWER);
         }
         return $arrayData;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 28
0
    /**
     * Imports a Project sent through the POST method ($_FILES)
     *
     * @param array  $arrayData      Data
     * @param string $option         Option for Project ("CREATE", "OVERWRITE", "DISABLE", "KEEP")
     * @param string $optionGroup    Option for Group ("CREATE", "RENAME", "MERGE")
     * @param array  $arrayFieldName The field's names
     *
     * return array Returns the data sent and the unique id of Project
     */
    public function importPostFile(array $arrayData, $option = "CREATE", $optionGroup = "CREATE", array $arrayFieldName = array())
    {
        try {
            //Set data
            $arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PROJECT_FILE";
            $arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION";
            $arrayFieldName["optionGroup"] = (isset($arrayFieldName["optionGroup"]))? $arrayFieldName["optionGroup"] : "OPTION_GROUP";

            $arrayFieldDefinition = array(
                $arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile")
            );

            $arrayFieldNameForException = $arrayFieldName;

            if (isset($_FILES[$arrayFieldName["projectFile"]])) {
                $_FILES["filePmx"] = $_FILES[$arrayFieldName["projectFile"]];
            }

            if (isset($arrayData[$arrayFieldName["projectFile"]]) &&
                isset($arrayData[$arrayFieldName["projectFile"]]["name"]) &&
                is_array($arrayData[$arrayFieldName["projectFile"]])
            ) {
                $arrayData[$arrayFieldName["projectFile"]] = $arrayData[$arrayFieldName["projectFile"]]["name"];
            }

            $optionCaseUpper = (strtoupper($option) == $option)? true : false;
            $option = strtoupper($option);

            $optionGroupCaseUpper = (strtoupper($optionGroup) == $optionGroup)? true : false;
            $optionGroup = strtoupper($optionGroup);

            //Verify data
            $process = new \ProcessMaker\BusinessModel\Process();
            $validator = new \ProcessMaker\BusinessModel\Validator();

            $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");

            $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);

            $arrayOptionDefaultValues = array("CREATE", "OVERWRITE", "DISABLE", "KEEP");
            $arrayOptionGroupDefaultValues = array("CREATE", "RENAME", "MERGE");

            $arrayAux = array(
                array($option,      $arrayOptionDefaultValues,      $arrayFieldNameForException["option"],      $optionCaseUpper),
                array($optionGroup, $arrayOptionGroupDefaultValues, $arrayFieldNameForException["optionGroup"], $optionGroupCaseUpper)
            );

            foreach ($arrayAux as $value) {
                $opt = $value[0];
                $arrayDefaultValues = $value[1];
                $fieldNameForException = $value[2];
                $caseUpper = $value[3];

                if ($opt != "") {
                    if (!in_array($opt, $arrayDefaultValues, true)) {
                        $strdv = implode("|", $arrayDefaultValues);

                        throw new \Exception(
                            \G::LoadTranslation(
                                "ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES",
                                array($fieldNameForException, ($caseUpper)? $strdv : strtolower($strdv))
                            )
                        );
                    }
                }
            }

            if ((isset($_FILES["filePmx"]) && pathinfo($_FILES["filePmx"]["name"], PATHINFO_EXTENSION) != "pmx") ||
                (isset($arrayData[$arrayFieldName["projectFile"]]) && pathinfo($arrayData[$arrayFieldName["projectFile"]], PATHINFO_EXTENSION) != "pmx")
            ) {
                throw new \Exception(\G::LoadTranslation("ID_IMPORTER_FILE_EXTENSION_IS_NOT_PMX"));
            }

            //Set variables
            $arrayAux = array(
                (($option != "")? "CREATE" : "") => self::IMPORT_OPTION_CREATE_NEW,
                "OVERWRITE" => self::IMPORT_OPTION_OVERWRITE,
                "DISABLE"   => self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
                "KEEP"      => self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW
            );

            $option = $arrayAux[$option];

            $arrayAux = array(
                (($optionGroup != "")? "CREATE" : "") => self::GROUP_IMPORT_OPTION_CREATE_NEW,
                "RENAME" => self::GROUP_IMPORT_OPTION_RENAME,
                "MERGE"  => self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
            );

            $optionGroup = $arrayAux[$optionGroup];

            if (isset($_FILES["filePmx"])) {
                $this->setSourceFromGlobals("filePmx");
            } else {
                $filePmx = rtrim($this->getSaveDir(), PATH_SEP) . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]];

                if (isset($arrayData[$arrayFieldName["projectFile"]]) && file_exists($filePmx)) {
                    $this->setSourceFile($filePmx);
                } else {
                    throw new \Exception(\G::LoadTranslation("ID_IMPORTER_FILE_DOES_NOT_EXIST", array($arrayFieldNameForException["projectFile"], $arrayData[$arrayFieldName["projectFile"]])));
                }
            }

            //Import
            try {
                $projectUid = $this->import($option, $optionGroup);

                $arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData);
            } catch (\Exception $e) {
                $strOpt  = implode("|", $arrayOptionDefaultValues);
                $strOptg = implode("|", $arrayOptionGroupDefaultValues);

                $strOpt = ($optionCaseUpper)? $strOpt : strtolower($strOpt);
                $strOptg = ($optionGroupCaseUpper)? $strOptg : strtolower($strOptg);

                $msg = str_replace(
                    array(
                        self::IMPORT_OPTION_CREATE_NEW,
                        self::IMPORT_OPTION_OVERWRITE,
                        self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW,
                        self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW,

                        self::GROUP_IMPORT_OPTION_CREATE_NEW,
                        self::GROUP_IMPORT_OPTION_RENAME,
                        self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT
                    ),
                    array_merge(explode("|", $strOpt), explode("|", $strOptg)),
                    $e->getMessage()
                );

                throw new \Exception($msg);
            }

            //Return
            if ($arrayFieldName["projectFile"] != strtoupper($arrayFieldName["projectFile"])) {
                $arrayData = array_change_key_case($arrayData, CASE_LOWER);
            }

            return $arrayData;
        } catch (\Exception $e) {
            throw $e;
        }
    }
Esempio n. 29
0
 /**
  *
  * @url GET /project/:prj_uid/dynaforms
  *
  * @param string $prj_uid {@min 32}{@max 32}
  */
 public function doGetDynaForms($prj_uid)
 {
     try {
         $process = new \ProcessMaker\BusinessModel\Process();
         $process->setFormatFieldNameInUppercase(false);
         $process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
         $_SESSION['PROCESS'] = $prj_uid;
         $response = $process->getDynaForms($prj_uid);
         $result   = $this->parserDataDynaForm($response);
         \G::LoadClass("pmDynaform");
         $pmDynaForm = new \pmDynaform();
         foreach ($result as $k => $form) {
             $result[$k]['formContent'] = (isset($form['formContent']) && $form['formContent'] != null)?json_decode($form['formContent']):"";
             $pmDynaForm->jsonr($result[$k]['formContent']);
             $result[$k]['index']       = $k;
         }
     } catch (\Exception $e) {
         throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
     }
     return $result;
 }
Esempio n. 30
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;
     }
 }