public function getAll($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER') { $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 : ''; $user = isset($user) ? $user : ''; $status = isset($status) ? strtoupper($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"; //$userUid = ( isset($_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] != '' ) ? $_SESSION['USER_LOGGED'] : null; <-- passed by param $oAppCache = new AppCacheView(); //get data configuration $conf = new Configurations(); $confCasesList = $conf->getConfiguration('casesList', $action == 'search' || $action == 'simple_search' ? 'sent' : $action); // var_dump($confCasesList); $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); // var_dump($Criteria); break; case 'selfservice': case 'unassigned': $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(); 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(); $CriteriaCount = $oAppCache->getToReassignCountCriteria(); break; case 'all': $Criteria = $oAppCache->getAllCasesListCriteria($userUid); $CriteriaCount = $oAppCache->getAllCasesCountCriteria($userUid); break; // general criteria probably will be deprecated // general criteria probably will be deprecated case 'gral': $Criteria = $oAppCache->getGeneralListCriteria(); $CriteriaCount = $oAppCache->getGeneralCountCriteria(); break; case 'todo': default: $Criteria = $oAppCache->getToDoListCriteria($userUid); $CriteriaCount = $oAppCache->getToDoCountCriteria($userUid); break; } if (!is_array($confCasesList)) { $rows = $this->getDefaultFields($action); $result = $this->genericJsonResponse('', array(), $rows, 20, ''); //$conf->saveObject($result,'casesList',$action,'','',''); } // add the process filter if ($process != '') { $Criteria->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL); $CriteriaCount->add(AppCacheViewPeer::PRO_UID, $process, Criteria::EQUAL); } // 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); } } else { if ($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)))); } } //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 == '') { $totalCount = $oAppCache->getSearchAllCount(); $doCountAlreadyExecuted = true; } if ($doCountAlreadyExecuted == false) { // in the case of reassign the distinct attribute shows a diferent count result comparing to the // original list if ($action == 'to_reassign' || $action == 'todo') { $distinct = false; } else { $distinct = true; } // 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); /* // 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(); // 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 ); } */ //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; }