function action_list($limit, $page, $sorter, $search, $filters) { $pk = self::pk(); $table_alias = "g"; $table = self::table(); $select_field = "{$table_alias}.*,{$table_alias}.{$pk} as `key`,c.cat_name"; $limit = empty($limit) ? 10 : intval($limit); $page = empty($page) ? 1 : intval($page); $condition = array(); if (!empty($search)) { self::_debug($search); $condition = json_decode($search, 1); } self::_debug($condition); if (!empty($filters)) { $filters = json_decode($filters, 1); self::_debug($filters); $condition = array_merge($condition, $filters); } self::_debug($condition); $where = 'where 1 = 1'; $args = array(); if (!empty($condition['god_name'])) { $where .= " and {$table_alias}.god_name like ?"; $args[] = "%" . $condition['stf_name'] . "%"; } $count_res = self::_db()->select_row("SELECT COUNT({$table_alias}.god_id) AS total FROM {$table} as g {$where}", $args); $records = $count_res['total']; $total_pages = $records > 0 ? ceil($records / $limit) : 1; $skip = ($page - 1) * $limit; $sorter_order_tpl = array("ascend" => "asc", "descend" => "desc"); if (!empty($sorter)) { $sorter = json_decode($sorter, 1); } $sorter_field_tpl = array("ord"); $sort_field = !empty($sorter['field']) && in_array($sorter['field'], $sorter_field_tpl) ? $sorter['field'] : $table_alias . "." . $pk; $sort_order = !empty($sorter['order']) && !empty($sorter_order_tpl[$sorter['order']]) ? $sorter_order_tpl[$sorter['order']] : "desc"; $order = "ORDER BY {$sort_field} {$sort_order}"; $left_join = self::get_join_sql(); $sql = "SELECT {$select_field} FROM {$table} as {$table_alias} {$left_join} {$where} {$order} LIMIT {$skip},{$limit} "; //self::_debug($sql); $rows = self::_db()->rows($sql, $args); $cats = \Controller\Admin\Ec\Category::getRows(); $res = array("total" => $records, "page" => $page, "total_pages" => $total_pages, "limit" => $limit, "skip" => $skip, "rows" => $rows, "cats" => $cats); if (!self::is_production()) { $res['debug'] = array("sql" => $sql, "args" => $args, "params" => array($limit, $page, $sorter, $search, $filters, $condition)); } return $res; }