PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / models / User_m.php

User_m.php in WP Directory Kit 1.2.4, at application/models/User_m.php

248 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8 class User_m extends Winter_MVC_Model {
9
10 public $_table_name = '';
11 public $_table_name_meta = '';
12 public $_order_by = 'user_nicename';
13 public $_primary_key = 'ID';
14 public $_own_columns = array();
15 public $_timestamps = TRUE;
16 protected $_primary_filter = 'intval';
17 public $form_admin = array();
18 public $fields_list = NULL;
19
20 public function __construct(){
21 parent::__construct();
22
23 global $wpdb;
24
25 $this->_table_name = $wpdb->users;
26 $this->_table_name_meta = $wpdb->usermeta;
27 }
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
56 public function get_agents($where = array(), $like = "meta_value LIKE '%wdk_agent%'")
57 {
58 $wp_usermeta_table = $this->_table_name_meta;
59
60 $this->db->select('*');
61 $this->db->from($this->_table_name);
62 $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id');
63 $this->db->where('meta_key', $this->db->prefix.'capabilities');
64 $this->db->where($where);
65 $this->db->like($like);
66
67 /*
68 if(!empty($or_like) && is_array($or_like)){
69 foreach($or_like as $key=>$value)
70 {
71 if(empty($value)) continue;
72 $this->db->or_like('meta_value', "%$value%");
73 }
74 }*/
75
76 $query = $this->get();
77
78 //$list_with_keys = array(0 => __('Root', 'wpdirectorykit'));
79 $list_with_keys = array();
80 if ($this->db->num_rows() > 0)
81 {
82 $results = $this->db->results();
83
84 foreach($results as $result)
85 {
86 $list_with_keys[$result->user_id] = $result->user_email.', '.$result->display_name;
87 }
88 }
89 //wmvc_dump($list_with_keys);
90
91 return $list_with_keys;
92 }
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)
95 {
96 $wp_usermeta_table = $this->_table_name_meta;
97 $this->load->model('listing_m');
98 $this->load->model('cachedusers_m');
99
100 $alt_agents_table = $this->db->prefix.'wdk_listings_users';
101
102 if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) {
103 $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,'.$this->cachedusers_m->_table_name.'.*');
104 } else {
105 $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');
106 }
107
108 $this->db->from($this->_table_name);
109
110 $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id');
111 $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');
112
113 $this->db->join($alt_agents_table.' ON '.$alt_agents_table.'.user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT');
114
115 if(defined( 'WDK_EXTENSIONS_CACHED_USERS_ACTIVATED' ) && WDK_EXTENSIONS_CACHED_USERS_ACTIVATED ) {
116 $this->db->join($this->cachedusers_m->_table_name.' ON '.$this->cachedusers_m->_table_name.'.cacheduser_user_id = '.$this->_table_name.'.ID', TRUE, 'LEFT');
117 }
118
119 $this->db->where($where);
120 $this->db->where('meta_key', $this->db->prefix.'capabilities');
121
122
123 if($only_listings_assigned) {
124 $this->db->where(array($this->db->prefix.'wdk_listings.user_id_editor != 0'=>NULL));
125 }
126
127 if(!empty($like))
128 $this->db->like($like);
129
130 $this->db->group_by('ID');
131
132 $this->db->limit($limit);
133 $this->db->offset($offset);
134
135 if(!empty($order_by)){
136 $this->db->order_by($order_by);
137 } else {
138 $this->db->order_by($this->_order_by);
139 }
140
141 $query = $this->db->get();
142
143 if ($this->db->num_rows() > 0)
144 return $this->db->results();
145
146 return array();
147 }
148
149 public function total($where = array(), $like = "meta_value LIKE '%wdk_agent%'", $only_listings_assigned = FALSE)
150 {
151 $wp_usermeta_table = $this->_table_name_meta;
152 $this->load->model('listing_m');
153 $this->db->select('COUNT(DISTINCT ID) as total_count, COUNT('.$this->db->prefix.'wdk_listings.user_id_editor) AS listings_counter');
154 $this->db->from($this->_table_name);
155
156 $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id');
157 $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');
158
159 $this->db->where($where);
160 $this->db->where('meta_key', $this->db->prefix.'capabilities');
161
162 if($only_listings_assigned) {
163 $this->db->where(array($this->db->prefix.'wdk_listings.user_id_editor != 0'=>NULL));
164 }
165
166 if(!empty($like))
167 $this->db->like($like);
168
169 $this->db->where($where);
170 $this->db->order_by($this->_order_by);
171 $query = $this->db->get();
172
173 $res = $this->db->results();
174
175 if(isset($res[0]->total_count))
176 return $res[0]->total_count;
177
178 return 0;
179 }
180
181 public function get_available_fields()
182 {
183 $fields = $this->db->list_fields($this->_table_name);
184
185 return $fields;
186 }
187
188 public function remove_user_data($user_id = NULL) {
189 if(empty($user_id)) return false;
190
191 /* listings */
192 $this->_remove_data_from('this', 'listing_m', 'user_id_editor', 'post_id', $user_id);
193
194 /* favorites */
195 $this->_remove_data_from('Winter_MVC_wdk_favorites', 'favorite_m', 'user_id', 'idfavorite', $user_id);
196
197 /* reservation */
198 $this->_remove_data_from('Winter_MVC_wdk_bookings', 'reservation_m', 'user_id', 'idreservation', $user_id);
199
200 /* membership subscription user */
201 $this->_remove_data_from('Winter_MVC_wdk_membership', 'subscription_user_m', 'user_id', 'idsubscription_user', $user_id);
202
203 /* reviews */
204 $this->_remove_data_from('Winter_MVC_wdk_reviews', 'reviews_m', 'user_id', 'idreviews', $user_id);
205
206 /* save search */
207 $this->_remove_data_from('Winter_MVC_wdk_save_search', 'save_search_m', 'user_id', 'idsave_search', $user_id);
208
209 /* listing claim */
210 $this->_remove_data_from('Winter_MVC_wdk_listing_claim', 'listing_claim_m', 'user_id', 'idlistingclaim', $user_id);
211
212 /* report abuse */
213 $this->_remove_data_from('Winter_MVC_wdk_report_abuse', 'report_abuse_m', 'user_id', 'idreportabuse', $user_id);
214
215 /* messages */
216 $this->_remove_data_from('this', 'messages_m', 'user_id_sender', 'idmessage', $user_id);
217
218 return TRUE;
219 }
220
221
222 private function _remove_data_from($addon_object_name, $model_name, $user_column, $row_id, $user_id) {
223
224 if($addon_object_name != 'this')
225 global ${$addon_object_name};
226
227 if($addon_object_name == 'this' || isset(${$addon_object_name})) {
228 if($addon_object_name != 'this') {
229 ${$addon_object_name}->model($model_name);
230 } else {
231 ${$addon_object_name}->load->model($model_name);
232 }
233
234 $this->db->select('*');
235 $this->db->where($user_column, $user_id);
236 $this->db->from(${$addon_object_name}->{$model_name}->_table_name);
237 $query = $this->db->get();
238 if ($this->db->num_rows() > 0){
239 foreach ($this->db->results() as $row) {
240 ${$addon_object_name}->{$model_name}->delete($row->{$row_id}, $user_id);
241 }
242 }
243
244 }
245 }
246
247 }
248 ?>