@@ -7,151 +7,151 @@ |
||
7 | 7 | abstract class EE_Table_Base |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * This holds the table_name without the table prefix. |
|
12 | - * |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - public $_table_name; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * This holds what is used as the alias for the table in queries. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $_table_alias; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Table's private key column |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_pk_column; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Whether this table is a global table (in multisite) or specific to site. |
|
36 | - * |
|
37 | - * @var bool |
|
38 | - */ |
|
39 | - protected $_global; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $table_name with or without wpdb prefix |
|
44 | - * @param string $pk_column |
|
45 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
46 | - * install, or whether each site on a multisite install has a copy of this table |
|
47 | - * @global wpdb $wpdb |
|
48 | - */ |
|
49 | - public function __construct($table_name, $pk_column, $global = false) |
|
50 | - { |
|
51 | - $this->_global = $global; |
|
52 | - $prefix = $this->get_table_prefix(); |
|
53 | - // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
54 | - if (strpos($table_name, $prefix) === 0) { |
|
55 | - $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
56 | - } |
|
57 | - $this->_table_name = $table_name; |
|
58 | - $this->_pk_column = $pk_column; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * This returns the table prefix for the current model state. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - * @global wpdb $wpdb |
|
67 | - */ |
|
68 | - public function get_table_prefix() |
|
69 | - { |
|
70 | - global $wpdb; |
|
71 | - if ($this->_global) { |
|
72 | - return $wpdb->base_prefix; |
|
73 | - } |
|
74 | - return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Used to set the table_alias property |
|
80 | - * |
|
81 | - * @param string $table_alias |
|
82 | - */ |
|
83 | - public function _construct_finalize_with_alias($table_alias) |
|
84 | - { |
|
85 | - $this->_table_alias = $table_alias; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function get_table_name() |
|
95 | - { |
|
96 | - return $this->get_table_prefix() . $this->_table_name; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Provides what is currently set as the alias for the table to be used in queries. |
|
102 | - * |
|
103 | - * @return string |
|
104 | - * @throws EE_Error |
|
105 | - */ |
|
106 | - public function get_table_alias() |
|
107 | - { |
|
108 | - if (! $this->_table_alias) { |
|
109 | - throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
110 | - } |
|
111 | - return $this->_table_alias; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string name of column of PK |
|
117 | - */ |
|
118 | - public function get_pk_column() |
|
119 | - { |
|
120 | - return $this->_pk_column; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * returns a string with the table alias, a period, and the private key's column. |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function get_fully_qualified_pk_column() |
|
130 | - { |
|
131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * returns the special sql for a inner select with a limit. |
|
137 | - * |
|
138 | - * @return string SQL select |
|
139 | - */ |
|
140 | - public function get_select_join_limit($limit) |
|
141 | - { |
|
142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Returns whether or not htis is a global table (ie, on multisite there's |
|
149 | - * only one of these tables, on the main blog) |
|
150 | - * |
|
151 | - * @return boolean |
|
152 | - */ |
|
153 | - public function is_global() |
|
154 | - { |
|
155 | - return $this->_global; |
|
156 | - } |
|
10 | + /** |
|
11 | + * This holds the table_name without the table prefix. |
|
12 | + * |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + public $_table_name; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * This holds what is used as the alias for the table in queries. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $_table_alias; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Table's private key column |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_pk_column; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Whether this table is a global table (in multisite) or specific to site. |
|
36 | + * |
|
37 | + * @var bool |
|
38 | + */ |
|
39 | + protected $_global; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $table_name with or without wpdb prefix |
|
44 | + * @param string $pk_column |
|
45 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
46 | + * install, or whether each site on a multisite install has a copy of this table |
|
47 | + * @global wpdb $wpdb |
|
48 | + */ |
|
49 | + public function __construct($table_name, $pk_column, $global = false) |
|
50 | + { |
|
51 | + $this->_global = $global; |
|
52 | + $prefix = $this->get_table_prefix(); |
|
53 | + // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
54 | + if (strpos($table_name, $prefix) === 0) { |
|
55 | + $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
56 | + } |
|
57 | + $this->_table_name = $table_name; |
|
58 | + $this->_pk_column = $pk_column; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * This returns the table prefix for the current model state. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + * @global wpdb $wpdb |
|
67 | + */ |
|
68 | + public function get_table_prefix() |
|
69 | + { |
|
70 | + global $wpdb; |
|
71 | + if ($this->_global) { |
|
72 | + return $wpdb->base_prefix; |
|
73 | + } |
|
74 | + return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Used to set the table_alias property |
|
80 | + * |
|
81 | + * @param string $table_alias |
|
82 | + */ |
|
83 | + public function _construct_finalize_with_alias($table_alias) |
|
84 | + { |
|
85 | + $this->_table_alias = $table_alias; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function get_table_name() |
|
95 | + { |
|
96 | + return $this->get_table_prefix() . $this->_table_name; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Provides what is currently set as the alias for the table to be used in queries. |
|
102 | + * |
|
103 | + * @return string |
|
104 | + * @throws EE_Error |
|
105 | + */ |
|
106 | + public function get_table_alias() |
|
107 | + { |
|
108 | + if (! $this->_table_alias) { |
|
109 | + throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
110 | + } |
|
111 | + return $this->_table_alias; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string name of column of PK |
|
117 | + */ |
|
118 | + public function get_pk_column() |
|
119 | + { |
|
120 | + return $this->_pk_column; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * returns a string with the table alias, a period, and the private key's column. |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function get_fully_qualified_pk_column() |
|
130 | + { |
|
131 | + return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * returns the special sql for a inner select with a limit. |
|
137 | + * |
|
138 | + * @return string SQL select |
|
139 | + */ |
|
140 | + public function get_select_join_limit($limit) |
|
141 | + { |
|
142 | + $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | + return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Returns whether or not htis is a global table (ie, on multisite there's |
|
149 | + * only one of these tables, on the main blog) |
|
150 | + * |
|
151 | + * @return boolean |
|
152 | + */ |
|
153 | + public function is_global() |
|
154 | + { |
|
155 | + return $this->_global; |
|
156 | + } |
|
157 | 157 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function get_table_name() |
95 | 95 | { |
96 | - return $this->get_table_prefix() . $this->_table_name; |
|
96 | + return $this->get_table_prefix().$this->_table_name; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function get_table_alias() |
107 | 107 | { |
108 | - if (! $this->_table_alias) { |
|
108 | + if ( ! $this->_table_alias) { |
|
109 | 109 | throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
110 | 110 | } |
111 | 111 | return $this->_table_alias; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function get_fully_qualified_pk_column() |
130 | 130 | { |
131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
131 | + return $this->get_table_alias().".".$this->get_pk_column(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function get_select_join_limit($limit) |
141 | 141 | { |
142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
142 | + $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit; |
|
143 | + return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 |