PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
← All changes | application/models/Category_m.php +80 -3 1.1.6 → 1.5.9 View file →
@@ -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 {
@@ -49,13 +86,46 @@
49 86 public function get_pagination($limit, $offset, $where = array(), $order_by = NULL)
50 87 {
51 88 $this->load->model('listing_m');
52 89
53 - $this->db->select($this->_table_name.'.*, COUNT('.$this->listing_m->_table_name.'.post_id) AS listings_counter');
90 + $this->db->select($this->_table_name.'.*, COUNT(DISTINCT '.$this->listing_m->_table_name.'.post_id) AS listings_counter, MAX('.$this->_table_name.'.level) as level');
91 +
92 + $this->db->join($this->_table_name.' AS category_table ON (CONCAT(",", category_table.parent_path, ",") LIKE CONCAT("%,", '.$this->_table_name.'.idcategory ,",%"))', TRUE, 'LEFT');
93 + $this->db->join($this->listing_m->_table_name.' ON (
94 + ('.$this->listing_m->_table_name.'.is_activated = 1 AND '.$this->listing_m->_table_name.'.is_approved = 1) AND
95 + ('.$this->listing_m->_table_name.'.category_id = '.$this->_table_name.'.idcategory
96 + OR '.$this->listing_m->_table_name.'.category_id = category_table.idcategory)
97 +
98 + )', TRUE, 'LEFT');
99 +
54 100 $this->db->from($this->_table_name);
55 101
56 - $this->db->join($this->listing_m->_table_name.' ON '.$this->listing_m->_table_name.'.category_id = '.$this->_table_name.'.idcategory', TRUE, 'LEFT');
102 + $this->db->where($where);
103 + $this->db->limit($limit);
104 + $this->db->offset($offset);
57 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');
125 +
126 + $this->db->from($this->_table_name);
127 +
58 128 $this->db->where($where);
59 129 $this->db->limit($limit);
60 130 $this->db->offset($offset);
61 131
@@ -93,8 +163,9 @@
93 163
94 164 if($this->_timestamps === TRUE && !isset($data['date']))
95 165 $data['date'] = current_time( 'mysql' );
96 166
167 + $data['level_0_id'] = 0;
97 168 $data['level'] = 0;
98 169 $data['parent_path'] = '';
99 170
100 171 if(!empty($data['parent_id']))
@@ -104,8 +175,14 @@
104 175 if(isset($parent[0]))
105 176 {
106 177 $data['level'] = $parent[0]->level + 1;
107 178 $data['parent_path'] = $parent[0]->parent_path.(!empty($parent[0]->parent_path)?',':'').$parent[0]->idcategory;
179 +
180 + if(strpos($data['parent_path'], ',') !== FALSE) {
181 + $data['level_0_id'] = substr($data['parent_path'],0,strpos($data['parent_path'], ','));
182 + } else {
183 + $data['level_0_id'] = $data['parent_path'];
184 + }
108 185 }
109 186 }
110 187
111 188 if(empty($data['order_index']))