| @@ -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 | } |
| @@ -122,9 +124,9 @@ | ||
| 122 | 124 | |
| 123 | 125 | $this->db->where($where); |
| 124 | 126 | |
| 125 | 127 | if(wdk_get_option('wdk_sub_listings_enable')) { |
| 126 | - $this->db->where(array('listing_parent_post_id IS NULL'=>NULL)); | |
| 128 | + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL)); | |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | $this->db->order_by($this->_order_by); |
| 130 | 132 | |
| @@ -157,11 +159,12 @@ | ||
| 157 | 159 | } else { |
| 158 | 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'); |
| 159 | 161 | } |
| 160 | 162 | |
| 161 | - $this->db->from($this->_table_name); | |
| 162 | - $this->db->join($post_table.' ON '.$this->_table_name.'.post_id = '.$post_table.'.ID'); | |
| 163 | - $this->db->join($fields_table.' ON '.$this->_table_name.'.post_id = '.$fields_table.'.post_id'); | |
| 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'); | |
| 164 | 167 | |
| 165 | 168 | /* join cached user data */ |
| 166 | 169 | if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) { |
| 167 | 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'); |
| @@ -174,8 +177,10 @@ | ||
| 174 | 177 | /*for($i = 2 ; $i <= 2; $i++) { |
| 175 | 178 | $this->db->join($this->db->prefix.'wdk_locations AS location_'.$i.' ON location_'.($i-1).'.parent_id = location_'.$i.'.idlocation', NULL, 'LEFT'); |
| 176 | 179 | }*/ |
| 177 | 180 | |
| 181 | + $this->db->where($post_table.'.post_type = \'wdk-listing\'', NULL); | |
| 182 | + | |
| 178 | 183 | if(isset($where['is_activated'])) { |
| 179 | 184 | $where[$this->db->prefix.'wdk_listings`.`is_activated'] = $where['is_activated']; |
| 180 | 185 | unset($where['is_activated']); |
| 181 | 186 | } |
| @@ -253,9 +258,9 @@ | ||
| 253 | 258 | $this->db->where($where); |
| 254 | 259 | } |
| 255 | 260 | |
| 256 | 261 | if(wdk_get_option('wdk_sub_listings_enable')) { |
| 257 | - $this->db->where(array('listing_parent_post_id IS NULL'=>NULL)); | |
| 262 | + $this->db->where(array('(listing_parent_post_id IS NULL OR listing_parent_post_id = 0)'=>NULL)); | |
| 258 | 263 | } |
| 259 | 264 | |
| 260 | 265 | $this->db->limit($limit); |
| 261 | 266 | $this->db->offset($offset); |
| @@ -266,8 +271,10 @@ | ||
| 266 | 271 | |
| 267 | 272 | $this->_primary_key = 'post_id'; |
| 268 | 273 | $this->_order_by = 'post_id DESC'; |
| 269 | 274 | |
| 275 | + //echo $this->db->last_query(); | |
| 276 | + | |
| 270 | 277 | if ($this->db->num_rows() > 0) |
| 271 | 278 | return $this->db->results(); |
| 272 | 279 | |
| 273 | 280 | return array(); |
| @@ -327,9 +334,23 @@ | ||
| 327 | 334 | if(!$this->check_deletable($post_id, $user_id)) return false; |
| 328 | 335 | |
| 329 | 336 | $this->load->model('listingfield_m'); |
| 330 | 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'); | |
| 331 | 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 | + | |
| 332 | 353 | /* remove listing */ |
| 333 | 354 | parent::delete($post_id); |
| 334 | 355 | $this->listingfield_m->delete($post_id); |
| 335 | 356 | $this->listingusers_m->delete($post_id); |
| @@ -336,8 +357,12 @@ | ||
| 336 | 357 | |
| 337 | 358 | /* remove post */ |
| 338 | 359 | wp_delete_post($post_id, true); |
| 339 | 360 | |
| 361 | + // Delete listing images if setting enabled | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 340 | 365 | do_action('wpdirectorykit/model/listing/delete', $post_id); |
| 341 | 366 | |
| 342 | 367 | return true; |
| 343 | 368 | |
| @@ -366,8 +391,17 @@ | ||
| 366 | 391 | $counter = intval(wdk_field_value('counter_views', $listing_id)); |
| 367 | 392 | } |
| 368 | 393 | |
| 369 | 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); | |
| 370 | 404 | } |
| 371 | 405 | |
| 372 | 406 | } |
| 373 | 407 | ?> |