public function getListForTable() { $res = new responseGmp(); $res->ignoreShellData(); $count = $this->getModel()->getCount(); $listReqData = array('limitFrom' => reqGmp::getVar('iDisplayStart'), 'limitTo' => reqGmp::getVar('iDisplayLength')); $displayColumns = $this->getView()->getDisplayColumns(); $displayColumnsKeys = array_keys($displayColumns); $iSortCol = reqGmp::getVar('iSortCol_0'); if (!is_null($iSortCol) && is_numeric($iSortCol)) { $listReqData['orderBy'] = $displayColumns[$displayColumnsKeys[$iSortCol]]['db']; $iSortDir = reqGmp::getVar('sSortDir_0'); if (!is_null($iSortDir)) { $listReqData['orderBy'] .= ' ' . strtoupper($iSortDir); } } $search = reqGmp::getVar('sSearch'); if (!is_null($search) && !empty($search)) { $dbSearch = dbGmp::escape($search); $listReqData['additionalCondition'] = 'title LIKE "%' . $dbSearch . '%" OR description LIKE "%' . $dbSearch . '%"'; } $list = $this->getModel()->getAllMarkers($listReqData, true); $res->addData('aaData', $this->_convertDataForDatatable($list)); $res->addData('iTotalRecords', $count); $res->addData('iTotalDisplayRecords', $count); $res->addData('sEcho', reqGmp::getVar('sEcho')); $res->addMessage(__('Done')); return $res->ajaxExec(); }
/** * Common method for list table data */ public function getListForTbl() { $res = new responseGmp(); $res->ignoreShellData(); $model = $this->getModel(); $page = (int) reqGmp::getVar('page'); $rowsLimit = (int) reqGmp::getVar('rows'); $orderBy = reqGmp::getVar('sidx'); $sortOrder = reqGmp::getVar('sord'); // Our custom search $search = reqGmp::getVar('search'); if ($search && !empty($search) && is_array($search)) { foreach ($search as $k => $v) { $v = trim($v); if (empty($v)) { continue; } if ($k == 'text_like') { $v = $this->_prepareTextLikeSearch($v); if (!empty($v)) { $model->addWhere(array('additionalCondition' => $v)); } } else { $model->addWhere(array($k => $v)); } } } // jqGrid search $isSearch = reqGmp::getVar('_search'); if ($isSearch) { $searchField = trim(reqGmp::getVar('searchField')); $searchString = trim(reqGmp::getVar('searchString')); if (!empty($searchField) && !empty($searchString)) { // For some cases - we will need to modify search keys and/or values before put it to the model $model->addWhere(array($this->_prepareSearchField($searchField) => $this->_prepareSearchString($searchString))); } } $model = $this->_prepareModelBeforeListSelect($model); // Get total pages count for current request $totalCount = $model->getCount(array('clear' => array('selectFields'))); $totalPages = 0; if ($totalCount > 0) { $totalPages = ceil($totalCount / $rowsLimit); } if ($page > $totalPages) { $page = $totalPages; } // Calc limits - to get data only for current set $limitStart = $rowsLimit * $page - $rowsLimit; // do not put $limit*($page - 1) if ($limitStart < 0) { $limitStart = 0; } $data = $model->setLimit($limitStart . ', ' . $rowsLimit)->setOrderBy($this->_prepareSortOrder($orderBy))->setSortOrder($sortOrder)->getFromTbl(); $data = $this->_prepareListForTbl($data); $res->addData('page', $page); $res->addData('total', $totalPages); $res->addData('rows', $data); $res->addData('records', $model->getLastGetCount()); $res = dispatcherGmp::applyFilters($this->getCode() . '_getListForTblResults', $res); $res->ajaxExec(); }