PluginProbe
WP Directory Kit / 1.1.0
WP Directory Kit v1.1.0
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.1.0, at application/models/User_m.php

141 lines 4.8 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 = 'wdk_locations';
11 public $_order_by = 'user_nicename';
12 public $_primary_key = 'ID';
13 public $_own_columns = array();
14 public $_timestamps = TRUE;
15 protected $_primary_filter = 'intval';
16 public $form_admin = array();
17 public $fields_list = NULL;
18
19 public function __construct(){
20 parent::__construct();
21
22 global $wpdb;
23
24 $this->_table_name = $wpdb->users;
25 }
26
27 public function get_agents($where = array(), $like = "meta_value LIKE '%wdk_agent%'")
28 {
29 $wp_usermeta_table = $this->db->prefix.'usermeta';
30
31 $this->db->select('*');
32 $this->db->from($this->_table_name);
33 $this->db->join($wp_usermeta_table.' ON '.$this->_table_name.'.ID = '.$wp_usermeta_table.'.user_id');
34 $this->db->where('meta_key', $this->db->prefix.'capabilities');
35 $this->db->where($where);
36 $this->db->like($like);
37
38 /*
39 if(!empty($or_like) && is_array($or_like)){
40 foreach($or_like as $key=>$value)
41 {
42 if(empty($value)) continue;
43 $this->db->or_like('meta_value', "%$value%");
44 }
45 }*/
46
47 $query = $this->get();
48
49 //$list_with_keys = array(0 => __('Root', 'wpdirectorykit'));
50 $list_with_keys = array();
51 if ($this->db->num_rows() > 0)
52 {
53 $results = $this->db->results();
54
55 foreach($results as $result)
56 {
57 $list_with_keys[$result->user_id] = $result->user_email.', '.$result->display_name;
58 }
59 }
60 //wmvc_dump($list_with_keys);
61
62 return $list_with_keys;
63 }
64
65 public function get_pagination($limit = NULL, $offset = NULL, $where = array(), $order_by = NULL, $like = "meta_value LIKE '%wdk_agent%'")
66 {
67 $wp_usermeta_table = $this->db->prefix.'usermeta';
68 $this->load->model('listingusers_m');
69 $this->load->model('listing_m');
70 $fields_table = $this->db->prefix.'wdk_listings_users';
71
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');
73 $this->db->from($this->_table_name);
74
75 $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');
78
79 $this->db->where($where);
80 $this->db->where('meta_key', $this->db->prefix.'capabilities');
81
82 if(!empty($like))
83 $this->db->like($like);
84
85 $this->db->group_by('ID');
86
87 $this->db->limit($limit);
88 $this->db->offset($offset);
89
90 if(!empty($order_by)){
91 $this->db->order_by($order_by);
92 } else {
93 $this->db->order_by($this->_order_by);
94 }
95
96 $query = $this->db->get();
97
98 if ($this->db->num_rows() > 0)
99 return $this->db->results();
100
101 return array();
102 }
103
104 public function total($where = array(), $like = "meta_value LIKE '%wdk_agent%'")
105 {
106 $wp_usermeta_table = $this->db->prefix.'usermeta';
107 $this->load->model('listingusers_m');
108 $this->load->model('listing_m');
109 $this->db->select('COUNT(DISTINCT ID) as total_count');
110 $this->db->from($this->_table_name);
111
112 $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');
115
116 $this->db->where($where);
117 $this->db->where('meta_key', $this->db->prefix.'capabilities');
118
119 if(!empty($like))
120 $this->db->like($like);
121
122 $this->db->where($where);
123 $this->db->order_by($this->_order_by);
124 $query = $this->db->get();
125
126 $res = $this->db->results();
127
128 if(isset($res[0]->total_count))
129 return $res[0]->total_count;
130
131 return 0;
132 }
133
134 public function get_available_fields()
135 {
136 $fields = $this->db->list_fields($this->_table_name);
137
138 return $fields;
139 }
140 }
141 ?>