Example #1
0
    public function getAll(
        $userUid,
        $start = null,
        $limit = null,
        $action = null,
        $filter = null,
        $search = null,
        $process = null,
        $status = null,
        $type = null,
        $dateFrom = null,
        $dateTo = null,
        $callback = null,
        $dir = null,
        $sort = "APP_CACHE_VIEW.APP_NUMBER",
        $category = null,
        $configuration = true,
        $paged = true
    ) {
        $callback = isset($callback)? $callback : "stcCallback1001";
        $dir = isset($dir)? $dir : "DESC";

        if (isset($sort)) {
            G::LoadClass('phpSqlParser');
            $parser = new PHPSQLParser($sort);
            $sort = $parser->parsed;
            $sort = $sort[''][0];
        }

        $sort = isset($sort)? $sort : "";
        $start = isset($start)? $start : "0";
        $limit = isset($limit)? $limit : "25";
        $filter = isset($filter)? $filter : "";
        $search = isset($search)? $search : "";
        $process = isset($process)? $process : "";
        $category = isset($category)? $category : "";
        $status = isset($status)? $status : "";
        $action = isset($action)? $action : "todo";
        $type = isset($type)? $type : "extjs";
        $dateFrom = isset($dateFrom)? $dateFrom : "";
        $dateTo = isset($dateTo)? $dateTo : "";

        G::LoadClass("BasePeer");
        G::LoadClass("configuration");
        //require_once ("classes/model/AppCacheView.php");
        //require_once ("classes/model/AppDelegation.php");
        //require_once ("classes/model/AdditionalTables.php");
        //require_once ("classes/model/AppDelay.php");
        //require_once ("classes/model/Fields.php");
        //require_once ("classes/model/Users.php");
        //require_once ("classes/model/Process.php");

        $oAppCache = new AppCacheView();

        if ($configuration == true) {
            //get data configuration
            $conf = new Configurations();
            $confCasesList = $conf->getConfiguration("casesList", ($action == "search" || $action == "simple_search")? "search" : $action);
            $oAppCache->confCasesList = $confCasesList;
        }

        $delimiter = DBAdapter::getStringDelimiter();

        // get the action based list
        switch ($action) {
            case "draft":
                $Criteria = $oAppCache->getDraftListCriteria($userUid);
                $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
                break;
            case "sent":
                $Criteria = $oAppCache->getSentListCriteria($userUid);
                $CriteriaCount = $oAppCache->getSentCountCriteria($userUid);

                if (!empty($status)) {
                    $Criteria->add(AppCacheViewPeer::APP_STATUS, $status);
                    $CriteriaCount->add(AppCacheViewPeer::APP_STATUS, $status);
                }
                break;
            case "selfservice":
            case "unassigned":
                //$userUid can't be empty or null
                $Criteria = $oAppCache->getUnassignedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getUnassignedCountCriteria($userUid);
                break;
            case "paused":
                $Criteria = $oAppCache->getPausedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
                break;
            case "completed":
                $Criteria = $oAppCache->getCompletedListCriteria($userUid);
                $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);
                break;
            case "cancelled":
                $Criteria = $oAppCache->getCancelledListCriteria($userUid);
                $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
                break;
            case "search":
                //$Criteria = $oAppCache->getSearchListCriteria();
                //$CriteriaCount = $oAppCache->getSearchCountCriteria();

                switch ($status) {
                    case "TO_DO":
                        $Criteria = $oAppCache->getToDoListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
                        break;
                    case "DRAFT":
                        $Criteria = $oAppCache->getDraftListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
                        break;
                    case "PAUSED":
                        $Criteria = $oAppCache->getPausedListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
                        break;
                    case "CANCELLED":
                        $Criteria = $oAppCache->getCancelledListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
                        break;
                    case "COMPLETED":
                        $Criteria = $oAppCache->getCompletedListCriteria($userUid);
                        $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);

                        $Criteria->add (AppCacheViewPeer::DEL_LAST_INDEX,"1");
                        $CriteriaCount->add (AppCacheViewPeer::DEL_LAST_INDEX,"1");
                        break;
                    default:
                        //All status
                        $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
                        $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
                        break;
                }
                break;
            case "simple_search":
                $Criteria = $oAppCache->getSimpleSearchListCriteria();
                $CriteriaCount = $oAppCache->getSimpleSearchCountCriteria();
                break;
            case "to_revise":
                $Criteria = $oAppCache->getToReviseListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToReviseCountCriteria($userUid);
                break;
            case "to_reassign":
                $Criteria = $oAppCache->getToReassignListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToReassignCountCriteria($userUid);
                break;
            case "all":
                $Criteria = $oAppCache->getAllCasesListCriteria($userUid);
                $CriteriaCount = $oAppCache->getAllCasesCountCriteria($userUid);
                break;
            case "gral":
                //General criteria probably will be deprecated
                $Criteria = $oAppCache->getGeneralListCriteria();
                $CriteriaCount = $oAppCache->getGeneralCountCriteria();
                break;
            case "todo":
                $Criteria = $oAppCache->getToDoListCriteria($userUid);
                $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
                break;
            default:
                //All status
                $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
                $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
                break;
        }

        $arrayTaskTypeToExclude = array("WEBENTRYEVENT", "END-MESSAGE-EVENT", "START-MESSAGE-EVENT", "INTERMEDIATE-THROW-MESSAGE-EVENT", "INTERMEDIATE-CATCH-MESSAGE-EVENT");

        $Criteria->addJoin(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
        $Criteria->add(TaskPeer::TAS_TYPE, $arrayTaskTypeToExclude, Criteria::NOT_IN);

        $CriteriaCount->addJoin(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
        $CriteriaCount->add(TaskPeer::TAS_TYPE, $arrayTaskTypeToExclude, Criteria::NOT_IN);

        $Criteria->addAlias( 'CU', 'USERS' );
        $Criteria->addJoin( AppCacheViewPeer::USR_UID, 'CU.USR_UID', Criteria::LEFT_JOIN );
        $Criteria->addAsColumn( 'USR_UID', 'CU.USR_UID' );
        $Criteria->addAsColumn( 'USR_FIRSTNAME', 'CU.USR_FIRSTNAME' );
        $Criteria->addAsColumn( 'USR_LASTNAME', 'CU.USR_LASTNAME' );
        $Criteria->addAsColumn( 'USR_USERNAME', 'CU.USR_USERNAME' );

        $CriteriaCount->addAlias( 'CU', 'USERS' );
        $CriteriaCount->addJoin( AppCacheViewPeer::USR_UID, 'CU.USR_UID', Criteria::LEFT_JOIN );
        $CriteriaCount->addAsColumn( 'USR_UID', 'CU.USR_UID' );
        $CriteriaCount->addAsColumn( 'USR_FIRSTNAME', 'CU.USR_FIRSTNAME' );
        $CriteriaCount->addAsColumn( 'USR_LASTNAME', 'CU.USR_LASTNAME' );
        $CriteriaCount->addAsColumn( 'USR_USERNAME', 'CU.USR_USERNAME' );

        //Current delegation
        $appdelcrTableName = AppCacheViewPeer::TABLE_NAME;
        $appdelcrAppTasTitle = "APPDELCR.APP_TAS_TITLE";
        $appdelcrAppTasTitleCount = $appdelcrAppTasTitle;

        switch ($action) {
            case "sent":
                $appdelcrTableName = AppDelegationPeer::TABLE_NAME;
                $appdelcrAppTasTitle = "(SELECT CON_VALUE FROM CONTENT WHERE CON_ID = APPDELCR.TAS_UID AND CON_LANG = " . $delimiter . SYS_LANG . $delimiter . " AND CON_CATEGORY = " . $delimiter . "TAS_TITLE" . $delimiter . ")";
                $appdelcrAppTasTitleCount = "APPDELCR.TAS_UID";
                break;
            case "to_reassign":
                $appdelcrAppTasTitle = "APP_CACHE_VIEW.APP_TAS_TITLE";
                $appdelcrAppTasTitleCount = $appdelcrAppTasTitle;
                break;
        }

        $Criteria->addAsColumn("APPDELCR_APP_TAS_TITLE", $appdelcrAppTasTitle);
        $CriteriaCount->addAsColumn("APPDELCR_APP_TAS_TITLE", $appdelcrAppTasTitleCount);

        $Criteria->addAsColumn("USRCR_USR_UID", "USRCR.USR_UID");
        $Criteria->addAsColumn("USRCR_USR_FIRSTNAME", "USRCR.USR_FIRSTNAME");
        $Criteria->addAsColumn("USRCR_USR_LASTNAME", "USRCR.USR_LASTNAME");
        $Criteria->addAsColumn("USRCR_USR_USERNAME", "USRCR.USR_USERNAME");

        $CriteriaCount->addAsColumn("USRCR_USR_UID", "USRCR.USR_UID");
        $CriteriaCount->addAsColumn("USRCR_USR_FIRSTNAME", "USRCR.USR_FIRSTNAME");
        $CriteriaCount->addAsColumn("USRCR_USR_LASTNAME", "USRCR.USR_LASTNAME");
        $CriteriaCount->addAsColumn("USRCR_USR_USERNAME", "USRCR.USR_USERNAME");

        $Criteria->addAlias("APPDELCR", $appdelcrTableName);
        $Criteria->addAlias("USRCR", UsersPeer::TABLE_NAME);

        $CriteriaCount->addAlias("APPDELCR", $appdelcrTableName);
        $CriteriaCount->addAlias("USRCR", UsersPeer::TABLE_NAME);

        $arrayCondition = array();
        $arrayCondition[] = array(AppCacheViewPeer::APP_UID, "APPDELCR.APP_UID");
        $arrayCondition[] = array("APPDELCR.DEL_LAST_INDEX", 1);
        $Criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
        $CriteriaCount->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);

        $arrayCondition = array();
        $arrayCondition[] = array("APPDELCR.USR_UID", "USRCR.USR_UID");
        $Criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
        $CriteriaCount->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);

        //Previous user

        if (($action == "todo" || $action == "selfservice" || $action == "unassigned" || $action == "paused" || $action == "to_revise" || $action == "sent") || ($status == "TO_DO" || $status == "DRAFT" || $status == "PAUSED" || $status == "CANCELLED" || $status == "COMPLETED")) {
            $Criteria->addAlias( 'PU', 'USERS' );
            $Criteria->addJoin( AppCacheViewPeer::PREVIOUS_USR_UID, 'PU.USR_UID', Criteria::LEFT_JOIN );
            $Criteria->addAsColumn( 'PREVIOUS_USR_FIRSTNAME', 'PU.USR_FIRSTNAME' );
            $Criteria->addAsColumn( 'PREVIOUS_USR_LASTNAME', 'PU.USR_LASTNAME' );
            $Criteria->addAsColumn( 'PREVIOUS_USR_USERNAME', 'PU.USR_USERNAME' );

            $CriteriaCount->addAlias( 'PU', 'USERS' );
            $CriteriaCount->addJoin( AppCacheViewPeer::PREVIOUS_USR_UID, 'PU.USR_UID', Criteria::LEFT_JOIN );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_FIRSTNAME', 'PU.USR_FIRSTNAME' );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_LASTNAME', 'PU.USR_LASTNAME' );
            $CriteriaCount->addAsColumn( 'PREVIOUS_USR_USERNAME', 'PU.USR_USERNAME' );
        }

        /*
        if (! is_array( $confCasesList )) {
            $rows = $this->getDefaultFields( $action );
            $result = $this->genericJsonResponse( '', array (), $rows, 20, '' );
            //$conf->saveObject($result,'casesList',$action,'','','');
        }
        */

        //Add the process filter
        if (!empty($process)) {
            $Criteria->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
            $CriteriaCount->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
        }

        //Add the category filter
        if (!empty($category)) {
            require_once 'classes/model/Process.php';
            $Criteria->addAlias("CP", "PROCESS");
            $Criteria->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
            $Criteria->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
            $Criteria->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");

            $CriteriaCount->addAlias("CP", "PROCESS");
            $CriteriaCount->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
            $CriteriaCount->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
            $CriteriaCount->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");
        }

        // add the user filter
        /*
        if ($user != '') {
            $Criteria->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
        }
        if ($status != '') {
            $Criteria->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
        }
        */

        if ($dateFrom != "") {
            if ($dateTo != "") {
                if ($dateFrom == $dateTo) {
                    $dateSame = $dateFrom;
                    $dateFrom = $dateSame . " 00:00:00";
                    $dateTo = $dateSame . " 23:59:59";
                } else {
                    $dateFrom = $dateFrom . " 00:00:00";
                    $dateTo = $dateTo . " 23:59:59";
                }

                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL )->addAnd( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL ) ) );
                $CriteriaCount->add( $CriteriaCount->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL )->addAnd( $Criteria->getNewCriterion( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL ) ) );
            } else {
                $dateFrom = $dateFrom . " 00:00:00";

                $Criteria->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL );
                $CriteriaCount->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL );
            }
        } elseif ($dateTo != "") {
            $dateTo = $dateTo . " 23:59:59";

            $Criteria->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL );
            $CriteriaCount->add( AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL );
        }

        //add the filter
        if ($filter != '') {
            switch ($filter) {
                case 'read':
                    $Criteria->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL );
                    break;
                case 'unread':
                    $Criteria->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
                    break;
                case 'started':
                    $Criteria->add( AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL );
                    $CriteriaCount->add( AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL );
                    break;
                case 'completed':
                    $Criteria->add( AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL );
                    $CriteriaCount->add( AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL );
                    break;
            }
        }

        //Add the search filter
        if ($search != '') {
            $oTmpCriteria = '';

            //If there is PMTable for this case list
            if (is_array($oAppCache->confCasesList) && count($oAppCache->confCasesList) > 0 && isset($oAppCache->confCasesList["PMTable"]) && trim($oAppCache->confCasesList["PMTable"]) != "") {
                //Default configuration fields array
                $defaultFields = $oAppCache->getDefaultFields();

                //Getting the table name
                $additionalTableUid = $oAppCache->confCasesList["PMTable"];

                $additionalTable = AdditionalTablesPeer::retrieveByPK($additionalTableUid);
                $tableName = $additionalTable->getAddTabName();

                $additionalTable = new AdditionalTables();
                $tableData = $additionalTable->load($additionalTableUid, true);

                $tableField = array();

                foreach ($tableData["FIELDS"] as $arrayField) {
                    $tableField[] = $arrayField["FLD_NAME"];
                }

                $oNewCriteria = new Criteria("workflow");
                $sw = 0;

                foreach ($oAppCache->confCasesList["second"]["data"] as $fieldData) {
                    if (!in_array($fieldData["name"], $defaultFields)) {
                        if (in_array($fieldData["name"], $tableField)) {
                            $fieldName = $tableName . "." . $fieldData["name"];

                            if ($sw == 0) {
                                $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, "%" . $search . "%", Criteria::LIKE);
                            } else {
                                $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, "%" . $search . "%", Criteria::LIKE)->addOr($oTmpCriteria);
                            }

                            $sw = 1;
                        }
                    }
                }

                //add the default and hidden DEL_INIT_DATE
            }

            // the criteria adds new fields if there are defined PM Table Fields in the cases list
            if ($oTmpCriteria != '') {
                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE )->addOr( $oTmpCriteria ) ) ) );
            } else {
                $Criteria->add( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE ) ) ) );
            }

            // the count query needs to be the normal criteria query if there are defined PM Table Fields in the cases list
            if ($oTmpCriteria != '') {
                $CriteriaCount = $Criteria;
            } else {
                $CriteriaCount->add( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->addOr( $CriteriaCount->getNewCriterion( AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE ) ) ) );
            }
        }

        // this is the optimal way or query to render the cases search list
        // fixing the bug related to the wrong data displayed in the list
        /*
        if ($action == 'search') {
            $oDatasetIndex = AppCacheViewPeer::doSelectRS( $Criteria );
            $oDatasetIndex->setFetchmode( ResultSet::FETCHMODE_ASSOC );
            $oDatasetIndex->next();
            $maxDelIndexList = array ();
            // a list of MAX_DEL_INDEXES is required in order to validate the right row
            while ($aRow = $oDatasetIndex->getRow()) {
                $maxDelIndexList[] = $aRow['MAX_DEL_INDEX'];
                $oDatasetIndex->next();
            }
            // adding the validation condition in order to get the right row using the group by sentence
            $Criteria->add( AppCacheViewPeer::DEL_INDEX, $maxDelIndexList, Criteria::IN );
            //
            //$params = array($maxDelIndexList);
        }
        */

        //here we count how many records exists for this criteria.
        //BUT there are some special cases, and if we dont optimize them the server will crash.
        $doCountAlreadyExecuted = $paged;
        //case 1. when the SEARCH action is selected and none filter, search criteria is defined,
        //we need to count using the table APPLICATION, because APP_CACHE_VIEW takes 3 seconds

        /*
        if ($action == 'search' && $filter == '' && $search == '' && $process == '' && $status == '' && $dateFrom == '' && $dateTo == '' && $category == '') {
            $totalCount = $oAppCache->getSearchAllCount();
            $doCountAlreadyExecuted = true;
        }
        if ($category != '') {
            $totalCount = $oAppCache->getSearchCountCriteria();
            $doCountAlreadyExecuted = true;
        }
        */
        $tableNameAux = '';
        $totalCount = 0;
        if ($doCountAlreadyExecuted == true) {
            // in the case of reassign the distinct attribute shows a diferent count result comparing to the
            // original list
            //Check also $distinct in the method getListCounters(), this in AppCacheView.php
            $distinct = true;

            if ($action != "sent" && (($action == "todo" || $action == "selfservice" || $action == "unassigned" || $action == "to_reassign" || $action == "to_revise") || ($status == "TO_DO"))) {
                $distinct = false;
            }

            // first check if there is a PMTable defined within the list,
            // the issue that brokes the normal criteria query seems to be fixed
            if (isset( $oAppCache->confCasesList['PMTable'] ) && ! empty( $oAppCache->confCasesList['PMTable'] )) {
                // then
                $oAdditionalTables = AdditionalTablesPeer::retrieveByPK( $oAppCache->confCasesList['PMTable'] );
                $tableName = $oAdditionalTables->getAddTabName();
                $tableNameAux = $tableName;
                $tableName = strtolower( $tableName );
                $tableNameArray = explode( '_', $tableName );
                foreach ($tableNameArray as $item) {
                    $newTableName[] = ucfirst( $item );
                }
                $tableName = implode( '', $newTableName );
                // so the pm table class can be invoqued from the pm table model clases
                if (! class_exists( $tableName )) {
                    require_once (PATH_DB . SYS_SYS . PATH_SEP . "classes" . PATH_SEP . $tableName . ".php");
                }
            }
            $totalCount = AppCacheViewPeer::doCount($CriteriaCount, $distinct);
        }

        //Add sortable options
        $sortBk = $sort;

        if ($sortBk != "") {
            $sort = "";

            //Current delegation (*)
            if (($action == "sent" || $action == "search" || $action == "simple_search" || $action == "to_revise" || $action == "to_reassign") && ($status != "TO_DO")) {
                switch ($sortBk) {
                    case "APP_CACHE_VIEW.APP_CURRENT_USER":
                        $sort = "USRCR_" . $conf->userNameFormatGetFirstFieldByUsersTable();
                        break;
                    case "APP_CACHE_VIEW.APP_TAS_TITLE":
                        $sort = "APPDELCR_APP_TAS_TITLE";
                        break;
                }
            }

            if (isset( $oAppCache->confCasesList['PMTable'] ) && ! empty( $oAppCache->confCasesList['PMTable'] ) && $tableNameAux != '') {
                $sortTable = explode(".", $sortBk);

                $additionalTableUid = $oAppCache->confCasesList["PMTable"];

                require_once 'classes/model/Fields.php';
                $oCriteria = new Criteria('workflow');

                $oCriteria->addSelectColumn(FieldsPeer::FLD_UID);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_INDEX);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_NAME);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DESCRIPTION);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_TYPE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_SIZE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_NULL);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_AUTO_INCREMENT);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_KEY);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FOREIGN_KEY_TABLE);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_NAME);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_DYN_UID);
                $oCriteria->addSelectColumn(FieldsPeer::FLD_FILTER);
                $oCriteria->add(FieldsPeer::ADD_TAB_UID, $additionalTableUid);
                $oCriteria->add(FieldsPeer::FLD_NAME, $sortTable[1]);
                $oCriteria->addAscendingOrderByColumn(FieldsPeer::FLD_INDEX);

                $oDataset = FieldsPeer::doSelectRS($oCriteria);
                $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                $oDataset->next();
                $row = $oDataset->getRow();
                if (is_array($row)) {
                    $sort = $tableNameAux . "." . $sortTable[1];
                }
            }

            if ($sort == "") {
                $sort = $sortBk;
            }

            if (!in_array($sort, $Criteria->getSelectColumns())) {
                $sort = AppCacheViewPeer::APP_NUMBER; //DEFAULT VALUE
            }

            if ($dir == "DESC") {
                $Criteria->addDescendingOrderByColumn($sort);
            } else {
                $Criteria->addAscendingOrderByColumn($sort);
            }
        }

        //limit the results according the interface
        $Criteria->setLimit( $limit );
        $Criteria->setOffset( $start );

        //execute the query
        $oDataset = AppCacheViewPeer::doSelectRS( $Criteria, Propel::getDbConnection('workflow_ro') );

        $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

        $result = array ();
        $result['totalCount'] = $totalCount;
        $rows = array ();
        $aPriorities = array ('1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH');
        $index = $start;

        while ($oDataset->next()) {
            $aRow = $oDataset->getRow();

            //$aRow = $oAppCache->replaceRowUserData($aRow);

            /*
             * For participated cases, we want the last step in the case, not only the last step this user participated. To do that we get every case information again for the last step. (This could be solved by a subquery, but Propel might not support it and subqueries can be slower for larger
             * datasets).
             */
             /*if ($action == 'sent' || $action == 'search') {
             $maxCriteria = new Criteria('workflow');
             $maxCriteria->add(AppCacheViewPeer::APP_UID, $aRow['APP_UID'], Criteria::EQUAL);
             $maxCriteria->addDescendingOrderByColumn(AppCacheViewPeer::DEL_INDEX);
             $maxCriteria->setLimit(1);

             $maxDataset = AppCacheViewPeer::doSelectRS( $maxCriteria );
             $maxDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
             $maxDataset->next();

             $newData = $maxDataset->getRow();
             foreach ($aRow as $col => $value) {
             if (array_key_exists($col, $newData))
             $aRow[$col] = $newData[$col];
             }

             $maxDataset->close();
              }*/

            //Current delegation (*) || $action == "search" || $action == "to_revise"
            if (($action == "sent" || $action == "simple_search" || $action == "to_reassign") && ($status != "TO_DO")) {
                //Current task
                $aRow["APP_TAS_TITLE"] = $aRow["APPDELCR_APP_TAS_TITLE"];

                //Current user
                //if ($action != "to_reassign" ) {
                if (($action != "to_reassign") && ($action != "search") && ($action != "to revise")) {
                    $aRow["USR_UID"] = $aRow["USRCR_USR_UID"];
                    $aRow["USR_FIRSTNAME"] = $aRow["USRCR_USR_FIRSTNAME"];
                    $aRow["USR_LASTNAME"] = $aRow["USRCR_USR_LASTNAME"];
                    $aRow["USR_USERNAME"] = $aRow["USRCR_USR_USERNAME"];
                }
            }

            //Unassigned user
            if (! isset( $aRow['APP_CURRENT_USER'] )) {
                $aRow['APP_CURRENT_USER'] = "******" . strtoupper(G::LoadTranslation("ID_UNASSIGNED")) . "]";
            }

            // replacing the status data with their respective translation
            if (isset( $aRow['APP_STATUS'] )) {
                $aRow['APP_STATUS_LABEL'] = G::LoadTranslation( "ID_{$aRow['APP_STATUS']}" );
            }

            // replacing the priority data with their respective translation
            if (isset( $aRow['DEL_PRIORITY'] )) {
                $aRow['DEL_PRIORITY'] = G::LoadTranslation( "ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}" );
            }

            $rows[] = $aRow;
        }

        $result['data'] = $rows;

        return $result;
    }
 public function getAll($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = "APP_CACHE_VIEW.APP_NUMBER", $category = null)
 {
     $callback = isset($callback) ? $callback : "stcCallback1001";
     $dir = isset($dir) ? $dir : "DESC";
     $sort = isset($sort) ? $sort : "";
     $start = isset($start) ? $start : "0";
     $limit = isset($limit) ? $limit : "25";
     $filter = isset($filter) ? $filter : "";
     $search = isset($search) ? $search : "";
     $process = isset($process) ? $process : "";
     $category = isset($category) ? $category : "";
     $status = isset($status) ? $status : "";
     $action = isset($action) ? $action : "todo";
     $type = isset($type) ? $type : "extjs";
     $dateFrom = isset($dateFrom) ? $dateFrom : "";
     $dateTo = isset($dateTo) ? $dateTo : "";
     G::LoadClass("BasePeer");
     G::LoadClass("configuration");
     //require_once ("classes/model/AppCacheView.php");
     //require_once ("classes/model/AppDelegation.php");
     //require_once ("classes/model/AdditionalTables.php");
     //require_once ("classes/model/AppDelay.php");
     //require_once ("classes/model/Fields.php");
     //require_once ("classes/model/Users.php");
     //require_once ("classes/model/Process.php");
     $oAppCache = new AppCacheView();
     //get data configuration
     $conf = new Configurations();
     $confCasesList = $conf->getConfiguration('casesList', $action == 'search' || $action == 'simple_search' ? 'sent' : $action);
     $oAppCache->confCasesList = $confCasesList;
     // get the action based list
     switch ($action) {
         case "draft":
             $Criteria = $oAppCache->getDraftListCriteria($userUid);
             $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
             break;
         case "sent":
             $Criteria = $oAppCache->getSentListCriteria($userUid);
             $CriteriaCount = $oAppCache->getSentCountCriteria($userUid);
             if (!empty($status)) {
                 $Criteria->add(AppCacheViewPeer::APP_STATUS, $status);
                 $CriteriaCount->add(AppCacheViewPeer::APP_STATUS, $status);
             }
             break;
         case "selfservice":
         case "unassigned":
             //$userUid can't be empty or null
             $Criteria = $oAppCache->getUnassignedListCriteria($userUid);
             $CriteriaCount = $oAppCache->getUnassignedCountCriteria($userUid);
             break;
         case "paused":
             $Criteria = $oAppCache->getPausedListCriteria($userUid);
             $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
             break;
         case "completed":
             $Criteria = $oAppCache->getCompletedListCriteria($userUid);
             $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);
             break;
         case "cancelled":
             $Criteria = $oAppCache->getCancelledListCriteria($userUid);
             $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
             break;
         case "search":
             //$Criteria = $oAppCache->getSearchListCriteria();
             //$CriteriaCount = $oAppCache->getSearchCountCriteria();
             switch ($status) {
                 case "TO_DO":
                     $Criteria = $oAppCache->getToDoListCriteria($userUid);
                     $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
                     break;
                 case "DRAFT":
                     $Criteria = $oAppCache->getDraftListCriteria($userUid);
                     $CriteriaCount = $oAppCache->getDraftCountCriteria($userUid);
                     break;
                 case "PAUSED":
                     $Criteria = $oAppCache->getPausedListCriteria($userUid);
                     $CriteriaCount = $oAppCache->getPausedCountCriteria($userUid);
                     break;
                 case "CANCELLED":
                     $Criteria = $oAppCache->getCancelledListCriteria($userUid);
                     $CriteriaCount = $oAppCache->getCancelledCountCriteria($userUid);
                     break;
                 case "COMPLETED":
                     $Criteria = $oAppCache->getCompletedListCriteria($userUid);
                     $CriteriaCount = $oAppCache->getCompletedCountCriteria($userUid);
                     break;
                 default:
                     //All status
                     $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
                     $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
                     break;
             }
             break;
         case "simple_search":
             $Criteria = $oAppCache->getSimpleSearchListCriteria();
             $CriteriaCount = $oAppCache->getSimpleSearchCountCriteria();
             break;
         case "to_revise":
             $Criteria = $oAppCache->getToReviseListCriteria($userUid);
             $CriteriaCount = $oAppCache->getToReviseCountCriteria($userUid);
             break;
         case "to_reassign":
             $Criteria = $oAppCache->getToReassignListCriteria($userUid);
             $CriteriaCount = $oAppCache->getToReassignCountCriteria($userUid);
             break;
         case "all":
             $Criteria = $oAppCache->getAllCasesListCriteria($userUid);
             $CriteriaCount = $oAppCache->getAllCasesCountCriteria($userUid);
             break;
         case "gral":
             //General criteria probably will be deprecated
             $Criteria = $oAppCache->getGeneralListCriteria();
             $CriteriaCount = $oAppCache->getGeneralCountCriteria();
             break;
         case "todo":
             $Criteria = $oAppCache->getToDoListCriteria($userUid);
             $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid);
             break;
         default:
             //All status
             $Criteria = $oAppCache->getAllCasesListCriteria2($userUid);
             $CriteriaCount = $oAppCache->getAllCasesCountCriteria2($userUid);
             break;
     }
     $Criteria->addAlias('CU', 'USERS');
     $Criteria->addJoin(AppCacheViewPeer::USR_UID, 'CU.USR_UID', Criteria::LEFT_JOIN);
     $Criteria->addAsColumn('USR_UID', 'CU.USR_UID');
     $Criteria->addAsColumn('USR_FIRSTNAME', 'CU.USR_FIRSTNAME');
     $Criteria->addAsColumn('USR_LASTNAME', 'CU.USR_LASTNAME');
     $Criteria->addAsColumn('USR_USERNAME', 'CU.USR_USERNAME');
     // Fix for previous user
     if ($action == "todo" || $action == "selfservice" || $action == "unassigned" || $action == "paused" || $action == "to_revise" || $action == "sent" || ($status == "TO_DO" || $status == "DRAFT" || $status == "PAUSED" || $status == "CANCELLED" || $status == "COMPLETED")) {
         $Criteria->addAlias('PU', 'USERS');
         $Criteria->addJoin(AppCacheViewPeer::PREVIOUS_USR_UID, 'PU.USR_UID', Criteria::LEFT_JOIN);
         $Criteria->addAsColumn('PREVIOUS_USR_FIRSTNAME', 'PU.USR_FIRSTNAME');
         $Criteria->addAsColumn('PREVIOUS_USR_LASTNAME', 'PU.USR_LASTNAME');
         $Criteria->addAsColumn('PREVIOUS_USR_USERNAME', 'PU.USR_USERNAME');
     }
     /*
     if (! is_array( $confCasesList )) {
         $rows = $this->getDefaultFields( $action );
         $result = $this->genericJsonResponse( '', array (), $rows, 20, '' );
         //$conf->saveObject($result,'casesList',$action,'','','');
     }
     */
     //Add the process filter
     if (!empty($process)) {
         $Criteria->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
         $CriteriaCount->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL);
     }
     //Add the category filter
     if (!empty($category)) {
         $Criteria->addAlias("CP", "PROCESS");
         $Criteria->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
         $Criteria->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
         $Criteria->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");
         $CriteriaCount->addAlias("CP", "PROCESS");
         $CriteriaCount->add("CP.PRO_CATEGORY", $category, Criteria::EQUAL);
         $CriteriaCount->addJoin(AppCacheViewPeer::PRO_UID, "CP.PRO_UID", Criteria::LEFT_JOIN);
         $CriteriaCount->addAsColumn("CATEGORY_UID", "CP.PRO_CATEGORY");
     }
     // add the user filter
     /*
     if ($user != '') {
         $Criteria->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
         $CriteriaCount->add( AppCacheViewPeer::USR_UID, $user, Criteria::EQUAL );
     }
     */
     /*
     if ($status != '') {
         $Criteria->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
         $CriteriaCount->add( AppCacheViewPeer::APP_STATUS, $status, Criteria::EQUAL );
     }
     */
     if ($dateFrom != '') {
         if ($dateTo != '') {
             $Criteria->add($Criteria->getNewCriterion(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL)->addAnd($Criteria->getNewCriterion(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL)));
             $CriteriaCount->add($CriteriaCount->getNewCriterion(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL)->addAnd($Criteria->getNewCriterion(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL)));
         } else {
             $Criteria->add(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL);
             $CriteriaCount->add(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL);
         }
     } elseif ($dateTo != '') {
         $Criteria->add(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL);
         $CriteriaCount->add(AppCacheViewPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL);
     }
     //add the filter
     if ($filter != '') {
         switch ($filter) {
             case 'read':
                 $Criteria->add(AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL);
                 $CriteriaCount->add(AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL);
                 break;
             case 'unread':
                 $Criteria->add(AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL);
                 $CriteriaCount->add(AppCacheViewPeer::DEL_INIT_DATE, null, Criteria::ISNULL);
                 break;
             case 'started':
                 $Criteria->add(AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL);
                 $CriteriaCount->add(AppCacheViewPeer::DEL_INDEX, 1, Criteria::EQUAL);
                 break;
             case 'completed':
                 $Criteria->add(AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL);
                 $CriteriaCount->add(AppCacheViewPeer::APP_STATUS, 'COMPLETED', Criteria::EQUAL);
                 break;
         }
     }
     //add the search filter
     if ($search != '') {
         $defaultFields = $oAppCache->getDefaultFields();
         $oTmpCriteria = '';
         // if there is PMTABLE for this case list:
         if (!empty($oAppCache->confCasesList) && isset($oAppCache->confCasesList['PMTable']) && trim($oAppCache->confCasesList['PMTable']) != '') {
             // getting the table name
             $oAdditionalTables = AdditionalTablesPeer::retrieveByPK($oAppCache->confCasesList['PMTable']);
             $tableName = $oAdditionalTables->getAddTabName();
             $oNewCriteria = new Criteria('workflow');
             $counter = 0;
             foreach ($oAppCache->confCasesList['second']['data'] as $fieldData) {
                 if (!in_array($fieldData['name'], $defaultFields)) {
                     $fieldName = $tableName . '.' . $fieldData['name'];
                     if ($counter == 0) {
                         $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, '%' . $search . '%', Criteria::LIKE);
                     } else {
                         $oTmpCriteria = $oNewCriteria->getNewCriterion($fieldName, '%' . $search . '%', Criteria::LIKE)->addOr($oTmpCriteria);
                     }
                     $counter++;
                 }
             }
             //add the default and hidden DEL_INIT_DATE
         }
         // the criteria adds new fields if there are defined PM Table Fields in the cases list
         if ($oTmpCriteria != '') {
             $Criteria->add($Criteria->getNewCriterion(AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($Criteria->getNewCriterion(AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($Criteria->getNewCriterion(AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE)->addOr($oTmpCriteria))));
         } else {
             $Criteria->add($Criteria->getNewCriterion(AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($Criteria->getNewCriterion(AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($Criteria->getNewCriterion(AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE))));
         }
         // the count query needs to be the normal criteria query if there are defined PM Table Fields in the cases list
         if ($oTmpCriteria != '') {
             $CriteriaCount = $Criteria;
         } else {
             $CriteriaCount->add($CriteriaCount->getNewCriterion(AppCacheViewPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($CriteriaCount->getNewCriterion(AppCacheViewPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr($CriteriaCount->getNewCriterion(AppCacheViewPeer::APP_NUMBER, $search, Criteria::LIKE))));
         }
     }
     // this is the optimal way or query to render the cases search list
     // fixing the bug related to the wrong data displayed in the list
     /*
     if ($action == 'search') {
         $oDatasetIndex = AppCacheViewPeer::doSelectRS( $Criteria );
         $oDatasetIndex->setFetchmode( ResultSet::FETCHMODE_ASSOC );
         $oDatasetIndex->next();
         $maxDelIndexList = array ();
         // a list of MAX_DEL_INDEXES is required in order to validate the right row
         while ($aRow = $oDatasetIndex->getRow()) {
             $maxDelIndexList[] = $aRow['MAX_DEL_INDEX'];
             $oDatasetIndex->next();
         }
         // adding the validation condition in order to get the right row using the group by sentence
         $Criteria->add( AppCacheViewPeer::DEL_INDEX, $maxDelIndexList, Criteria::IN );
         //
         //$params = array($maxDelIndexList);
     }
     */
     //here we count how many records exists for this criteria.
     //BUT there are some special cases, and if we dont optimize them the server will crash.
     $doCountAlreadyExecuted = false;
     //case 1. when the SEARCH action is selected and none filter, search criteria is defined,
     //we need to count using the table APPLICATION, because APP_CACHE_VIEW takes 3 seconds
     /*
     if ($action == 'search' && $filter == '' && $search == '' && $process == '' && $status == '' && $dateFrom == '' && $dateTo == '' && $category == '') {
         $totalCount = $oAppCache->getSearchAllCount();
         $doCountAlreadyExecuted = true;
     }
     if ($category != '') {
         $totalCount = $oAppCache->getSearchCountCriteria();
         $doCountAlreadyExecuted = true;
     }
     */
     if ($doCountAlreadyExecuted == false) {
         // in the case of reassign the distinct attribute shows a diferent count result comparing to the
         // original list
         //Check also $distinct in the method getListCounters(), this in AppCacheView.php
         $distinct = true;
         if ($action == "todo" || $action == "to_reassign" || $status == "TO_DO") {
             $distinct = false;
         }
         // first check if there is a PMTable defined within the list,
         // the issue that brokes the normal criteria query seems to be fixed
         if (isset($oAppCache->confCasesList['PMTable']) && !empty($oAppCache->confCasesList['PMTable'])) {
             // then
             $oAdditionalTables = AdditionalTablesPeer::retrieveByPK($oAppCache->confCasesList['PMTable']);
             $tableName = $oAdditionalTables->getAddTabName();
             $tableName = strtolower($tableName);
             $tableNameArray = explode('_', $tableName);
             foreach ($tableNameArray as $item) {
                 $newTableName[] = ucfirst($item);
             }
             $tableName = implode('', $newTableName);
             // so the pm table class can be invoqued from the pm table model clases
             if (!class_exists($tableName)) {
                 require_once PATH_DB . SYS_SYS . PATH_SEP . "classes" . PATH_SEP . $tableName . ".php";
             }
         }
         $totalCount = AppCacheViewPeer::doCount($CriteriaCount, $distinct);
     }
     //add sortable options
     if ($sort != '') {
         if ($dir == 'DESC') {
             $Criteria->addDescendingOrderByColumn($sort);
         } else {
             $Criteria->addAscendingOrderByColumn($sort);
         }
     }
     //limit the results according the interface
     $Criteria->setLimit($limit);
     $Criteria->setOffset($start);
     //execute the query
     $oDataset = AppCacheViewPeer::doSelectRS($Criteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $oDataset->next();
     $result = array();
     $result['totalCount'] = $totalCount;
     $rows = array();
     $aPriorities = array('1' => 'VL', '2' => 'L', '3' => 'N', '4' => 'H', '5' => 'VH');
     $index = $start;
     while ($aRow = $oDataset->getRow()) {
         //$aRow = $oAppCache->replaceRowUserData($aRow);
         /*
          * For participated cases, we want the last step in the case, not only the last step this user participated. To do that we get every case information again for the last step. (This could be solved by a subquery, but Propel might not support it and subqueries can be slower for larger
          * datasets).
          */
         /*if ($action == 'sent' || $action == 'search') {
                      $maxCriteria = new Criteria('workflow');
                      $maxCriteria->add(AppCacheViewPeer::APP_UID, $aRow['APP_UID'], Criteria::EQUAL);
                      $maxCriteria->addDescendingOrderByColumn(AppCacheViewPeer::DEL_INDEX);
                      $maxCriteria->setLimit(1);
         
                      $maxDataset = AppCacheViewPeer::doSelectRS( $maxCriteria );
                      $maxDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
                      $maxDataset->next();
         
                      $newData = $maxDataset->getRow();
                      foreach ($aRow as $col => $value) {
                      if (array_key_exists($col, $newData))
                      $aRow[$col] = $newData[$col];
                      }
         
                      $maxDataset->close();
                       }*/
         if (!isset($aRow['APP_CURRENT_USER'])) {
             $aRow['APP_CURRENT_USER'] = "******";
         }
         // replacing the status data with their respective translation
         if (isset($aRow['APP_STATUS'])) {
             $aRow['APP_STATUS'] = G::LoadTranslation("ID_{$aRow['APP_STATUS']}");
         }
         // replacing the priority data with their respective translation
         if (isset($aRow['DEL_PRIORITY'])) {
             $aRow['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}");
         }
         $rows[] = $aRow;
         $oDataset->next();
     }
     $result['data'] = $rows;
     return $result;
 }