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/Listing_m.php +115 -21 1.1.6 → 1.5.9 View file →
@@ -38,13 +38,13 @@
38 38
39 39 $post_table = $this->db->prefix.'posts';
40 40 $fields_table = $this->db->prefix.'wdk_listings_fields';
41 41
42 - $this->db->select('COUNT(DISTINCT '.$this->db->prefix.'wdk_listings.post_id) as total_count');
43 - $this->db->from($this->_table_name);
44 -
45 - $this->db->join($post_table.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID');
46 - $this->db->join($fields_table.' ON '.$this->_table_name.'.post_id = '.$fields_table.'.post_id');
42 + $this->db->select('COUNT(DISTINCT '.$post_table.'.ID) as total_count');
43 + $this->db->from($post_table);
44 +
45 + $this->db->join($this->_table_name.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID', NULL, 'LEFT');
46 + $this->db->join($fields_table.' ON '.$post_table.'.ID = '.$fields_table.'.post_id', NULL, 'LEFT');
47 47
48 48 /* locations */
49 49 $this->db->join($this->db->prefix.'wdk_locations AS location_table ON '.$this->_table_name.'.location_id = location_table.idlocation', NULL, 'LEFT');
50 50 $this->db->join($this->db->prefix.'wdk_categories AS category_table ON '.$this->_table_name.'.category_id = category_table.idcategory', NULL, 'LEFT');
@@ -58,13 +58,15 @@
58 58
59 59 global $Winter_MVC_wdk_favorites;
60 60 if(!empty($user_id) && isset($Winter_MVC_wdk_favorites))
61 61 {
62 - $this->db->join($this->db->prefix.'wdk_favorite AS favorite_table ON '.$this->_table_name.'.post_id = favorite_table.post_id', NULL, 'LEFT');
62 + $this->db->join($this->db->prefix.'wdk_favorite AS favorite_table ON '.$post_table.'.ID = favorite_table.post_id', NULL, 'LEFT');
63 63 }
64 64
65 65 // [/Favorites join]
66 66
67 + $this->db->where($post_table.'.post_type = \'wdk-listing\'', NULL);
68 +
67 69 if(isset($where['is_activated'])){
68 70 $where[$this->db->prefix.'wdk_listings`.`is_activated'] = $where['is_activated'];
69 71 unset($where['is_activated']);
70 72 }
@@ -73,35 +75,60 @@
73 75 $where[$this->db->prefix.'wdk_listings`.`is_approved'] = $where['is_approved'];
74 76 unset($where['is_approved']);
75 77 }
76 78
77 - if( (!wmvc_user_in_role('administrator') && $user_check) || (!is_null($user_id) && !empty($user_id) && $user_check ) )
79 +
80 + if( (!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage') && $user_check) || (!is_null($user_id) && !empty($user_id) && $user_check ) )
78 81 {
79 82 if($show_other_agents_litings)
80 83 {
81 84 $this->db->join($this->db->prefix.'wdk_listings_users ON '.$this->_table_name.'.post_id = '.$this->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
85 +
86 + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
87 + $this->db->join($this->db->prefix.'wdk_membership_agency_agent ON
88 + ('.$this->db->prefix.'wdk_membership_agency_agent.agency_id = '.esc_sql($user_id).'
89 + AND '.$this->db->prefix.'wdk_membership_agency_agent.agent_id = `'.$this->db->prefix.'wdk_listings`.`user_id_editor` AND '.$this->db->prefix.'wdk_membership_agency_agent.status = "CONFIRMED")', NULL, 'LEFT');
90 + }
91 +
82 92 $this->db->distinct($this->_table_name.'.post_id');
93 +
94 + $user_check_id = NULL;
83 95 if(!is_null($user_id) && !empty($user_id))
84 96 {
85 - $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_id.' )'=>NULL));
97 + $user_check_id = $user_id;
86 98 }
87 99 elseif($this->current_user_id)
88 100 {
89 - $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$this->current_user_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$this->current_user_id.' )'=>NULL));
101 + $user_check_id = $this->current_user_id;
90 102 }
103 +
104 + if($user_check_id)
105 + {
106 + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
107 + $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_membership_agency_agent`.`agency_id` = '.$user_check_id.' )'=>NULL));
108 + } else {
109 + $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_check_id.' )'=>NULL));
110 + }
111 + }
112 +
91 113 } else {
92 114 if(!is_null($user_id) && !empty($user_id))
93 115 {
94 116 $this->db->where($this->db->prefix.'wdk_listings`.`user_id_editor', $user_id);
95 117 }
96 - elseif($this->current_user_id)
118 + elseif($this->current_user_id)
97 119 {
98 120 $this->db->where($this->db->prefix.'wdk_listings`.`user_id_editor', $this->current_user_id);
99 121 }
100 122 }
101 123 }
102 -
124 +
103 125 $this->db->where($where);
126 +
127 + if(wdk_get_option('wdk_sub_listings_enable')) {
128 + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL));
129 + }
130 +
104 131 $this->db->order_by($this->_order_by);
105 132
106 133 $query = $this->db->get();
107 134
@@ -117,8 +144,10 @@
117 144 }
118 145
119 146 public function get_pagination($limit, $offset, $where = array(), $user_check = FALSE, $user_id=NULL, $show_other_agents_litings = FALSE)
120 147 {
148 + $this->load->model('cachedusers_m');
149 +
121 150 $this->_primary_key = $this->db->prefix.'wdk_listings`.`post_id';
122 151 $this->_order_by = $this->db->prefix.'wdk_listings.post_id DESC';
123 152
124 153 $post_table = $this->db->prefix.'posts';
@@ -124,13 +153,24 @@
124 153 $post_table = $this->db->prefix.'posts';
125 154 $fields_table = $this->db->prefix.'wdk_listings_fields';
126 155
127 156
128 - $this->db->select($this->_table_name.'.*, '.$post_table.'.*,'.$fields_table.'.*,'.$fields_table.'.post_id AS fields_post_id');
129 - $this->db->from($this->_table_name);
130 - $this->db->join($post_table.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID');
131 - $this->db->join($fields_table.' ON '.$this->_table_name.'.post_id = '.$fields_table.'.post_id');
157 + if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) {
158 + $this->db->select($this->_table_name.'.*, '.$post_table.'.*,'.$fields_table.'.*,'.$fields_table.'.post_id AS fields_post_id, location_table.location_title, category_table.category_title,'.$this->cachedusers_m->_table_name.'.*');
159 + } else {
160 + $this->db->select($this->_table_name.'.*, '.$post_table.'.*,'.$fields_table.'.*,'.$fields_table.'.post_id AS fields_post_id, location_table.location_title, category_table.category_title');
161 + }
162 +
163 + $this->db->from($post_table);
164 +
165 + $this->db->join($this->_table_name.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID', NULL, 'LEFT');
166 + $this->db->join($fields_table.' ON '.$this->_table_name.'.post_id = '.$fields_table.'.post_id', NULL, 'LEFT');
132 167
168 + /* join cached user data */
169 + if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) {
170 + $this->db->join($this->cachedusers_m->_table_name.' ON '.$this->cachedusers_m->_table_name.'.cacheduser_user_id = '.$this->_table_name.'.user_id_editor', TRUE, 'LEFT');
171 + }
172 +
133 173 /* locations */
134 174 $this->db->join($this->db->prefix.'wdk_locations AS location_table ON '.$this->_table_name.'.location_id = location_table.idlocation', NULL, 'LEFT');
135 175 $this->db->join($this->db->prefix.'wdk_categories AS category_table ON '.$this->_table_name.'.category_id = category_table.idcategory', NULL, 'LEFT');
136 176 /* for parents search*/
@@ -137,8 +177,10 @@
137 177 /*for($i = 2 ; $i <= 2; $i++) {
138 178 $this->db->join($this->db->prefix.'wdk_locations AS location_'.$i.' ON location_'.($i-1).'.parent_id = location_'.$i.'.idlocation', NULL, 'LEFT');
139 179 }*/
140 180
181 + $this->db->where($post_table.'.post_type = \'wdk-listing\'', NULL);
182 +
141 183 if(isset($where['is_activated'])) {
142 184 $where[$this->db->prefix.'wdk_listings`.`is_activated'] = $where['is_activated'];
143 185 unset($where['is_activated']);
144 186 }
@@ -166,23 +208,41 @@
166 208 $this->db->join($this->db->prefix.'wdk_favorite AS favorite_table ON ('.$this->_table_name.'.post_id = favorite_table.post_id AND favorite_table.user_id = '.esc_sql($this->current_user_id).')', NULL, 'LEFT');
167 209 }
168 210 }
169 211
170 - // [/Favorites join]
171 - if( (!wmvc_user_in_role('administrator') && $user_check) || (!is_null($user_id) && !empty($user_id) && $user_check ) )
212 + if( (!wmvc_user_in_role('administrator') && !current_user_can('wdk_listings_manage') && $user_check) || (!is_null($user_id) && !empty($user_id) && $user_check ) )
172 213 {
173 214 if($show_other_agents_litings)
174 215 {
175 216 $this->db->join($this->db->prefix.'wdk_listings_users ON '.$this->_table_name.'.post_id = '.$this->db->prefix.'wdk_listings_users.post_id', NULL, 'LEFT');
217 +
218 + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
219 + $this->db->join($this->db->prefix.'wdk_membership_agency_agent ON
220 + ('.$this->db->prefix.'wdk_membership_agency_agent.agency_id = '.esc_sql($user_id).'
221 + AND '.$this->db->prefix.'wdk_membership_agency_agent.agent_id = `'.$this->db->prefix.'wdk_listings`.`user_id_editor` AND '.$this->db->prefix.'wdk_membership_agency_agent.status = "CONFIRMED")', NULL, 'LEFT');
222 + }
223 +
176 224 $this->db->distinct($this->_table_name.'.post_id');
225 +
226 + $user_check_id = NULL;
177 227 if(!is_null($user_id) && !empty($user_id))
178 228 {
179 - $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_id.' )'=>NULL));
229 + $user_check_id = $user_id;
180 230 }
181 231 elseif($this->current_user_id)
182 232 {
183 - $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$this->current_user_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$this->current_user_id.' )'=>NULL));
233 + $user_check_id = $this->current_user_id;
184 234 }
235 +
236 + if($user_check_id)
237 + {
238 + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php')) {
239 + $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_membership_agency_agent`.`agency_id` = '.$user_check_id.' )'=>NULL));
240 + } else {
241 + $this->db->where(array('(`'.$this->db->prefix.'wdk_listings`.`user_id_editor` = '.$user_check_id.' OR `'.$this->db->prefix.'wdk_listings_users`.`user_id` = '.$user_check_id.' )'=>NULL));
242 + }
243 + }
244 +
185 245 } else {
186 246 if(!is_null($user_id) && !empty($user_id))
187 247 {
188 248 $this->db->where($this->db->prefix.'wdk_listings`.`user_id_editor', $user_id);
@@ -197,8 +257,11 @@
197 257 } else {
198 258 $this->db->where($where);
199 259 }
200 260
261 + if(wdk_get_option('wdk_sub_listings_enable')) {
262 + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL));
263 + }
201 264
202 265 $this->db->limit($limit);
203 266 $this->db->offset($offset);
204 267
@@ -208,8 +271,10 @@
208 271
209 272 $this->_primary_key = 'post_id';
210 273 $this->_order_by = 'post_id DESC';
211 274
275 + //echo $this->db->last_query();
276 +
212 277 if ($this->db->num_rows() > 0)
213 278 return $this->db->results();
214 279
215 280 return array();
@@ -223,12 +288,14 @@
223 288
224 289 $post_table = $this->db->prefix.'posts';
225 290 $fields_table = $this->db->prefix.'wdk_listings_fields';
226 291
227 - $this->db->select($this->_table_name.'.*, '.$post_table.'.*,'.$fields_table.'.*,'.$fields_table.'.post_id AS fields_post_id');
292 + $this->db->select($this->_table_name.'.*, '.$post_table.'.*,'.$fields_table.'.*,'.$fields_table.'.post_id AS fields_post_id,location_table.location_title, category_table.category_title');
228 293 $this->db->from($this->_table_name);
229 294 $this->db->join($post_table.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID');
230 295 $this->db->join($fields_table.' ON '.$this->_table_name.'.post_id = '.$fields_table.'.post_id');
296 + $this->db->join($this->db->prefix.'wdk_locations AS location_table ON '.$this->listing_m->_table_name.'.location_id = location_table.idlocation', NULL, 'LEFT');
297 + $this->db->join($this->db->prefix.'wdk_categories AS category_table ON '.$this->listing_m->_table_name.'.category_id = category_table.idcategory', NULL, 'LEFT');
231 298
232 299 /*$query = $this->db->get();
233 300
234 301 if ($this->db->num_rows() > 0)
@@ -245,9 +312,9 @@
245 312 }
246 313
247 314 public function check_deletable($post_id, $user_id=NULL)
248 315 {
249 - if(wmvc_user_in_role('administrator')) return true;
316 + if(wmvc_user_in_role('administrator') || current_user_can('wdk_listings_manage')) return true;
250 317
251 318 $this->load->model('listing_m');
252 319 $listing = $this->listing_m->get($post_id, TRUE);
253 320
@@ -267,9 +334,23 @@
267 334 if(!$this->check_deletable($post_id, $user_id)) return false;
268 335
269 336 $this->load->model('listingfield_m');
270 337 $this->load->model('listingusers_m');
338 +
339 + /* remove images direct */
340 + if ( get_option('wdk_remove_direct_listing_images', false)) {
341 + global $Winter_MVC_WDK;
342 + $Winter_MVC_WDK->load_helper('listing');
271 343
344 + $listing_images = wdk_field_value('listing_images', $post_id);
345 + if(!empty($listing_images)) {
346 + $image_ids = explode(',', $listing_images);
347 + foreach ($image_ids as $key => $image_id) {
348 + wp_delete_attachment($image_id, true);
349 + }
350 + }
351 + }
352 +
272 353 /* remove listing */
273 354 parent::delete($post_id);
274 355 $this->listingfield_m->delete($post_id);
275 356 $this->listingusers_m->delete($post_id);
@@ -276,8 +357,12 @@
276 357
277 358 /* remove post */
278 359 wp_delete_post($post_id, true);
279 360
361 + // Delete listing images if setting enabled
362 +
363 +
364 +
280 365 do_action('wpdirectorykit/model/listing/delete', $post_id);
281 366
282 367 return true;
283 368
@@ -306,8 +391,17 @@
306 391 $counter = intval(wdk_field_value('counter_views', $listing_id));
307 392 }
308 393
309 394 $this->update(array('counter_views' => ++$counter), $listing_id);
395 + }
396 +
397 + public function update_listings_views($listing_ids = [], $increment = 1)
398 + {
399 + if(empty($listing_ids) )
400 + return false;
401 +
402 + $sql = 'UPDATE '.$this->_table_name.' SET `counter_results_views` = `counter_results_views`+'.$increment.' WHERE post_id IN ('.join(',', $listing_ids).')';
403 + $this->db->query($sql);
310 404 }
311 405
312 406 }
313 407 ?>