@@ -9,17 +9,49 @@ discard block |
||
9 | 9 | |
10 | 10 | interface WordPoints_HierarchyI { |
11 | 11 | public function get(); |
12 | + |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + */ |
|
12 | 16 | public function push( $field, $data ); |
17 | + |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
13 | 21 | public function pop(); |
14 | 22 | public function set_field( $field, $value ); |
23 | + |
|
24 | + /** |
|
25 | + * @param string $field |
|
26 | + * @param string $sub |
|
27 | + * @param string $sub_2 |
|
28 | + */ |
|
15 | 29 | public function get_field( $field, $sub = null, $sub_2 = null ); |
16 | 30 | public function get_id(); |
17 | 31 | public function go_to( $id ); |
32 | + |
|
33 | + /** |
|
34 | + * @param string $field |
|
35 | + * |
|
36 | + * @return void |
|
37 | + */ |
|
18 | 38 | public function push_to( $field, $value ); |
39 | + |
|
40 | + /** |
|
41 | + * @return boolean |
|
42 | + */ |
|
19 | 43 | public function ascend(); |
44 | + |
|
45 | + /** |
|
46 | + * @return boolean |
|
47 | + */ |
|
20 | 48 | public function descend( $to = null ); |
21 | 49 | public function is_main(); |
22 | 50 | public function next(); |
51 | + |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
23 | 55 | public function reset(); |
24 | 56 | } |
25 | 57 | |
@@ -134,6 +166,9 @@ discard block |
||
134 | 166 | protected $current = 0; |
135 | 167 | protected $i = 0; |
136 | 168 | |
169 | + /** |
|
170 | + * @param string $descendant_index |
|
171 | + */ |
|
137 | 172 | public function __construct( $descendant_index ) { |
138 | 173 | $this->descendant_index = $descendant_index; |
139 | 174 | } |
@@ -196,10 +231,16 @@ discard block |
||
196 | 231 | $this->current = 0; |
197 | 232 | } |
198 | 233 | |
234 | + /** |
|
235 | + * @param string $field |
|
236 | + */ |
|
199 | 237 | public function set_field( $field, $value ) { |
200 | 238 | $this->hierarchy[ $this->current ][ $field ] = $value; |
201 | 239 | } |
202 | 240 | |
241 | + /** |
|
242 | + * @param string $field |
|
243 | + */ |
|
203 | 244 | public function get_field( $field, $sub = null, $sub_2 = null ) { |
204 | 245 | |
205 | 246 | if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
@@ -225,6 +266,9 @@ discard block |
||
225 | 266 | return $this->hierarchy[ $this->current ][ $field ]; |
226 | 267 | } |
227 | 268 | |
269 | + /** |
|
270 | + * @param string $field |
|
271 | + */ |
|
228 | 272 | public function push_to( $field, $value ) { |
229 | 273 | |
230 | 274 | if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
@@ -9,15 +9,15 @@ discard block |
||
9 | 9 | |
10 | 10 | interface WordPoints_HierarchyI { |
11 | 11 | public function get(); |
12 | - public function push( $field, $data ); |
|
12 | + public function push($field, $data); |
|
13 | 13 | public function pop(); |
14 | - public function set_field( $field, $value ); |
|
15 | - public function get_field( $field, $sub = null, $sub_2 = null ); |
|
14 | + public function set_field($field, $value); |
|
15 | + public function get_field($field, $sub = null, $sub_2 = null); |
|
16 | 16 | public function get_id(); |
17 | - public function go_to( $id ); |
|
18 | - public function push_to( $field, $value ); |
|
17 | + public function go_to($id); |
|
18 | + public function push_to($field, $value); |
|
19 | 19 | public function ascend(); |
20 | - public function descend( $to = null ); |
|
20 | + public function descend($to = null); |
|
21 | 21 | public function is_main(); |
22 | 22 | public function next(); |
23 | 23 | public function reset(); |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | protected $descendant_index; |
32 | 32 | |
33 | 33 | public function __construct() { |
34 | - $this->current =& $this->hierarchy; |
|
34 | + $this->current = & $this->hierarchy; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function get() { |
38 | 38 | return $this->hierarchy; |
39 | 39 | } |
40 | 40 | |
41 | - public function push( $field, $data ) { |
|
41 | + public function push($field, $data) { |
|
42 | 42 | |
43 | - if ( ! isset( $this->current['slug'] ) || $this->current['slug'] !== $field ) { |
|
43 | + if ( ! isset($this->current['slug']) || $this->current['slug'] !== $field) { |
|
44 | 44 | |
45 | - if ( ! empty( $this->hierarchy ) ) { |
|
46 | - $this->current[ $this->descendant_index ][ $field ] = $data; |
|
47 | - $this->current =& $this->current[ $this->descendant_index ][ $field ]; |
|
45 | + if ( ! empty($this->hierarchy)) { |
|
46 | + $this->current[$this->descendant_index][$field] = $data; |
|
47 | + $this->current = & $this->current[$this->descendant_index][$field]; |
|
48 | 48 | } else { |
49 | 49 | $this->current = $this->stack[0] = $data; |
50 | 50 | } |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | |
58 | 58 | public function pop() { |
59 | 59 | |
60 | - unset( $this->current ); |
|
60 | + unset($this->current); |
|
61 | 61 | |
62 | - $this->current = array_pop( $this->stack ); |
|
62 | + $this->current = array_pop($this->stack); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function reset() { |
66 | 66 | // unset( $this->current_arg ); |
67 | - $this->current =& $this->hierarchy; |
|
67 | + $this->current = & $this->hierarchy; |
|
68 | 68 | $this->stack = array(); |
69 | 69 | } |
70 | 70 | |
@@ -80,30 +80,30 @@ discard block |
||
80 | 80 | // return $this->current[ $field ]; |
81 | 81 | // } |
82 | 82 | |
83 | - public function push_to( $field, $value ) { |
|
83 | + public function push_to($field, $value) { |
|
84 | 84 | |
85 | - if ( ! isset( $this->current[ $field ] ) ) { |
|
85 | + if ( ! isset($this->current[$field])) { |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | //var_dump( $field, $value,$this->current[ $field ] ); |
89 | - $this->current[ $field ][] = $value; |
|
89 | + $this->current[$field][] = $value; |
|
90 | 90 | } |
91 | 91 | |
92 | - public function set_sub_field( $slug, $field, $value ) { |
|
93 | - $this->current[ $this->descendant_index ][ $slug ][ $field ] = $value; |
|
92 | + public function set_sub_field($slug, $field, $value) { |
|
93 | + $this->current[$this->descendant_index][$slug][$field] = $value; |
|
94 | 94 | } |
95 | 95 | |
96 | - public function get_sub_field( $slug, $field ) { |
|
97 | - return $this->current[ $this->descendant_index ][ $slug ][ $field ]; |
|
96 | + public function get_sub_field($slug, $field) { |
|
97 | + return $this->current[$this->descendant_index][$slug][$field]; |
|
98 | 98 | } |
99 | 99 | |
100 | - public function get_sub_data( $slug ) { |
|
101 | - return $this->current[ $this->descendant_index ][ $slug ]; |
|
100 | + public function get_sub_data($slug) { |
|
101 | + return $this->current[$this->descendant_index][$slug]; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function ascend() { |
105 | 105 | |
106 | - if ( ! $this->stack ) { |
|
106 | + if ( ! $this->stack) { |
|
107 | 107 | return false; |
108 | 108 | } |
109 | 109 | |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - public function descend( $to = null ) { |
|
115 | + public function descend($to = null) { |
|
116 | 116 | |
117 | - if ( ! isset( $this->hierarchy[ $this->descendant_index ] ) ) { |
|
117 | + if ( ! isset($this->hierarchy[$this->descendant_index])) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - reset( $this->current[ $this->descendant_index ] ); |
|
122 | - $field = key( $this->current[ $this->descendant_index ] ); |
|
123 | - $this->current =& $this->current[ $this->descendant_index ][ $field ]; |
|
121 | + reset($this->current[$this->descendant_index]); |
|
122 | + $field = key($this->current[$this->descendant_index]); |
|
123 | + $this->current = & $this->current[$this->descendant_index][$field]; |
|
124 | 124 | |
125 | 125 | $this->stack[] = $this->current; |
126 | 126 | |
@@ -134,52 +134,52 @@ discard block |
||
134 | 134 | protected $current = 0; |
135 | 135 | protected $i = 0; |
136 | 136 | |
137 | - public function __construct( $descendant_index ) { |
|
137 | + public function __construct($descendant_index) { |
|
138 | 138 | $this->descendant_index = $descendant_index; |
139 | 139 | } |
140 | 140 | |
141 | 141 | public function get() { |
142 | 142 | // var_dump( $this->hierarchy ); |
143 | 143 | |
144 | - if ( empty( $this->hierarchy ) ) { |
|
144 | + if (empty($this->hierarchy)) { |
|
145 | 145 | return array(); |
146 | 146 | } |
147 | 147 | |
148 | - return $this->build_hierarchy( $this->hierarchy[0] ); |
|
148 | + return $this->build_hierarchy($this->hierarchy[0]); |
|
149 | 149 | } |
150 | 150 | |
151 | - protected function build_hierarchy( $arg ) { |
|
151 | + protected function build_hierarchy($arg) { |
|
152 | 152 | |
153 | - if ( isset( $arg[ $this->descendant_index ] ) ) { |
|
153 | + if (isset($arg[$this->descendant_index])) { |
|
154 | 154 | |
155 | - foreach ( $arg[ $this->descendant_index ] as $sub_arg => $i ) { |
|
156 | - $arg[ $this->descendant_index ][ $sub_arg ] = $this->build_hierarchy( $this->hierarchy[ $i ] ); |
|
155 | + foreach ($arg[$this->descendant_index] as $sub_arg => $i) { |
|
156 | + $arg[$this->descendant_index][$sub_arg] = $this->build_hierarchy($this->hierarchy[$i]); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - if ( isset( $arg['_parent'] ) ) { |
|
161 | - unset( $arg['_parent'] ); |
|
160 | + if (isset($arg['_parent'])) { |
|
161 | + unset($arg['_parent']); |
|
162 | 162 | } |
163 | 163 | |
164 | - unset( $arg['_i'] ); |
|
164 | + unset($arg['_i']); |
|
165 | 165 | |
166 | 166 | return $arg; |
167 | 167 | } |
168 | 168 | |
169 | - public function push( $field, $data ) { |
|
169 | + public function push($field, $data) { |
|
170 | 170 | |
171 | - if ( ! isset( $this->hierarchy[ $this->current ]['slug'] ) || $this->hierarchy[ $this->current ]['slug'] !== $field ) { |
|
171 | + if ( ! isset($this->hierarchy[$this->current]['slug']) || $this->hierarchy[$this->current]['slug'] !== $field) { |
|
172 | 172 | |
173 | 173 | $i = $this->i++; |
174 | 174 | |
175 | - if ( ! empty( $this->hierarchy ) ) { |
|
176 | - $this->hierarchy[ $this->current ][ $this->descendant_index ][ $field ] = $i; |
|
175 | + if ( ! empty($this->hierarchy)) { |
|
176 | + $this->hierarchy[$this->current][$this->descendant_index][$field] = $i; |
|
177 | 177 | $data['_parent'] = $this->current; |
178 | 178 | } |
179 | 179 | |
180 | - $this->hierarchy[ $i ] = $data; |
|
181 | - $this->hierarchy[ $i ]['slug'] = $field; |
|
182 | - $this->hierarchy[ $i ]['_i'] = $i; |
|
180 | + $this->hierarchy[$i] = $data; |
|
181 | + $this->hierarchy[$i]['slug'] = $field; |
|
182 | + $this->hierarchy[$i]['_i'] = $i; |
|
183 | 183 | |
184 | 184 | $this->current = $i; |
185 | 185 | } |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | |
188 | 188 | public function pop() { |
189 | 189 | |
190 | - $this->current = isset( $this->hierarchy[ $this->current ]['_parent'] ) |
|
191 | - ? $this->hierarchy[ $this->current ]['_parent'] |
|
190 | + $this->current = isset($this->hierarchy[$this->current]['_parent']) |
|
191 | + ? $this->hierarchy[$this->current]['_parent'] |
|
192 | 192 | : 0; |
193 | 193 | } |
194 | 194 | |
@@ -196,95 +196,95 @@ discard block |
||
196 | 196 | $this->current = 0; |
197 | 197 | } |
198 | 198 | |
199 | - public function set_field( $field, $value ) { |
|
200 | - $this->hierarchy[ $this->current ][ $field ] = $value; |
|
199 | + public function set_field($field, $value) { |
|
200 | + $this->hierarchy[$this->current][$field] = $value; |
|
201 | 201 | } |
202 | 202 | |
203 | - public function get_field( $field, $sub = null, $sub_2 = null ) { |
|
203 | + public function get_field($field, $sub = null, $sub_2 = null) { |
|
204 | 204 | |
205 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
|
205 | + if ( ! isset($this->hierarchy[$this->current][$field])) { |
|
206 | 206 | return null; |
207 | 207 | } |
208 | 208 | |
209 | - if ( isset( $sub ) ) { |
|
210 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ][ $sub ] ) ) { |
|
209 | + if (isset($sub)) { |
|
210 | + if ( ! isset($this->hierarchy[$this->current][$field][$sub])) { |
|
211 | 211 | return null; |
212 | 212 | } |
213 | 213 | |
214 | - if ( isset( $sub_2 ) ) { |
|
215 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ][ $sub ][ $sub_2 ] ) ) { |
|
214 | + if (isset($sub_2)) { |
|
215 | + if ( ! isset($this->hierarchy[$this->current][$field][$sub][$sub_2])) { |
|
216 | 216 | return null; |
217 | 217 | } else { |
218 | - return $this->hierarchy[ $this->current ][ $field ][ $sub ][ $sub_2 ]; |
|
218 | + return $this->hierarchy[$this->current][$field][$sub][$sub_2]; |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - return $this->hierarchy[ $this->current ][ $field ][ $sub ]; |
|
222 | + return $this->hierarchy[$this->current][$field][$sub]; |
|
223 | 223 | } |
224 | 224 | |
225 | - return $this->hierarchy[ $this->current ][ $field ]; |
|
225 | + return $this->hierarchy[$this->current][$field]; |
|
226 | 226 | } |
227 | 227 | |
228 | - public function push_to( $field, $value ) { |
|
228 | + public function push_to($field, $value) { |
|
229 | 229 | |
230 | - if ( ! isset( $this->hierarchy[ $this->current ][ $field ] ) ) { |
|
230 | + if ( ! isset($this->hierarchy[$this->current][$field])) { |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | //var_dump( $field, $value,$this->current[ $field ] ); |
234 | - $this->hierarchy[ $this->current ][ $field ][] = $value; |
|
234 | + $this->hierarchy[$this->current][$field][] = $value; |
|
235 | 235 | } |
236 | 236 | |
237 | - public function set_sub_field( $slug, $field, $value ) { |
|
238 | - $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ][ $field ] = $value; |
|
237 | + public function set_sub_field($slug, $field, $value) { |
|
238 | + $this->hierarchy[$this->current][$this->descendant_index][$slug][$field] = $value; |
|
239 | 239 | } |
240 | 240 | |
241 | - public function get_sub_field( $slug, $field ) { |
|
241 | + public function get_sub_field($slug, $field) { |
|
242 | 242 | |
243 | - return $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ][ $field ]; |
|
243 | + return $this->hierarchy[$this->current][$this->descendant_index][$slug][$field]; |
|
244 | 244 | } |
245 | 245 | |
246 | - public function get_sub_data( $slug ) { |
|
247 | - return $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ]; |
|
246 | + public function get_sub_data($slug) { |
|
247 | + return $this->hierarchy[$this->current][$this->descendant_index][$slug]; |
|
248 | 248 | } |
249 | 249 | |
250 | - public function has_child( $slug ) { |
|
251 | - return isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ] ); |
|
250 | + public function has_child($slug) { |
|
251 | + return isset($this->hierarchy[$this->current][$this->descendant_index][$slug]); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | public function get_children() { |
255 | - return isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $slug ] ); |
|
255 | + return isset($this->hierarchy[$this->current][$this->descendant_index][$slug]); |
|
256 | 256 | |
257 | 257 | } |
258 | 258 | |
259 | 259 | public function ascend() { |
260 | 260 | |
261 | - if ( ! isset( $this->hierarchy[ $this->current ]['_parent'] ) ) { |
|
261 | + if ( ! isset($this->hierarchy[$this->current]['_parent'])) { |
|
262 | 262 | return false; |
263 | 263 | } |
264 | 264 | |
265 | - $this->current = $this->hierarchy[ $this->current ]['_parent']; |
|
265 | + $this->current = $this->hierarchy[$this->current]['_parent']; |
|
266 | 266 | |
267 | 267 | return true; |
268 | 268 | } |
269 | 269 | |
270 | - public function descend( $to = null ) { |
|
270 | + public function descend($to = null) { |
|
271 | 271 | |
272 | - if ( ! isset( $this->hierarchy[ $this->current ][ $this->descendant_index ] ) ) { |
|
272 | + if ( ! isset($this->hierarchy[$this->current][$this->descendant_index])) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - if ( isset( $to ) ) { |
|
276 | + if (isset($to)) { |
|
277 | 277 | |
278 | - if ( ! isset( $this->hierarchy[ $this->current ][ $this->descendant_index ][ $to ] ) ) { |
|
278 | + if ( ! isset($this->hierarchy[$this->current][$this->descendant_index][$to])) { |
|
279 | 279 | return false; |
280 | 280 | } |
281 | 281 | |
282 | - $this->current = $this->hierarchy[ $this->current ][ $this->descendant_index ][ $to ]; |
|
282 | + $this->current = $this->hierarchy[$this->current][$this->descendant_index][$to]; |
|
283 | 283 | |
284 | 284 | } else { |
285 | 285 | |
286 | 286 | $this->current = reset( |
287 | - $this->hierarchy[ $this->current ][ $this->descendant_index ] |
|
287 | + $this->hierarchy[$this->current][$this->descendant_index] |
|
288 | 288 | ); |
289 | 289 | } |
290 | 290 | |
@@ -293,29 +293,29 @@ discard block |
||
293 | 293 | |
294 | 294 | public function next() { |
295 | 295 | |
296 | - if ( ! isset( $this->hierarchy[ $this->current ]['_parent'] ) ) { |
|
296 | + if ( ! isset($this->hierarchy[$this->current]['_parent'])) { |
|
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | - $parent = $this->hierarchy[ $this->current ]['_parent']; |
|
300 | + $parent = $this->hierarchy[$this->current]['_parent']; |
|
301 | 301 | |
302 | - if ( ! isset( $this->hierarchy[ $parent ][ $this->descendant_index ] ) ) { |
|
302 | + if ( ! isset($this->hierarchy[$parent][$this->descendant_index])) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | |
306 | - $sub_args = $this->hierarchy[ $parent ][ $this->descendant_index ]; |
|
306 | + $sub_args = $this->hierarchy[$parent][$this->descendant_index]; |
|
307 | 307 | |
308 | - reset( $sub_args ); |
|
308 | + reset($sub_args); |
|
309 | 309 | |
310 | - while ( current( $sub_args ) !== $this->current ) { |
|
311 | - next( $sub_args ); |
|
310 | + while (current($sub_args) !== $this->current) { |
|
311 | + next($sub_args); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( ! next( $sub_args ) ) { |
|
314 | + if ( ! next($sub_args)) { |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | |
318 | - $this->current = current( $sub_args ); |
|
318 | + $this->current = current($sub_args); |
|
319 | 319 | |
320 | 320 | return true; |
321 | 321 | } |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | return $this->current; |
325 | 325 | } |
326 | 326 | |
327 | - public function go_to( $id ) { |
|
327 | + public function go_to($id) { |
|
328 | 328 | |
329 | - if ( false === wordpoints_posint( $id ) || $id < 0 ) { |
|
329 | + if (false === wordpoints_posint($id) || $id < 0) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 |
@@ -73,6 +73,10 @@ |
||
73 | 73 | |
74 | 74 | |
75 | 75 | interface WordPoints_Hook_Reactor_RetroactiveI extends WordPoints_Hook_Retroactive_Query_ModifierI { |
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
76 | 80 | public function retroactive_hit( $target, array $records, WordPoints_Hook_Event_RetroactiveI $event, WordPoints_Hook_ReactionI $reaction ); |
77 | 81 | } |
78 | 82 |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | |
74 | 74 | |
75 | 75 | interface WordPoints_Hook_Reactor_RetroactiveI extends WordPoints_Hook_Retroactive_Query_ModifierI { |
76 | - public function retroactive_hit( $target, array $records, WordPoints_Hook_Event_RetroactiveI $event, WordPoints_Hook_ReactionI $reaction ); |
|
76 | + public function retroactive_hit($target, array $records, WordPoints_Hook_Event_RetroactiveI $event, WordPoints_Hook_ReactionI $reaction); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | abstract class WordPoints_Hook_Reactor_Retroactive implements WordPoints_Hook_Reactor_RetroactiveI { |
80 | 80 | |
81 | - public function modify_retroactive_query( WordPoints_Hook_Retroactive_QueryI $query ) { |
|
81 | + public function modify_retroactive_query(WordPoints_Hook_Retroactive_QueryI $query) { |
|
82 | 82 | |
83 | - $query->set_target( $query->get_reaction()->get_meta( 'target' ) ); |
|
83 | + $query->set_target($query->get_reaction()->get_meta('target')); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public function reverse_hits() { |
@@ -97,17 +97,17 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * @since 1.0.0 |
99 | 99 | */ |
100 | - public function retroactive_hit( $target, array $records, WordPoints_Hook_Event_RetroactiveI $event, WordPoints_Hook_ReactionI $reaction ) { |
|
100 | + public function retroactive_hit($target, array $records, WordPoints_Hook_Event_RetroactiveI $event, WordPoints_Hook_ReactionI $reaction) { |
|
101 | 101 | |
102 | - $count = count( $records ); |
|
102 | + $count = count($records); |
|
103 | 103 | |
104 | 104 | wordpoints_alter_points( |
105 | 105 | $target |
106 | - , $reaction->get_meta( 'points' ) * $count |
|
107 | - , $reaction->get_meta( 'points_type' ) |
|
108 | - , 'retroactive_' . $reaction->get_event_slug() |
|
109 | - , array( 'count' => $count ) |
|
110 | - , $event->get_retroactive_description( $reaction ) |
|
106 | + , $reaction->get_meta('points') * $count |
|
107 | + , $reaction->get_meta('points_type') |
|
108 | + , 'retroactive_'.$reaction->get_event_slug() |
|
109 | + , array('count' => $count) |
|
110 | + , $event->get_retroactive_description($reaction) |
|
111 | 111 | ); |
112 | 112 | } |
113 | 113 | |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | |
140 | 140 | $logs = $query->get(); |
141 | 141 | |
142 | - if ( ! $logs ) { |
|
142 | + if ( ! $logs) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - foreach ( $logs as $log ) { |
|
146 | + foreach ($logs as $log) { |
|
147 | 147 | |
148 | 148 | wordpoints_alter_points( |
149 | 149 | $log->user_id |
150 | - , - ( $log->points / wordpoints_get_points_log_meta( $log->id, 'count', true ) ) |
|
150 | + , -($log->points / wordpoints_get_points_log_meta($log->id, 'count', true)) |
|
151 | 151 | , $log->points_type |
152 | 152 | , "reverse_{$event}" |
153 | - , array( 'original_log_id' => $log->id ) |
|
153 | + , array('original_log_id' => $log->id) |
|
154 | 154 | , $args->get_description() |
155 | 155 | ); |
156 | 156 | |
157 | - wordpoints_add_points_log_meta( $log->id, 'auto_reversed', $args->get_entity_id() ); |
|
157 | + wordpoints_add_points_log_meta($log->id, 'auto_reversed', $args->get_entity_id()); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | |
197 | 197 | protected $results; |
198 | 198 | |
199 | - public function __construct( WordPoints_Hook_ReactionI $reaction ) { |
|
199 | + public function __construct(WordPoints_Hook_ReactionI $reaction) { |
|
200 | 200 | |
201 | 201 | $this->reaction = $reaction; |
202 | - $this->arg_hierarchy = new WordPoints_Hierarchy( 'sub_args' ); |
|
202 | + $this->arg_hierarchy = new WordPoints_Hierarchy('sub_args'); |
|
203 | 203 | $this->hooks = wordpoints_hooks(); |
204 | 204 | $this->entities = wordpoints_entities(); |
205 | - $this->validator = new WordPoints_Hook_Reaction_Validator( $reaction, true ); |
|
205 | + $this->validator = new WordPoints_Hook_Reaction_Validator($reaction, true); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | public function get_reaction() { |
@@ -215,11 +215,11 @@ discard block |
||
215 | 215 | |
216 | 216 | public function get_results() { |
217 | 217 | |
218 | - if ( ! isset( $this->results ) ) { |
|
218 | + if ( ! isset($this->results)) { |
|
219 | 219 | |
220 | 220 | $this->execute(); |
221 | 221 | |
222 | - if ( $this->validator->had_errors() ) { |
|
222 | + if ($this->validator->had_errors()) { |
|
223 | 223 | $this->results = $this->validator; |
224 | 224 | } |
225 | 225 | } |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | $this->filter_results(); |
237 | 237 | $this->group_results(); |
238 | 238 | |
239 | - } catch ( WordPoints_Hook_Validator_Exception $e ) { |
|
240 | - unset( $e ); |
|
239 | + } catch (WordPoints_Hook_Validator_Exception $e) { |
|
240 | + unset($e); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
@@ -245,32 +245,32 @@ discard block |
||
245 | 245 | |
246 | 246 | $event_slug = $this->reaction->get_event_slug(); |
247 | 247 | |
248 | - $event = $this->hooks->events->get( $event_slug ); |
|
248 | + $event = $this->hooks->events->get($event_slug); |
|
249 | 249 | |
250 | - if ( ! ( $event instanceof WordPoints_Hook_Event_RetroactiveI ) ) { |
|
251 | - $this->validator->add_error( 'invalid hook' ); |
|
250 | + if ( ! ($event instanceof WordPoints_Hook_Event_RetroactiveI)) { |
|
251 | + $this->validator->add_error('invalid hook'); |
|
252 | 252 | } |
253 | 253 | |
254 | - foreach ( $this->hooks->events->args->get_children( $event_slug ) as $arg ) { |
|
254 | + foreach ($this->hooks->events->args->get_children($event_slug) as $arg) { |
|
255 | 255 | $this->arg_hierarchy_push( // TODO |
256 | 256 | $arg |
257 | 257 | ); |
258 | 258 | } |
259 | 259 | |
260 | - if ( $event instanceof WordPoints_Hook_Retroactive_Query_ModifierI ) { |
|
261 | - $event->modify_retroactive_query( $this ); |
|
260 | + if ($event instanceof WordPoints_Hook_Retroactive_Query_ModifierI) { |
|
261 | + $event->modify_retroactive_query($this); |
|
262 | 262 | $this->reset(); |
263 | 263 | } |
264 | 264 | |
265 | - $reactor = $this->hooks->reactors->get( $this->reaction->get_reactor_slug() ); |
|
265 | + $reactor = $this->hooks->reactors->get($this->reaction->get_reactor_slug()); |
|
266 | 266 | |
267 | - $reactor->modify_retroactive_query( $this ); |
|
267 | + $reactor->modify_retroactive_query($this); |
|
268 | 268 | $this->reset(); |
269 | 269 | |
270 | - foreach ( $this->hooks->extensions->get_all() as $extension ) { |
|
270 | + foreach ($this->hooks->extensions->get_all() as $extension) { |
|
271 | 271 | |
272 | - if ( $extension instanceof WordPoints_Hook_Retroactive_Query_ModifierI ) { |
|
273 | - $extension->modify_retroactive_query( $this ); |
|
272 | + if ($extension instanceof WordPoints_Hook_Retroactive_Query_ModifierI) { |
|
273 | + $extension->modify_retroactive_query($this); |
|
274 | 274 | $this->reset(); |
275 | 275 | } |
276 | 276 | } |
@@ -278,125 +278,125 @@ discard block |
||
278 | 278 | |
279 | 279 | protected function perform_query() { |
280 | 280 | |
281 | - $this->queries = new WordPoints_Hierarchy( 'sub_queries' ); |
|
282 | - $this->consolidate_queries( array( $this->arg_hierarchy->get() ) ); |
|
283 | - unset( $this->query ); |
|
281 | + $this->queries = new WordPoints_Hierarchy('sub_queries'); |
|
282 | + $this->consolidate_queries(array($this->arg_hierarchy->get())); |
|
283 | + unset($this->query); |
|
284 | 284 | |
285 | 285 | $this->queries->reset(); |
286 | 286 | |
287 | 287 | // Find the tip of a query. |
288 | - $this->results = $this->execute_queries( $this->queries->get() ); |
|
288 | + $this->results = $this->execute_queries($this->queries->get()); |
|
289 | 289 | |
290 | - if ( is_wp_error( $this->results ) ) { |
|
291 | - $this->validator->add_error( $this->results ); |
|
290 | + if (is_wp_error($this->results)) { |
|
291 | + $this->validator->add_error($this->results); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | - protected function consolidate_queries( $arg_hierarchy, $storage_type = null ) { |
|
295 | + protected function consolidate_queries($arg_hierarchy, $storage_type = null) { |
|
296 | 296 | |
297 | - foreach ( $arg_hierarchy as $data ) { |
|
298 | - $this->consolidate_query( $data ); |
|
297 | + foreach ($arg_hierarchy as $data) { |
|
298 | + $this->consolidate_query($data); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | - protected function consolidate_query( $data ) { |
|
302 | + protected function consolidate_query($data) { |
|
303 | 303 | |
304 | - if ( $data['storage_info']['type'] !== $this->queries->get_field( 'slug' ) ) { |
|
304 | + if ($data['storage_info']['type'] !== $this->queries->get_field('slug')) { |
|
305 | 305 | |
306 | 306 | $parent_id = null; |
307 | - if ( isset( $this->query ) ) { |
|
307 | + if (isset($this->query)) { |
|
308 | 308 | $parent_id = $this->query->get_id(); |
309 | 309 | } |
310 | 310 | |
311 | - $this->query = new WordPoints_Hierarchy( 'sub_args' ); |
|
311 | + $this->query = new WordPoints_Hierarchy('sub_args'); |
|
312 | 312 | |
313 | 313 | $this->queries->push( |
314 | 314 | $data['storage_info']['type'] |
315 | - , array( 'query' => $this->query, 'parent_id' => $parent_id ) |
|
315 | + , array('query' => $this->query, 'parent_id' => $parent_id) |
|
316 | 316 | ); |
317 | 317 | |
318 | 318 | $pushed_query = true; |
319 | 319 | } |
320 | 320 | |
321 | - if ( isset( $data['sub_args'] ) ) { |
|
321 | + if (isset($data['sub_args'])) { |
|
322 | 322 | $sub_args = $data['sub_args']; |
323 | - unset( $data['sub_args'] ); |
|
323 | + unset($data['sub_args']); |
|
324 | 324 | } |
325 | 325 | |
326 | - $this->query->push( $data['slug'], $data ); |
|
326 | + $this->query->push($data['slug'], $data); |
|
327 | 327 | |
328 | - if ( isset( $sub_args ) ) { |
|
329 | - $this->consolidate_queries( $sub_args, $data['storage_info']['type'] ); |
|
328 | + if (isset($sub_args)) { |
|
329 | + $this->consolidate_queries($sub_args, $data['storage_info']['type']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $this->query->pop(); |
333 | 333 | |
334 | - if ( ! empty( $pushed_query ) ) { |
|
334 | + if ( ! empty($pushed_query)) { |
|
335 | 335 | $this->queries->pop(); |
336 | - $this->query = $this->queries->get_field( 'query' ); |
|
336 | + $this->query = $this->queries->get_field('query'); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
340 | - protected function execute_queries( $queries ) { |
|
340 | + protected function execute_queries($queries) { |
|
341 | 341 | |
342 | 342 | /** @var WordPoints_HierarchyI $query */ |
343 | 343 | $query = $queries['query']; |
344 | 344 | |
345 | - if ( isset( $queries['sub_queries'] ) ) { |
|
346 | - foreach ( $queries['sub_queries'] as $query_data ) { |
|
345 | + if (isset($queries['sub_queries'])) { |
|
346 | + foreach ($queries['sub_queries'] as $query_data) { |
|
347 | 347 | |
348 | - $results = $this->execute_queries( $query_data ); |
|
348 | + $results = $this->execute_queries($query_data); |
|
349 | 349 | |
350 | - if ( is_wp_error( $results ) ) { |
|
350 | + if (is_wp_error($results)) { |
|
351 | 351 | return $results; |
352 | 352 | } |
353 | 353 | |
354 | - if ( empty( $results ) ) { |
|
354 | + if (empty($results)) { |
|
355 | 355 | return array(); |
356 | 356 | } |
357 | 357 | |
358 | 358 | /** @var WordPoints_HierarchyI $child_query */ |
359 | 359 | $child_query = $query_data['query']; |
360 | - $query->go_to( $query_data['parent_id'] ); |
|
360 | + $query->go_to($query_data['parent_id']); |
|
361 | 361 | |
362 | 362 | $condition = array( |
363 | 363 | // 'field' => $child_query->get_field( 'slug' ), |
364 | 364 | 'compare' => 'in', |
365 | 365 | 'value' => wp_list_pluck( |
366 | 366 | $results |
367 | - , $child_query->get_field( 'storage_info', 'meta', 'id_field' ) |
|
367 | + , $child_query->get_field('storage_info', 'meta', 'id_field') |
|
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | |
371 | - $query->push_to( 'conditions', $condition ); |
|
371 | + $query->push_to('conditions', $condition); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | 375 | $query->reset(); |
376 | - $storage_type = $query->get_field( 'storage_info', 'type' ); |
|
376 | + $storage_type = $query->get_field('storage_info', 'type'); |
|
377 | 377 | |
378 | - $executor = $this->hooks->retroactive_query_executors->get( $storage_type ); |
|
378 | + $executor = $this->hooks->retroactive_query_executors->get($storage_type); |
|
379 | 379 | |
380 | - if ( ! $executor ) { |
|
380 | + if ( ! $executor) { |
|
381 | 381 | $this->validator->add_error( |
382 | - sprintf( 'unknown storage type "%s".', $storage_type ) |
|
382 | + sprintf('unknown storage type "%s".', $storage_type) |
|
383 | 383 | ); |
384 | 384 | } |
385 | 385 | |
386 | - return $executor->execute( array( $query->get() ) ); |
|
386 | + return $executor->execute(array($query->get())); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | protected function filter_results() { |
390 | 390 | |
391 | - $reactor = $this->hooks->reactors->get( $this->reaction->get_reactor_slug() ); |
|
391 | + $reactor = $this->hooks->reactors->get($this->reaction->get_reactor_slug()); |
|
392 | 392 | |
393 | - if ( $reactor instanceof WordPoints_Hook_Retroactive_Query_FilterI ) { |
|
394 | - $reactor->filter_retroactive_query( $this ); |
|
393 | + if ($reactor instanceof WordPoints_Hook_Retroactive_Query_FilterI) { |
|
394 | + $reactor->filter_retroactive_query($this); |
|
395 | 395 | } |
396 | 396 | |
397 | - foreach ( $this->hooks->extensions->get_all() as $extension ) { |
|
398 | - if ( $extension instanceof WordPoints_Hook_Retroactive_Query_FilterI ) { |
|
399 | - $extension->filter_retroactive_query( $this ); |
|
397 | + foreach ($this->hooks->extensions->get_all() as $extension) { |
|
398 | + if ($extension instanceof WordPoints_Hook_Retroactive_Query_FilterI) { |
|
399 | + $extension->filter_retroactive_query($this); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
@@ -405,27 +405,27 @@ discard block |
||
405 | 405 | |
406 | 406 | $grouped_results = array(); |
407 | 407 | |
408 | - foreach ( $this->results as $result ) { |
|
409 | - $grouped_results[ $result->target ][] = $result; |
|
408 | + foreach ($this->results as $result) { |
|
409 | + $grouped_results[$result->target][] = $result; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $this->results = $grouped_results; |
413 | 413 | } |
414 | 414 | |
415 | - public function add_condition( array $condition ) { |
|
415 | + public function add_condition(array $condition) { |
|
416 | 416 | |
417 | - $this->arg_hierarchy->push_to( 'conditions', $condition ); |
|
417 | + $this->arg_hierarchy->push_to('conditions', $condition); |
|
418 | 418 | } |
419 | 419 | |
420 | - public function select_value( $data = array() ) { |
|
420 | + public function select_value($data = array()) { |
|
421 | 421 | |
422 | - $this->arg_hierarchy->set_field( 'select', $data ); |
|
422 | + $this->arg_hierarchy->set_field('select', $data); |
|
423 | 423 | } |
424 | 424 | |
425 | - public function set_target( $target_arg ) { |
|
425 | + public function set_target($target_arg) { |
|
426 | 426 | |
427 | - foreach ( $target_arg as $arg_slug ) { |
|
428 | - $this->arg_hierarchy_push( $arg_slug ); |
|
427 | + foreach ($target_arg as $arg_slug) { |
|
428 | + $this->arg_hierarchy_push($arg_slug); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | // $id = $this->arg_hierarchy->get_id(); |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | // $field = $this->arg_hierarchy->get_field( 'storage_info', 'meta', 'field' ); |
436 | 436 | // $this->arg_hierarchy->ascend(); |
437 | 437 | // } else { |
438 | - $field = $this->arg_hierarchy->get_field( 'storage_info', 'meta', 'id_field' ); |
|
438 | + $field = $this->arg_hierarchy->get_field('storage_info', 'meta', 'id_field'); |
|
439 | 439 | // } |
440 | 440 | |
441 | - $this->select_value( array( 'field' => $field, 'as' => 'target' ) ); |
|
441 | + $this->select_value(array('field' => $field, 'as' => 'target')); |
|
442 | 442 | |
443 | 443 | // $this->arg_hierarchy->go_to( $id ); |
444 | 444 | } |
@@ -450,40 +450,40 @@ discard block |
||
450 | 450 | * @return WordPoints_EntityishI |
451 | 451 | */ |
452 | 452 | public function get_arg() { |
453 | - return $this->arg_hierarchy->get_field( 'arg' ); |
|
453 | + return $this->arg_hierarchy->get_field('arg'); |
|
454 | 454 | } |
455 | 455 | |
456 | - public function arg_hierarchy_push( $slug ) { |
|
456 | + public function arg_hierarchy_push($slug) { |
|
457 | 457 | |
458 | - $current_slug = $this->arg_hierarchy->get_field( 'slug' ); |
|
458 | + $current_slug = $this->arg_hierarchy->get_field('slug'); |
|
459 | 459 | |
460 | - if ( $current_slug === $slug && $this->arg_hierarchy->is_main() ) { |
|
460 | + if ($current_slug === $slug && $this->arg_hierarchy->is_main()) { |
|
461 | 461 | return; |
462 | 462 | } |
463 | 463 | |
464 | 464 | // if ( $current_slug !== $slug ) { |
465 | 465 | |
466 | - if ( empty( $current_slug ) ) { |
|
467 | - $arg = $this->entities->get( $slug ); |
|
466 | + if (empty($current_slug)) { |
|
467 | + $arg = $this->entities->get($slug); |
|
468 | 468 | } else { |
469 | 469 | |
470 | 470 | // If this child exists, don't overwrite it, just descend into it. |
471 | - if ( $this->arg_hierarchy->has_child( $slug ) ) { |
|
472 | - $this->arg_hierarchy->descend( $slug ); |
|
471 | + if ($this->arg_hierarchy->has_child($slug)) { |
|
472 | + $this->arg_hierarchy->descend($slug); |
|
473 | 473 | return; |
474 | 474 | } |
475 | 475 | |
476 | - $parent_arg = $this->arg_hierarchy->get_field( 'arg' ); |
|
476 | + $parent_arg = $this->arg_hierarchy->get_field('arg'); |
|
477 | 477 | |
478 | - if ( $parent_arg instanceof WordPoints_Entity_ParentI ) { |
|
479 | - $arg = $parent_arg->get_child( $slug ); |
|
478 | + if ($parent_arg instanceof WordPoints_Entity_ParentI) { |
|
479 | + $arg = $parent_arg->get_child($slug); |
|
480 | 480 | } else { |
481 | 481 | return; // TODO |
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | - if ( $arg instanceof WordPoints_Entity_Array ) { |
|
486 | - $arg = $this->entities->get( $arg->get_entity_slug() ); |
|
485 | + if ($arg instanceof WordPoints_Entity_Array) { |
|
486 | + $arg = $this->entities->get($arg->get_entity_slug()); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | $data['arg'] = $arg; |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | // TODO check if storage type is recognized? |
492 | 492 | $data['storage_info'] = $arg->get_storage_info(); |
493 | 493 | |
494 | - $this->arg_hierarchy->push( $slug, $data ); |
|
494 | + $this->arg_hierarchy->push($slug, $data); |
|
495 | 495 | |
496 | 496 | // } else { |
497 | 497 | // $data = array(); |
@@ -508,11 +508,11 @@ discard block |
||
508 | 508 | } |
509 | 509 | |
510 | 510 | interface WordPoints_Hook_Retroactive_Query_FilterI { |
511 | - public function filter_retroactive_query( WordPoints_Hook_Retroactive_QueryI $query ); |
|
511 | + public function filter_retroactive_query(WordPoints_Hook_Retroactive_QueryI $query); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | interface WordPoints_Hook_Retroactive_Query_ExecutorI { |
515 | - public function execute( $query ); |
|
515 | + public function execute($query); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /* |
@@ -541,48 +541,48 @@ discard block |
||
541 | 541 | protected $array; |
542 | 542 | protected $results; |
543 | 543 | |
544 | - public function execute( $query ) { |
|
544 | + public function execute($query) { |
|
545 | 545 | |
546 | - foreach ( $query as $arg_data ) { |
|
546 | + foreach ($query as $arg_data) { |
|
547 | 547 | |
548 | 548 | $meta = $arg_data['storage_info']['meta']; |
549 | 549 | |
550 | - if ( isset( $meta['getter'] ) ) { |
|
550 | + if (isset($meta['getter'])) { |
|
551 | 551 | $this->array = $meta['getter'](); |
552 | 552 | } |
553 | 553 | |
554 | - if ( isset( $arg_data['conditions'] ) ) { |
|
554 | + if (isset($arg_data['conditions'])) { |
|
555 | 555 | |
556 | - foreach ( $arg_data['conditions'] as $condition ) { |
|
556 | + foreach ($arg_data['conditions'] as $condition) { |
|
557 | 557 | |
558 | - if ( ! isset( $condition['field'] ) ) { |
|
559 | - if ( $arg_data['arg'] instanceof WordPoints_Entity_Attr ) { |
|
558 | + if ( ! isset($condition['field'])) { |
|
559 | + if ($arg_data['arg'] instanceof WordPoints_Entity_Attr) { |
|
560 | 560 | $condition['field'] = $meta['field']; |
561 | 561 | } else { |
562 | 562 | $condition['field'] = $meta['id_field']; |
563 | 563 | } |
564 | 564 | } |
565 | 565 | |
566 | - if ( ! isset( $condition['condition'] ) ) { |
|
566 | + if ( ! isset($condition['condition'])) { |
|
567 | 567 | $condition['condition'] = '='; |
568 | 568 | } |
569 | 569 | |
570 | 570 | $filter_args = array(); |
571 | 571 | |
572 | - switch ( $condition['condition'] ) { |
|
572 | + switch ($condition['condition']) { |
|
573 | 573 | |
574 | 574 | case '=': |
575 | - $filter_args[ $condition['field'] ] = $condition['value']; |
|
575 | + $filter_args[$condition['field']] = $condition['value']; |
|
576 | 576 | break; |
577 | 577 | |
578 | 578 | case 'in': |
579 | 579 | // TODO |
580 | 580 | |
581 | 581 | default: |
582 | - return new WP_Error( 'invalid condition type' ); |
|
582 | + return new WP_Error('invalid condition type'); |
|
583 | 583 | } |
584 | 584 | |
585 | - $this->array = wp_list_filter( $this->array, $filter_args ); |
|
585 | + $this->array = wp_list_filter($this->array, $filter_args); |
|
586 | 586 | } |
587 | 587 | } |
588 | 588 | |
@@ -590,9 +590,9 @@ discard block |
||
590 | 590 | // $builder->add_field( $arg_data['select'] ); |
591 | 591 | // } |
592 | 592 | |
593 | - if ( isset( $arg_data['sub_args'] ) ) { |
|
593 | + if (isset($arg_data['sub_args'])) { |
|
594 | 594 | $this->parent_data = $arg_data; |
595 | - $this->array = $this->execute( $arg_data['sub_args'] ); |
|
595 | + $this->array = $this->execute($arg_data['sub_args']); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | $this->results = $this->array; |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | } |
603 | 603 | } |
604 | 604 | |
605 | -wordpoints_hooks()->retroactive_query_executors->register( 'array', 'WordPoints_Hook_Retroactive_Query_Executor_Array' ); |
|
605 | +wordpoints_hooks()->retroactive_query_executors->register('array', 'WordPoints_Hook_Retroactive_Query_Executor_Array'); |
|
606 | 606 | |
607 | 607 | class WordPoints_Hook_Retroactive_Query_Executor_MySQL |
608 | 608 | implements WordPoints_Hook_Retroactive_Query_ExecutorI { |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | |
622 | 622 | protected $entered_join; |
623 | 623 | |
624 | - public function execute( $query ) { |
|
624 | + public function execute($query) { |
|
625 | 625 | // WE should be getting a hierarchy object here. |
626 | 626 | // This will let us loop over things easier. |
627 | 627 | // We'll also need to be marking the non-usable parts of the query. |
@@ -631,69 +631,69 @@ discard block |
||
631 | 631 | |
632 | 632 | $this->builder = new WordPoints_Query_Builder_DB_MySQL(); |
633 | 633 | |
634 | - $this->build_query( $query ); |
|
634 | + $this->build_query($query); |
|
635 | 635 | |
636 | 636 | $sql = $this->builder->get_query(); |
637 | 637 | |
638 | - if ( is_wp_error( $sql ) ) { |
|
638 | + if (is_wp_error($sql)) { |
|
639 | 639 | return $sql; |
640 | 640 | } |
641 | 641 | |
642 | - return $wpdb->get_results( $sql ); |
|
642 | + return $wpdb->get_results($sql); |
|
643 | 643 | } |
644 | 644 | |
645 | - protected function build_query( $args ) { |
|
645 | + protected function build_query($args) { |
|
646 | 646 | |
647 | - foreach ( $args as $arg_data ) { |
|
647 | + foreach ($args as $arg_data) { |
|
648 | 648 | |
649 | 649 | $this->arg_data = $arg_data; |
650 | 650 | |
651 | - if ( isset( $arg_data['storage_info']['meta']['table_name'] ) ) { |
|
652 | - $this->build_table_schema( $arg_data['storage_info']['meta'] ); |
|
651 | + if (isset($arg_data['storage_info']['meta']['table_name'])) { |
|
652 | + $this->build_table_schema($arg_data['storage_info']['meta']); |
|
653 | 653 | } |
654 | 654 | |
655 | - if ( isset( $arg_data['conditions'] ) ) { |
|
656 | - $this->build_conditions( $arg_data['conditions'] ); |
|
655 | + if (isset($arg_data['conditions'])) { |
|
656 | + $this->build_conditions($arg_data['conditions']); |
|
657 | 657 | } |
658 | 658 | |
659 | - if ( isset( $arg_data['select'] ) ) { |
|
660 | - $this->builder->add_field( $arg_data['select'] ); |
|
659 | + if (isset($arg_data['select'])) { |
|
660 | + $this->builder->add_field($arg_data['select']); |
|
661 | 661 | } |
662 | 662 | |
663 | - if ( isset( $arg_data['sub_args'] ) ) { |
|
663 | + if (isset($arg_data['sub_args'])) { |
|
664 | 664 | |
665 | 665 | $this->grandparent_data = $this->parent_data; |
666 | 666 | $this->parent_data = $arg_data; |
667 | 667 | |
668 | - $this->build_query( $arg_data['sub_args'] ); |
|
668 | + $this->build_query($arg_data['sub_args']); |
|
669 | 669 | |
670 | 670 | $this->parent_data = $this->grandparent_data; |
671 | 671 | } |
672 | 672 | |
673 | - if ( isset( $this->entered_join ) ) { |
|
673 | + if (isset($this->entered_join)) { |
|
674 | 674 | $this->builder->exit_join(); |
675 | 675 | $this->entered_join = null; |
676 | 676 | } |
677 | 677 | } |
678 | 678 | } |
679 | 679 | |
680 | - protected function build_table_schema( $db ) { |
|
680 | + protected function build_table_schema($db) { |
|
681 | 681 | |
682 | - if ( $this->builder->get_table() ) { |
|
682 | + if ($this->builder->get_table()) { |
|
683 | 683 | |
684 | - if ( $this->parent_data['arg'] instanceof WordPoints_Entity_Relationship ) { |
|
684 | + if ($this->parent_data['arg'] instanceof WordPoints_Entity_Relationship) { |
|
685 | 685 | $primary_field = $this->parent_data['storage_info']['meta']['field']; |
686 | 686 | $join_field = $db['id_field']; |
687 | 687 | //$primary_field = $this->arg_data['arg']->get_secondary_field(); |
688 | - } elseif ( $this->arg_data['arg'] instanceof WordPoints_Entity_Relationship ) { |
|
688 | + } elseif ($this->arg_data['arg'] instanceof WordPoints_Entity_Relationship) { |
|
689 | 689 | $join_field = $db['join_field']; |
690 | 690 | $primary_field = $this->parent_data['storage_info']['meta']['id_field']; |
691 | 691 | } else { |
692 | - throw new WordPoints_Query_Builder_Exception( 'Houston, we have a problem.' ); |
|
692 | + throw new WordPoints_Query_Builder_Exception('Houston, we have a problem.'); |
|
693 | 693 | } |
694 | 694 | |
695 | - if ( is_array( $primary_field ) && isset( $primary_field['table_name'] ) ) { |
|
696 | - $this->builder->enter_join( $primary_field ); |
|
695 | + if (is_array($primary_field) && isset($primary_field['table_name'])) { |
|
696 | + $this->builder->enter_join($primary_field); |
|
697 | 697 | $primary_field = $primary_field['on']['join_field']; |
698 | 698 | } |
699 | 699 | |
@@ -705,26 +705,26 @@ discard block |
||
705 | 705 | ), |
706 | 706 | ); |
707 | 707 | |
708 | - if ( isset( $db['join_where'] ) ) { |
|
708 | + if (isset($db['join_where'])) { |
|
709 | 709 | $join['where'] = $db['join_where']; |
710 | 710 | } |
711 | 711 | |
712 | - $this->builder->enter_join( $join ); |
|
712 | + $this->builder->enter_join($join); |
|
713 | 713 | |
714 | 714 | $this->entered_join = true; |
715 | 715 | |
716 | 716 | } else { |
717 | - $this->builder->set_table( $db['table_name'] ); |
|
718 | - $this->builder->add_field( $db['id_field'] ); |
|
717 | + $this->builder->set_table($db['table_name']); |
|
718 | + $this->builder->add_field($db['id_field']); |
|
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
722 | - protected function build_conditions( $conditions ) { |
|
722 | + protected function build_conditions($conditions) { |
|
723 | 723 | |
724 | 724 | // Join conditions should be pushed to the end. |
725 | 725 | $join_conditions = array(); |
726 | 726 | |
727 | - foreach ( $conditions as $condition ) { |
|
727 | + foreach ($conditions as $condition) { |
|
728 | 728 | |
729 | 729 | // THis needs to be the identifier field for the type of arg that this |
730 | 730 | // field represents. |
@@ -732,43 +732,43 @@ discard block |
||
732 | 732 | // However, for a relationship it could be something else. |
733 | 733 | // Ultimately, this will have to be left up to the arg object to |
734 | 734 | // decide. |
735 | - if ( ! isset( $condition['field'] ) ) { |
|
736 | - if ( $this->arg_data['arg'] instanceof WordPoints_Entity_Relationship ) { |
|
735 | + if ( ! isset($condition['field'])) { |
|
736 | + if ($this->arg_data['arg'] instanceof WordPoints_Entity_Relationship) { |
|
737 | 737 | // $condition['field'] = $this->arg_data['arg']->get_secondary_field(); |
738 | 738 | $condition['field'] = $this->arg_data['storage_info']['meta']['field']; |
739 | 739 | |
740 | - if ( is_array( $condition['field'] && isset( $condition['field']['table_name'] ) ) ) { |
|
740 | + if (is_array($condition['field'] && isset($condition['field']['table_name']))) { |
|
741 | 741 | $join_conditions[] = $condition; |
742 | 742 | continue; |
743 | 743 | } |
744 | - } elseif ( $this->arg_data['arg'] instanceof WordPoints_Entity_Attr ) { |
|
744 | + } elseif ($this->arg_data['arg'] instanceof WordPoints_Entity_Attr) { |
|
745 | 745 | $condition['field'] = $this->arg_data['arg']->get_field(); |
746 | 746 | } else { |
747 | - var_dump($this->arg_data['arg']);exit; |
|
747 | + var_dump($this->arg_data['arg']); exit; |
|
748 | 748 | } |
749 | 749 | } |
750 | 750 | |
751 | - $this->builder->where( $condition ); |
|
751 | + $this->builder->where($condition); |
|
752 | 752 | } |
753 | 753 | |
754 | - $join_count = count( $join_conditions ); |
|
754 | + $join_count = count($join_conditions); |
|
755 | 755 | $i = 0; |
756 | 756 | |
757 | - foreach ( $join_conditions as $condition ) { |
|
757 | + foreach ($join_conditions as $condition) { |
|
758 | 758 | |
759 | 759 | $i++; |
760 | 760 | |
761 | - $this->builder->enter_join( $condition['field'] ); |
|
761 | + $this->builder->enter_join($condition['field']); |
|
762 | 762 | |
763 | 763 | $condition['field'] = $condition['field']['on']['primary_field']; |
764 | 764 | |
765 | - $this->builder->where( $condition ); |
|
765 | + $this->builder->where($condition); |
|
766 | 766 | |
767 | 767 | $this->builder->exit_join(); |
768 | 768 | |
769 | 769 | // If there are more join conditions, we need to leave a fresh, trailing |
770 | 770 | // join for the next one to join to. |
771 | - if ( $i < $join_count ) { |
|
771 | + if ($i < $join_count) { |
|
772 | 772 | |
773 | 773 | // There is a current join, but it is already being used, so we |
774 | 774 | // need to exit it. |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | } |
785 | 785 | |
786 | 786 | |
787 | -wordpoints_hooks()->retroactive_query_executors->register( 'db', 'WordPoints_Hook_Retroactive_Query_Executor_MySQL' ); |
|
787 | +wordpoints_hooks()->retroactive_query_executors->register('db', 'WordPoints_Hook_Retroactive_Query_Executor_MySQL'); |
|
788 | 788 | |
789 | 789 | |
790 | 790 | // EOF |
@@ -8,12 +8,32 @@ |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | interface WordPoints_Hook_Reaction_SettingI { |
11 | + |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
11 | 15 | public function __construct( $slug ); |
16 | + |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
12 | 20 | public function get_type(); |
21 | + |
|
22 | + /** |
|
23 | + * @return string |
|
24 | + */ |
|
13 | 25 | public function get_label(); |
26 | + |
|
27 | + /** |
|
28 | + * @return boolean |
|
29 | + */ |
|
14 | 30 | public function is_required(); |
15 | 31 | public function get( WordPoints_Hook_ReactionI $reaction ); |
16 | 32 | public function validate( $value, WordPoints_Hook_Reaction_Validator $validator ); |
33 | + |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + */ |
|
17 | 37 | public function save( $value, WordPoints_Hook_ReactionI $reaction, $is_new ); |
18 | 38 | } |
19 | 39 |
@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | interface WordPoints_Hook_Reaction_SettingI { |
11 | - public function __construct( $slug ); |
|
11 | + public function __construct($slug); |
|
12 | 12 | public function get_type(); |
13 | 13 | public function get_label(); |
14 | 14 | public function is_required(); |
15 | - public function get( WordPoints_Hook_ReactionI $reaction ); |
|
16 | - public function validate( $value, WordPoints_Hook_Reaction_Validator $validator ); |
|
17 | - public function save( $value, WordPoints_Hook_ReactionI $reaction, $is_new ); |
|
15 | + public function get(WordPoints_Hook_ReactionI $reaction); |
|
16 | + public function validate($value, WordPoints_Hook_Reaction_Validator $validator); |
|
17 | + public function save($value, WordPoints_Hook_ReactionI $reaction, $is_new); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | class WordPoints_Hook_Reaction_Setting implements WordPoints_Hook_Reaction_SettingI { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | protected $type = 'hidden'; |
24 | 24 | protected $required = true; |
25 | 25 | |
26 | - public function __construct( $slug ) { |
|
26 | + public function __construct($slug) { |
|
27 | 27 | $this->slug = $slug; |
28 | 28 | } |
29 | 29 | |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | return $this->required; |
40 | 40 | } |
41 | 41 | |
42 | - public function get( WordPoints_Hook_ReactionI $reaction ) { |
|
43 | - return $reaction->get_meta( $this->slug ); |
|
42 | + public function get(WordPoints_Hook_ReactionI $reaction) { |
|
43 | + return $reaction->get_meta($this->slug); |
|
44 | 44 | } |
45 | 45 | |
46 | - public function validate( $value, WordPoints_Hook_Reaction_Validator $validator ) { |
|
46 | + public function validate($value, WordPoints_Hook_Reaction_Validator $validator) { |
|
47 | 47 | |
48 | - if ( $this->is_required() && '' === trim( $value ) ) { |
|
48 | + if ($this->is_required() && '' === trim($value)) { |
|
49 | 49 | |
50 | 50 | $validator->add_error( |
51 | 51 | sprintf( |
52 | - __( '%s cannot be empty.', 'wordpoints' ) |
|
52 | + __('%s cannot be empty.', 'wordpoints') |
|
53 | 53 | , $this->get_label() |
54 | 54 | ) |
55 | 55 | , $this->slug |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | return $value; |
60 | 60 | } |
61 | 61 | |
62 | - public function save( $value, WordPoints_Hook_ReactionI $reaction, $is_new ) { |
|
63 | - $reaction->update_meta( $this->slug, $value ); |
|
62 | + public function save($value, WordPoints_Hook_ReactionI $reaction, $is_new) { |
|
63 | + $reaction->update_meta($this->slug, $value); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | // |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | |
83 | 83 | $fields = array(); |
84 | 84 | |
85 | - foreach ( $this->settings as $slug => $class ) { |
|
85 | + foreach ($this->settings as $slug => $class) { |
|
86 | 86 | |
87 | 87 | /** @var WordPoints_Hook_Reaction_SettingI $setting */ |
88 | - $setting = new $class( $slug ); |
|
88 | + $setting = new $class($slug); |
|
89 | 89 | |
90 | - $fields[ $slug ] = array( |
|
90 | + $fields[$slug] = array( |
|
91 | 91 | 'type' => $setting->get_type(), |
92 | 92 | 'label' => $setting->get_label(), |
93 | 93 | 'required' => $setting->is_required(), |
@@ -97,29 +97,29 @@ discard block |
||
97 | 97 | return $fields; |
98 | 98 | } |
99 | 99 | |
100 | - public function save_settings( $reaction, $settings, $is_new ) { |
|
100 | + public function save_settings($reaction, $settings, $is_new) { |
|
101 | 101 | |
102 | - foreach ( $this->settings as $slug => $class ) { |
|
102 | + foreach ($this->settings as $slug => $class) { |
|
103 | 103 | |
104 | 104 | /** @var WordPoints_Hook_Reaction_SettingI $setting */ |
105 | - $setting = new $class( $slug ); |
|
105 | + $setting = new $class($slug); |
|
106 | 106 | |
107 | - $value = isset( $settings[ $slug ] ) ? $settings[ $slug ] : null; |
|
107 | + $value = isset($settings[$slug]) ? $settings[$slug] : null; |
|
108 | 108 | |
109 | - $setting->save( $value, $reaction, $is_new ); |
|
109 | + $setting->save($value, $reaction, $is_new); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - public function validate_settings( $settings, $validator ) { |
|
113 | + public function validate_settings($settings, $validator) { |
|
114 | 114 | |
115 | - foreach ( $this->settings as $slug => $class ) { |
|
115 | + foreach ($this->settings as $slug => $class) { |
|
116 | 116 | |
117 | 117 | /** @var WordPoints_Hook_Reaction_SettingI $setting */ |
118 | - $setting = new $class( $slug ); |
|
118 | + $setting = new $class($slug); |
|
119 | 119 | |
120 | - $value = isset( $settings[ $slug ] ) ? $settings[ $slug ] : null; |
|
120 | + $value = isset($settings[$slug]) ? $settings[$slug] : null; |
|
121 | 121 | |
122 | - $settings[ $slug ] = $setting->validate( $value, $validator ); |
|
122 | + $settings[$slug] = $setting->validate($value, $validator); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $settings; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @param WordPoints_Hooks $hooks |
135 | 135 | */ |
136 | -function wordpoints_hook_settings_app( $hooks ) { |
|
137 | - $hooks->sub_apps->register( 'settings', 'WordPoints_Hook_Settings' ); |
|
136 | +function wordpoints_hook_settings_app($hooks) { |
|
137 | + $hooks->sub_apps->register('settings', 'WordPoints_Hook_Settings'); |
|
138 | 138 | } |
139 | -add_action( 'wordpoints_hooks_init', 'wordpoints_hook_settings_app' ); |
|
139 | +add_action('wordpoints_hooks_init', 'wordpoints_hook_settings_app'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param WordPoints_Hook_Settings $settings |
147 | 147 | */ |
148 | -function wordpoints_register_hook_settings( $settings ) { |
|
148 | +function wordpoints_register_hook_settings($settings) { |
|
149 | 149 | |
150 | - add_action( 'wordpoints_hook_reaction_save', array( $settings, 'save_settings' ), 10, 3 ); |
|
151 | - add_filter( 'wordpoints_hook_reaction_validate', array( $settings, 'validate_settings' ), 10, 2 ); |
|
150 | + add_action('wordpoints_hook_reaction_save', array($settings, 'save_settings'), 10, 3); |
|
151 | + add_filter('wordpoints_hook_reaction_validate', array($settings, 'validate_settings'), 10, 2); |
|
152 | 152 | |
153 | - $settings->register( 'description', 'WordPoints_Hook_Reaction_Setting_Description' ); |
|
153 | + $settings->register('description', 'WordPoints_Hook_Reaction_Setting_Description'); |
|
154 | 154 | } |
155 | -add_action( 'wordpoints_hook_settings_init', 'wordpoints_register_hook_settings' ); |
|
155 | +add_action('wordpoints_hook_settings_init', 'wordpoints_register_hook_settings'); |
|
156 | 156 | |
157 | 157 | // EOF |
@@ -9,12 +9,36 @@ |
||
9 | 9 | |
10 | 10 | |
11 | 11 | interface WordPoints_Query_BuilderI { |
12 | + |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + */ |
|
12 | 16 | public function set_fields( $fields ); |
17 | + |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
13 | 21 | public function add_field( $field ); |
22 | + |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
14 | 26 | public function set_table( $table_name ); |
15 | 27 | public function get_table(); |
28 | + |
|
29 | + /** |
|
30 | + * @return void |
|
31 | + */ |
|
16 | 32 | public function enter_join( $join ); |
33 | + |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + */ |
|
17 | 37 | public function exit_join(); |
38 | + |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
18 | 42 | public function where( $condition ); |
19 | 43 | public function get_query(); |
20 | 44 | } |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | |
10 | 10 | |
11 | 11 | interface WordPoints_Query_BuilderI { |
12 | - public function set_fields( $fields ); |
|
13 | - public function add_field( $field ); |
|
14 | - public function set_table( $table_name ); |
|
12 | + public function set_fields($fields); |
|
13 | + public function add_field($field); |
|
14 | + public function set_table($table_name); |
|
15 | 15 | public function get_table(); |
16 | - public function enter_join( $join ); |
|
16 | + public function enter_join($join); |
|
17 | 17 | public function exit_join(); |
18 | - public function where( $condition ); |
|
18 | + public function where($condition); |
|
19 | 19 | public function get_query(); |
20 | 20 | } |
21 | 21 | |
@@ -33,55 +33,55 @@ discard block |
||
33 | 33 | protected $aliases = array(); |
34 | 34 | |
35 | 35 | public function __construct() { |
36 | - $this->query = new WordPoints_Hierarchy( 'joins' ); |
|
37 | - $this->query->push( '', array() ); |
|
36 | + $this->query = new WordPoints_Hierarchy('joins'); |
|
37 | + $this->query->push('', array()); |
|
38 | 38 | } |
39 | 39 | |
40 | - public function set_fields( $fields ) { |
|
41 | - $this->query->set_field( 'fields', $fields ); |
|
40 | + public function set_fields($fields) { |
|
41 | + $this->query->set_field('fields', $fields); |
|
42 | 42 | } |
43 | 43 | |
44 | - public function add_field( $field ) { |
|
45 | - $this->query->push_to( 'fields', $field ); |
|
44 | + public function add_field($field) { |
|
45 | + $this->query->push_to('fields', $field); |
|
46 | 46 | } |
47 | 47 | |
48 | - public function set_table( $table_name ) { |
|
49 | - $this->query->set_field( 'table_name', $table_name ); |
|
48 | + public function set_table($table_name) { |
|
49 | + $this->query->set_field('table_name', $table_name); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function get_table() { |
53 | - return $this->query->get_field( 'table_name' ); |
|
53 | + return $this->query->get_field('table_name'); |
|
54 | 54 | } |
55 | 55 | |
56 | - protected function get_alias( $data ) { |
|
56 | + protected function get_alias($data) { |
|
57 | 57 | |
58 | - if ( ! isset( $this->aliases[ $data['table_name'] ] ) ) { |
|
59 | - $this->aliases[ $data['table_name'] ] = 0; |
|
58 | + if ( ! isset($this->aliases[$data['table_name']])) { |
|
59 | + $this->aliases[$data['table_name']] = 0; |
|
60 | 60 | } |
61 | 61 | |
62 | - return $data['table_name'] . '_' . ++$this->aliases[ $data['table_name'] ]; |
|
62 | + return $data['table_name'].'_'.++$this->aliases[$data['table_name']]; |
|
63 | 63 | } |
64 | 64 | |
65 | - public function enter_join( $join ) { |
|
66 | - $alias = $this->get_alias( $join ); |
|
67 | - $this->query->push( $alias, $join ); |
|
65 | + public function enter_join($join) { |
|
66 | + $alias = $this->get_alias($join); |
|
67 | + $this->query->push($alias, $join); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public function exit_join() { |
71 | 71 | $this->query->pop(); |
72 | 72 | } |
73 | 73 | |
74 | - public function where( $condition ) { |
|
74 | + public function where($condition) { |
|
75 | 75 | |
76 | - $where = $this->query->get_field( 'where' ); |
|
76 | + $where = $this->query->get_field('where'); |
|
77 | 77 | |
78 | - if ( ! is_array( $where ) ) { |
|
78 | + if ( ! is_array($where)) { |
|
79 | 79 | $where = array(); |
80 | 80 | } |
81 | 81 | |
82 | 82 | $where[] = $condition; |
83 | 83 | |
84 | - $this->query->set_field( 'where', $where ); |
|
84 | + $this->query->set_field('where', $where); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -101,64 +101,64 @@ discard block |
||
101 | 101 | |
102 | 102 | var_dump($this->query); |
103 | 103 | try { |
104 | - $this->build_query( $this->query->get() ); |
|
105 | - } catch ( WordPoints_Query_Builder_Exception $e ) { |
|
106 | - return new WP_Error( $e->getMessage(), $e->getTraceAsString() ); |
|
104 | + $this->build_query($this->query->get()); |
|
105 | + } catch (WordPoints_Query_Builder_Exception $e) { |
|
106 | + return new WP_Error($e->getMessage(), $e->getTraceAsString()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return $this->sql; |
110 | 110 | } |
111 | 111 | |
112 | - protected function build_query( $query ) { |
|
112 | + protected function build_query($query) { |
|
113 | 113 | |
114 | - var_dump( __METHOD__, $query ); |
|
114 | + var_dump(__METHOD__, $query); |
|
115 | 115 | |
116 | - $this->alias = $this->get_alias( $query ); |
|
116 | + $this->alias = $this->get_alias($query); |
|
117 | 117 | |
118 | - $this->build_fields( $query ); |
|
119 | - $this->build_from( $query ); |
|
120 | - $this->build_joins( $query ); |
|
121 | - $this->build_where( $query ); |
|
118 | + $this->build_fields($query); |
|
119 | + $this->build_from($query); |
|
120 | + $this->build_joins($query); |
|
121 | + $this->build_where($query); |
|
122 | 122 | $this->build_select(); |
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function build_select() { |
126 | 126 | |
127 | - if ( empty( $this->fields ) ) { |
|
128 | - throw new WordPoints_Query_Builder_Exception( 'no fields' ); |
|
127 | + if (empty($this->fields)) { |
|
128 | + throw new WordPoints_Query_Builder_Exception('no fields'); |
|
129 | 129 | } |
130 | 130 | |
131 | - $this->sql = 'SELECT' . $this->fields . $this->sql; |
|
131 | + $this->sql = 'SELECT'.$this->fields.$this->sql; |
|
132 | 132 | } |
133 | 133 | |
134 | - protected function build_fields( $query ) { |
|
134 | + protected function build_fields($query) { |
|
135 | 135 | |
136 | - if ( empty( $query['fields'] ) ) { |
|
136 | + if (empty($query['fields'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - foreach ( $query['fields'] as $field ) { |
|
140 | + foreach ($query['fields'] as $field) { |
|
141 | 141 | |
142 | - if ( ! is_array( $field ) ) { |
|
143 | - $field = array( 'field' => $field ); |
|
142 | + if ( ! is_array($field)) { |
|
143 | + $field = array('field' => $field); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( ! isset( $field['field'] ) ) { |
|
147 | - throw new WordPoints_Query_Builder_Exception( 'invalid field' ); |
|
146 | + if ( ! isset($field['field'])) { |
|
147 | + throw new WordPoints_Query_Builder_Exception('invalid field'); |
|
148 | 148 | } |
149 | 149 | |
150 | - if ( ! empty( $this->fields ) ) { |
|
150 | + if ( ! empty($this->fields)) { |
|
151 | 151 | $this->fields .= ','; |
152 | 152 | } |
153 | 153 | |
154 | - $this->fields .= ' ' . $this->build_field( $field['field'] ); |
|
154 | + $this->fields .= ' '.$this->build_field($field['field']); |
|
155 | 155 | |
156 | 156 | $as = $field['field']; |
157 | - if ( isset( $field['as'] ) ) { |
|
157 | + if (isset($field['as'])) { |
|
158 | 158 | $as = $field['as']; |
159 | 159 | } |
160 | 160 | |
161 | - $this->fields .= ' AS `' . $this->escape_identifier( $as ) . '`'; |
|
161 | + $this->fields .= ' AS `'.$this->escape_identifier($as).'`'; |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -171,118 +171,118 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @throws WordPoints_Query_Builder_Exception |
173 | 173 | */ |
174 | - protected function build_field( $field ) { |
|
174 | + protected function build_field($field) { |
|
175 | 175 | |
176 | - $field_name = $this->get_field_name( $field ); |
|
176 | + $field_name = $this->get_field_name($field); |
|
177 | 177 | |
178 | - $sql = '`' . $this->escape_identifier( $this->alias ) . '`'; |
|
179 | - $sql .= '.`' . $this->escape_identifier( $field_name ) . '`'; |
|
178 | + $sql = '`'.$this->escape_identifier($this->alias).'`'; |
|
179 | + $sql .= '.`'.$this->escape_identifier($field_name).'`'; |
|
180 | 180 | |
181 | 181 | return $sql; |
182 | 182 | } |
183 | 183 | |
184 | - protected function build_from( $query ) { |
|
184 | + protected function build_from($query) { |
|
185 | 185 | |
186 | - if ( ! isset( $query['table_name'] ) ) { |
|
187 | - throw new WordPoints_Query_Builder_Exception( 'table_name' ); |
|
186 | + if ( ! isset($query['table_name'])) { |
|
187 | + throw new WordPoints_Query_Builder_Exception('table_name'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $this->sql .= "\n"; |
191 | - $this->sql .= 'FROM `' . $this->escape_identifier( $query['table_name'] ) . '`'; |
|
192 | - $this->sql .= ' AS `' . $this->escape_identifier( $this->alias ) . '`'; |
|
191 | + $this->sql .= 'FROM `'.$this->escape_identifier($query['table_name']).'`'; |
|
192 | + $this->sql .= ' AS `'.$this->escape_identifier($this->alias).'`'; |
|
193 | 193 | } |
194 | 194 | |
195 | - protected function build_joins( $query ) { |
|
195 | + protected function build_joins($query) { |
|
196 | 196 | |
197 | - if ( ! isset( $query['joins'] ) ) { |
|
197 | + if ( ! isset($query['joins'])) { |
|
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | - foreach ( $query['joins'] as $join ) { |
|
202 | - $this->build_join( $join ); |
|
201 | + foreach ($query['joins'] as $join) { |
|
202 | + $this->build_join($join); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - protected function build_join( $join ) { |
|
206 | + protected function build_join($join) { |
|
207 | 207 | |
208 | - if ( ! isset( $join['table_name'] ) ) { |
|
209 | - throw new WordPoints_Query_Builder_Exception( 'join table_name' ); |
|
208 | + if ( ! isset($join['table_name'])) { |
|
209 | + throw new WordPoints_Query_Builder_Exception('join table_name'); |
|
210 | 210 | } |
211 | 211 | |
212 | - if ( ! isset( $join['on'] ) ) { |
|
213 | - throw new WordPoints_Query_Builder_Exception( 'join on' ); |
|
212 | + if ( ! isset($join['on'])) { |
|
213 | + throw new WordPoints_Query_Builder_Exception('join on'); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( ! isset( $join['on']['join_field'] ) ) { |
|
217 | - throw new WordPoints_Query_Builder_Exception( 'join on join_field' ); |
|
216 | + if ( ! isset($join['on']['join_field'])) { |
|
217 | + throw new WordPoints_Query_Builder_Exception('join on join_field'); |
|
218 | 218 | } |
219 | 219 | |
220 | - if ( ! isset( $join['on']['primary_field'] ) ) { |
|
221 | - throw new WordPoints_Query_Builder_Exception( 'join on primary_field' ); |
|
220 | + if ( ! isset($join['on']['primary_field'])) { |
|
221 | + throw new WordPoints_Query_Builder_Exception('join on primary_field'); |
|
222 | 222 | } |
223 | 223 | |
224 | - $alias = $this->get_alias( $join ); |
|
224 | + $alias = $this->get_alias($join); |
|
225 | 225 | |
226 | 226 | $this->sql .= "\n"; |
227 | - $this->sql .= 'INNER JOIN `' . $this->escape_identifier( $join['table_name'] ) . '`'; |
|
228 | - $this->sql .= ' AS `' . $this->escape_identifier( $alias ) . '`'; |
|
229 | - $this->sql .= "\n\t" . 'ON ' . $this->build_field( $join['on']['primary_field'] ); |
|
227 | + $this->sql .= 'INNER JOIN `'.$this->escape_identifier($join['table_name']).'`'; |
|
228 | + $this->sql .= ' AS `'.$this->escape_identifier($alias).'`'; |
|
229 | + $this->sql .= "\n\t".'ON '.$this->build_field($join['on']['primary_field']); |
|
230 | 230 | |
231 | 231 | $old_alias = $this->alias; |
232 | 232 | $this->alias = $alias; |
233 | 233 | |
234 | - $this->sql .= ' = ' . $this->build_field( $join['on']['join_field'] ); |
|
234 | + $this->sql .= ' = '.$this->build_field($join['on']['join_field']); |
|
235 | 235 | |
236 | - $this->build_fields( $join ); |
|
236 | + $this->build_fields($join); |
|
237 | 237 | |
238 | - if ( isset( $join['where'] ) ) { |
|
239 | - foreach ( $join['where'] as $condition ) { |
|
240 | - $this->build_condition( $condition ); |
|
238 | + if (isset($join['where'])) { |
|
239 | + foreach ($join['where'] as $condition) { |
|
240 | + $this->build_condition($condition); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - $this->build_joins( $join ); |
|
244 | + $this->build_joins($join); |
|
245 | 245 | |
246 | 246 | $this->alias = $old_alias; |
247 | 247 | } |
248 | 248 | |
249 | - protected function build_where( $query ) { |
|
249 | + protected function build_where($query) { |
|
250 | 250 | |
251 | - if ( empty( $query['where'] ) ) { |
|
251 | + if (empty($query['where'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->sql .= "\n"; |
256 | 256 | $this->sql .= 'WHERE 1=1'; |
257 | 257 | |
258 | - foreach ( $query['where'] as $condition ) { |
|
259 | - $this->build_condition( $condition ); |
|
258 | + foreach ($query['where'] as $condition) { |
|
259 | + $this->build_condition($condition); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - protected function build_condition( $condition ) { |
|
263 | + protected function build_condition($condition) { |
|
264 | 264 | |
265 | 265 | global $wpdb; |
266 | 266 | |
267 | - if ( ! isset( $condition['field'], $condition['value'] ) ) { |
|
267 | + if ( ! isset($condition['field'], $condition['value'])) { |
|
268 | 268 | var_dump($condition); |
269 | - throw new WordPoints_Query_Builder_Exception( 'bad condition' ); |
|
269 | + throw new WordPoints_Query_Builder_Exception('bad condition'); |
|
270 | 270 | } |
271 | 271 | |
272 | - if ( ! isset( $condition['compare'] ) ) { |
|
272 | + if ( ! isset($condition['compare'])) { |
|
273 | 273 | $condition['compare'] = '='; |
274 | 274 | } |
275 | 275 | |
276 | 276 | $this->sql .= "\n\t"; |
277 | 277 | |
278 | - $this->build_condition_type( $condition ); |
|
278 | + $this->build_condition_type($condition); |
|
279 | 279 | |
280 | - $field_type = $this->get_field_type( $condition['field'] ); |
|
281 | - if ( 'serialized_array' === $field_type ) { |
|
282 | - if ( is_array( $condition['value'] ) ) { |
|
283 | - if ( isset( $condition['compare'] ) && 'in' === $condition['compare'] ) { |
|
280 | + $field_type = $this->get_field_type($condition['field']); |
|
281 | + if ('serialized_array' === $field_type) { |
|
282 | + if (is_array($condition['value'])) { |
|
283 | + if (isset($condition['compare']) && 'in' === $condition['compare']) { |
|
284 | 284 | $this->sql .= '( 1=0 '; |
285 | - foreach ( $condition['value'] as $index => $value ) { |
|
285 | + foreach ($condition['value'] as $index => $value) { |
|
286 | 286 | $this->build_condition( |
287 | 287 | array( |
288 | 288 | 'type' => 'or', |
@@ -296,13 +296,13 @@ discard block |
||
296 | 296 | return; |
297 | 297 | } |
298 | 298 | } else { |
299 | - $condition['value'] = $this->serialize_value( $condition['value'] ); |
|
299 | + $condition['value'] = $this->serialize_value($condition['value']); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - $this->sql .= $this->build_field( $condition['field'] ); |
|
303 | + $this->sql .= $this->build_field($condition['field']); |
|
304 | 304 | |
305 | - switch ( $condition['compare'] ) { |
|
305 | + switch ($condition['compare']) { |
|
306 | 306 | |
307 | 307 | case '=': |
308 | 308 | $this->sql .= ' = '; |
@@ -313,18 +313,18 @@ discard block |
||
313 | 313 | break; |
314 | 314 | |
315 | 315 | case 'in': |
316 | - $this->sql .= ' IN (' . wordpoints_prepare__in( $condition['value'] ) . ')'; |
|
316 | + $this->sql .= ' IN ('.wordpoints_prepare__in($condition['value']).')'; |
|
317 | 317 | return; |
318 | 318 | |
319 | 319 | default: |
320 | - throw new WordPoints_Query_Builder_Exception( 'bad condition comparison' ); |
|
320 | + throw new WordPoints_Query_Builder_Exception('bad condition comparison'); |
|
321 | 321 | } |
322 | 322 | |
323 | - if ( ! is_scalar( $condition['value'] ) ) { |
|
324 | - throw new WordPoints_Query_Builder_Exception( 'bad condition value' ); |
|
323 | + if ( ! is_scalar($condition['value'])) { |
|
324 | + throw new WordPoints_Query_Builder_Exception('bad condition value'); |
|
325 | 325 | } |
326 | 326 | |
327 | - $this->sql .= $wpdb->prepare( '%s', $condition['value'] ); |
|
327 | + $this->sql .= $wpdb->prepare('%s', $condition['value']); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,13 +336,13 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @throws WordPoints_Query_Builder_Exception |
338 | 338 | */ |
339 | - protected function build_condition_type( $condition ) { |
|
339 | + protected function build_condition_type($condition) { |
|
340 | 340 | |
341 | - if ( ! isset( $condition['type'] ) ) { |
|
341 | + if ( ! isset($condition['type'])) { |
|
342 | 342 | $condition['type'] = 'and'; |
343 | 343 | } |
344 | 344 | |
345 | - switch ( $condition['type'] ) { |
|
345 | + switch ($condition['type']) { |
|
346 | 346 | |
347 | 347 | case 'and': |
348 | 348 | $this->sql .= 'AND '; |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | break; |
354 | 354 | |
355 | 355 | default: |
356 | - throw new WordPoints_Query_Builder_Exception( 'bad condition type' ); |
|
356 | + throw new WordPoints_Query_Builder_Exception('bad condition type'); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | - protected function escape_identifier( $identifier ) { |
|
360 | + protected function escape_identifier($identifier) { |
|
361 | 361 | |
362 | - return str_replace( '`', '``', $identifier ); |
|
362 | + return str_replace('`', '``', $identifier); |
|
363 | 363 | } |
364 | 364 | |
365 | - protected function get_field_name( $field ) { |
|
365 | + protected function get_field_name($field) { |
|
366 | 366 | |
367 | - if ( is_array( $field ) ) { |
|
367 | + if (is_array($field)) { |
|
368 | 368 | |
369 | - if ( ! isset( $field['name'] ) ) { |
|
370 | - throw new WordPoints_Query_Builder_Exception( 'field name' ); |
|
369 | + if ( ! isset($field['name'])) { |
|
370 | + throw new WordPoints_Query_Builder_Exception('field name'); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | $field = $field['name']; |
@@ -376,22 +376,22 @@ discard block |
||
376 | 376 | return $field; |
377 | 377 | } |
378 | 378 | |
379 | - protected function get_field_type( $field ) { |
|
379 | + protected function get_field_type($field) { |
|
380 | 380 | |
381 | - if ( is_array( $field ) && isset( $field['type'] ) ) { |
|
381 | + if (is_array($field) && isset($field['type'])) { |
|
382 | 382 | return $field['type']; |
383 | 383 | } |
384 | 384 | |
385 | 385 | return 'string'; |
386 | 386 | } |
387 | 387 | |
388 | - protected function serialize_value( $value ) { |
|
388 | + protected function serialize_value($value) { |
|
389 | 389 | |
390 | - if ( is_string( $value ) ) { |
|
391 | - $value = '"' . $value . '"'; |
|
390 | + if (is_string($value)) { |
|
391 | + $value = '"'.$value.'"'; |
|
392 | 392 | } |
393 | 393 | |
394 | - return '%:' . $value . ';%'; |
|
394 | + return '%:'.$value.';%'; |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 |
@@ -284,6 +284,9 @@ |
||
284 | 284 | return $entities; |
285 | 285 | } |
286 | 286 | |
287 | + /** |
|
288 | + * @param integer $count |
|
289 | + */ |
|
287 | 290 | protected function check_count( $count ) { |
288 | 291 | |
289 | 292 | if ( isset( $this->settings['max'] ) && $count > $this->settings['max'] ) { |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | interface WordPoints_SpecI { |
12 | 12 | public function get_title(); |
13 | 13 | public function get_settings_fields(); |
14 | - public function validate_settings( $settings ); |
|
14 | + public function validate_settings($settings); |
|
15 | 15 | public function is_met(); |
16 | - public function get_error( $name ); |
|
16 | + public function get_error($name); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | abstract class WordPoints_Spec implements WordPoints_SpecI { |
@@ -25,38 +25,38 @@ discard block |
||
25 | 25 | * @param $value |
26 | 26 | * @param $expected |
27 | 27 | */ |
28 | - public function __construct( $value, $expected ) { |
|
28 | + public function __construct($value, $expected) { |
|
29 | 29 | $this->value = $value; |
30 | 30 | $this->expected = $expected; |
31 | 31 | } |
32 | 32 | |
33 | - public function validate_settings( $settings ) { |
|
33 | + public function validate_settings($settings) { |
|
34 | 34 | |
35 | 35 | $data_types = wordpoints_apps()->data_types; |
36 | 36 | |
37 | - foreach ( $this->get_settings_fields() as $setting => $data ) { |
|
37 | + foreach ($this->get_settings_fields() as $setting => $data) { |
|
38 | 38 | |
39 | - if ( ! isset( $settings[ $setting ] ) ) { |
|
39 | + if ( ! isset($settings[$setting])) { |
|
40 | 40 | |
41 | - if ( ! empty( $data['required'] ) ) { |
|
41 | + if ( ! empty($data['required'])) { |
|
42 | 42 | return 'error'; // TODO |
43 | 43 | } |
44 | 44 | |
45 | 45 | } else { |
46 | 46 | |
47 | - $data_type = $data_types->get( $data['type'] ); |
|
47 | + $data_type = $data_types->get($data['type']); |
|
48 | 48 | |
49 | - if ( ! $data_type instanceof WordPoints_Data_TypeI ) { |
|
49 | + if ( ! $data_type instanceof WordPoints_Data_TypeI) { |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | - $value = $data_type->validate_value( $settings[ $setting ] ); |
|
53 | + $value = $data_type->validate_value($settings[$setting]); |
|
54 | 54 | |
55 | - if ( is_wp_error( $value ) ) { |
|
55 | + if (is_wp_error($value)) { |
|
56 | 56 | return $value; |
57 | 57 | } |
58 | 58 | |
59 | - $settings[ $setting ] = $value; |
|
59 | + $settings[$setting] = $value; |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | class WordPoints_Spec_Number_Max extends WordPoints_Spec { |
68 | 68 | |
69 | 69 | public function get_title() { |
70 | - return __( 'Maximum', 'wordpoints' ); |
|
70 | + return __('Maximum', 'wordpoints'); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | public function get_settings_fields() { |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | return $this->value <= $this->expected; |
86 | 86 | } |
87 | 87 | |
88 | - public function get_error( $name ) { |
|
88 | + public function get_error($name) { |
|
89 | 89 | |
90 | 90 | return sprintf( |
91 | - __( '%1$s must not be more than %2$s.', 'wordpoints' ) |
|
91 | + __('%1$s must not be more than %2$s.', 'wordpoints') |
|
92 | 92 | , $name |
93 | 93 | , $this->expected |
94 | 94 | ); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | class WordPoints_Spec_String_Length_Max extends WordPoints_Spec { |
99 | 99 | |
100 | 100 | public function get_title() { |
101 | - return __( 'Maximum Length', 'wordpoints' ); |
|
101 | + return __('Maximum Length', 'wordpoints'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function get_settings_fields() { |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | public function is_met() { |
115 | - return strlen( $this->value ) <= $this->expected; |
|
115 | + return strlen($this->value) <= $this->expected; |
|
116 | 116 | } |
117 | 117 | |
118 | - public function get_error( $name ) { |
|
118 | + public function get_error($name) { |
|
119 | 119 | |
120 | 120 | return sprintf( |
121 | - __( '%1$s must not be longer than %2$s characters.', 'wordpoints' ) |
|
121 | + __('%1$s must not be longer than %2$s characters.', 'wordpoints') |
|
122 | 122 | , $name |
123 | 123 | , $this->expected |
124 | 124 | ); |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | class WordPoints_Spec_String_Contains extends WordPoints_Spec { |
130 | 130 | |
131 | 131 | public function get_title() { |
132 | - return __( 'Contains', 'wordpoints' ); |
|
132 | + return __('Contains', 'wordpoints'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | public function get_settings_fields() { |
136 | 136 | } |
137 | 137 | |
138 | 138 | public function is_met() { |
139 | - return false !== strpos( $this->value, $this->expected ); |
|
139 | + return false !== strpos($this->value, $this->expected); |
|
140 | 140 | } |
141 | 141 | |
142 | - public function get_error( $name ) { |
|
142 | + public function get_error($name) { |
|
143 | 143 | |
144 | 144 | return sprintf( |
145 | - __( '%1$s must contain "%2$s".', 'wordpoints' ) // TODO quotes |
|
145 | + __('%1$s must contain "%2$s".', 'wordpoints') // TODO quotes |
|
146 | 146 | , $name |
147 | 147 | , $this->expected |
148 | 148 | ); |
@@ -165,19 +165,19 @@ discard block |
||
165 | 165 | protected $validator; |
166 | 166 | |
167 | 167 | public function get_title() { |
168 | - return __( 'Contains', 'wordpoints' ); |
|
168 | + return __('Contains', 'wordpoints'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | public function get_settings_fields() { |
172 | 172 | return array( |
173 | 173 | 'min' => array( |
174 | 174 | 'slug' => 'min', |
175 | - 'label' => __( 'Minimum number of items', 'wordpoints' ), |
|
175 | + 'label' => __('Minimum number of items', 'wordpoints'), |
|
176 | 176 | 'type' => 'number', |
177 | 177 | ), |
178 | 178 | 'max' => array( |
179 | 179 | 'slug' => 'max', |
180 | - 'label' => __( 'Maximum number of items', 'wordpoints' ), |
|
180 | + 'label' => __('Maximum number of items', 'wordpoints'), |
|
181 | 181 | 'type' => 'number', |
182 | 182 | ), |
183 | 183 | ); |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | WordPoints_Hook_Reaction_Validator $validator |
190 | 190 | ) { |
191 | 191 | |
192 | - if ( ! $this->arg_type_supported( $arg, $validator ) ) { |
|
192 | + if ( ! $this->arg_type_supported($arg, $validator)) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
196 | 196 | $this->settings = $settings; |
197 | 197 | $this->validator = $validator; |
198 | 198 | |
199 | - if ( ! $this->validate_count() ) { |
|
199 | + if ( ! $this->validate_count()) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
203 | - if ( isset( $settings['conditions'] ) ) { |
|
203 | + if (isset($settings['conditions'])) { |
|
204 | 204 | $this->validate_conditions(); |
205 | 205 | } |
206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
210 | 210 | protected function validate_count() { |
211 | 211 | |
212 | 212 | if ( |
213 | - ! empty( $this->settings['max'] ) |
|
214 | - && ! wordpoints_posint( $this->settings['max'] ) |
|
213 | + ! empty($this->settings['max']) |
|
214 | + && ! wordpoints_posint($this->settings['max']) |
|
215 | 215 | ) { |
216 | 216 | $this->validator->add_error( |
217 | - __( 'The maximum must be a positive integer.', 'wordpoints' ) |
|
217 | + __('The maximum must be a positive integer.', 'wordpoints') |
|
218 | 218 | , 'max' |
219 | 219 | ); |
220 | 220 | } |
221 | 221 | |
222 | 222 | if ( |
223 | - ! empty( $this->settings['min'] ) |
|
224 | - && ! wordpoints_posint( $this->settings['min'] ) |
|
223 | + ! empty($this->settings['min']) |
|
224 | + && ! wordpoints_posint($this->settings['min']) |
|
225 | 225 | ) { |
226 | 226 | $this->validator->add_error( |
227 | - __( 'The minimum must be a positive integer.', 'wordpoints' ) |
|
227 | + __('The minimum must be a positive integer.', 'wordpoints') |
|
228 | 228 | , 'min' |
229 | 229 | ); |
230 | 230 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | ); |
240 | 240 | |
241 | 241 | $conditions = $conditions_extension->validate_settings( |
242 | - array( 'conditions' => $this->settings['conditions'] ) |
|
242 | + array('conditions' => $this->settings['conditions']) |
|
243 | 243 | , $this->validator |
244 | 244 | , $this->validator->get_event_args() |
245 | 245 | ); |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | |
250 | 250 | public function is_met() { |
251 | 251 | |
252 | - $entities = $this->filter_entities( $this->value ); |
|
252 | + $entities = $this->filter_entities($this->value); |
|
253 | 253 | |
254 | - return $this->check_count( count( $entities ) ); |
|
254 | + return $this->check_count(count($entities)); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -263,41 +263,41 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @return WordPoints_Entity[] |
265 | 265 | */ |
266 | - protected function filter_entities( $entities ) { |
|
266 | + protected function filter_entities($entities) { |
|
267 | 267 | |
268 | 268 | $conditions_extension = wordpoints_hooks()->extensions->get( |
269 | 269 | 'conditions' |
270 | 270 | ); |
271 | 271 | |
272 | - foreach ( $entities as $index => $entity ) { |
|
272 | + foreach ($entities as $index => $entity) { |
|
273 | 273 | |
274 | 274 | $matches = $conditions_extension->conditions_are_met( |
275 | 275 | $this->expected['conditions'] |
276 | - , new WordPoints_Hook_Event_Args( array( $entity ) ) |
|
276 | + , new WordPoints_Hook_Event_Args(array($entity)) |
|
277 | 277 | ); |
278 | 278 | |
279 | - if ( ! $matches ) { |
|
280 | - unset( $entities[ $index ] ); |
|
279 | + if ( ! $matches) { |
|
280 | + unset($entities[$index]); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | 284 | return $entities; |
285 | 285 | } |
286 | 286 | |
287 | - protected function check_count( $count ) { |
|
287 | + protected function check_count($count) { |
|
288 | 288 | |
289 | - if ( isset( $this->settings['max'] ) && $count > $this->settings['max'] ) { |
|
289 | + if (isset($this->settings['max']) && $count > $this->settings['max']) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - if ( isset( $this->settings['min'] ) && $count < $this->settings['min'] ) { |
|
293 | + if (isset($this->settings['min']) && $count < $this->settings['min']) { |
|
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | 297 | return true; |
298 | 298 | } |
299 | 299 | |
300 | - public function get_error( $name ) { |
|
300 | + public function get_error($name) { |
|
301 | 301 | // TODO: Implement get_error() method. |
302 | 302 | } |
303 | 303 | } |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @since 1.0.0 |
46 | 46 | */ |
47 | -require_once( dirname( __FILE__ ) . '/includes/constants.php' ); |
|
47 | +require_once(dirname(__FILE__).'/includes/constants.php'); |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * The module's functions. |
51 | 51 | * |
52 | 52 | * @since 1.0.0 |
53 | 53 | */ |
54 | -require_once( dirname( __FILE__ ) . '/includes/functions.php' ); |
|
54 | +require_once(dirname(__FILE__).'/includes/functions.php'); |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * The module's actions and filters. |
58 | 58 | * |
59 | 59 | * @since 1.0.0 |
60 | 60 | */ |
61 | -require_once( dirname( __FILE__ ) . '/includes/actions.php' ); |
|
61 | +require_once(dirname(__FILE__).'/includes/actions.php'); |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Class autoloader. |
@@ -67,22 +67,22 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @since 1.0.0 |
69 | 69 | */ |
70 | -require_once( dirname( __FILE__ ) . '/includes/classes/class/autoloader.php' ); |
|
70 | +require_once(dirname(__FILE__).'/includes/classes/class/autoloader.php'); |
|
71 | 71 | |
72 | 72 | // Register the classes to autoload. |
73 | 73 | WordPoints_Class_Autoloader::register_dir( |
74 | - dirname( __FILE__ ) . '/includes/classes' |
|
74 | + dirname(__FILE__).'/includes/classes' |
|
75 | 75 | , 'WordPoints_' |
76 | 76 | ); |
77 | 77 | |
78 | -if ( is_admin() ) { |
|
78 | +if (is_admin()) { |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Administration-side code. |
82 | 82 | * |
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | - require_once( dirname( __FILE__ ) . '/admin/admin.php' ); |
|
85 | + require_once(dirname(__FILE__).'/admin/admin.php'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // EOF |
@@ -28,46 +28,46 @@ |
||
28 | 28 | /** |
29 | 29 | * @since 1.0.0 |
30 | 30 | */ |
31 | - public function __construct( $slug ) { |
|
31 | + public function __construct($slug) { |
|
32 | 32 | |
33 | 33 | $this->registry = new WordPoints_Class_Registry(); |
34 | 34 | |
35 | - parent::__construct( $slug ); |
|
35 | + parent::__construct($slug); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @since 1.0.0 |
40 | 40 | */ |
41 | - public function get_all( array $args = array() ) { |
|
42 | - return $this->registry->get_all( $args ); |
|
41 | + public function get_all(array $args = array()) { |
|
42 | + return $this->registry->get_all($args); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @since 1.0.0 |
47 | 47 | */ |
48 | - public function get( $slug, array $args = array() ) { |
|
49 | - return $this->registry->get( $slug, $args ); |
|
48 | + public function get($slug, array $args = array()) { |
|
49 | + return $this->registry->get($slug, $args); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @since 1.0.0 |
54 | 54 | */ |
55 | - public function register( $slug, $class, array $args = array() ) { |
|
56 | - return $this->registry->register( $slug, $class, $args ); |
|
55 | + public function register($slug, $class, array $args = array()) { |
|
56 | + return $this->registry->register($slug, $class, $args); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @since 1.0.0 |
61 | 61 | */ |
62 | - public function deregister( $slug ) { |
|
63 | - $this->registry->deregister( $slug ); |
|
62 | + public function deregister($slug) { |
|
63 | + $this->registry->deregister($slug); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @since 1.0.0 |
68 | 68 | */ |
69 | - public function is_registered( $slug ) { |
|
70 | - return $this->registry->is_registered( $slug ); |
|
69 | + public function is_registered($slug) { |
|
70 | + return $this->registry->is_registered($slug); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | * @param string $dir The full path of the directory. |
63 | 63 | * @param string $prefix The prefix used for class names in this directory. |
64 | 64 | */ |
65 | - public static function register_dir( $dir, $prefix ) { |
|
65 | + public static function register_dir($dir, $prefix) { |
|
66 | 66 | |
67 | - if ( ! self::$added_action ) { |
|
68 | - add_action( 'wordpoints_modules_loaded', __CLASS__ . '::init', 0 ); |
|
67 | + if ( ! self::$added_action) { |
|
68 | + add_action('wordpoints_modules_loaded', __CLASS__.'::init', 0); |
|
69 | 69 | self::$added_action = true; |
70 | 70 | } |
71 | 71 | |
72 | - self::$prefixes[ $prefix ]['length'] = strlen( $prefix ); |
|
73 | - self::$prefixes[ $prefix ]['dirs'][] = trailingslashit( $dir ); |
|
72 | + self::$prefixes[$prefix]['length'] = strlen($prefix); |
|
73 | + self::$prefixes[$prefix]['dirs'][] = trailingslashit($dir); |
|
74 | 74 | |
75 | 75 | self::$sorted = false; |
76 | 76 | } |
@@ -86,31 +86,31 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @param string $class_name The name fo the class to load. |
88 | 88 | */ |
89 | - public static function load_class( $class_name ) { |
|
89 | + public static function load_class($class_name) { |
|
90 | 90 | |
91 | - if ( ! self::$sorted ) { |
|
92 | - arsort( self::$prefixes ); |
|
91 | + if ( ! self::$sorted) { |
|
92 | + arsort(self::$prefixes); |
|
93 | 93 | self::$sorted = true; |
94 | 94 | } |
95 | 95 | |
96 | - foreach ( self::$prefixes as $prefix => $data ) { |
|
96 | + foreach (self::$prefixes as $prefix => $data) { |
|
97 | 97 | |
98 | - if ( substr( $class_name, 0, $data['length'] ) !== $prefix ) { |
|
98 | + if (substr($class_name, 0, $data['length']) !== $prefix) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | - $trimmed_class_name = substr( $class_name, $data['length'] ); |
|
102 | + $trimmed_class_name = substr($class_name, $data['length']); |
|
103 | 103 | |
104 | - $file_name = str_replace( '_', '/', strtolower( $trimmed_class_name ) ); |
|
105 | - $file_name = $file_name . '.php'; |
|
104 | + $file_name = str_replace('_', '/', strtolower($trimmed_class_name)); |
|
105 | + $file_name = $file_name.'.php'; |
|
106 | 106 | |
107 | - foreach ( $data['dirs'] as $dir ) { |
|
107 | + foreach ($data['dirs'] as $dir) { |
|
108 | 108 | |
109 | - if ( ! file_exists( $dir . $file_name ) ) { |
|
109 | + if ( ! file_exists($dir.$file_name)) { |
|
110 | 110 | continue; |
111 | 111 | } |
112 | 112 | |
113 | - require_once( $dir . $file_name ); |
|
113 | + require_once($dir.$file_name); |
|
114 | 114 | |
115 | 115 | return; |
116 | 116 | } |
@@ -135,16 +135,16 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public static function init() { |
137 | 137 | |
138 | - if ( function_exists( 'spl_autoload_register' ) ) { |
|
138 | + if (function_exists('spl_autoload_register')) { |
|
139 | 139 | |
140 | - spl_autoload_register( __CLASS__ . '::load_class' ); |
|
140 | + spl_autoload_register(__CLASS__.'::load_class'); |
|
141 | 141 | |
142 | 142 | } else { |
143 | 143 | |
144 | - foreach ( self::$prefixes as $prefix => $data ) { |
|
145 | - foreach ( $data['dirs'] as $dir ) { |
|
146 | - if ( file_exists( $dir . '/index.php' ) ) { |
|
147 | - require( $dir . '/index.php' ); |
|
144 | + foreach (self::$prefixes as $prefix => $data) { |
|
145 | + foreach ($data['dirs'] as $dir) { |
|
146 | + if (file_exists($dir.'/index.php')) { |
|
147 | + require($dir.'/index.php'); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | } |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * @since 1.0.0 |
31 | 31 | */ |
32 | - public function get_all( array $args = array() ) { |
|
32 | + public function get_all(array $args = array()) { |
|
33 | 33 | |
34 | - $classes = array_diff_key( $this->classes, $this->objects ); |
|
34 | + $classes = array_diff_key($this->classes, $this->objects); |
|
35 | 35 | |
36 | - if ( ! empty( $classes ) ) { |
|
36 | + if ( ! empty($classes)) { |
|
37 | 37 | |
38 | 38 | $objects = WordPoints_Class_Registry::construct_with_args( |
39 | 39 | $classes |
@@ -49,40 +49,40 @@ discard block |
||
49 | 49 | /** |
50 | 50 | * @since 1.0.0 |
51 | 51 | */ |
52 | - public function get( $slug, array $args = array() ) { |
|
52 | + public function get($slug, array $args = array()) { |
|
53 | 53 | |
54 | - if ( ! isset( $this->objects[ $slug ] ) ) { |
|
54 | + if ( ! isset($this->objects[$slug])) { |
|
55 | 55 | |
56 | - $object = parent::get( $slug, $args ); |
|
56 | + $object = parent::get($slug, $args); |
|
57 | 57 | |
58 | - if ( ! $object ) { |
|
58 | + if ( ! $object) { |
|
59 | 59 | return false; |
60 | 60 | } |
61 | 61 | |
62 | - $this->objects[ $slug ] = $object; |
|
62 | + $this->objects[$slug] = $object; |
|
63 | 63 | } |
64 | 64 | |
65 | - return $this->objects[ $slug ]; |
|
65 | + return $this->objects[$slug]; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @since 1.0.0 |
70 | 70 | */ |
71 | - public function register( $slug, $class, array $args = array() ) { |
|
71 | + public function register($slug, $class, array $args = array()) { |
|
72 | 72 | |
73 | - unset( $this->objects[ $slug ] ); |
|
73 | + unset($this->objects[$slug]); |
|
74 | 74 | |
75 | - return parent::register( $slug, $class, $args ); |
|
75 | + return parent::register($slug, $class, $args); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @since 1.0.0 |
80 | 80 | */ |
81 | - public function deregister( $slug ) { |
|
81 | + public function deregister($slug) { |
|
82 | 82 | |
83 | - parent::deregister( $slug ); |
|
83 | + parent::deregister($slug); |
|
84 | 84 | |
85 | - unset( $this->objects[ $slug ] ); |
|
85 | + unset($this->objects[$slug]); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 |