| @@ -90,22 +90,42 @@ | ||
| 90 | 90 | |
| 91 | 91 | return $list_with_keys; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - public function get_pagination($limit = NULL, $offset = NULL, $where = array(), $order_by = NULL, $like = "meta_value LIKE '%wdk_agent%'", $show_other_agents_litings = FALSE, $only_listings_assigned = FALSE) | |
| 94 | + public function get_pagination($limit = NULL, $offset = NULL, $where = array(), $order_by = NULL, $like = "meta_value LIKE '%wdk_agent%'", $show_other_agents_litings = FALSE, $only_listings_assigned = FALSE, $count_agency_listings_false = TRUE) | |
| 95 | 95 | { |
| 96 | 96 | $wp_usermeta_table = $this->_table_name_meta; |
| 97 | 97 | $this->load->model('listing_m'); |
| 98 | + $this->load->model('cachedusers_m'); | |
| 99 | + | |
| 98 | 100 | $alt_agents_table = $this->db->prefix.'wdk_listings_users'; |
| 101 | + $select_list = 'ID,user_login,user_nicename,user_email,display_name,user_status,user_url, COUNT('.$this->db->prefix.'wdk_listings.user_id_editor) AS listings_counter'; | |
| 99 | 102 | |
| 100 | - $this->db->select('ID,user_login,user_nicename,user_email,display_name,user_status,user_url, COUNT('.$this->db->prefix.'wdk_listings.user_id_editor) AS listings_counter'); | |
| 103 | + if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) { | |
| 104 | + $select_list .=','.$this->cachedusers_m->_table_name.'.*'; | |
| 105 | + } | |
| 106 | + | |
| 107 | + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php') && $count_agency_listings_false ) { | |
| 108 | + $select_list .=', SUM('.$this->db->prefix.'wdk_membership_agency_agent.listings_count) AS agency_listings_counter'; | |
| 109 | + } | |
| 110 | + | |
| 111 | + $this->db->select($select_list); | |
| 101 | 112 | $this->db->from($this->_table_name); |
| 102 | 113 | |
| 103 | 114 | $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); |
| 104 | - $this->db->join($this->listing_m->_table_name.' ON '.$this->listing_m->_table_name.'.user_id_editor = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 115 | + $this->db->join($this->listing_m->_table_name.' ON ('.$this->listing_m->_table_name.'.user_id_editor = '.$this->_table_name.'.ID AND ('.$this->listing_m->_table_name.'.is_activated = 1 AND '.$this->listing_m->_table_name.'.is_approved = 1))', TRUE, 'LEFT'); | |
| 105 | 116 | |
| 106 | 117 | $this->db->join($alt_agents_table.' ON '.$alt_agents_table.'.user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT'); |
| 107 | 118 | |
| 119 | + | |
| 120 | + if(function_exists('run_wdk_membership') && file_exists(WDK_MEMBERSHIP_PATH.'application/models/Agency_agent_m.php') && $count_agency_listings_false) { | |
| 121 | + $this->db->join($this->db->prefix.'wdk_membership_agency_agent ON ('.$this->db->prefix.'wdk_membership_agency_agent.agency_id = '.$this->_table_name.'.ID AND '.$this->db->prefix.'wdk_membership_agency_agent.status = "CONFIRMED")', TRUE, 'LEFT'); | |
| 122 | + } | |
| 123 | + | |
| 124 | + if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) { | |
| 125 | + $this->db->join($this->cachedusers_m->_table_name.' ON '.$this->cachedusers_m->_table_name.'.cacheduser_user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 126 | + } | |
| 127 | + | |
| 108 | 128 | $this->db->where($where); |
| 109 | 129 | $this->db->where('meta_key', $this->db->prefix.'capabilities'); |
| 110 | 130 | |
| 111 | 131 | |
| @@ -142,9 +162,9 @@ | ||
| 142 | 162 | $this->db->select('COUNT(DISTINCT ID) as total_count, COUNT('.$this->db->prefix.'wdk_listings.user_id_editor) AS listings_counter'); |
| 143 | 163 | $this->db->from($this->_table_name); |
| 144 | 164 | |
| 145 | 165 | $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); |
| 146 | - $this->db->join($this->listing_m->_table_name.' ON '.$this->listing_m->_table_name.'.user_id_editor = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 166 | + $this->db->join($this->listing_m->_table_name.' ON ('.$this->listing_m->_table_name.'.user_id_editor = '.$this->_table_name.'.ID AND ('.$this->listing_m->_table_name.'.is_activated = 1 AND '.$this->listing_m->_table_name.'.is_approved = 1) )', TRUE, 'LEFT'); | |
| 147 | 167 | |
| 148 | 168 | $this->db->where($where); |
| 149 | 169 | $this->db->where('meta_key', $this->db->prefix.'capabilities'); |
| 150 | 170 | |
| @@ -172,6 +192,66 @@ | ||
| 172 | 192 | $fields = $this->db->list_fields($this->_table_name); |
| 173 | 193 | |
| 174 | 194 | return $fields; |
| 175 | 195 | } |
| 196 | + | |
| 197 | + public function remove_user_data($user_id = NULL) { | |
| 198 | + if(empty($user_id)) return false; | |
| 199 | + | |
| 200 | + /* listings */ | |
| 201 | + $this->_remove_data_from('this', 'listing_m', 'user_id_editor', 'post_id', $user_id); | |
| 202 | + | |
| 203 | + /* favorites */ | |
| 204 | + $this->_remove_data_from('Winter_MVC_wdk_favorites', 'favorite_m', 'user_id', 'idfavorite', $user_id); | |
| 205 | + | |
| 206 | + /* reservation */ | |
| 207 | + $this->_remove_data_from('Winter_MVC_wdk_bookings', 'reservation_m', 'user_id', 'idreservation', $user_id); | |
| 208 | + | |
| 209 | + /* membership subscription user */ | |
| 210 | + $this->_remove_data_from('Winter_MVC_wdk_membership', 'subscription_user_m', 'user_id', 'idsubscription_user', $user_id); | |
| 211 | + | |
| 212 | + /* reviews */ | |
| 213 | + $this->_remove_data_from('Winter_MVC_wdk_reviews', 'reviews_m', 'user_id', 'idreviews', $user_id); | |
| 214 | + | |
| 215 | + /* save search */ | |
| 216 | + $this->_remove_data_from('Winter_MVC_wdk_save_search', 'save_search_m', 'user_id', 'idsave_search', $user_id); | |
| 217 | + | |
| 218 | + /* listing claim */ | |
| 219 | + $this->_remove_data_from('Winter_MVC_wdk_listing_claim', 'listing_claim_m', 'user_id', 'idlistingclaim', $user_id); | |
| 220 | + | |
| 221 | + /* report abuse */ | |
| 222 | + $this->_remove_data_from('Winter_MVC_wdk_report_abuse', 'report_abuse_m', 'user_id', 'idreportabuse', $user_id); | |
| 223 | + | |
| 224 | + /* messages */ | |
| 225 | + $this->_remove_data_from('this', 'messages_m', 'user_id_sender', 'idmessage', $user_id); | |
| 226 | + | |
| 227 | + return TRUE; | |
| 228 | + } | |
| 229 | + | |
| 230 | + | |
| 231 | + private function _remove_data_from($addon_object_name, $model_name, $user_column, $row_id, $user_id) { | |
| 232 | + | |
| 233 | + if($addon_object_name != 'this') | |
| 234 | + global ${$addon_object_name}; | |
| 235 | + | |
| 236 | + if($addon_object_name == 'this' || isset(${$addon_object_name})) { | |
| 237 | + if($addon_object_name != 'this') { | |
| 238 | + ${$addon_object_name}->model($model_name); | |
| 239 | + } else { | |
| 240 | + ${$addon_object_name}->load->model($model_name); | |
| 241 | + } | |
| 242 | + | |
| 243 | + $this->db->select('*'); | |
| 244 | + $this->db->where($user_column, $user_id); | |
| 245 | + $this->db->from(${$addon_object_name}->{$model_name}->_table_name); | |
| 246 | + $query = $this->db->get(); | |
| 247 | + if ($this->db->num_rows() > 0){ | |
| 248 | + foreach ($this->db->results() as $row) { | |
| 249 | + ${$addon_object_name}->{$model_name}->delete($row->{$row_id}, $user_id); | |
| 250 | + } | |
| 251 | + } | |
| 252 | + | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 176 | 256 | } |
| 177 | 257 | ?> |