| @@ -14,13 +14,50 @@ | ||
| 14 | 14 | public $_timestamps = TRUE; |
| 15 | 15 | protected $_primary_filter = 'intval'; |
| 16 | 16 | public $form_admin = array(); |
| 17 | 17 | public $fields_list = NULL; |
| 18 | - | |
| 18 | + public $allowedOrderBy = array( | |
| 19 | + 'idcategory', | |
| 20 | + 'parent_id', | |
| 21 | + 'page_id', | |
| 22 | + 'lang_code', | |
| 23 | + 'date', | |
| 24 | + 'parent_path', | |
| 25 | + 'order_index', | |
| 26 | + 'level', | |
| 27 | + 'icon_id', | |
| 28 | + 'image_id', | |
| 29 | + 'font_icon_code', | |
| 30 | + 'code', | |
| 31 | + 'hubspot_id', | |
| 32 | + 'category_title', | |
| 33 | + 'marker_image_id', | |
| 34 | + 'level_0_id', | |
| 35 | + 'icon_path', | |
| 36 | + 'image_path', | |
| 37 | + 'marker_image_path', | |
| 38 | + 'category_color', | |
| 39 | + 'titles_for_search', | |
| 40 | + 'listings_counter' | |
| 41 | + ); | |
| 42 | + | |
| 19 | 43 | public function __construct(){ |
| 20 | 44 | parent::__construct(); |
| 45 | + | |
| 46 | + // Add allowedOrderBy with table + prefix format | |
| 47 | + $table_prefix = $this->db->prefix . $this->_table_name . '.'; | |
| 48 | + $updatedAllowedOrderBy = array(); | |
| 49 | + foreach ($this->allowedOrderBy as $col) { | |
| 50 | + $updatedAllowedOrderBy[] = $col; | |
| 51 | + $updatedAllowedOrderBy[] = $table_prefix . $col; | |
| 52 | + } | |
| 53 | + $this->allowedOrderBy = array_unique($updatedAllowedOrderBy); | |
| 21 | 54 | } |
| 22 | 55 | |
| 56 | + public function getAllowedOrderBy() { | |
| 57 | + return $this->allowedOrderBy; | |
| 58 | + } | |
| 59 | + | |
| 23 | 60 | /* [START] For dynamic data table */ |
| 24 | 61 | |
| 25 | 62 | public function get_available_fields() |
| 26 | 63 | { |
| @@ -58,8 +95,34 @@ | ||
| 58 | 95 | ('.$this->listing_m->_table_name.'.category_id = '.$this->_table_name.'.idcategory |
| 59 | 96 | OR '.$this->listing_m->_table_name.'.category_id = category_table.idcategory) |
| 60 | 97 | |
| 61 | 98 | )', TRUE, 'LEFT'); |
| 99 | + | |
| 100 | + $this->db->from($this->_table_name); | |
| 101 | + | |
| 102 | + $this->db->where($where); | |
| 103 | + $this->db->limit($limit); | |
| 104 | + $this->db->offset($offset); | |
| 105 | + | |
| 106 | + $this->db->group_by('idcategory'); | |
| 107 | + | |
| 108 | + if(!empty($order_by)){ | |
| 109 | + $this->db->order_by($order_by); | |
| 110 | + } else { | |
| 111 | + $this->db->order_by($this->_order_by); | |
| 112 | + } | |
| 113 | + | |
| 114 | + $query = $this->db->get(); | |
| 115 | + | |
| 116 | + if ($this->db->num_rows() > 0) | |
| 117 | + return $this->db->results(); | |
| 118 | + | |
| 119 | + return array(); | |
| 120 | + } | |
| 121 | + | |
| 122 | + public function get_pagination_simple($limit, $offset, $where = array(), $order_by = NULL) | |
| 123 | + { | |
| 124 | + $this->load->model('listing_m'); | |
| 62 | 125 | |
| 63 | 126 | $this->db->from($this->_table_name); |
| 64 | 127 | |
| 65 | 128 | $this->db->where($where); |