| @@ -6,9 +6,10 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | class User_m extends Winter_MVC_Model { |
| 9 | 9 | |
| 10 | - public $_table_name = 'wdk_locations'; | |
| 10 | + public $_table_name = ''; | |
| 11 | + public $_table_name_meta = ''; | |
| 11 | 12 | public $_order_by = 'user_nicename'; |
| 12 | 13 | public $_primary_key = 'ID'; |
| 13 | 14 | public $_own_columns = array(); |
| 14 | 15 | public $_timestamps = TRUE; |
| @@ -21,13 +22,41 @@ | ||
| 21 | 22 | |
| 22 | 23 | global $wpdb; |
| 23 | 24 | |
| 24 | 25 | $this->_table_name = $wpdb->users; |
| 26 | + $this->_table_name_meta = $wpdb->usermeta; | |
| 25 | 27 | } |
| 26 | 28 | |
| 29 | + public function get_agents_names($where = array(), $like = "meta_value LIKE '%wdk_agent%'") | |
| 30 | + { | |
| 31 | + $wp_usermeta_table = $this->_table_name_meta; | |
| 32 | + | |
| 33 | + $this->db->select('*'); | |
| 34 | + $this->db->from($this->_table_name); | |
| 35 | + $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); | |
| 36 | + $this->db->where('meta_key', $this->db->prefix.'capabilities'); | |
| 37 | + $this->db->where($where); | |
| 38 | + $this->db->like($like); | |
| 39 | + | |
| 40 | + $query = $this->get(); | |
| 41 | + | |
| 42 | + $list_with_keys = array(); | |
| 43 | + if ($this->db->num_rows() > 0) | |
| 44 | + { | |
| 45 | + $results = $this->db->results(); | |
| 46 | + | |
| 47 | + foreach($results as $result) | |
| 48 | + { | |
| 49 | + $list_with_keys[$result->user_id] = '#'.$result->ID.', '.$result->display_name; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 53 | + return $list_with_keys; | |
| 54 | + } | |
| 55 | + | |
| 27 | 56 | public function get_agents($where = array(), $like = "meta_value LIKE '%wdk_agent%'") |
| 28 | 57 | { |
| 29 | - $wp_usermeta_table = $this->db->prefix.'usermeta'; | |
| 58 | + $wp_usermeta_table = $this->_table_name_meta; | |
| 30 | 59 | |
| 31 | 60 | $this->db->select('*'); |
| 32 | 61 | $this->db->from($this->_table_name); |
| 33 | 62 | $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); |
| @@ -61,25 +90,50 @@ | ||
| 61 | 90 | |
| 62 | 91 | return $list_with_keys; |
| 63 | 92 | } |
| 64 | 93 | |
| 65 | - public function get_pagination($limit = NULL, $offset = NULL, $where = array(), $order_by = NULL, $like = "meta_value LIKE '%wdk_agent%'") | |
| 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) | |
| 66 | 95 | { |
| 67 | - $wp_usermeta_table = $this->db->prefix.'usermeta'; | |
| 68 | - $this->load->model('listingusers_m'); | |
| 96 | + $wp_usermeta_table = $this->_table_name_meta; | |
| 69 | 97 | $this->load->model('listing_m'); |
| 70 | - $fields_table = $this->db->prefix.'wdk_listings_users'; | |
| 98 | + $this->load->model('cachedusers_m'); | |
| 99 | + | |
| 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'; | |
| 71 | 102 | |
| 72 | - $this->db->select('ID,user_login,user_nicename,user_email,display_name,user_status,user_url, COUNT('.$this->db->prefix.'wdk_listings_users.user_id) 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); | |
| 73 | 112 | $this->db->from($this->_table_name); |
| 74 | 113 | |
| 75 | 114 | $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); |
| 76 | - $this->db->join($this->listingusers_m->_table_name.' ON '.$this->listingusers_m->_table_name.'.user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 77 | - $this->db->join($this->listing_m->_table_name.' ON '.$this->listing_m->_table_name.'.post_id = '.$this->listingusers_m->_table_name.'.post_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'); | |
| 78 | 116 | |
| 117 | + $this->db->join($alt_agents_table.' ON '.$alt_agents_table.'.user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 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 | + | |
| 79 | 128 | $this->db->where($where); |
| 80 | 129 | $this->db->where('meta_key', $this->db->prefix.'capabilities'); |
| 81 | 130 | |
| 131 | + | |
| 132 | + if($only_listings_assigned) { | |
| 133 | + $this->db->where(array($this->db->prefix.'wdk_listings.user_id_editor != 0'=>NULL)); | |
| 134 | + } | |
| 135 | + | |
| 82 | 136 | if(!empty($like)) |
| 83 | 137 | $this->db->like($like); |
| 84 | 138 | |
| 85 | 139 | $this->db->group_by('ID'); |
| @@ -93,9 +147,9 @@ | ||
| 93 | 147 | $this->db->order_by($this->_order_by); |
| 94 | 148 | } |
| 95 | 149 | |
| 96 | 150 | $query = $this->db->get(); |
| 97 | - | |
| 151 | + | |
| 98 | 152 | if ($this->db->num_rows() > 0) |
| 99 | 153 | return $this->db->results(); |
| 100 | 154 | |
| 101 | 155 | return array(); |
| @@ -100,23 +154,25 @@ | ||
| 100 | 154 | |
| 101 | 155 | return array(); |
| 102 | 156 | } |
| 103 | 157 | |
| 104 | - public function total($where = array(), $like = "meta_value LIKE '%wdk_agent%'") | |
| 158 | + public function total($where = array(), $like = "meta_value LIKE '%wdk_agent%'", $only_listings_assigned = FALSE) | |
| 105 | 159 | { |
| 106 | - $wp_usermeta_table = $this->db->prefix.'usermeta'; | |
| 107 | - $this->load->model('listingusers_m'); | |
| 160 | + $wp_usermeta_table = $this->_table_name_meta; | |
| 108 | 161 | $this->load->model('listing_m'); |
| 109 | - $this->db->select('COUNT(DISTINCT ID) as total_count'); | |
| 162 | + $this->db->select('COUNT(DISTINCT ID) as total_count, COUNT('.$this->db->prefix.'wdk_listings.user_id_editor) AS listings_counter'); | |
| 110 | 163 | $this->db->from($this->_table_name); |
| 111 | 164 | |
| 112 | 165 | $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id'); |
| 113 | - $this->db->join($this->listingusers_m->_table_name.' ON '.$this->listingusers_m->_table_name.'.user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT'); | |
| 114 | - $this->db->join($this->listing_m->_table_name.' ON '.$this->listing_m->_table_name.'.post_id = '.$this->listingusers_m->_table_name.'.post_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'); | |
| 115 | 167 | |
| 116 | 168 | $this->db->where($where); |
| 117 | 169 | $this->db->where('meta_key', $this->db->prefix.'capabilities'); |
| 118 | 170 | |
| 171 | + if($only_listings_assigned) { | |
| 172 | + $this->db->where(array($this->db->prefix.'wdk_listings.user_id_editor != 0'=>NULL)); | |
| 173 | + } | |
| 174 | + | |
| 119 | 175 | if(!empty($like)) |
| 120 | 176 | $this->db->like($like); |
| 121 | 177 | |
| 122 | 178 | $this->db->where($where); |
| @@ -136,6 +192,66 @@ | ||
| 136 | 192 | $fields = $this->db->list_fields($this->_table_name); |
| 137 | 193 | |
| 138 | 194 | return $fields; |
| 139 | 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 | + | |
| 140 | 256 | } |
| 141 | 257 | ?> |