Esempio n. 1
0
    /**

     * Get list for Cases

     *

     * @access public

     * @param array $dataList, Data for list

     * @return array

     *

     * @author Brayan Pereyra (Cochalo) <*****@*****.**>

     * @copyright Colosa - Bolivia

    */

    public function getList($listName = 'inbox', $dataList = array(), $total = false)

    {

        Validator::isArray($dataList, '$dataList');

        if (!isset($dataList["userId"])) {

            throw (new \Exception(\G::LoadTranslation("ID_USER_NOT_EXIST", array('userId',''))));

        } else {

            Validator::usrUid($dataList["userId"], "userId");

        }



        $userUid = $dataList["userId"];

        $filters["paged"]    = isset( $dataList["paged"] ) ? $dataList["paged"] : true;

        $filters['count']    = isset( $dataList['count'] ) ? $dataList['count'] : true;

        $filters["category"] = isset( $dataList["category"] ) ? $dataList["category"] : "";

        $filters["process"]  = isset( $dataList["process"] ) ? $dataList["process"] : "";

        $filters["search"]   = isset( $dataList["search"] ) ? $dataList["search"] : "";

        $filters["filter"]   = isset( $dataList["filter"] ) ? $dataList["filter"] : "";

        $filters["dateFrom"] = (!empty( $dataList["dateFrom"] )) ? substr( $dataList["dateFrom"], 0, 10 ) : "";

        $filters["dateTo"]   = (!empty( $dataList["dateTo"] )) ? substr( $dataList["dateTo"], 0, 10 ) : "";



        $filters["start"]    = isset( $dataList["start"] ) ? $dataList["start"] : "0";

        $filters["limit"]    = isset( $dataList["limit"] ) ? $dataList["limit"] : "25";

        $filters["sort"]     = isset( $dataList["sort"] ) ? $dataList["sort"] : "";

        $filters["dir"]      = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC";



        $filters["action"]   = isset( $dataList["action"] ) ? $dataList["action"] : "";



        // Select list

        switch ($listName) {

            case 'inbox':

                $list = new \ListInbox();

                $listpeer = 'ListInboxPeer';

                break;

            case 'participated_history':

                $list = new \ListParticipatedHistory();

                $listpeer = 'ListParticipatedHistoryPeer';

                break;

            case 'participated_last':

                $list = new \ListParticipatedLast();

                $listpeer = 'ListParticipatedLastPeer';

                break;

            case 'completed':

                $list = new \ListCompleted();

                $listpeer = 'ListCompletedPeer';

                break;

            case 'paused':

                $list = new \ListPaused();

                $listpeer = 'ListPausedPeer';

                break;

            case 'canceled':

                $list = new \ListCanceled();

                $listpeer = 'ListCanceledPeer';

                break;

            case 'my_inbox':

                $list = new \ListMyInbox();

                $listpeer = 'ListMyInboxPeer';

                break;

            case 'unassigned':

                $list = new \ListUnassigned();

                $listpeer = 'ListUnassignedPeer';

                break;

        }





        // Validate filters

        $filters["start"] = (int)$filters["start"];

        $filters["start"] = abs($filters["start"]);

        if ($filters["start"] != 0) {

            $filters["start"]+1;

        }



        $filters["limit"] = (int)$filters["limit"];

        $filters["limit"] = abs($filters["limit"]);

        if ($filters["limit"] == 0) {

            G::LoadClass("configuration");

            $conf = new \Configurations();

            $generalConfCasesList = $conf->getConfiguration('ENVIRONMENT_SETTINGS', '');

            if (isset($generalConfCasesList['casesListRowNumber'])) {

                $filters["limit"] = (int)$generalConfCasesList['casesListRowNumber'];

            } else {

                $filters["limit"] = 25;

            }

        } else {

            $filters["limit"] = (int)$filters["limit"];

        }



        $filters["sort"] = G::toUpper($filters["sort"]);

        $columnsList = $listpeer::getFieldNames(\BasePeer::TYPE_FIELDNAME);

        if (!(in_array($filters["sort"], $columnsList))) {

            $filters["sort"] = '';

        }



        $filters["dir"] = G::toUpper($filters["dir"]);

        if (!($filters["dir"] == 'DESC' || $filters["dir"] == 'ASC')) {

            $filters["dir"] = 'DESC';

        }

        if ($filters["process"] != '') {

            Validator::proUid($filters["process"], '$pro_uid');

        }

        if ($filters["category"] != '') {

            Validator::catUid($filters["category"], '$cat_uid');

        }

        if ($filters["dateFrom"] != '') {

            Validator::isDate($filters["dateFrom"], 'Y-m-d', '$date_from');

        }

        if ($filters["dateTo"] != '') {

            Validator::isDate($filters["dateTo"], 'Y-m-d', '$date_to');

        }



        if ($total) {

            $total = $list->countTotal($userUid, $filters);

            return $total;

        }



        $result = $list->loadList($userUid, $filters);

        if (!empty($result)) {

            foreach ($result as &$value) {

                if (isset($value['DEL_PREVIOUS_USR_UID'])) {

                    $value['PREVIOUS_USR_UID']       = $value['DEL_PREVIOUS_USR_UID'];

                    $value['PREVIOUS_USR_USERNAME']  = $value['DEL_PREVIOUS_USR_USERNAME'];

                    $value['PREVIOUS_USR_FIRSTNAME'] = $value['DEL_PREVIOUS_USR_FIRSTNAME'];

                    $value['PREVIOUS_USR_LASTNAME']  = $value['DEL_PREVIOUS_USR_LASTNAME'];

                }

                if (isset($value['DEL_DUE_DATE'])) {

                    $value['DEL_TASK_DUE_DATE'] = $value['DEL_DUE_DATE'];

                }

                if (isset($value['APP_PAUSED_DATE'])) {

                    $value['APP_UPDATE_DATE']   = $value['APP_PAUSED_DATE'];

                }

                if (isset($value['DEL_CURRENT_USR_USERNAME'])) {

                    $value['USR_USERNAME']      = $value['DEL_CURRENT_USR_USERNAME'];

                    $value['USR_FIRSTNAME']     = $value['DEL_CURRENT_USR_FIRSTNAME'];

                    $value['USR_LASTNAME']      = $value['DEL_CURRENT_USR_LASTNAME'];

                    $value['APP_UPDATE_DATE']   = $value['DEL_DELEGATE_DATE'];

                }

                if (isset($value['APP_STATUS'])) {

                    $value['APP_STATUS_LABEL']  = G::LoadTranslation( "ID_{$value['APP_STATUS']}" );

                }





                //$value = array_change_key_case($value, CASE_LOWER);

            }

        }

        $response = array();

        if ($filters["paged"]) {

            $filtersData = array();

            $filtersData['start']       = $filters["start"];

            $filtersData['limit']       = $filters["limit"];

            $filtersData['sort']        = G::toLower($filters["sort"]);

            $filtersData['dir']         = G::toLower($filters["dir"]);

            $filtersData['cat_uid']     = $filters["category"];

            $filtersData['pro_uid']     = $filters["process"];

            $filtersData['search']      = $filters["search"];

            $filtersData['date_from']   = $filters["dateFrom"];

            $filtersData['date_to']     = $filters["dateTo"];

            $response['filters']        = $filtersData;

            $response['data']           = $result;

            $filtersData['action']      = $filters["action"];

            $response['totalCount']     = $list->countTotal($userUid, $filtersData);

        } else {

            $response = $result;

        }

        return $response;

    }
Esempio n. 2
0
    /**
     * Save new case note
     *
     * @access public
     * @param string $app_uid, Uid for case
     * @param array $app_data, Data for case variables
     *
     * @author Brayan Pereyra (Cochalo) <*****@*****.**>
     * @copyright Colosa - Bolivia
     */
    public function saveCaseNote($app_uid, $usr_uid, $note_content, $send_mail = false)
    {
        Validator::isString($app_uid, '$app_uid');
        Validator::appUid($app_uid, '$app_uid');

        Validator::isString($usr_uid, '$usr_uid');
        Validator::usrUid($usr_uid, '$usr_uid');

        Validator::isString($note_content, '$note_content');
        if (strlen($note_content) > 500) {
            throw (new \Exception(\G::LoadTranslation("ID_INVALID_MAX_PERMITTED", array($note_content,'500'))));
        }

        Validator::isBoolean($send_mail, '$send_mail');

        $case = new \Cases();
        $caseLoad = $case->loadCase($app_uid);
        $pro_uid  = $caseLoad['PRO_UID'];
        $tas_uid  = \AppDelegation::getCurrentTask($app_uid);
        $respView  = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'VIEW' );
        $respBlock = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'BLOCK' );
        if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) {
            throw (new \Exception(\G::LoadTranslation("ID_CASES_NOTES_NO_PERMISSIONS")));
        }

        $note_content = addslashes($note_content);
        $appNote = new \AppNotes();
        $appNote->addCaseNote($app_uid, $usr_uid, $note_content, intval($send_mail));
    }
Esempio n. 3
0
 /**
  * Return starting task by users
  *
  * @param string $sProcessUID {@min 32} {@max 32}
  * @param string $sUserUID {@min 32} {@max 32}
  *
  * return array
  *
  * @access public
  */
 public function getProjectStartingTaskUsers($sProcessUID, $sUserUID)
 {
     try {
         Validator::proUid($sProcessUID, '$prj_uid');
         Validator::usrUid($sUserUID, '$usr_uid');
         $aUsers = array();
         \G::LoadClass('case');
         $oCase = new \Cases();
         $startTasks = $oCase->getStartCases($sUserUID);
         if (sizeof($startTasks) > 1) {
             foreach ($startTasks as $task) {
                 if (isset($task['pro_uid']) && $task['pro_uid'] == $sProcessUID) {
                     $taskValue = explode('(', $task['value']);
                     $tasksLastIndex = count($taskValue) - 1;
                     $taskValue = explode(')', $taskValue[$tasksLastIndex]);
                     $aUsers[] = array('act_uid' => $task['uid'], 'act_name' => $taskValue[0]);
                 }
             }
         }
         if (sizeof($aUsers) < 1) {
             throw new \Exception(\G::LoadTranslation("ID_USER_NOT_INITIAL ACTIVITIES", array($sUserUID)));
         }
         return $aUsers;
     } catch (Exception $e) {
         throw $e;
     }
 }
Esempio n. 4
0
 /**
  * Get process list bookmark for start case
  *
  * @param string $usrUid id of user
  * @param string $typeView type of view
  *
  * return array Return an array with process list that the user can start.
  */
 public function getCasesListBookmarkStarCase($usrUid, $typeView)
 {
     try {
         Validator::usrUid($usrUid, '$usr_uid');
         $user = new \Users();
         $fields = $user->load($usrUid);
         $bookmark = empty($fields['USR_BOOKMARK_START_CASES']) ? array() : unserialize($fields['USR_BOOKMARK_START_CASES']);
         //Getting group id and adding the user id
         $group = new \Groups();
         $groups = $group->getActiveGroupsForAnUser($usrUid);
         $groups[] = $usrUid;
         $c = new \Criteria();
         $c->clearSelectColumns();
         $c->addSelectColumn(\TaskPeer::TAS_UID);
         $c->addSelectColumn(\TaskPeer::PRO_UID);
         $c->addJoin(\TaskPeer::PRO_UID, \ProcessPeer::PRO_UID, \Criteria::LEFT_JOIN);
         $c->addJoin(\TaskPeer::TAS_UID, \TaskUserPeer::TAS_UID, \Criteria::LEFT_JOIN);
         $c->add(\ProcessPeer::PRO_STATUS, 'ACTIVE');
         $c->add(\TaskPeer::TAS_START, 'TRUE');
         $c->add(\TaskUserPeer::USR_UID, $groups, \Criteria::IN);
         $c->add(\TaskPeer::TAS_UID, $bookmark, \Criteria::IN);
         $c->addAsColumn('TAS_TITLE', 'C1.CON_VALUE');
         $c->addAlias("C1", 'CONTENT');
         $tasTitleConds = array();
         $tasTitleConds[] = array(\TaskPeer::TAS_UID, 'C1.CON_ID');
         $tasTitleConds[] = array('C1.CON_CATEGORY', \DBAdapter::getStringDelimiter() . 'TAS_TITLE' . \DBAdapter::getStringDelimiter());
         $tasTitleConds[] = array('C1.CON_LANG', \DBAdapter::getStringDelimiter() . SYS_LANG . \DBAdapter::getStringDelimiter());
         $c->addJoinMC($tasTitleConds, \Criteria::LEFT_JOIN);
         $c->addAsColumn('PRO_TITLE', 'C2.CON_VALUE');
         $c->addAlias("C2", 'CONTENT');
         $proTitleConds = array();
         $proTitleConds[] = array(\ProcessPeer::PRO_UID, 'C2.CON_ID');
         $proTitleConds[] = array('C2.CON_CATEGORY', \DBAdapter::getStringDelimiter() . 'PRO_TITLE' . \DBAdapter::getStringDelimiter());
         $proTitleConds[] = array('C2.CON_LANG', \DBAdapter::getStringDelimiter() . SYS_LANG . \DBAdapter::getStringDelimiter());
         $c->addJoinMC($proTitleConds, \Criteria::LEFT_JOIN);
         if ($typeView == 'category') {
             $c->addAsColumn('PRO_CATEGORY', 'PCS.PRO_CATEGORY');
             $c->addAsColumn('CATEGORY_NAME', 'PCSCAT.CATEGORY_NAME');
             $c->addAlias('PCS', 'PROCESS');
             $c->addAlias('PCSCAT', 'PROCESS_CATEGORY');
             $aConditions = array();
             $aConditions[] = array(\TaskPeer::PRO_UID, 'PCS.PRO_UID');
             $c->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
             $aConditions = array();
             $aConditions[] = array('PCS.PRO_CATEGORY', 'PCSCAT.CATEGORY_UID');
             $c->addJoinMC($aConditions, \Criteria::LEFT_JOIN);
         }
         $c->setDistinct();
         $rs = \TaskPeer::doSelectRS($c);
         $rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
         $processList = array();
         while ($rs->next()) {
             $row = $rs->getRow();
             if ($typeView == 'category') {
                 $processList[] = array('tas_uid' => $row['TAS_UID'], 'pro_title' => $row['PRO_TITLE'] . '(' . $row['TAS_TITLE'] . ')', 'pro_uid' => $row['PRO_UID'], 'pro_category' => $row['PRO_CATEGORY'], 'category_name' => $row['CATEGORY_NAME']);
             } else {
                 $processList[] = array('tas_uid' => $row['TAS_UID'], 'pro_title' => $row['PRO_TITLE'] . '(' . $row['TAS_TITLE'] . ')', 'pro_uid' => $row['PRO_UID']);
             }
         }
         if (count($processList) == 0) {
             $processList['success'] = 'failure';
             $processList['message'] = G::LoadTranslation('ID_NOT_HAVE_BOOKMARKED_PROCESSES');
         }
         return $processList;
     } catch (\Exception $e) {
         throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
     }
 }
Esempio n. 5
0
 /**
  * Save Department
  * @var string $dep_data. Data for Process
  * @var string $create. Flag for create or update
  *
  * @access public
  * @author Brayan Pereyra (Cochalo) <*****@*****.**>
  * @copyright Colosa - Bolivia
  *
  * @return array
  */
 public function saveDepartment($dep_data, $create = true)
 {
     Validator::isArray($dep_data, '$dep_data');
     Validator::isNotEmpty($dep_data, '$dep_data');
     Validator::isBoolean($create, '$create');
     $dep_data = array_change_key_case($dep_data, CASE_UPPER);
     if ($create) {
         unset($dep_data["DEP_UID"]);
     }
     $oDepartment = new \Department();
     if (isset($dep_data['DEP_UID']) && $dep_data['DEP_UID'] != '') {
         Validator::depUid($dep_data['DEP_UID']);
     }
     if (isset($dep_data['DEP_PARENT']) && $dep_data['DEP_PARENT'] != '') {
         Validator::depUid($dep_data['DEP_PARENT'], 'dep_parent');
     }
     if (isset($dep_data['DEP_MANAGER']) && $dep_data['DEP_MANAGER'] != '') {
         Validator::usrUid($dep_data['DEP_MANAGER'], 'dep_manager');
     }
     if (isset($dep_data['DEP_STATUS'])) {
         Validator::depStatus($dep_data['DEP_STATUS']);
     }
     if (!$create) {
         if (isset($dep_data["DEP_TITLE"])) {
             $this->throwExceptionIfExistsTitle($dep_data["DEP_TITLE"], strtolower("DEP_TITLE"), $dep_data["DEP_UID"]);
             $dep_data["DEPO_TITLE"] = $dep_data["DEP_TITLE"];
         }
         $oDepartment->update($dep_data);
         $oDepartment->updateDepartmentManager($dep_data['DEP_UID']);
     } else {
         if (isset($dep_data['DEP_TITLE'])) {
             $this->throwExceptionIfExistsTitle($dep_data["DEP_TITLE"], strtolower("DEP_TITLE"));
         } else {
             throw new \Exception(\G::LoadTranslation("ID_FIELD_REQUIRED", array('dep_title')));
         }
         $dep_uid = $oDepartment->create($dep_data);
         $response = $this->getDepartment($dep_uid);
         return $response;
     }
 }