Commit | Line | Data |
---|---|---|
a087cc8d FB |
1 | <?php |
2 | /*************************************************************************** | |
d4c08d89 | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
a087cc8d FB |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
d865c296 FB |
22 | |
23 | /****************** | |
24 | * CONDITIONS | |
25 | ******************/ | |
26 | ||
8363588b | 27 | // {{{ interface UserFilterCondition |
2d83cac9 RB |
28 | /** This interface describe objects which filter users based |
29 | * on various parameters. | |
30 | * The parameters of the filter must be given to the constructor. | |
31 | * The buildCondition function is called by UserFilter when | |
32 | * actually building the query. That function must call | |
33 | * $uf->addWheteverFilter so that the UserFilter makes | |
34 | * adequate joins. It must return the 'WHERE' condition to use | |
35 | * with the filter. | |
36 | */ | |
dcc63ed5 | 37 | interface UserFilterCondition extends PlFilterCondition |
a087cc8d | 38 | { |
a087cc8d | 39 | } |
8363588b | 40 | // }}} |
a087cc8d | 41 | |
77902bed | 42 | // {{{ class UFC_HasProfile |
53eae167 RB |
43 | /** Filters users who have a profile |
44 | */ | |
77902bed | 45 | class UFC_HasProfile implements UserFilterCondition |
eb1449b8 | 46 | { |
dcc63ed5 | 47 | public function buildCondition(PlFilter &$uf) |
eb1449b8 | 48 | { |
aaf70eb8 FB |
49 | $uf->requireProfiles(); |
50 | return 'p.pid IS NOT NULL'; | |
eb1449b8 FB |
51 | } |
52 | } | |
8363588b | 53 | // }}} |
eb1449b8 | 54 | |
ddba9d4f RB |
55 | // {{{ class UFC_Hruid |
56 | /** Filters users based on their hruid | |
57 | * @param $val Either an hruid, or a list of those | |
58 | */ | |
59 | class UFC_Hruid implements UserFilterCondition | |
60 | { | |
61 | private $hruids; | |
62 | ||
63 | public function __construct($val) | |
64 | { | |
65 | if (!is_array($val)) { | |
66 | $val = array($val); | |
67 | } | |
68 | $this->hruids = $val; | |
69 | } | |
70 | ||
71 | public function buildCondition(PlFilter &$uf) | |
72 | { | |
7752f73f | 73 | $uf->requireAccounts(); |
bde68f05 | 74 | return XDB::format('a.hruid IN {?}', $this->hruids); |
ddba9d4f RB |
75 | } |
76 | } | |
77 | // }}} | |
78 | ||
3e993f7a FB |
79 | // {{{ class UFC_Hrpid |
80 | /** Filters users based on the hrpid of their profiles | |
81 | * @param $val Either an hrpid, or a list of those | |
82 | */ | |
83 | class UFC_Hrpid implements UserFilterCondition | |
84 | { | |
85 | private $hrpids; | |
86 | ||
87 | public function __construct($val) | |
88 | { | |
89 | if (!is_array($val)) { | |
90 | $val = array($val); | |
91 | } | |
92 | $this->hrpids = $val; | |
93 | } | |
94 | ||
95 | public function buildCondition(PlFilter &$uf) | |
96 | { | |
97 | $uf->requireProfiles(); | |
bde68f05 | 98 | return XDB::format('p.hrpid IN {?}', $this->hrpids); |
3e993f7a FB |
99 | } |
100 | } | |
101 | // }}} | |
102 | ||
f73a4f1b RB |
103 | // {{{ class UFC_Ip |
104 | /** Filters users based on one of their last IPs | |
105 | * @param $ip IP from which connection are checked | |
106 | */ | |
107 | class UFC_Ip implements UserFilterCondition | |
108 | { | |
109 | private $ip; | |
110 | ||
111 | public function __construct($ip) | |
112 | { | |
113 | $this->ip = $ip; | |
114 | } | |
115 | ||
116 | public function buildCondition(PlFilter &$uf) | |
117 | { | |
118 | $sub = $uf->addLoggerFilter(); | |
119 | $ip = ip_to_uint($this->ip); | |
120 | return XDB::format($sub . '.ip = {?} OR ' . $sub . '.forward_ip = {?}', $ip, $ip); | |
121 | } | |
122 | } | |
123 | // }}} | |
124 | ||
d7ddf29b RB |
125 | // {{{ class UFC_Comment |
126 | class UFC_Comment implements UserFilterCondition | |
127 | { | |
128 | private $text; | |
129 | ||
130 | public function __construct($text) | |
131 | { | |
132 | $this->text = $text; | |
133 | } | |
134 | ||
135 | public function buildCondition(PlFilter &$uf) | |
136 | { | |
137 | $uf->requireProfiles(); | |
658b4c83 | 138 | return 'p.freetext ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->text); |
d7ddf29b RB |
139 | } |
140 | } | |
141 | // }}} | |
142 | ||
8363588b | 143 | // {{{ class UFC_Promo |
5d2e55c7 | 144 | /** Filters users based on promotion |
53eae167 RB |
145 | * @param $comparison Comparison operator (>, =, ...) |
146 | * @param $grade Formation on which to restrict, UserFilter::DISPLAY for "any formation" | |
5d2e55c7 | 147 | * @param $promo Promotion on which the filter is based |
53eae167 | 148 | */ |
a087cc8d FB |
149 | class UFC_Promo implements UserFilterCondition |
150 | { | |
a087cc8d FB |
151 | |
152 | private $grade; | |
153 | private $promo; | |
154 | private $comparison; | |
155 | ||
156 | public function __construct($comparison, $grade, $promo) | |
157 | { | |
158 | $this->grade = $grade; | |
159 | $this->comparison = $comparison; | |
160 | $this->promo = $promo; | |
38c6fe96 FB |
161 | if ($this->grade != UserFilter::DISPLAY) { |
162 | UserFilter::assertGrade($this->grade); | |
163 | } | |
a087cc8d FB |
164 | } |
165 | ||
dcc63ed5 | 166 | public function buildCondition(PlFilter &$uf) |
a087cc8d | 167 | { |
38c6fe96 FB |
168 | if ($this->grade == UserFilter::DISPLAY) { |
169 | $sub = $uf->addDisplayFilter(); | |
1a23a02b | 170 | return XDB::format('pd' . $sub . '.promo ' . $this->comparison . ' {?}', $this->promo); |
38c6fe96 FB |
171 | } else { |
172 | $sub = $uf->addEducationFilter(true, $this->grade); | |
173 | $field = 'pe' . $sub . '.' . UserFilter::promoYear($this->grade); | |
174 | return $field . ' IS NOT NULL AND ' . $field . ' ' . $this->comparison . ' ' . XDB::format('{?}', $this->promo); | |
175 | } | |
784745ce FB |
176 | } |
177 | } | |
8363588b | 178 | // }}} |
784745ce | 179 | |
9e8bacfb FB |
180 | // {{{ class UFC_SchoolId |
181 | /** Filters users based on their shoold identifier | |
182 | * @param type Parameter type (Xorg, AX, School) | |
183 | * @param value School id value | |
184 | */ | |
185 | class UFC_SchooldId implements UserFilterCondition | |
186 | { | |
187 | const AX = 'ax'; | |
188 | const Xorg = 'xorg'; | |
189 | const School = 'school'; | |
190 | ||
191 | private $type; | |
192 | private $id; | |
193 | ||
194 | static public function assertType($type) | |
195 | { | |
196 | if ($type != self::AX && $type != self::Xorg && $type != self::School) { | |
197 | Platal::page()->killError("Type de matricule invalide: $type"); | |
198 | } | |
199 | } | |
200 | ||
201 | public function __construct($type, $id) | |
202 | { | |
203 | $this->type = $type; | |
204 | $this->id = $id; | |
205 | self::assertType($type); | |
206 | } | |
207 | ||
208 | public function buildCondition(PlFilter &$uf) | |
209 | { | |
210 | $uf->requireProfiles(); | |
211 | $id = $this->id; | |
212 | $type = $this->type; | |
213 | if ($type == self::School) { | |
214 | $type = self::Xorg; | |
215 | $id = Profile::getXorgId($id); | |
216 | } | |
217 | return XDB::format('p.' . $type . '_id = {?}', $id); | |
218 | } | |
219 | } | |
220 | // }}} | |
221 | ||
fb3b6547 | 222 | // {{{ class UFC_EducationSchool |
d7ddf29b RB |
223 | /** Filters users by formation |
224 | * @param $val The formation to search (either ID or array of IDs) | |
225 | */ | |
fb3b6547 | 226 | class UFC_EducationSchool implements UserFilterCondition |
a7f8e48a | 227 | { |
d7ddf29b | 228 | private $val; |
a7f8e48a | 229 | |
d7ddf29b | 230 | public function __construct($val) |
a7f8e48a | 231 | { |
d7ddf29b RB |
232 | if (!is_array($val)) { |
233 | $val = array($val); | |
234 | } | |
235 | $this->val = $val; | |
a7f8e48a RB |
236 | } |
237 | ||
238 | public function buildCondition(PlFilter &$uf) | |
239 | { | |
240 | $sub = $uf->addEducationFilter(); | |
bde68f05 | 241 | return XDB::format('pe' . $sub . '.eduid IN {?}', $this->val); |
a7f8e48a RB |
242 | } |
243 | } | |
244 | // }}} | |
245 | ||
fb3b6547 RB |
246 | // {{{ class UFC_EducationDegree |
247 | class UFC_EducationDegree implements UserFilterCondition | |
d7ddf29b RB |
248 | { |
249 | private $diploma; | |
250 | ||
251 | public function __construct($diploma) | |
252 | { | |
253 | if (! is_array($diploma)) { | |
254 | $diploma = array($diploma); | |
255 | } | |
256 | $this->diploma = $diploma; | |
257 | } | |
258 | ||
259 | public function buildCondition(PlFilter &$uf) | |
260 | { | |
261 | $sub = $uf->addEducationFilter(); | |
bde68f05 | 262 | return XDB::format('pee' . $sub . '.degreeid IN {?}', $this->val); |
d7ddf29b RB |
263 | } |
264 | } | |
265 | // }}} | |
266 | ||
fb3b6547 RB |
267 | // {{{ class UFC_EducationField |
268 | class UFC_EducationField implements UserFilterCondition | |
d7ddf29b RB |
269 | { |
270 | private $val; | |
271 | ||
272 | public function __construct($val) | |
273 | { | |
46e88fe3 RB |
274 | if (!is_array($val)) { |
275 | $val = array($val); | |
276 | } | |
d7ddf29b RB |
277 | $this->val = $val; |
278 | } | |
279 | ||
280 | public function buildCondition(PlFilter &$uf) | |
281 | { | |
282 | $sub = $uf->addEducationFilter(); | |
bde68f05 | 283 | return XDB::format('pee' . $sub . '.fieldid IN {?}', $this->val); |
d7ddf29b RB |
284 | } |
285 | } | |
286 | // }}} | |
287 | ||
8363588b | 288 | // {{{ class UFC_Name |
53eae167 | 289 | /** Filters users based on name |
5d2e55c7 | 290 | * @param $type Type of name field on which filtering is done (firstname, lastname...) |
53eae167 | 291 | * @param $text Text on which to filter |
5d2e55c7 | 292 | * @param $mode Flag indicating search type (prefix, suffix, with particule...) |
53eae167 | 293 | */ |
784745ce FB |
294 | class UFC_Name implements UserFilterCondition |
295 | { | |
658b4c83 RB |
296 | const PREFIX = XDB::WILDCARD_PREFIX; // 0x001 |
297 | const SUFFIX = XDB::WILDCARD_SUFFIX; // 0x002 | |
298 | const CONTAINS = XDB::WILDCARD_CONTAINS; // 0x003 | |
299 | const PARTICLE = 0x007; // self::CONTAINS | 0x004 | |
300 | const VARIANTS = 0x008; | |
784745ce FB |
301 | |
302 | private $type; | |
303 | private $text; | |
304 | private $mode; | |
305 | ||
306 | public function __construct($type, $text, $mode) | |
307 | { | |
308 | $this->type = $type; | |
309 | $this->text = $text; | |
310 | $this->mode = $mode; | |
311 | } | |
312 | ||
313 | private function buildNameQuery($type, $variant, $where, UserFilter &$uf) | |
314 | { | |
315 | $sub = $uf->addNameFilter($type, $variant); | |
316 | return str_replace('$ME', 'pn' . $sub, $where); | |
317 | } | |
318 | ||
dcc63ed5 | 319 | public function buildCondition(PlFilter &$uf) |
784745ce FB |
320 | { |
321 | $left = '$ME.name'; | |
784745ce FB |
322 | if (($this->mode & self::PARTICLE) == self::PARTICLE) { |
323 | $left = 'CONCAT($ME.particle, \' \', $ME.name)'; | |
324 | } | |
658b4c83 RB |
325 | $right = XDB::formatWildcards($this->mode & self::CONTAINS, $this->text); |
326 | ||
327 | $cond = $left . $right; | |
784745ce | 328 | $conds = array($this->buildNameQuery($this->type, null, $cond, $uf)); |
913a4e90 RB |
329 | if (($this->mode & self::VARIANTS) != 0 && isset(Profile::$name_variants[$this->type])) { |
330 | foreach (Profile::$name_variants[$this->type] as $var) { | |
784745ce FB |
331 | $conds[] = $this->buildNameQuery($this->type, $var, $cond, $uf); |
332 | } | |
333 | } | |
334 | return implode(' OR ', $conds); | |
a087cc8d FB |
335 | } |
336 | } | |
8363588b | 337 | // }}} |
a087cc8d | 338 | |
40585144 RB |
339 | // {{{ class UFC_NameTokens |
340 | /** Selects users based on tokens in their name (for quicksearch) | |
341 | * @param $tokens An array of tokens to search | |
342 | * @param $flags Flags the tokens must have (e.g 'public' for public search) | |
343 | * @param $soundex (bool) Whether those tokens are fulltext or soundex | |
344 | */ | |
345 | class UFC_NameTokens implements UserFilterCondition | |
346 | { | |
347 | /* Flags */ | |
348 | const FLAG_PUBLIC = 'public'; | |
349 | ||
350 | private $tokens; | |
351 | private $flags; | |
352 | private $soundex; | |
79a0b464 | 353 | private $exact; |
40585144 | 354 | |
79a0b464 | 355 | public function __construct($tokens, $flags = array(), $soundex = false, $exact = false) |
40585144 RB |
356 | { |
357 | $this->tokens = $tokens; | |
358 | if (is_array($flags)) { | |
359 | $this->flags = $flags; | |
360 | } else { | |
361 | $this->flags = array($flags); | |
362 | } | |
363 | $this->soundex = $soundex; | |
79a0b464 | 364 | $this->exact = $exact; |
40585144 RB |
365 | } |
366 | ||
dcc63ed5 | 367 | public function buildCondition(PlFilter &$uf) |
40585144 | 368 | { |
79a0b464 | 369 | $sub = $uf->addNameTokensFilter(!($this->exact || $this->soundex)); |
40585144 RB |
370 | $conds = array(); |
371 | if ($this->soundex) { | |
bde68f05 | 372 | $conds[] = XDB::format($sub . '.soundex IN {?}', $this->tokens); |
79a0b464 | 373 | } else if ($this->exact) { |
bde68f05 | 374 | $conds[] = XDB::format($sub . '.token IN {?}', $this->tokens); |
40585144 RB |
375 | } else { |
376 | $tokconds = array(); | |
377 | foreach ($this->tokens as $token) { | |
416d4244 | 378 | $tokconds[] = $sub . '.token ' . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $token); |
40585144 RB |
379 | } |
380 | $conds[] = implode(' OR ', $tokconds); | |
381 | } | |
382 | ||
383 | if ($this->flags != null) { | |
bde68f05 | 384 | $conds[] = XDB::format($sub . '.flags IN {?}', $this->flags); |
40585144 RB |
385 | } |
386 | ||
387 | return implode(' AND ', $conds); | |
388 | } | |
389 | } | |
390 | // }}} | |
391 | ||
0fb3713c RB |
392 | // {{{ class UFC_Nationality |
393 | class UFC_Nationality implements UserFilterCondition | |
394 | { | |
d7ddf29b | 395 | private $val; |
0fb3713c | 396 | |
d7ddf29b | 397 | public function __construct($val) |
0fb3713c | 398 | { |
d7ddf29b RB |
399 | if (!is_array($val)) { |
400 | $val = array($val); | |
401 | } | |
402 | $this->val = $val; | |
0fb3713c RB |
403 | } |
404 | ||
405 | public function buildCondition(PlFilter &$uf) | |
406 | { | |
d7ddf29b RB |
407 | $uf->requireProfiles(); |
408 | $nat = XDB::formatArray($this->val); | |
409 | $conds = array( | |
410 | 'p.nationality1 IN ' . $nat, | |
411 | 'p.nationality2 IN ' . $nat, | |
412 | 'p.nationality3 IN ' . $nat, | |
413 | ); | |
414 | return implode(' OR ', $conds); | |
0fb3713c RB |
415 | } |
416 | } | |
417 | // }}} | |
418 | ||
8363588b | 419 | // {{{ class UFC_Dead |
53eae167 RB |
420 | /** Filters users based on death date |
421 | * @param $comparison Comparison operator | |
422 | * @param $date Date to which death date should be compared | |
423 | */ | |
4927ee54 FB |
424 | class UFC_Dead implements UserFilterCondition |
425 | { | |
38c6fe96 FB |
426 | private $comparison; |
427 | private $date; | |
428 | ||
429 | public function __construct($comparison = null, $date = null) | |
4927ee54 | 430 | { |
38c6fe96 FB |
431 | $this->comparison = $comparison; |
432 | $this->date = $date; | |
4927ee54 FB |
433 | } |
434 | ||
dcc63ed5 | 435 | public function buildCondition(PlFilter &$uf) |
4927ee54 | 436 | { |
d7ddf29b | 437 | $uf->requireProfiles(); |
38c6fe96 FB |
438 | $str = 'p.deathdate IS NOT NULL'; |
439 | if (!is_null($this->comparison)) { | |
440 | $str .= ' AND p.deathdate ' . $this->comparison . ' ' . XDB::format('{?}', date('Y-m-d', $this->date)); | |
4927ee54 | 441 | } |
38c6fe96 | 442 | return $str; |
4927ee54 FB |
443 | } |
444 | } | |
8363588b | 445 | // }}} |
4927ee54 | 446 | |
8363588b | 447 | // {{{ class UFC_Registered |
53eae167 RB |
448 | /** Filters users based on registration state |
449 | * @param $active Whether we want to use only "active" users (i.e with a valid redirection) | |
450 | * @param $comparison Comparison operator | |
451 | * @param $date Date to which users registration date should be compared | |
452 | */ | |
4927ee54 FB |
453 | class UFC_Registered implements UserFilterCondition |
454 | { | |
455 | private $active; | |
38c6fe96 FB |
456 | private $comparison; |
457 | private $date; | |
458 | ||
459 | public function __construct($active = false, $comparison = null, $date = null) | |
4927ee54 | 460 | { |
b2e8fc54 | 461 | $this->active = $active; |
38c6fe96 FB |
462 | $this->comparison = $comparison; |
463 | $this->date = $date; | |
4927ee54 FB |
464 | } |
465 | ||
dcc63ed5 | 466 | public function buildCondition(PlFilter &$uf) |
4927ee54 | 467 | { |
d7ddf29b | 468 | $uf->requireAccounts(); |
4927ee54 | 469 | if ($this->active) { |
38c6fe96 | 470 | $date = 'a.uid IS NOT NULL AND a.state = \'active\''; |
4927ee54 | 471 | } else { |
38c6fe96 FB |
472 | $date = 'a.uid IS NOT NULL AND a.state != \'pending\''; |
473 | } | |
474 | if (!is_null($this->comparison)) { | |
475 | $date .= ' AND a.registration_date ' . $this->comparison . ' ' . XDB::format('{?}', date('Y-m-d', $this->date)); | |
4927ee54 | 476 | } |
38c6fe96 | 477 | return $date; |
4927ee54 FB |
478 | } |
479 | } | |
8363588b | 480 | // }}} |
4927ee54 | 481 | |
8363588b | 482 | // {{{ class UFC_ProfileUpdated |
53eae167 RB |
483 | /** Filters users based on profile update date |
484 | * @param $comparison Comparison operator | |
485 | * @param $date Date to which profile update date must be compared | |
486 | */ | |
7e735012 FB |
487 | class UFC_ProfileUpdated implements UserFilterCondition |
488 | { | |
489 | private $comparison; | |
490 | private $date; | |
491 | ||
492 | public function __construct($comparison = null, $date = null) | |
493 | { | |
494 | $this->comparison = $comparison; | |
495 | $this->date = $date; | |
496 | } | |
497 | ||
dcc63ed5 | 498 | public function buildCondition(PlFilter &$uf) |
7e735012 | 499 | { |
d7ddf29b | 500 | $uf->requireProfiles(); |
7e735012 FB |
501 | return 'p.last_change ' . $this->comparison . XDB::format(' {?}', date('Y-m-d H:i:s', $this->date)); |
502 | } | |
503 | } | |
8363588b | 504 | // }}} |
7e735012 | 505 | |
8363588b | 506 | // {{{ class UFC_Birthday |
53eae167 RB |
507 | /** Filters users based on next birthday date |
508 | * @param $comparison Comparison operator | |
509 | * @param $date Date to which users next birthday date should be compared | |
510 | */ | |
7e735012 FB |
511 | class UFC_Birthday implements UserFilterCondition |
512 | { | |
513 | private $comparison; | |
514 | private $date; | |
515 | ||
516 | public function __construct($comparison = null, $date = null) | |
517 | { | |
518 | $this->comparison = $comparison; | |
519 | $this->date = $date; | |
520 | } | |
521 | ||
dcc63ed5 | 522 | public function buildCondition(PlFilter &$uf) |
7e735012 | 523 | { |
d7ddf29b | 524 | $uf->requireProfiles(); |
7e735012 FB |
525 | return 'p.next_birthday ' . $this->comparison . XDB::format(' {?}', date('Y-m-d', $this->date)); |
526 | } | |
527 | } | |
8363588b | 528 | // }}} |
7e735012 | 529 | |
8363588b | 530 | // {{{ class UFC_Sex |
53eae167 RB |
531 | /** Filters users based on sex |
532 | * @parm $sex One of User::GENDER_MALE or User::GENDER_FEMALE, for selecting users | |
533 | */ | |
4927ee54 FB |
534 | class UFC_Sex implements UserFilterCondition |
535 | { | |
536 | private $sex; | |
537 | public function __construct($sex) | |
538 | { | |
539 | $this->sex = $sex; | |
540 | } | |
541 | ||
dcc63ed5 | 542 | public function buildCondition(PlFilter &$uf) |
4927ee54 FB |
543 | { |
544 | if ($this->sex != User::GENDER_MALE && $this->sex != User::GENDER_FEMALE) { | |
545 | return self::COND_FALSE; | |
546 | } else { | |
d7ddf29b | 547 | $uf->requireProfiles(); |
24e08e33 | 548 | return XDB::format('p.sex = {?}', $this->sex == User::GENDER_FEMALE ? 'female' : 'male'); |
4927ee54 FB |
549 | } |
550 | } | |
551 | } | |
8363588b | 552 | // }}} |
4927ee54 | 553 | |
8363588b | 554 | // {{{ class UFC_Group |
53eae167 | 555 | /** Filters users based on group membership |
5d2e55c7 RB |
556 | * @param $group Group whose members we are selecting |
557 | * @param $anim Whether to restrict selection to animators of that group | |
53eae167 | 558 | */ |
4927ee54 FB |
559 | class UFC_Group implements UserFilterCondition |
560 | { | |
561 | private $group; | |
5d2e55c7 RB |
562 | private $anim; |
563 | public function __construct($group, $anim = false) | |
4927ee54 FB |
564 | { |
565 | $this->group = $group; | |
5d2e55c7 | 566 | $this->anim = $anim; |
4927ee54 FB |
567 | } |
568 | ||
dcc63ed5 | 569 | public function buildCondition(PlFilter &$uf) |
4927ee54 FB |
570 | { |
571 | $sub = $uf->addGroupFilter($this->group); | |
572 | $where = 'gpm' . $sub . '.perms IS NOT NULL'; | |
5d2e55c7 | 573 | if ($this->anim) { |
4927ee54 FB |
574 | $where .= ' AND gpm' . $sub . '.perms = \'admin\''; |
575 | } | |
576 | return $where; | |
577 | } | |
578 | } | |
8363588b | 579 | // }}} |
4927ee54 | 580 | |
0fb3713c | 581 | // {{{ class UFC_Binet |
d7ddf29b RB |
582 | /** Selects users based on their belonging to a given (list of) binet |
583 | * @param $binet either a binet_id or an array of binet_ids | |
584 | */ | |
0fb3713c RB |
585 | class UFC_Binet implements UserFilterCondition |
586 | { | |
d7ddf29b | 587 | private $val; |
0fb3713c | 588 | |
d7ddf29b | 589 | public function __construct($val) |
0fb3713c | 590 | { |
d7ddf29b RB |
591 | if (!is_array($val)) { |
592 | $val = array($val); | |
593 | } | |
594 | $this->val = $val; | |
0fb3713c RB |
595 | } |
596 | ||
597 | public function buildCondition(PlFilter &$uf) | |
598 | { | |
d7ddf29b | 599 | $sub = $uf->addBinetsFilter(); |
bde68f05 | 600 | return XDB::format($sub . '.binet_id IN {?}', $this->val); |
a7f8e48a RB |
601 | } |
602 | } | |
603 | // }}} | |
604 | ||
605 | // {{{ class UFC_Section | |
46e88fe3 RB |
606 | /** Selects users based on section |
607 | * @param $section ID of the section | |
608 | */ | |
a7f8e48a RB |
609 | class UFC_Section implements UserFilterCondition |
610 | { | |
611 | private $section; | |
612 | ||
613 | public function __construct($section) | |
614 | { | |
615 | $this->section = $section; | |
616 | } | |
617 | ||
618 | public function buildCondition(PlFilter &$uf) | |
619 | { | |
620 | $uf->requireProfiles(); | |
621 | return 'p.section = ' . XDB::format('{?}', $this->section); | |
0fb3713c RB |
622 | } |
623 | } | |
624 | // }}} | |
625 | ||
8363588b | 626 | // {{{ class UFC_Email |
2d6329a2 | 627 | /** Filters users based on an email or a list of emails |
53eae167 RB |
628 | * @param $emails List of emails whose owner must be selected |
629 | */ | |
2d6329a2 | 630 | class UFC_Email implements UserFilterCondition |
21401768 FB |
631 | { |
632 | private $emails; | |
2d6329a2 | 633 | public function __construct() |
21401768 | 634 | { |
2d6329a2 | 635 | $this->emails = func_get_args(); |
21401768 FB |
636 | } |
637 | ||
dcc63ed5 | 638 | public function buildCondition(PlFilter &$uf) |
21401768 | 639 | { |
2d6329a2 FB |
640 | $foreign = array(); |
641 | $virtual = array(); | |
642 | $aliases = array(); | |
21401768 FB |
643 | $cond = array(); |
644 | ||
645 | if (count($this->emails) == 0) { | |
dcc63ed5 | 646 | return PlFilterCondition::COND_TRUE; |
21401768 FB |
647 | } |
648 | ||
649 | foreach ($this->emails as $entry) { | |
650 | if (User::isForeignEmailAddress($entry)) { | |
2d6329a2 | 651 | $foreign[] = $entry; |
21401768 | 652 | } else if (User::isVirtualEmailAddress($entry)) { |
2d6329a2 | 653 | $virtual[] = $entry; |
21401768 | 654 | } else { |
21401768 | 655 | @list($user, $domain) = explode('@', $entry); |
2d6329a2 | 656 | $aliases[] = $user; |
21401768 FB |
657 | } |
658 | } | |
2d6329a2 FB |
659 | |
660 | if (count($foreign) > 0) { | |
661 | $sub = $uf->addEmailRedirectFilter($foreign); | |
bde68f05 | 662 | $cond[] = XDB::format('e' . $sub . '.email IS NOT NULL OR a.email IN {?}', $foreign); |
2d6329a2 FB |
663 | } |
664 | if (count($virtual) > 0) { | |
665 | $sub = $uf->addVirtualEmailFilter($virtual); | |
666 | $cond[] = 'vr' . $sub . '.redirect IS NOT NULL'; | |
667 | } | |
668 | if (count($aliases) > 0) { | |
669 | $sub = $uf->addAliasFilter($aliases); | |
670 | $cond[] = 'al' . $sub . '.alias IS NOT NULL'; | |
671 | } | |
21401768 FB |
672 | return '(' . implode(') OR (', $cond) . ')'; |
673 | } | |
674 | } | |
8363588b | 675 | // }}} |
d865c296 | 676 | |
8363588b | 677 | // {{{ class UFC_Address |
2b9ca54d | 678 | abstract class UFC_Address implements UserFilterCondition |
c4b24511 | 679 | { |
2b9ca54d | 680 | /** Valid address type ('hq' is reserved for company addresses) |
036d1637 | 681 | */ |
2b9ca54d RB |
682 | const TYPE_HOME = 1; |
683 | const TYPE_PRO = 2; | |
684 | const TYPE_ANY = 3; | |
c4b24511 | 685 | |
2b9ca54d | 686 | /** Text for these types |
036d1637 | 687 | */ |
2b9ca54d RB |
688 | protected static $typetexts = array( |
689 | self::TYPE_HOME => 'home', | |
690 | self::TYPE_PRO => 'pro', | |
691 | ); | |
692 | ||
693 | protected $type; | |
c4b24511 | 694 | |
036d1637 RB |
695 | /** Flags for addresses |
696 | */ | |
697 | const FLAG_CURRENT = 0x0001; | |
698 | const FLAG_TEMP = 0x0002; | |
699 | const FLAG_SECOND = 0x0004; | |
700 | const FLAG_MAIL = 0x0008; | |
701 | const FLAG_CEDEX = 0x0010; | |
702 | ||
703 | // Binary OR of those flags | |
704 | const FLAG_ANY = 0x001F; | |
705 | ||
706 | /** Text of these flags | |
707 | */ | |
2b9ca54d | 708 | protected static $flagtexts = array( |
036d1637 RB |
709 | self::FLAG_CURRENT => 'current', |
710 | self::FLAG_TEMP => 'temporary', | |
711 | self::FLAG_SECOND => 'secondary', | |
712 | self::FLAG_MAIL => 'mail', | |
713 | self::FLAG_CEDEX => 'cedex', | |
714 | ); | |
715 | ||
2b9ca54d RB |
716 | protected $flags; |
717 | ||
718 | public function __construct($type = null, $flags = null) | |
719 | { | |
720 | $this->type = $type; | |
721 | $this->flags = $flags; | |
722 | } | |
723 | ||
724 | protected function initConds($sub) | |
725 | { | |
726 | $conds = array(); | |
727 | $types = array(); | |
728 | foreach (self::$typetexts as $flag => $type) { | |
729 | if ($flag & $this->type) { | |
730 | $types[] = $type; | |
731 | } | |
732 | } | |
733 | if (count($types)) { | |
6b140032 | 734 | $conds[] = XDB::format($sub . '.type IN {?}', $types); |
2b9ca54d RB |
735 | } |
736 | ||
737 | if ($this->flags != self::FLAG_ANY) { | |
738 | foreach(self::$flagtexts as $flag => $text) { | |
739 | if ($flag & $this->flags) { | |
740 | $conds[] = 'FIND_IN_SET(' . XDB::format('{?}', $text) . ', ' . $sub . '.flags)'; | |
741 | } | |
742 | } | |
743 | } | |
744 | return $conds; | |
745 | } | |
746 | ||
747 | } | |
748 | // }}} | |
749 | ||
750 | // {{{ class UFC_AddressText | |
751 | /** Select users based on their address, using full text search | |
752 | * @param $text Text for filter in fulltext search | |
658b4c83 | 753 | * @param $textSearchMode Mode for search (one of XDB::WILDCARD_*) |
2b9ca54d RB |
754 | * @param $type Filter on address type |
755 | * @param $flags Filter on address flags | |
756 | * @param $country Filter on address country | |
757 | * @param $locality Filter on address locality | |
758 | */ | |
759 | class UFC_AddressText extends UFC_Address | |
760 | { | |
2b9ca54d | 761 | |
036d1637 | 762 | private $text; |
2b9ca54d RB |
763 | private $textSearchMode; |
764 | ||
658b4c83 | 765 | public function __construct($text = null, $textSearchMode = XDB::WILDCARD_CONTAINS, |
2b9ca54d RB |
766 | $type = null, $flags = self::FLAG_ANY, $country = null, $locality = null) |
767 | { | |
768 | parent::__construct($type, $flags); | |
769 | $this->text = $text; | |
770 | $this->textSearchMode = $textSearchMode; | |
771 | $this->country = $country; | |
772 | $this->locality = $locality; | |
773 | } | |
774 | ||
775 | private function mkMatch($txt) | |
776 | { | |
658b4c83 | 777 | return XDB::formatWildcards($this->textSearchMode, $txt); |
2b9ca54d RB |
778 | } |
779 | ||
780 | public function buildCondition(PlFilter &$uf) | |
781 | { | |
782 | $sub = $uf->addAddressFilter(); | |
783 | $conds = $this->initConds($sub); | |
784 | if ($this->text != null) { | |
785 | $conds[] = $sub . '.text' . $this->mkMatch($this->text); | |
786 | } | |
787 | ||
788 | if ($this->country != null) { | |
789 | $subc = $uf->addAddressCountryFilter(); | |
790 | $subconds = array(); | |
791 | $subconds[] = $subc . '.country' . $this->mkMatch($this->country); | |
792 | $subconds[] = $subc . '.countryFR' . $this->mkMatch($this->country); | |
793 | $conds[] = implode(' OR ', $subconds); | |
794 | } | |
795 | ||
796 | if ($this->locality != null) { | |
797 | $subl = $uf->addAddressLocalityFilter(); | |
798 | $conds[] = $subl . '.name' . $this->mkMatch($this->locality); | |
799 | } | |
800 | ||
801 | return implode(' AND ', $conds); | |
802 | } | |
803 | } | |
804 | // }}} | |
805 | ||
46e88fe3 | 806 | // {{{ class UFC_AddressField |
2b9ca54d | 807 | /** Filters users based on their address, |
46e88fe3 RB |
808 | * @param $val Either a code for one of the fields, or an array of such codes |
809 | * @param $fieldtype The type of field to look for | |
2b9ca54d RB |
810 | * @param $type Filter on address type |
811 | * @param $flags Filter on address flags | |
2b9ca54d | 812 | */ |
46e88fe3 | 813 | class UFC_AddressField extends UFC_Address |
2b9ca54d | 814 | { |
46e88fe3 RB |
815 | const FIELD_COUNTRY = 1; |
816 | const FIELD_ADMAREA = 2; | |
817 | const FIELD_SUBADMAREA = 3; | |
818 | const FIELD_LOCALITY = 4; | |
819 | const FIELD_ZIPCODE = 5; | |
820 | ||
2b9ca54d RB |
821 | /** Data of the filter |
822 | */ | |
46e88fe3 RB |
823 | private $val; |
824 | private $fieldtype; | |
036d1637 | 825 | |
46e88fe3 | 826 | public function __construct($val, $fieldtype, $type = null, $flags = self::FLAG_ANY) |
036d1637 | 827 | { |
2b9ca54d | 828 | parent::__construct($type, $flags); |
46e88fe3 RB |
829 | |
830 | if (!is_array($val)) { | |
831 | $val = array($val); | |
832 | } | |
833 | $this->val = $val; | |
834 | $this->fieldtype = $fieldtype; | |
c4b24511 RB |
835 | } |
836 | ||
dcc63ed5 | 837 | public function buildCondition(PlFilter &$uf) |
c4b24511 | 838 | { |
036d1637 | 839 | $sub = $uf->addAddressFilter(); |
d7ddf29b | 840 | $conds = $this->initConds($sub); |
036d1637 | 841 | |
46e88fe3 RB |
842 | switch ($this->fieldtype) { |
843 | case self::FIELD_COUNTRY: | |
844 | $field = 'countryId'; | |
845 | break; | |
846 | case self::FIELD_ADMAREA: | |
847 | $field = 'administrativeAreaId'; | |
848 | break; | |
849 | case self::FIELD_SUBADMAREA: | |
850 | $field = 'subAdministrativeAreaId'; | |
851 | break; | |
852 | case self::FIELD_LOCALITY: | |
853 | $field = 'localityId'; | |
854 | break; | |
855 | case self::FIELD_ZIPCODE: | |
856 | $field = 'postalCode'; | |
857 | break; | |
858 | default: | |
61f61261 | 859 | Platal::page()->killError('Invalid address field type: ' . $this->fieldtype); |
46e88fe3 | 860 | } |
bde68f05 | 861 | $conds[] = XDB::format($sub . '.' . $field . ' IN {?}', $this->val); |
036d1637 RB |
862 | |
863 | return implode(' AND ', $conds); | |
c4b24511 RB |
864 | } |
865 | } | |
8363588b | 866 | // }}} |
c4b24511 | 867 | |
8363588b | 868 | // {{{ class UFC_Corps |
4083b126 RB |
869 | /** Filters users based on the corps they belong to |
870 | * @param $corps Corps we are looking for (abbreviation) | |
871 | * @param $type Whether we search for original or current corps | |
872 | */ | |
873 | class UFC_Corps implements UserFilterCondition | |
874 | { | |
5d2e55c7 RB |
875 | const CURRENT = 1; |
876 | const ORIGIN = 2; | |
4083b126 RB |
877 | |
878 | private $corps; | |
879 | private $type; | |
880 | ||
881 | public function __construct($corps, $type = self::CURRENT) | |
882 | { | |
883 | $this->corps = $corps; | |
884 | $this->type = $type; | |
885 | } | |
886 | ||
dcc63ed5 | 887 | public function buildCondition(PlFilter &$uf) |
4083b126 | 888 | { |
5d2e55c7 RB |
889 | /** Tables shortcuts: |
890 | * pc for profile_corps, | |
4083b126 RB |
891 | * pceo for profile_corps_enum - orginal |
892 | * pcec for profile_corps_enum - current | |
893 | */ | |
894 | $sub = $uf->addCorpsFilter($this->type); | |
895 | $cond = $sub . '.abbreviation = ' . $corps; | |
896 | return $cond; | |
897 | } | |
898 | } | |
8363588b | 899 | // }}} |
4083b126 | 900 | |
8363588b | 901 | // {{{ class UFC_Corps_Rank |
4083b126 RB |
902 | /** Filters users based on their rank in the corps |
903 | * @param $rank Rank we are looking for (abbreviation) | |
904 | */ | |
905 | class UFC_Corps_Rank implements UserFilterCondition | |
906 | { | |
907 | private $rank; | |
908 | public function __construct($rank) | |
909 | { | |
910 | $this->rank = $rank; | |
911 | } | |
912 | ||
dcc63ed5 | 913 | public function buildCondition(PlFilter &$uf) |
4083b126 | 914 | { |
5d2e55c7 | 915 | /** Tables shortcuts: |
4083b126 RB |
916 | * pcr for profile_corps_rank |
917 | */ | |
918 | $sub = $uf->addCorpsRankFilter(); | |
919 | $cond = $sub . '.abbreviation = ' . $rank; | |
920 | return $cond; | |
921 | } | |
922 | } | |
8363588b | 923 | // }}} |
4083b126 | 924 | |
6a99c3ac RB |
925 | // {{{ class UFC_Job_Company |
926 | /** Filters users based on the company they belong to | |
927 | * @param $type The field being searched (self::JOBID, self::JOBNAME or self::JOBACRONYM) | |
928 | * @param $value The searched value | |
929 | */ | |
4e2f2ad2 | 930 | class UFC_Job_Company implements UserFilterCondition |
6a99c3ac RB |
931 | { |
932 | const JOBID = 'id'; | |
933 | const JOBNAME = 'name'; | |
934 | const JOBACRONYM = 'acronym'; | |
935 | ||
936 | private $type; | |
937 | private $value; | |
938 | ||
939 | public function __construct($type, $value) | |
940 | { | |
941 | $this->assertType($type); | |
942 | $this->type = $type; | |
943 | $this->value = $value; | |
944 | } | |
945 | ||
946 | private function assertType($type) | |
947 | { | |
948 | if ($type != self::JOBID && $type != self::JOBNAME && $type != self::JOBACRONYM) { | |
5d2e55c7 | 949 | Platal::page()->killError("Type de recherche non valide."); |
6a99c3ac RB |
950 | } |
951 | } | |
952 | ||
dcc63ed5 | 953 | public function buildCondition(PlFilter &$uf) |
6a99c3ac RB |
954 | { |
955 | $sub = $uf->addJobCompanyFilter(); | |
956 | $cond = $sub . '.' . $this->type . ' = ' . XDB::format('{?}', $this->value); | |
957 | return $cond; | |
958 | } | |
959 | } | |
960 | // }}} | |
961 | ||
962 | // {{{ class UFC_Job_Sectorization | |
963 | /** Filters users based on the ((sub)sub)sector they work in | |
46e88fe3 | 964 | * @param $val The ID of the sector, or an array of such IDs |
d7ddf29b | 965 | * @param $type The kind of search (subsubsector/subsector/sector) |
6a99c3ac | 966 | */ |
4e2f2ad2 | 967 | class UFC_Job_Sectorization implements UserFilterCondition |
6a99c3ac | 968 | { |
d7ddf29b RB |
969 | private $val; |
970 | private $type; | |
6a99c3ac | 971 | |
d7ddf29b RB |
972 | public function __construct($val, $type = UserFilter::JOB_SECTOR) |
973 | { | |
974 | self::assertType($type); | |
46e88fe3 RB |
975 | if (!is_array($val)) { |
976 | $val = array($val); | |
977 | } | |
d7ddf29b RB |
978 | $this->val = $val; |
979 | $this->type = $type; | |
980 | } | |
6a99c3ac | 981 | |
d7ddf29b | 982 | private static function assertType($type) |
6a99c3ac | 983 | { |
d7ddf29b RB |
984 | if ($type != UserFilter::JOB_SECTOR && $type != UserFilter::JOB_SUBSECTOR && $type != UserFilter::JOB_SUBSUBSECTOR) { |
985 | Platal::page()->killError("Type de secteur non valide."); | |
986 | } | |
6a99c3ac RB |
987 | } |
988 | ||
dcc63ed5 | 989 | public function buildCondition(PlFilter &$uf) |
6a99c3ac | 990 | { |
d7ddf29b RB |
991 | $sub = $uf->addJobSectorizationFilter($this->type); |
992 | return $sub . '.id = ' . XDB::format('{?}', $this->val); | |
6a99c3ac RB |
993 | } |
994 | } | |
995 | // }}} | |
996 | ||
997 | // {{{ class UFC_Job_Description | |
998 | /** Filters users based on their job description | |
999 | * @param $description The text being searched for | |
1000 | * @param $fields The fields to search for (user-defined, ((sub|)sub|)sector) | |
1001 | */ | |
4e2f2ad2 | 1002 | class UFC_Job_Description implements UserFilterCondition |
6a99c3ac RB |
1003 | { |
1004 | ||
6a99c3ac RB |
1005 | private $description; |
1006 | private $fields; | |
1007 | ||
01cc5f9e | 1008 | public function __construct($description, $fields) |
6a99c3ac RB |
1009 | { |
1010 | $this->fields = $fields; | |
1011 | $this->description = $description; | |
1012 | } | |
1013 | ||
dcc63ed5 | 1014 | public function buildCondition(PlFilter &$uf) |
6a99c3ac RB |
1015 | { |
1016 | $conds = array(); | |
1017 | if ($this->fields & UserFilter::JOB_USERDEFINED) { | |
1018 | $sub = $uf->addJobFilter(); | |
658b4c83 | 1019 | $conds[] = $sub . '.description ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
6a99c3ac | 1020 | } |
01cc5f9e RB |
1021 | if ($this->fields & UserFilter::JOB_CV) { |
1022 | $uf->requireProfiles(); | |
658b4c83 | 1023 | $conds[] = 'p.cv ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
01cc5f9e | 1024 | } |
6a99c3ac RB |
1025 | if ($this->fields & UserFilter::JOB_SECTOR) { |
1026 | $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SECTOR); | |
658b4c83 | 1027 | $conds[] = $sub . '.name ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
6a99c3ac RB |
1028 | } |
1029 | if ($this->fields & UserFilter::JOB_SUBSECTOR) { | |
1030 | $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSECTOR); | |
658b4c83 | 1031 | $conds[] = $sub . '.name ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
6a99c3ac RB |
1032 | } |
1033 | if ($this->fields & UserFilter::JOB_SUBSUBSECTOR) { | |
1034 | $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_SUBSUBSECTOR); | |
658b4c83 | 1035 | $conds[] = $sub . '.name ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
6a99c3ac | 1036 | $sub = $uf->addJobSectorizationFilter(UserFilter::JOB_ALTERNATES); |
658b4c83 | 1037 | $conds[] = $sub . '.name ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description); |
6a99c3ac RB |
1038 | } |
1039 | return implode(' OR ', $conds); | |
1040 | } | |
1041 | } | |
1042 | // }}} | |
1043 | ||
0a2e9c74 RB |
1044 | // {{{ class UFC_Networking |
1045 | /** Filters users based on network identity (IRC, ...) | |
1046 | * @param $type Type of network (-1 for any) | |
1047 | * @param $value Value to search | |
1048 | */ | |
4e2f2ad2 | 1049 | class UFC_Networking implements UserFilterCondition |
0a2e9c74 RB |
1050 | { |
1051 | private $type; | |
1052 | private $value; | |
1053 | ||
1054 | public function __construct($type, $value) | |
1055 | { | |
1056 | $this->type = $type; | |
1057 | $this->value = $value; | |
1058 | } | |
1059 | ||
dcc63ed5 | 1060 | public function buildCondition(PlFilter &$uf) |
0a2e9c74 RB |
1061 | { |
1062 | $sub = $uf->addNetworkingFilter(); | |
1063 | $conds = array(); | |
658b4c83 | 1064 | $conds[] = $sub . '.address ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value); |
0a2e9c74 RB |
1065 | if ($this->type != -1) { |
1066 | $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type); | |
1067 | } | |
1068 | return implode(' AND ', $conds); | |
1069 | } | |
1070 | } | |
1071 | // }}} | |
1072 | ||
6d62969e RB |
1073 | // {{{ class UFC_Phone |
1074 | /** Filters users based on their phone number | |
1075 | * @param $num_type Type of number (pro/user/home) | |
1076 | * @param $phone_type Type of phone (fixed/mobile/fax) | |
1077 | * @param $number Phone number | |
1078 | */ | |
4e2f2ad2 | 1079 | class UFC_Phone implements UserFilterCondition |
6d62969e RB |
1080 | { |
1081 | const NUM_PRO = 'pro'; | |
1082 | const NUM_USER = 'user'; | |
1083 | const NUM_HOME = 'address'; | |
1084 | const NUM_ANY = 'any'; | |
1085 | ||
1086 | const PHONE_FIXED = 'fixed'; | |
1087 | const PHONE_MOBILE = 'mobile'; | |
1088 | const PHONE_FAX = 'fax'; | |
1089 | const PHONE_ANY = 'any'; | |
1090 | ||
1091 | private $num_type; | |
1092 | private $phone_type; | |
1093 | private $number; | |
1094 | ||
1095 | public function __construct($number, $num_type = self::NUM_ANY, $phone_type = self::PHONE_ANY) | |
1096 | { | |
9b8e5fb4 | 1097 | require_once('profil.func.inc.php'); |
6d62969e RB |
1098 | $this->number = $number; |
1099 | $this->num_type = $num_type; | |
1100 | $this->phone_type = format_phone_number($phone_type); | |
1101 | } | |
1102 | ||
dcc63ed5 | 1103 | public function buildCondition(PlFilter &$uf) |
6d62969e RB |
1104 | { |
1105 | $sub = $uf->addPhoneFilter(); | |
1106 | $conds = array(); | |
1107 | $conds[] = $sub . '.search_tel = ' . XDB::format('{?}', $this->number); | |
1108 | if ($this->num_type != self::NUM_ANY) { | |
1109 | $conds[] = $sub . '.link_type = ' . XDB::format('{?}', $this->num_type); | |
1110 | } | |
1111 | if ($this->phone_type != self::PHONE_ANY) { | |
1112 | $conds[] = $sub . '.tel_type = ' . XDB::format('{?}', $this->phone_type); | |
1113 | } | |
1114 | return implode(' AND ', $conds); | |
1115 | } | |
1116 | } | |
1117 | // }}} | |
1118 | ||
ceb512d2 RB |
1119 | // {{{ class UFC_Medal |
1120 | /** Filters users based on their medals | |
1121 | * @param $medal ID of the medal | |
1122 | * @param $grade Grade of the medal (null for 'any') | |
1123 | */ | |
4e2f2ad2 | 1124 | class UFC_Medal implements UserFilterCondition |
ceb512d2 RB |
1125 | { |
1126 | private $medal; | |
1127 | private $grade; | |
1128 | ||
1129 | public function __construct($medal, $grade = null) | |
1130 | { | |
1131 | $this->medal = $medal; | |
1132 | $this->grade = $grade; | |
1133 | } | |
1134 | ||
dcc63ed5 | 1135 | public function buildCondition(PlFilter &$uf) |
ceb512d2 RB |
1136 | { |
1137 | $conds = array(); | |
1138 | $sub = $uf->addMedalFilter(); | |
1139 | $conds[] = $sub . '.mid = ' . XDB::format('{?}', $this->medal); | |
1140 | if ($this->grade != null) { | |
1141 | $conds[] = $sub . '.gid = ' . XDB::format('{?}', $this->grade); | |
1142 | } | |
1143 | return implode(' AND ', $conds); | |
1144 | } | |
1145 | } | |
1146 | // }}} | |
1147 | ||
470d14f6 FB |
1148 | // {{{ class UFC_Photo |
1149 | /** Filters profiles with photo | |
1150 | */ | |
1151 | class UFC_Photo implements UserFilterCondition | |
1152 | { | |
1153 | public function buildCondition(PlFilter &$uf) | |
1154 | { | |
1155 | $uf->addPhotoFilter(); | |
1156 | return 'photo.attach IS NOT NULL'; | |
1157 | } | |
1158 | } | |
1159 | // }}} | |
1160 | ||
671b7073 RB |
1161 | // {{{ class UFC_Mentor_Expertise |
1162 | /** Filters users by mentoring expertise | |
1163 | * @param $expertise Domain of expertise | |
1164 | */ | |
4e2f2ad2 | 1165 | class UFC_Mentor_Expertise implements UserFilterCondition |
671b7073 RB |
1166 | { |
1167 | private $expertise; | |
1168 | ||
1169 | public function __construct($expertise) | |
1170 | { | |
1171 | $this->expertise = $expertise; | |
1172 | } | |
1173 | ||
dcc63ed5 | 1174 | public function buildCondition(PlFilter &$uf) |
671b7073 RB |
1175 | { |
1176 | $sub = $uf->addMentorFilter(UserFilter::MENTOR_EXPERTISE); | |
658b4c83 | 1177 | return $sub . '.expertise ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->expertise); |
671b7073 RB |
1178 | } |
1179 | } | |
1180 | // }}} | |
1181 | ||
1182 | // {{{ class UFC_Mentor_Country | |
1183 | /** Filters users by mentoring country | |
1184 | * @param $country Two-letters code of country being searched | |
1185 | */ | |
4e2f2ad2 | 1186 | class UFC_Mentor_Country implements UserFilterCondition |
671b7073 RB |
1187 | { |
1188 | private $country; | |
1189 | ||
1190 | public function __construct($country) | |
1191 | { | |
1192 | $this->country = $country; | |
1193 | } | |
1194 | ||
dcc63ed5 | 1195 | public function buildCondition(PlFilter &$uf) |
671b7073 RB |
1196 | { |
1197 | $sub = $uf->addMentorFilter(UserFilter::MENTOR_COUNTRY); | |
1198 | return $sub . '.country = ' . XDB::format('{?}', $this->country); | |
1199 | } | |
1200 | } | |
1201 | // }}} | |
1202 | ||
1203 | // {{{ class UFC_Mentor_Sectorization | |
1204 | /** Filters users based on mentoring (sub|)sector | |
c5da8574 RB |
1205 | * @param $sector ID of (sub)sector |
1206 | * @param $type Whether we are looking for a sector or a subsector | |
671b7073 | 1207 | */ |
4e2f2ad2 | 1208 | class UFC_Mentor_Sectorization implements UserFilterCondition |
671b7073 | 1209 | { |
c5da8574 RB |
1210 | const SECTOR = 1; |
1211 | const SUBSECTOR = 2; | |
671b7073 | 1212 | private $sector; |
c5da8574 | 1213 | private $type; |
671b7073 | 1214 | |
c5da8574 | 1215 | public function __construct($sector, $type = self::SECTOR) |
671b7073 RB |
1216 | { |
1217 | $this->sector = $sector; | |
c5da8574 | 1218 | $this->type = $type; |
671b7073 RB |
1219 | } |
1220 | ||
dcc63ed5 | 1221 | public function buildCondition(PlFilter &$uf) |
671b7073 RB |
1222 | { |
1223 | $sub = $uf->addMentorFilter(UserFilter::MENTOR_SECTOR); | |
c5da8574 RB |
1224 | if ($this->type == self::SECTOR) { |
1225 | $field = 'sectorid'; | |
1226 | } else { | |
1227 | $field = 'subsectorid'; | |
671b7073 | 1228 | } |
c5da8574 | 1229 | return $sub . '.' . $field . ' = ' . XDB::format('{?}', $this->sector); |
671b7073 RB |
1230 | } |
1231 | } | |
1232 | // }}} | |
1233 | ||
8363588b | 1234 | // {{{ class UFC_UserRelated |
5d2e55c7 | 1235 | /** Filters users based on a relation toward a user |
53eae167 RB |
1236 | * @param $user User to which searched users are related |
1237 | */ | |
4e7bf1e0 | 1238 | abstract class UFC_UserRelated implements UserFilterCondition |
3f42a6ad | 1239 | { |
009b8ab7 FB |
1240 | protected $user; |
1241 | public function __construct(PlUser &$user) | |
1242 | { | |
1243 | $this->user =& $user; | |
3f42a6ad | 1244 | } |
4e7bf1e0 | 1245 | } |
8363588b | 1246 | // }}} |
3f42a6ad | 1247 | |
8363588b | 1248 | // {{{ class UFC_Contact |
5d2e55c7 | 1249 | /** Filters users who belong to selected user's contacts |
53eae167 | 1250 | */ |
4e7bf1e0 FB |
1251 | class UFC_Contact extends UFC_UserRelated |
1252 | { | |
dcc63ed5 | 1253 | public function buildCondition(PlFilter &$uf) |
3f42a6ad | 1254 | { |
009b8ab7 | 1255 | $sub = $uf->addContactFilter($this->user->id()); |
3f42a6ad FB |
1256 | return 'c' . $sub . '.contact IS NOT NULL'; |
1257 | } | |
1258 | } | |
8363588b | 1259 | // }}} |
3f42a6ad | 1260 | |
8363588b | 1261 | // {{{ class UFC_WatchRegistration |
53eae167 RB |
1262 | /** Filters users being watched by selected user |
1263 | */ | |
4e7bf1e0 FB |
1264 | class UFC_WatchRegistration extends UFC_UserRelated |
1265 | { | |
dcc63ed5 | 1266 | public function buildCondition(PlFilter &$uf) |
4e7bf1e0 | 1267 | { |
a87530ea | 1268 | if (!$this->user->watchType('registration')) { |
dcc63ed5 | 1269 | return PlFilterCondition::COND_FALSE; |
009b8ab7 FB |
1270 | } |
1271 | $uids = $this->user->watchUsers(); | |
1272 | if (count($uids) == 0) { | |
dcc63ed5 | 1273 | return PlFilterCondition::COND_FALSE; |
009b8ab7 | 1274 | } else { |
bde68f05 | 1275 | return XDB::format('$UID IN {?}', $uids); |
009b8ab7 | 1276 | } |
4e7bf1e0 FB |
1277 | } |
1278 | } | |
8363588b | 1279 | // }}} |
4e7bf1e0 | 1280 | |
8363588b | 1281 | // {{{ class UFC_WatchPromo |
53eae167 RB |
1282 | /** Filters users belonging to a promo watched by selected user |
1283 | * @param $user Selected user (the one watching promo) | |
1284 | * @param $grade Formation the user is watching | |
1285 | */ | |
4e7bf1e0 FB |
1286 | class UFC_WatchPromo extends UFC_UserRelated |
1287 | { | |
1288 | private $grade; | |
009b8ab7 | 1289 | public function __construct(PlUser &$user, $grade = UserFilter::GRADE_ING) |
4e7bf1e0 | 1290 | { |
009b8ab7 | 1291 | parent::__construct($user); |
4e7bf1e0 FB |
1292 | $this->grade = $grade; |
1293 | } | |
1294 | ||
dcc63ed5 | 1295 | public function buildCondition(PlFilter &$uf) |
4e7bf1e0 | 1296 | { |
009b8ab7 FB |
1297 | $promos = $this->user->watchPromos(); |
1298 | if (count($promos) == 0) { | |
dcc63ed5 | 1299 | return PlFilterCondition::COND_FALSE; |
009b8ab7 FB |
1300 | } else { |
1301 | $sube = $uf->addEducationFilter(true, $this->grade); | |
1302 | $field = 'pe' . $sube . '.' . UserFilter::promoYear($this->grade); | |
bde68f05 | 1303 | return XDB::format($field . ' IN {?}', $promos); |
009b8ab7 | 1304 | } |
4e7bf1e0 FB |
1305 | } |
1306 | } | |
8363588b | 1307 | // }}} |
4e7bf1e0 | 1308 | |
8363588b | 1309 | // {{{ class UFC_WatchContact |
53eae167 RB |
1310 | /** Filters users watched by selected user |
1311 | */ | |
009b8ab7 | 1312 | class UFC_WatchContact extends UFC_Contact |
4e7bf1e0 | 1313 | { |
dcc63ed5 | 1314 | public function buildCondition(PlFilter &$uf) |
4e7bf1e0 | 1315 | { |
009b8ab7 | 1316 | if (!$this->user->watchContacts()) { |
dcc63ed5 | 1317 | return PlFilterCondition::COND_FALSE; |
009b8ab7 FB |
1318 | } |
1319 | return parent::buildCondition($uf); | |
4e7bf1e0 FB |
1320 | } |
1321 | } | |
8363588b | 1322 | // }}} |
4e7bf1e0 | 1323 | |
48885bbe FB |
1324 | // {{{ class UFC_MarketingHash |
1325 | /** Filters users using the hash generated | |
1326 | * to send marketing emails to him. | |
1327 | */ | |
1328 | class UFC_MarketingHash implements UserFilterCondition | |
1329 | { | |
1330 | private $hash; | |
1331 | ||
1332 | public function __construct($hash) | |
1333 | { | |
1334 | $this->hash = $hash; | |
1335 | } | |
1336 | ||
1337 | public function buildCondition(PlFilter &$uf) | |
1338 | { | |
1339 | $table = $uf->addMarketingHash(); | |
1340 | return XDB::format('rm.hash = {?}', $this->hash); | |
1341 | } | |
1342 | } | |
416d4244 | 1343 | // }}} |
4e7bf1e0 | 1344 | |
d865c296 FB |
1345 | /****************** |
1346 | * ORDERS | |
1347 | ******************/ | |
1348 | ||
8363588b | 1349 | // {{{ class UserFilterOrder |
2d83cac9 RB |
1350 | /** Base class for ordering results of a query. |
1351 | * Parameters for the ordering must be given to the constructor ($desc for a | |
1352 | * descending order). | |
1353 | * The getSortTokens function is used to get actual ordering part of the query. | |
1354 | */ | |
7ca75030 | 1355 | abstract class UserFilterOrder extends PlFilterOrder |
d865c296 | 1356 | { |
2d83cac9 RB |
1357 | /** This function must return the tokens to use for ordering |
1358 | * @param &$uf The UserFilter whose results must be ordered | |
1359 | * @return The name of the field to use for ordering results | |
1360 | */ | |
61f61261 | 1361 | // abstract protected function getSortTokens(UserFilter &$uf); |
d865c296 | 1362 | } |
8363588b | 1363 | // }}} |
d865c296 | 1364 | |
8363588b | 1365 | // {{{ class UFO_Promo |
5d2e55c7 RB |
1366 | /** Orders users by promotion |
1367 | * @param $grade Formation whose promotion users should be sorted by (restricts results to users of that formation) | |
53eae167 RB |
1368 | * @param $desc Whether sort is descending |
1369 | */ | |
d865c296 FB |
1370 | class UFO_Promo extends UserFilterOrder |
1371 | { | |
1372 | private $grade; | |
1373 | ||
1374 | public function __construct($grade = null, $desc = false) | |
1375 | { | |
009b8ab7 | 1376 | parent::__construct($desc); |
d865c296 | 1377 | $this->grade = $grade; |
d865c296 FB |
1378 | } |
1379 | ||
61f61261 | 1380 | protected function getSortTokens(PlFilter &$uf) |
d865c296 FB |
1381 | { |
1382 | if (UserFilter::isGrade($this->grade)) { | |
1383 | $sub = $uf->addEducationFilter($this->grade); | |
1384 | return 'pe' . $sub . '.' . UserFilter::promoYear($this->grade); | |
1385 | } else { | |
1386 | $sub = $uf->addDisplayFilter(); | |
1387 | return 'pd' . $sub . '.promo'; | |
1388 | } | |
1389 | } | |
1390 | } | |
8363588b | 1391 | // }}} |
d865c296 | 1392 | |
8363588b | 1393 | // {{{ class UFO_Name |
53eae167 | 1394 | /** Sorts users by name |
5d2e55c7 RB |
1395 | * @param $type Type of name on which to sort (firstname...) |
1396 | * @param $variant Variant of that name to use (marital, ordinary...) | |
53eae167 RB |
1397 | * @param $particle Set to true if particles should be included in the sorting order |
1398 | * @param $desc If sort order should be descending | |
1399 | */ | |
d865c296 FB |
1400 | class UFO_Name extends UserFilterOrder |
1401 | { | |
1402 | private $type; | |
1403 | private $variant; | |
1404 | private $particle; | |
1405 | ||
1406 | public function __construct($type, $variant = null, $particle = false, $desc = false) | |
1407 | { | |
009b8ab7 | 1408 | parent::__construct($desc); |
d865c296 FB |
1409 | $this->type = $type; |
1410 | $this->variant = $variant; | |
1411 | $this->particle = $particle; | |
d865c296 FB |
1412 | } |
1413 | ||
61f61261 | 1414 | protected function getSortTokens(PlFilter &$uf) |
d865c296 | 1415 | { |
913a4e90 | 1416 | if (Profile::isDisplayName($this->type)) { |
d865c296 FB |
1417 | $sub = $uf->addDisplayFilter(); |
1418 | return 'pd' . $sub . '.' . $this->type; | |
1419 | } else { | |
1420 | $sub = $uf->addNameFilter($this->type, $this->variant); | |
1421 | if ($this->particle) { | |
1422 | return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)'; | |
1423 | } else { | |
1424 | return 'pn' . $sub . '.name'; | |
1425 | } | |
1426 | } | |
1427 | } | |
1428 | } | |
8363588b | 1429 | // }}} |
d865c296 | 1430 | |
40585144 RB |
1431 | // {{{ class UFO_Score |
1432 | class UFO_Score extends UserFilterOrder | |
1433 | { | |
61f61261 | 1434 | protected function getSortTokens(PlFilter &$uf) |
40585144 RB |
1435 | { |
1436 | $sub = $uf->addNameTokensFilter(); | |
1437 | return 'SUM(' . $sub . '.score)'; | |
1438 | } | |
1439 | } | |
1440 | // }}} | |
1441 | ||
8363588b | 1442 | // {{{ class UFO_Registration |
53eae167 RB |
1443 | /** Sorts users based on registration date |
1444 | */ | |
38c6fe96 FB |
1445 | class UFO_Registration extends UserFilterOrder |
1446 | { | |
61f61261 | 1447 | protected function getSortTokens(PlFilter &$uf) |
38c6fe96 | 1448 | { |
009b8ab7 | 1449 | return 'a.registration_date'; |
38c6fe96 | 1450 | } |
009b8ab7 | 1451 | } |
8363588b | 1452 | // }}} |
38c6fe96 | 1453 | |
8363588b | 1454 | // {{{ class UFO_Birthday |
53eae167 RB |
1455 | /** Sorts users based on next birthday date |
1456 | */ | |
009b8ab7 FB |
1457 | class UFO_Birthday extends UserFilterOrder |
1458 | { | |
61f61261 | 1459 | protected function getSortTokens(PlFilter &$uf) |
38c6fe96 | 1460 | { |
009b8ab7 | 1461 | return 'p.next_birthday'; |
38c6fe96 FB |
1462 | } |
1463 | } | |
8363588b | 1464 | // }}} |
38c6fe96 | 1465 | |
8363588b | 1466 | // {{{ class UFO_ProfileUpdate |
53eae167 RB |
1467 | /** Sorts users based on last profile update |
1468 | */ | |
009b8ab7 FB |
1469 | class UFO_ProfileUpdate extends UserFilterOrder |
1470 | { | |
61f61261 | 1471 | protected function getSortTokens(PlFilter &$uf) |
009b8ab7 FB |
1472 | { |
1473 | return 'p.last_change'; | |
1474 | } | |
1475 | } | |
8363588b | 1476 | // }}} |
009b8ab7 | 1477 | |
8363588b | 1478 | // {{{ class UFO_Death |
53eae167 RB |
1479 | /** Sorts users based on death date |
1480 | */ | |
009b8ab7 FB |
1481 | class UFO_Death extends UserFilterOrder |
1482 | { | |
61f61261 | 1483 | protected function getSortTokens(PlFilter &$uf) |
009b8ab7 FB |
1484 | { |
1485 | return 'p.deathdate'; | |
1486 | } | |
1487 | } | |
8363588b | 1488 | // }}} |
009b8ab7 FB |
1489 | |
1490 | ||
d865c296 FB |
1491 | /*********************************** |
1492 | ********************************* | |
1493 | USER FILTER CLASS | |
1494 | ********************************* | |
1495 | ***********************************/ | |
1496 | ||
8363588b | 1497 | // {{{ class UserFilter |
2d83cac9 RB |
1498 | /** This class provides a convenient and centralized way of filtering users. |
1499 | * | |
1500 | * Usage: | |
1501 | * $uf = new UserFilter(new UFC_Blah($x, $y), new UFO_Coin($z, $t)); | |
1502 | * | |
1503 | * Resulting UserFilter can be used to: | |
1504 | * - get a list of User objects matching the filter | |
1505 | * - get a list of UIDs matching the filter | |
1506 | * - get the number of users matching the filter | |
1507 | * - check whether a given User matches the filter | |
1508 | * - filter a list of User objects depending on whether they match the filter | |
1509 | * | |
1510 | * Usage for UFC and UFO objects: | |
1511 | * A UserFilter will call all private functions named XXXJoins. | |
1512 | * These functions must return an array containing the list of join | |
1513 | * required by the various UFC and UFO associated to the UserFilter. | |
1514 | * Entries in those returned array are of the following form: | |
1515 | * 'join_tablealias' => array('join_type', 'joined_table', 'join_criter') | |
1516 | * which will be translated into : | |
1517 | * join_type JOIN joined_table AS join_tablealias ON (join_criter) | |
1518 | * in the final query. | |
1519 | * | |
1520 | * In the join_criter text, $ME is replaced with 'join_tablealias', $PID with | |
913a4e90 | 1521 | * profile.pid, and $UID with accounts.uid. |
2d83cac9 RB |
1522 | * |
1523 | * For each kind of "JOIN" needed, a function named addXXXFilter() should be defined; | |
1524 | * its parameter will be used to set various private vars of the UserFilter describing | |
1525 | * the required joins ; such a function shall return the "join_tablealias" to use | |
1526 | * when referring to the joined table. | |
1527 | * | |
1528 | * For example, if data from profile_job must be available to filter results, | |
1529 | * the UFC object will call $uf-addJobFilter(), which will set the 'with_pj' var and | |
1530 | * return 'pj', the short name to use when referring to profile_job; when building | |
1531 | * the query, calling the jobJoins function will return an array containing a single | |
1532 | * row: | |
1533 | * 'pj' => array('left', 'profile_job', '$ME.pid = $UID'); | |
1534 | * | |
1535 | * The 'register_optional' function can be used to generate unique table aliases when | |
1536 | * the same table has to be joined several times with different aliases. | |
1537 | */ | |
9b8e5fb4 | 1538 | class UserFilter extends PlFilter |
a087cc8d | 1539 | { |
9b8e5fb4 | 1540 | protected $joinMethods = array(); |
7ca75030 | 1541 | |
61f61261 RB |
1542 | protected $joinMetas = array( |
1543 | '$PID' => 'p.pid', | |
1544 | '$UID' => 'a.uid', | |
9b8e5fb4 | 1545 | ); |
d865c296 | 1546 | |
a087cc8d | 1547 | private $root; |
24e08e33 | 1548 | private $sort = array(); |
784745ce | 1549 | private $query = null; |
24e08e33 | 1550 | private $orderby = null; |
784745ce | 1551 | |
aa21c568 | 1552 | private $lastcount = null; |
d865c296 | 1553 | |
24e08e33 | 1554 | public function __construct($cond = null, $sort = null) |
5dd9d823 | 1555 | { |
06598c13 | 1556 | if (empty($this->joinMethods)) { |
d865c296 FB |
1557 | $class = new ReflectionClass('UserFilter'); |
1558 | foreach ($class->getMethods() as $method) { | |
1559 | $name = $method->getName(); | |
1560 | if (substr($name, -5) == 'Joins' && $name != 'buildJoins') { | |
06598c13 | 1561 | $this->joinMethods[] = $name; |
d865c296 FB |
1562 | } |
1563 | } | |
1564 | } | |
5dd9d823 | 1565 | if (!is_null($cond)) { |
06598c13 | 1566 | if ($cond instanceof PlFilterCondition) { |
5dd9d823 FB |
1567 | $this->setCondition($cond); |
1568 | } | |
1569 | } | |
24e08e33 FB |
1570 | if (!is_null($sort)) { |
1571 | if ($sort instanceof UserFilterOrder) { | |
1572 | $this->addSort($sort); | |
d865c296 FB |
1573 | } else if (is_array($sort)) { |
1574 | foreach ($sort as $s) { | |
1575 | $this->addSort($s); | |
1576 | } | |
24e08e33 FB |
1577 | } |
1578 | } | |
5dd9d823 FB |
1579 | } |
1580 | ||
784745ce FB |
1581 | private function buildQuery() |
1582 | { | |
d865c296 FB |
1583 | if (is_null($this->orderby)) { |
1584 | $orders = array(); | |
1585 | foreach ($this->sort as $sort) { | |
1586 | $orders = array_merge($orders, $sort->buildSort($this)); | |
1587 | } | |
1588 | if (count($orders) == 0) { | |
1589 | $this->orderby = ''; | |
1590 | } else { | |
1591 | $this->orderby = 'ORDER BY ' . implode(', ', $orders); | |
1592 | } | |
1593 | } | |
784745ce FB |
1594 | if (is_null($this->query)) { |
1595 | $where = $this->root->buildCondition($this); | |
f7ea7450 RB |
1596 | if ($this->with_forced_sn) { |
1597 | $this->requireProfiles(); | |
1598 | $from = 'search_name AS sn'; | |
1599 | } else if ($this->with_accounts) { | |
b8dcf62d RB |
1600 | $from = 'accounts AS a'; |
1601 | } else { | |
1602 | $this->requireProfiles(); | |
1603 | $from = 'profiles AS p'; | |
1604 | } | |
f7ea7450 | 1605 | $joins = $this->buildJoins(); |
b8dcf62d | 1606 | $this->query = 'FROM ' . $from . ' |
784745ce FB |
1607 | ' . $joins . ' |
1608 | WHERE (' . $where . ')'; | |
1609 | } | |
1610 | } | |
1611 | ||
7ca75030 | 1612 | private function getUIDList($uids = null, PlLimit &$limit) |
d865c296 | 1613 | { |
b8dcf62d | 1614 | $this->requireAccounts(); |
d865c296 | 1615 | $this->buildQuery(); |
7ca75030 | 1616 | $lim = $limit->getSql(); |
d865c296 FB |
1617 | $cond = ''; |
1618 | if (!is_null($uids)) { | |
bde68f05 | 1619 | $cond = XDB::format(' AND a.uid IN {?}', $uids); |
d865c296 FB |
1620 | } |
1621 | $fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS a.uid | |
1622 | ' . $this->query . $cond . ' | |
1623 | GROUP BY a.uid | |
1624 | ' . $this->orderby . ' | |
7ca75030 | 1625 | ' . $lim); |
d865c296 FB |
1626 | $this->lastcount = (int)XDB::fetchOneCell('SELECT FOUND_ROWS()'); |
1627 | return $fetched; | |
1628 | } | |
1629 | ||
043b104b RB |
1630 | private function getPIDList($pids = null, PlLimit &$limit) |
1631 | { | |
1632 | $this->requireProfiles(); | |
1633 | $this->buildQuery(); | |
1634 | $lim = $limit->getSql(); | |
1635 | $cond = ''; | |
1636 | if (!is_null($pids)) { | |
bde68f05 | 1637 | $cond = XDB::format(' AND p.pid IN {?}', $pids); |
043b104b RB |
1638 | } |
1639 | $fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS p.pid | |
1640 | ' . $this->query . $cond . ' | |
1641 | GROUP BY p.pid | |
1642 | ' . $this->orderby . ' | |
1643 | ' . $lim); | |
1644 | $this->lastcount = (int)XDB::fetchOneCell('SELECT FOUND_ROWS()'); | |
1645 | return $fetched; | |
1646 | } | |
1647 | ||
434570c4 FB |
1648 | private static function defaultLimit($limit) { |
1649 | if ($limit == null) { | |
1650 | return new PlLimit(); | |
1651 | } else { | |
1652 | return $limit; | |
1653 | } | |
1654 | } | |
1655 | ||
a087cc8d FB |
1656 | /** Check that the user match the given rule. |
1657 | */ | |
1658 | public function checkUser(PlUser &$user) | |
1659 | { | |
b8dcf62d | 1660 | $this->requireAccounts(); |
784745ce FB |
1661 | $this->buildQuery(); |
1662 | $count = (int)XDB::fetchOneCell('SELECT COUNT(*) | |
1663 | ' . $this->query . XDB::format(' AND a.uid = {?}', $user->id())); | |
1664 | return $count == 1; | |
a087cc8d FB |
1665 | } |
1666 | ||
043b104b RB |
1667 | /** Check that the profile match the given rule. |
1668 | */ | |
1669 | public function checkProfile(Profile &$profile) | |
1670 | { | |
1671 | $this->requireProfiles(); | |
1672 | $this->buildQuery(); | |
1673 | $count = (int)XDB::fetchOneCell('SELECT COUNT(*) | |
1674 | ' . $this->query . XDB::format(' AND p.pid = {?}', $profile->id())); | |
1675 | return $count == 1; | |
1676 | } | |
1677 | ||
1678 | /** Default filter is on users | |
a087cc8d | 1679 | */ |
434570c4 | 1680 | public function filter(array $users, $limit = null) |
a087cc8d | 1681 | { |
434570c4 | 1682 | return $this->filterUsers($users, self::defaultLimit($limit)); |
043b104b RB |
1683 | } |
1684 | ||
1685 | /** Filter a list of users to extract the users matching the rule. | |
1686 | */ | |
434570c4 | 1687 | public function filterUsers(array $users, $limit = null) |
043b104b | 1688 | { |
434570c4 | 1689 | $limit = self::defaultLimit($limit); |
b8dcf62d | 1690 | $this->requireAccounts(); |
4927ee54 FB |
1691 | $this->buildQuery(); |
1692 | $table = array(); | |
1693 | $uids = array(); | |
1694 | foreach ($users as $user) { | |
07eb5b0e FB |
1695 | if ($user instanceof PlUser) { |
1696 | $uid = $user->id(); | |
1697 | } else { | |
1698 | $uid = $user; | |
1699 | } | |
1700 | $uids[] = $uid; | |
1701 | $table[$uid] = $user; | |
4927ee54 | 1702 | } |
7ca75030 | 1703 | $fetched = $this->getUIDList($uids, $limit); |
a087cc8d | 1704 | $output = array(); |
4927ee54 FB |
1705 | foreach ($fetched as $uid) { |
1706 | $output[] = $table[$uid]; | |
a087cc8d FB |
1707 | } |
1708 | return $output; | |
1709 | } | |
1710 | ||
043b104b RB |
1711 | /** Filter a list of profiles to extract the users matching the rule. |
1712 | */ | |
434570c4 | 1713 | public function filterProfiles(array $profiles, $limit = null) |
043b104b | 1714 | { |
434570c4 | 1715 | $limit = self::defaultLimit($limit); |
043b104b RB |
1716 | $this->requireProfiles(); |
1717 | $this->buildQuery(); | |
1718 | $table = array(); | |
1719 | $pids = array(); | |
1720 | foreach ($profiles as $profile) { | |
1721 | if ($profile instanceof Profile) { | |
1722 | $pid = $profile->id(); | |
1723 | } else { | |
1724 | $pid = $profile; | |
1725 | } | |
1726 | $pids[] = $pid; | |
1727 | $table[$pid] = $profile; | |
1728 | } | |
1729 | $fetched = $this->getPIDList($pids, $limit); | |
1730 | $output = array(); | |
1731 | foreach ($fetched as $pid) { | |
1732 | $output[] = $table[$pid]; | |
1733 | } | |
1734 | return $output; | |
1735 | } | |
1736 | ||
434570c4 | 1737 | public function getUIDs($limit = null) |
7ca75030 | 1738 | { |
833a6e86 FB |
1739 | $limit = self::defaultLimit($limit); |
1740 | return $this->getUIDList(null, $limit); | |
7ca75030 RB |
1741 | } |
1742 | ||
ad27b22e FB |
1743 | public function getUID($pos = 0) |
1744 | { | |
1745 | $uids =$this->getUIDList(null, new PlFilter(1, $pos)); | |
1746 | if (count($uids) == 0) { | |
1747 | return null; | |
1748 | } else { | |
1749 | return $uids[0]; | |
1750 | } | |
1751 | } | |
1752 | ||
434570c4 | 1753 | public function getPIDs($limit = null) |
043b104b | 1754 | { |
833a6e86 FB |
1755 | $limit = self::defaultLimit($limit); |
1756 | return $this->getPIDList(null, $limit); | |
043b104b RB |
1757 | } |
1758 | ||
ad27b22e FB |
1759 | public function getPID($pos = 0) |
1760 | { | |
1761 | $pids =$this->getPIDList(null, new PlFilter(1, $pos)); | |
1762 | if (count($pids) == 0) { | |
1763 | return null; | |
1764 | } else { | |
1765 | return $pids[0]; | |
1766 | } | |
1767 | } | |
1768 | ||
434570c4 | 1769 | public function getUsers($limit = null) |
4927ee54 | 1770 | { |
7ca75030 | 1771 | return User::getBulkUsersWithUIDs($this->getUIDs($limit)); |
d865c296 FB |
1772 | } |
1773 | ||
ad27b22e FB |
1774 | public function getUser($pos = 0) |
1775 | { | |
1776 | $uid = $this->getUID($pos); | |
1777 | if ($uid == null) { | |
1778 | return null; | |
1779 | } else { | |
1780 | return User::getWithUID($uid); | |
1781 | } | |
1782 | } | |
1783 | ||
0d906109 RB |
1784 | public function iterUsers($limit = null) |
1785 | { | |
1786 | return User::iterOverUIDs($this->getUIDs($limit)); | |
1787 | } | |
1788 | ||
00f83317 | 1789 | public function getProfiles($limit = null, $fields = 0x0000, $visibility = null) |
043b104b | 1790 | { |
00f83317 | 1791 | return Profile::getBulkProfilesWithPIDs($this->getPIDs($limit), $fields, $visibility); |
043b104b RB |
1792 | } |
1793 | ||
00f83317 | 1794 | public function getProfile($pos = 0, $fields = 0x0000, $visibility = null) |
ad27b22e FB |
1795 | { |
1796 | $pid = $this->getPID($pos); | |
1797 | if ($pid == null) { | |
1798 | return null; | |
1799 | } else { | |
00f83317 | 1800 | return Profile::get($pid, $fields, $visibility); |
ad27b22e FB |
1801 | } |
1802 | } | |
1803 | ||
00f83317 | 1804 | public function iterProfiles($limit = null, $fields = 0x0000, $visibility = null) |
0d906109 | 1805 | { |
00f83317 | 1806 | return Profile::iterOverPIDs($this->getPIDs($limit), true, $fields, $visibility); |
0d906109 RB |
1807 | } |
1808 | ||
434570c4 | 1809 | public function get($limit = null) |
d865c296 | 1810 | { |
7ca75030 | 1811 | return $this->getUsers($limit); |
4927ee54 FB |
1812 | } |
1813 | ||
aaf70eb8 | 1814 | |
d865c296 | 1815 | public function getTotalCount() |
4927ee54 | 1816 | { |
38c6fe96 | 1817 | if (is_null($this->lastcount)) { |
aa21c568 | 1818 | $this->buildQuery(); |
2b9ca54d | 1819 | if ($this->with_accounts) { |
b8dcf62d RB |
1820 | $field = 'a.uid'; |
1821 | } else { | |
1822 | $field = 'p.pid'; | |
1823 | } | |
1824 | return (int)XDB::fetchOneCell('SELECT COUNT(DISTINCT ' . $field . ') | |
7e735012 | 1825 | ' . $this->query); |
38c6fe96 FB |
1826 | } else { |
1827 | return $this->lastcount; | |
1828 | } | |
4927ee54 FB |
1829 | } |
1830 | ||
9b8e5fb4 | 1831 | public function setCondition(PlFilterCondition &$cond) |
a087cc8d FB |
1832 | { |
1833 | $this->root =& $cond; | |
784745ce | 1834 | $this->query = null; |
a087cc8d FB |
1835 | } |
1836 | ||
9b8e5fb4 | 1837 | public function addSort(PlFilterOrder &$sort) |
24e08e33 | 1838 | { |
d865c296 FB |
1839 | $this->sort[] = $sort; |
1840 | $this->orderby = null; | |
24e08e33 FB |
1841 | } |
1842 | ||
a087cc8d FB |
1843 | static public function getLegacy($promo_min, $promo_max) |
1844 | { | |
a087cc8d | 1845 | if ($promo_min != 0) { |
784745ce | 1846 | $min = new UFC_Promo('>=', self::GRADE_ING, intval($promo_min)); |
5dd9d823 | 1847 | } else { |
88c31faf | 1848 | $min = new PFC_True(); |
a087cc8d | 1849 | } |
a087cc8d | 1850 | if ($promo_max != 0) { |
784745ce | 1851 | $max = new UFC_Promo('<=', self::GRADE_ING, intval($promo_max)); |
a087cc8d | 1852 | } else { |
88c31faf | 1853 | $max = new PFC_True(); |
a087cc8d | 1854 | } |
9b8e5fb4 | 1855 | return new UserFilter(new PFC_And($min, $max)); |
a087cc8d | 1856 | } |
784745ce | 1857 | |
07eb5b0e FB |
1858 | static public function sortByName() |
1859 | { | |
913a4e90 | 1860 | return array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); |
07eb5b0e FB |
1861 | } |
1862 | ||
1863 | static public function sortByPromo() | |
1864 | { | |
913a4e90 | 1865 | return array(new UFO_Promo(), new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); |
07eb5b0e FB |
1866 | } |
1867 | ||
aa21c568 FB |
1868 | static private function getDBSuffix($string) |
1869 | { | |
2d6329a2 FB |
1870 | if (is_array($string)) { |
1871 | if (count($string) == 1) { | |
1872 | return self::getDBSuffix(array_pop($string)); | |
1873 | } | |
1874 | return md5(implode('|', $string)); | |
1875 | } else { | |
1876 | return preg_replace('/[^a-z0-9]/i', '', $string); | |
1877 | } | |
aa21c568 FB |
1878 | } |
1879 | ||
1880 | ||
2d83cac9 RB |
1881 | /** Stores a new (and unique) table alias in the &$table table |
1882 | * @param &$table Array in which the table alias must be stored | |
1883 | * @param $val Value which will then be used to build the join | |
1884 | * @return Name of the newly created alias | |
1885 | */ | |
aa21c568 FB |
1886 | private $option = 0; |
1887 | private function register_optional(array &$table, $val) | |
1888 | { | |
1889 | if (is_null($val)) { | |
1890 | $sub = $this->option++; | |
1891 | $index = null; | |
1892 | } else { | |
1893 | $sub = self::getDBSuffix($val); | |
1894 | $index = $val; | |
1895 | } | |
1896 | $sub = '_' . $sub; | |
1897 | $table[$sub] = $index; | |
1898 | return $sub; | |
1899 | } | |
784745ce | 1900 | |
b8dcf62d RB |
1901 | /** PROFILE VS ACCOUNT |
1902 | */ | |
f7ea7450 RB |
1903 | private $with_profiles = false; |
1904 | private $with_accounts = false; | |
1905 | private $with_forced_sn = false; | |
b8dcf62d RB |
1906 | public function requireAccounts() |
1907 | { | |
1908 | $this->with_accounts = true; | |
1909 | } | |
1910 | ||
1911 | public function requireProfiles() | |
1912 | { | |
1913 | $this->with_profiles = true; | |
1914 | } | |
1915 | ||
f7ea7450 RB |
1916 | /** Forces the "FROM" to use search_name instead of accounts or profiles */ |
1917 | public function forceSearchName() | |
1918 | { | |
1919 | $this->with_forced_sn = true; | |
1920 | } | |
1921 | ||
b8dcf62d RB |
1922 | protected function accountJoins() |
1923 | { | |
1924 | $joins = array(); | |
f7ea7450 RB |
1925 | /** Quick search is much more efficient with sn first and PID second */ |
1926 | if ($this->with_forced_sn) { | |
5c412626 | 1927 | $joins['p'] = PlSqlJoin::left('profiles', '$PID = sn.pid'); |
f7ea7450 | 1928 | if ($this->with_accounts) { |
5c412626 FB |
1929 | $joins['ap'] = PlSqlJoin::left('account_profiles', '$ME.pid = $PID'); |
1930 | $joins['a'] = PlSqlJoin::left('accounts', '$UID = ap.uid'); | |
f7ea7450 RB |
1931 | } |
1932 | } else if ($this->with_profiles && $this->with_accounts) { | |
5c412626 FB |
1933 | $joins['ap'] = PlSqlJoin::left('account_profiles', '$ME.uid = $UID AND FIND_IN_SET(\'owner\', ap.perms)'); |
1934 | $joins['p'] = PlSqlJoin::left('profiles', '$PID = ap.pid'); | |
b8dcf62d RB |
1935 | } |
1936 | return $joins; | |
1937 | } | |
1938 | ||
d865c296 FB |
1939 | /** DISPLAY |
1940 | */ | |
38c6fe96 | 1941 | const DISPLAY = 'display'; |
d865c296 FB |
1942 | private $pd = false; |
1943 | public function addDisplayFilter() | |
1944 | { | |
b8dcf62d | 1945 | $this->requireProfiles(); |
d865c296 FB |
1946 | $this->pd = true; |
1947 | return ''; | |
1948 | } | |
1949 | ||
9b8e5fb4 | 1950 | protected function displayJoins() |
d865c296 FB |
1951 | { |
1952 | if ($this->pd) { | |
5c412626 | 1953 | return array('pd' => PlSqlJoin::left('profile_display', '$ME.pid = $PID')); |
d865c296 FB |
1954 | } else { |
1955 | return array(); | |
1956 | } | |
1957 | } | |
1958 | ||
f73a4f1b RB |
1959 | /** LOGGER |
1960 | */ | |
1961 | ||
1962 | private $with_logger = false; | |
1963 | public function addLoggerFilter() | |
1964 | { | |
1965 | $this->with_logger = true; | |
1966 | $this->requireAccounts(); | |
1967 | return 'ls'; | |
1968 | } | |
1969 | protected function loggerJoins() | |
1970 | { | |
1971 | $joins = array(); | |
1972 | if ($this->with_logger) { | |
5c412626 | 1973 | $joins['ls'] = PlSqlJoin::left('log_sessions', '$ME.uid = $UID'); |
f73a4f1b RB |
1974 | } |
1975 | return $joins; | |
1976 | } | |
1977 | ||
784745ce FB |
1978 | /** NAMES |
1979 | */ | |
784745ce FB |
1980 | |
1981 | static public function assertName($name) | |
1982 | { | |
07613cdd | 1983 | if (!DirEnum::getID(DirEnum::NAMETYPES, $name)) { |
9b8e5fb4 | 1984 | Platal::page()->kill('Invalid name type: ' . $name); |
784745ce FB |
1985 | } |
1986 | } | |
1987 | ||
1988 | private $pn = array(); | |
784745ce FB |
1989 | public function addNameFilter($type, $variant = null) |
1990 | { | |
b8dcf62d | 1991 | $this->requireProfiles(); |
784745ce FB |
1992 | if (!is_null($variant)) { |
1993 | $ft = $type . '_' . $variant; | |
1994 | } else { | |
1995 | $ft = $type; | |
1996 | } | |
1997 | $sub = '_' . $ft; | |
1998 | self::assertName($ft); | |
1999 | ||
2000 | if (!is_null($variant) && $variant == 'other') { | |
aa21c568 | 2001 | $sub .= $this->option++; |
784745ce | 2002 | } |
07613cdd | 2003 | $this->pn[$sub] = DirEnum::getID(DirEnum::NAMETYPES, $ft); |
784745ce FB |
2004 | return $sub; |
2005 | } | |
2006 | ||
9b8e5fb4 | 2007 | protected function nameJoins() |
784745ce FB |
2008 | { |
2009 | $joins = array(); | |
2010 | foreach ($this->pn as $sub => $type) { | |
5c412626 | 2011 | $joins['pn' . $sub] = PlSqlJoin::left('profile_name', '$ME.pid = $PID AND $ME.typeid = {?}', $type); |
784745ce FB |
2012 | } |
2013 | return $joins; | |
2014 | } | |
2015 | ||
40585144 RB |
2016 | /** NAMETOKENS |
2017 | */ | |
2018 | private $with_sn = false; | |
f7ea7450 RB |
2019 | // Set $doingQuickSearch to true if you wish to optimize the query |
2020 | public function addNameTokensFilter($doingQuickSearch = false) | |
40585144 RB |
2021 | { |
2022 | $this->requireProfiles(); | |
f7ea7450 | 2023 | $this->with_forced_sn = ($this->with_forced_sn || $doingQuickSearch); |
40585144 RB |
2024 | $this->with_sn = true; |
2025 | return 'sn'; | |
2026 | } | |
2027 | ||
2028 | protected function nameTokensJoins() | |
2029 | { | |
f7ea7450 RB |
2030 | /* We don't return joins, since with_sn forces the SELECT to run on search_name first */ |
2031 | if ($this->with_sn && !$this->with_forced_sn) { | |
2032 | return array( | |
05fa89a5 | 2033 | 'sn' => PlSqlJoin::left('search_name', '$ME.pid = $PID') |
f7ea7450 RB |
2034 | ); |
2035 | } else { | |
2036 | return array(); | |
40585144 | 2037 | } |
40585144 RB |
2038 | } |
2039 | ||
a7f8e48a RB |
2040 | /** NATIONALITY |
2041 | */ | |
2042 | ||
2043 | private $with_nat = false; | |
2044 | public function addNationalityFilter() | |
2045 | { | |
2046 | $this->with_nat = true; | |
2047 | return 'ngc'; | |
2048 | } | |
2049 | ||
2050 | protected function nationalityJoins() | |
2051 | { | |
2052 | $joins = array(); | |
2053 | if ($this->with_nat) { | |
5c412626 | 2054 | $joins['ngc'] = PlSqlJoin::left('geoloc_countries', '$ME.iso_3166_1_a2 = p.nationality1 OR $ME.iso_3166_1_a2 = p.nationality2 OR $ME.iso_3166_1_a2 = p.nationality3'); |
a7f8e48a RB |
2055 | } |
2056 | return $joins; | |
2057 | } | |
2058 | ||
784745ce FB |
2059 | /** EDUCATION |
2060 | */ | |
2061 | const GRADE_ING = 'Ing.'; | |
2062 | const GRADE_PHD = 'PhD'; | |
2063 | const GRADE_MST = 'M%'; | |
2064 | static public function isGrade($grade) | |
2065 | { | |
38c6fe96 | 2066 | return $grade == self::GRADE_ING || $grade == self::GRADE_PHD || $grade == self::GRADE_MST; |
784745ce FB |
2067 | } |
2068 | ||
2069 | static public function assertGrade($grade) | |
2070 | { | |
2071 | if (!self::isGrade($grade)) { | |
ad27b22e | 2072 | Platal::page()->killError("Diplôme non valide: $grade"); |
784745ce FB |
2073 | } |
2074 | } | |
2075 | ||
d865c296 FB |
2076 | static public function promoYear($grade) |
2077 | { | |
2078 | // XXX: Definition of promotion for phds and masters might change in near future. | |
2079 | return ($grade == UserFilter::GRADE_ING) ? 'entry_year' : 'grad_year'; | |
2080 | } | |
2081 | ||
784745ce FB |
2082 | private $pepe = array(); |
2083 | private $with_pee = false; | |
784745ce FB |
2084 | public function addEducationFilter($x = false, $grade = null) |
2085 | { | |
b8dcf62d | 2086 | $this->requireProfiles(); |
784745ce | 2087 | if (!$x) { |
aa21c568 FB |
2088 | $index = $this->option; |
2089 | $sub = $this->option++; | |
784745ce FB |
2090 | } else { |
2091 | self::assertGrade($grade); | |
2092 | $index = $grade; | |
2093 | $sub = $grade[0]; | |
2094 | $this->with_pee = true; | |
2095 | } | |
2096 | $sub = '_' . $sub; | |
2097 | $this->pepe[$index] = $sub; | |
2098 | return $sub; | |
2099 | } | |
2100 | ||
9b8e5fb4 | 2101 | protected function educationJoins() |
784745ce FB |
2102 | { |
2103 | $joins = array(); | |
2104 | if ($this->with_pee) { | |
5c412626 | 2105 | $joins['pee'] = PlSqlJoin::inner('profile_education_enum', 'pee.abbreviation = \'X\''); |
784745ce FB |
2106 | } |
2107 | foreach ($this->pepe as $grade => $sub) { | |
2108 | if ($this->isGrade($grade)) { | |
5c412626 FB |
2109 | $joins['pe' . $sub] = PlSqlJoin::left('profile_education', '$ME.eduid = pee.id AND $ME.pid = $PID'); |
2110 | $joins['pede' . $sub] = PlSqlJoin::inner('profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid AND $ME.abbreviation LIKE {?}', $grade); | |
784745ce | 2111 | } else { |
5c412626 FB |
2112 | $joins['pe' . $sub] = PlSqlJoin::left('profile_education', '$ME.pid = $PID'); |
2113 | $joins['pee' . $sub] = PlSqlJoin::inner('profile_education_enum', '$ME.id = pe' . $sub . '.eduid'); | |
2114 | $joins['pede' . $sub] = PlSqlJoin::inner('profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid'); | |
784745ce FB |
2115 | } |
2116 | } | |
2117 | return $joins; | |
2118 | } | |
4927ee54 FB |
2119 | |
2120 | ||
2121 | /** GROUPS | |
2122 | */ | |
2123 | private $gpm = array(); | |
4927ee54 FB |
2124 | public function addGroupFilter($group = null) |
2125 | { | |
b8dcf62d | 2126 | $this->requireAccounts(); |
4927ee54 | 2127 | if (!is_null($group)) { |
4aae4d2c | 2128 | if (is_int($group) || ctype_digit($group)) { |
4927ee54 FB |
2129 | $index = $sub = $group; |
2130 | } else { | |
2131 | $index = $group; | |
aa21c568 | 2132 | $sub = self::getDBSuffix($group); |
4927ee54 FB |
2133 | } |
2134 | } else { | |
aa21c568 | 2135 | $sub = 'group_' . $this->option++; |
4927ee54 FB |
2136 | $index = null; |
2137 | } | |
2138 | $sub = '_' . $sub; | |
2139 | $this->gpm[$sub] = $index; | |
2140 | return $sub; | |
2141 | } | |
2142 | ||
9b8e5fb4 | 2143 | protected function groupJoins() |
4927ee54 FB |
2144 | { |
2145 | $joins = array(); | |
2146 | foreach ($this->gpm as $sub => $key) { | |
2147 | if (is_null($key)) { | |
5c412626 FB |
2148 | $joins['gpa' . $sub] = PlSqlJoin::inner('groups'); |
2149 | $joins['gpm' . $sub] = PlSqlJoin::left('group_members', '$ME.uid = $UID AND $ME.asso_id = gpa' . $sub . '.id'); | |
4aae4d2c | 2150 | } else if (is_int($key) || ctype_digit($key)) { |
5c412626 | 2151 | $joins['gpm' . $sub] = PlSqlJoin::left('group_members', '$ME.uid = $UID AND $ME.asso_id = ' . $key); |
4927ee54 | 2152 | } else { |
5c412626 FB |
2153 | $joins['gpa' . $sub] = PlSqlJoin::inner('groups', '$ME.diminutif = {?}', $key); |
2154 | $joins['gpm' . $sub] = PlSqlJoin::left('group_members', '$ME.uid = $UID AND $ME.asso_id = gpa' . $sub . '.id'); | |
4927ee54 FB |
2155 | } |
2156 | } | |
2157 | return $joins; | |
0fb3713c RB |
2158 | } |
2159 | ||
2160 | /** BINETS | |
2161 | */ | |
2162 | ||
a7f8e48a RB |
2163 | private $with_bi = false; |
2164 | private $with_bd = false; | |
d7ddf29b | 2165 | public function addBinetsFilter($with_enum = false) |
0fb3713c RB |
2166 | { |
2167 | $this->requireProfiles(); | |
a7f8e48a RB |
2168 | $this->with_bi = true; |
2169 | if ($with_enum) { | |
2170 | $this->with_bd = true; | |
2171 | return 'bd'; | |
2172 | } else { | |
2173 | return 'bi'; | |
2174 | } | |
0fb3713c RB |
2175 | } |
2176 | ||
2177 | protected function binetsJoins() | |
2178 | { | |
2179 | $joins = array(); | |
a7f8e48a | 2180 | if ($this->with_bi) { |
5c412626 | 2181 | $joins['bi'] = PlSqlJoin::left('profile_binets', '$ME.pid = $PID'); |
0fb3713c | 2182 | } |
a7f8e48a | 2183 | if ($this->with_bd) { |
5c412626 | 2184 | $joins['bd'] = PlSqlJoin::left('profile_binet_enum', '$ME.id = bi.binet_id'); |
a7f8e48a | 2185 | } |
0fb3713c | 2186 | return $joins; |
4927ee54 | 2187 | } |
aa21c568 FB |
2188 | |
2189 | /** EMAILS | |
2190 | */ | |
2191 | private $e = array(); | |
2192 | public function addEmailRedirectFilter($email = null) | |
2193 | { | |
b8dcf62d | 2194 | $this->requireAccounts(); |
aa21c568 FB |
2195 | return $this->register_optional($this->e, $email); |
2196 | } | |
2197 | ||
2198 | private $ve = array(); | |
2199 | public function addVirtualEmailFilter($email = null) | |
2200 | { | |
21401768 | 2201 | $this->addAliasFilter(self::ALIAS_FORLIFE); |
aa21c568 FB |
2202 | return $this->register_optional($this->ve, $email); |
2203 | } | |
2204 | ||
21401768 FB |
2205 | const ALIAS_BEST = 'bestalias'; |
2206 | const ALIAS_FORLIFE = 'forlife'; | |
aa21c568 FB |
2207 | private $al = array(); |
2208 | public function addAliasFilter($alias = null) | |
2209 | { | |
b8dcf62d | 2210 | $this->requireAccounts(); |
aa21c568 FB |
2211 | return $this->register_optional($this->al, $alias); |
2212 | } | |
2213 | ||
9b8e5fb4 | 2214 | protected function emailJoins() |
aa21c568 FB |
2215 | { |
2216 | global $globals; | |
2217 | $joins = array(); | |
2218 | foreach ($this->e as $sub=>$key) { | |
2219 | if (is_null($key)) { | |
5c412626 | 2220 | $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\''); |
aa21c568 | 2221 | } else { |
2d6329a2 FB |
2222 | if (!is_array($key)) { |
2223 | $key = array($key); | |
2224 | } | |
bde68f05 FB |
2225 | $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\' |
2226 | AND $ME.email IN {?}' . $key); | |
aa21c568 FB |
2227 | } |
2228 | } | |
21401768 | 2229 | foreach ($this->al as $sub=>$key) { |
aa21c568 | 2230 | if (is_null($key)) { |
5c412626 | 2231 | $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')'); |
21401768 | 2232 | } else if ($key == self::ALIAS_BEST) { |
5c412626 | 2233 | $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\') AND FIND_IN_SET(\'bestalias\', $ME.flags)'); |
21401768 | 2234 | } else if ($key == self::ALIAS_FORLIFE) { |
5c412626 | 2235 | $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type = \'a_vie\''); |
aa21c568 | 2236 | } else { |
2d6329a2 FB |
2237 | if (!is_array($key)) { |
2238 | $key = array($key); | |
2239 | } | |
bde68f05 FB |
2240 | $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\') |
2241 | AND $ME.alias IN {?}', $key); | |
aa21c568 | 2242 | } |
aa21c568 | 2243 | } |
21401768 | 2244 | foreach ($this->ve as $sub=>$key) { |
aa21c568 | 2245 | if (is_null($key)) { |
5c412626 | 2246 | $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\''); |
aa21c568 | 2247 | } else { |
2d6329a2 FB |
2248 | if (!is_array($key)) { |
2249 | $key = array($key); | |
2250 | } | |
bde68f05 | 2251 | $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\' AND $ME.alias IN {?}', $key); |
aa21c568 | 2252 | } |
5c412626 FB |
2253 | $joins['vr' . $sub] = PlSqlJoin::left('virtual_redirect', |
2254 | '$ME.vid = v' . $sub . '.vid | |
2255 | AND ($ME.redirect IN (CONCAT(al_forlife.alias, \'@\', {?}), | |
2256 | CONCAT(al_forlife.alias, \'@\', {?}), | |
2257 | a.email))', | |
2258 | $globals->mail->domain, $globals->mail->domain2); | |
aa21c568 FB |
2259 | } |
2260 | return $joins; | |
2261 | } | |
3f42a6ad FB |
2262 | |
2263 | ||
c4b24511 RB |
2264 | /** ADDRESSES |
2265 | */ | |
036d1637 | 2266 | private $with_pa = false; |
c4b24511 RB |
2267 | public function addAddressFilter() |
2268 | { | |
b8dcf62d | 2269 | $this->requireProfiles(); |
036d1637 RB |
2270 | $this->with_pa = true; |
2271 | return 'pa'; | |
c4b24511 RB |
2272 | } |
2273 | ||
2b9ca54d RB |
2274 | private $with_pac = false; |
2275 | public function addAddressCountryFilter() | |
2276 | { | |
2277 | $this->requireProfiles(); | |
2278 | $this->addAddressFilter(); | |
2279 | $this->with_pac = true; | |
2280 | return 'gc'; | |
2281 | } | |
2282 | ||
d7ddf29b | 2283 | private $with_pal = false; |
2b9ca54d RB |
2284 | public function addAddressLocalityFilter() |
2285 | { | |
2286 | $this->requireProfiles(); | |
2287 | $this->addAddressFilter(); | |
2288 | $this->with_pal = true; | |
2289 | return 'gl'; | |
2290 | } | |
2291 | ||
9b8e5fb4 | 2292 | protected function addressJoins() |
c4b24511 RB |
2293 | { |
2294 | $joins = array(); | |
036d1637 | 2295 | if ($this->with_pa) { |
5c412626 | 2296 | $joins['pa'] = PlSqlJoin::left('profile_addresses', '$ME.pid = $PID'); |
c4b24511 | 2297 | } |
2b9ca54d | 2298 | if ($this->with_pac) { |
5c412626 | 2299 | $joins['gc'] = PlSqlJoin::left('geoloc_countries', '$ME.iso_3166_1_a2 = pa.countryID'); |
2b9ca54d RB |
2300 | } |
2301 | if ($this->with_pal) { | |
5c412626 | 2302 | $joins['gl'] = PlSqlJoin::left('geoloc_localities', '$ME.id = pa.localityID'); |
2b9ca54d | 2303 | } |
c4b24511 RB |
2304 | return $joins; |
2305 | } | |
2306 | ||
2307 | ||
4083b126 RB |
2308 | /** CORPS |
2309 | */ | |
2310 | ||
2311 | private $pc = false; | |
2312 | private $pce = array(); | |
2313 | private $pcr = false; | |
2314 | public function addCorpsFilter($type) | |
2315 | { | |
b8dcf62d | 2316 | $this->requireProfiles(); |
4083b126 RB |
2317 | $this->pc = true; |
2318 | if ($type == UFC_Corps::CURRENT) { | |
2319 | $pce['pcec'] = 'current_corpsid'; | |
2320 | return 'pcec'; | |
2321 | } else if ($type == UFC_Corps::ORIGIN) { | |
2322 | $pce['pceo'] = 'original_corpsid'; | |
2323 | return 'pceo'; | |
2324 | } | |
2325 | } | |
2326 | ||
2327 | public function addCorpsRankFilter() | |
2328 | { | |
b8dcf62d | 2329 | $this->requireProfiles(); |
4083b126 RB |
2330 | $this->pc = true; |
2331 | $this->pcr = true; | |
2332 | return 'pcr'; | |
2333 | } | |
2334 | ||
9b8e5fb4 | 2335 | protected function corpsJoins() |
4083b126 RB |
2336 | { |
2337 | $joins = array(); | |
2338 | if ($this->pc) { | |
5c412626 | 2339 | $joins['pc'] = PlSqlJoin::left('profile_corps', '$ME.pid = $PID'); |
4083b126 RB |
2340 | } |
2341 | if ($this->pcr) { | |
5c412626 | 2342 | $joins['pcr'] = PlSqlJoin::left('profile_corps_rank_enum', '$ME.id = pc.rankid'); |
4083b126 RB |
2343 | } |
2344 | foreach($this->pce as $sub => $field) { | |
5c412626 | 2345 | $joins[$sub] = PlSqlJoin::left('profile_corps_enum', '$ME.id = pc.' . $field); |
4083b126 RB |
2346 | } |
2347 | return $joins; | |
2348 | } | |
2349 | ||
6a99c3ac RB |
2350 | /** JOBS |
2351 | */ | |
2352 | ||
61f61261 RB |
2353 | const JOB_SECTOR = 0x0001; |
2354 | const JOB_SUBSECTOR = 0x0002; | |
2355 | const JOB_SUBSUBSECTOR = 0x0004; | |
2356 | const JOB_ALTERNATES = 0x0008; | |
2357 | const JOB_USERDEFINED = 0x0010; | |
2358 | const JOB_CV = 0x0020; | |
2359 | ||
2360 | const JOB_SECTORIZATION = 0x000F; | |
2361 | const JOB_ANY = 0x003F; | |
6a99c3ac RB |
2362 | |
2363 | /** Joins : | |
2364 | * pj => profile_job | |
2365 | * pje => profile_job_enum | |
2366 | * pjse => profile_job_sector_enum | |
2367 | * pjsse => profile_job_subsector_enum | |
2368 | * pjssse => profile_job_subsubsector_enum | |
2369 | * pja => profile_job_alternates | |
2370 | */ | |
2371 | private $with_pj = false; | |
2372 | private $with_pje = false; | |
2373 | private $with_pjse = false; | |
2374 | private $with_pjsse = false; | |
2375 | private $with_pjssse = false; | |
2376 | private $with_pja = false; | |
2377 | ||
2378 | public function addJobFilter() | |
2379 | { | |
b8dcf62d | 2380 | $this->requireProfiles(); |
6a99c3ac RB |
2381 | $this->with_pj = true; |
2382 | return 'pj'; | |
2383 | } | |
2384 | ||
2385 | public function addJobCompanyFilter() | |
2386 | { | |
2387 | $this->addJobFilter(); | |
2388 | $this->with_pje = true; | |
2389 | return 'pje'; | |
2390 | } | |
2391 | ||
2392 | public function addJobSectorizationFilter($type) | |
2393 | { | |
2394 | $this->addJobFilter(); | |
2395 | if ($type == self::JOB_SECTOR) { | |
2396 | $this->with_pjse = true; | |
2397 | return 'pjse'; | |
2398 | } else if ($type == self::JOB_SUBSECTOR) { | |
2399 | $this->with_pjsse = true; | |
2400 | return 'pjsse'; | |
2401 | } else if ($type == self::JOB_SUBSUBSECTOR) { | |
2402 | $this->with_pjssse = true; | |
2403 | return 'pjssse'; | |
2404 | } else if ($type == self::JOB_ALTERNATES) { | |
2405 | $this->with_pja = true; | |
2406 | return 'pja'; | |
2407 | } | |
2408 | } | |
2409 | ||
9b8e5fb4 | 2410 | protected function jobJoins() |
6a99c3ac RB |
2411 | { |
2412 | $joins = array(); | |
2413 | if ($this->with_pj) { | |
5c412626 | 2414 | $joins['pj'] = PlSqlJoin::left('profile_job', '$ME.pid = $PID'); |
6a99c3ac RB |
2415 | } |
2416 | if ($this->with_pje) { | |
5c412626 | 2417 | $joins['pje'] = PlSqlJoin::left('profile_job_enum', '$ME.id = pj.jobid'); |
6a99c3ac RB |
2418 | } |
2419 | if ($this->with_pjse) { | |
5c412626 | 2420 | $joins['pjse'] = PlSqlJoin::left('profile_job_sector_enum', '$ME.id = pj.sectorid'); |
6a99c3ac RB |
2421 | } |
2422 | if ($this->with_pjsse) { | |
5c412626 | 2423 | $joins['pjsse'] = PlSqlJoin::left('profile_job_subsector_enum', '$ME.id = pj.subsectorid'); |
6a99c3ac RB |
2424 | } |
2425 | if ($this->with_pjssse) { | |
5c412626 | 2426 | $joins['pjssse'] = PlSqlJoin::left('profile_job_subsubsector_enum', '$ME.id = pj.subsubsectorid'); |
6a99c3ac RB |
2427 | } |
2428 | if ($this->with_pja) { | |
5c412626 | 2429 | $joins['pja'] = PlSqlJoin::left('profile_job_alternates', '$ME.subsubsectorid = pj.subsubsectorid'); |
6a99c3ac RB |
2430 | } |
2431 | return $joins; | |
2432 | } | |
2433 | ||
0a2e9c74 RB |
2434 | /** NETWORKING |
2435 | */ | |
2436 | ||
2437 | private $with_pnw = false; | |
2438 | public function addNetworkingFilter() | |
2439 | { | |
b8dcf62d | 2440 | $this->requireAccounts(); |
0a2e9c74 RB |
2441 | $this->with_pnw = true; |
2442 | return 'pnw'; | |
2443 | } | |
2444 | ||
9b8e5fb4 | 2445 | protected function networkingJoins() |
0a2e9c74 RB |
2446 | { |
2447 | $joins = array(); | |
2448 | if ($this->with_pnw) { | |
5c412626 | 2449 | $joins['pnw'] = PlSqlJoin::left('profile_networking', '$ME.pid = $PID'); |
0a2e9c74 RB |
2450 | } |
2451 | return $joins; | |
2452 | } | |
2453 | ||
6d62969e RB |
2454 | /** PHONE |
2455 | */ | |
2456 | ||
2d83cac9 | 2457 | private $with_ptel = false; |
6d62969e RB |
2458 | |
2459 | public function addPhoneFilter() | |
2460 | { | |
b8dcf62d | 2461 | $this->requireAccounts(); |
2d83cac9 | 2462 | $this->with_ptel = true; |
6d62969e RB |
2463 | return 'ptel'; |
2464 | } | |
2465 | ||
9b8e5fb4 | 2466 | protected function phoneJoins() |
6d62969e RB |
2467 | { |
2468 | $joins = array(); | |
2d83cac9 | 2469 | if ($this->with_ptel) { |
5c412626 | 2470 | $joins['ptel'] = PlSqlJoin::left('profile_phones', '$ME.pid = $PID'); |
6d62969e RB |
2471 | } |
2472 | return $joins; | |
2473 | } | |
2474 | ||
ceb512d2 RB |
2475 | /** MEDALS |
2476 | */ | |
2477 | ||
2d83cac9 | 2478 | private $with_pmed = false; |
ceb512d2 RB |
2479 | public function addMedalFilter() |
2480 | { | |
b8dcf62d | 2481 | $this->requireProfiles(); |
2d83cac9 | 2482 | $this->with_pmed = true; |
ceb512d2 RB |
2483 | return 'pmed'; |
2484 | } | |
2485 | ||
9b8e5fb4 | 2486 | protected function medalJoins() |
ceb512d2 RB |
2487 | { |
2488 | $joins = array(); | |
2d83cac9 | 2489 | if ($this->with_pmed) { |
5c412626 | 2490 | $joins['pmed'] = PlSqlJoin::left('profile_medals', '$ME.pid = $PID'); |
ceb512d2 RB |
2491 | } |
2492 | return $joins; | |
2493 | } | |
2494 | ||
671b7073 RB |
2495 | /** MENTORING |
2496 | */ | |
2497 | ||
2498 | private $pms = array(); | |
2499 | const MENTOR_EXPERTISE = 1; | |
2500 | const MENTOR_COUNTRY = 2; | |
2501 | const MENTOR_SECTOR = 3; | |
2502 | ||
2503 | public function addMentorFilter($type) | |
2504 | { | |
b8dcf62d | 2505 | $this->requireAccounts(); |
671b7073 | 2506 | switch($type) { |
4a93c3a3 RB |
2507 | case self::MENTOR_EXPERTISE: |
2508 | $this->pms['pme'] = 'profile_mentor'; | |
671b7073 | 2509 | return 'pme'; |
4a93c3a3 RB |
2510 | case self::MENTOR_COUNTRY: |
2511 | $this->pms['pmc'] = 'profile_mentor_country'; | |
671b7073 | 2512 | return 'pmc'; |
4a93c3a3 RB |
2513 | case self::MENTOR_SECTOR: |
2514 | $this->pms['pms'] = 'profile_mentor_sector'; | |
671b7073 RB |
2515 | return 'pms'; |
2516 | default: | |
5d2e55c7 | 2517 | Platal::page()->killError("Undefined mentor filter."); |
671b7073 RB |
2518 | } |
2519 | } | |
2520 | ||
9b8e5fb4 | 2521 | protected function mentorJoins() |
671b7073 RB |
2522 | { |
2523 | $joins = array(); | |
2524 | foreach ($this->pms as $sub => $tab) { | |
5c412626 | 2525 | $joins[$sub] = PlSqlJoin::left($tab, '$ME.pid = $PID'); |
671b7073 RB |
2526 | } |
2527 | return $joins; | |
2528 | } | |
2529 | ||
3f42a6ad FB |
2530 | /** CONTACTS |
2531 | */ | |
2532 | private $cts = array(); | |
2533 | public function addContactFilter($uid = null) | |
2534 | { | |
c96da6c1 | 2535 | $this->requireProfiles(); |
3f42a6ad FB |
2536 | return $this->register_optional($this->cts, is_null($uid) ? null : 'user_' . $uid); |
2537 | } | |
2538 | ||
9b8e5fb4 | 2539 | protected function contactJoins() |
3f42a6ad FB |
2540 | { |
2541 | $joins = array(); | |
2542 | foreach ($this->cts as $sub=>$key) { | |
2543 | if (is_null($key)) { | |
5c412626 | 2544 | $joins['c' . $sub] = PlSqlJoin::left('contacts', '$ME.contact = $PID'); |
3f42a6ad | 2545 | } else { |
5c412626 | 2546 | $joins['c' . $sub] = PlSqlJoin::left('contacts', '$ME.uid = {?} AND $ME.contact = $PID', substr($key, 5)); |
3f42a6ad FB |
2547 | } |
2548 | } | |
2549 | return $joins; | |
2550 | } | |
4e7bf1e0 FB |
2551 | |
2552 | ||
2553 | /** CARNET | |
2554 | */ | |
2555 | private $wn = array(); | |
2556 | public function addWatchRegistrationFilter($uid = null) | |
2557 | { | |
b8dcf62d | 2558 | $this->requireAccounts(); |
4e7bf1e0 FB |
2559 | return $this->register_optional($this->wn, is_null($uid) ? null : 'user_' . $uid); |
2560 | } | |
2561 | ||
2562 | private $wp = array(); | |
2563 | public function addWatchPromoFilter($uid = null) | |
2564 | { | |
b8dcf62d | 2565 | $this->requireAccounts(); |
4e7bf1e0 FB |
2566 | return $this->register_optional($this->wp, is_null($uid) ? null : 'user_' . $uid); |
2567 | } | |
2568 | ||
2569 | private $w = array(); | |
2570 | public function addWatchFilter($uid = null) | |
2571 | { | |
b8dcf62d | 2572 | $this->requireAccounts(); |
4e7bf1e0 FB |
2573 | return $this->register_optional($this->w, is_null($uid) ? null : 'user_' . $uid); |
2574 | } | |
2575 | ||
9b8e5fb4 | 2576 | protected function watchJoins() |
4e7bf1e0 FB |
2577 | { |
2578 | $joins = array(); | |
2579 | foreach ($this->w as $sub=>$key) { | |
2580 | if (is_null($key)) { | |
5c412626 | 2581 | $joins['w' . $sub] = PlSqlJoin::left('watch'); |
4e7bf1e0 | 2582 | } else { |
5c412626 | 2583 | $joins['w' . $sub] = PlSqlJoin::left('watch', '$ME.uid = {?}', substr($key, 5)); |
4e7bf1e0 FB |
2584 | } |
2585 | } | |
2586 | foreach ($this->wn as $sub=>$key) { | |
2587 | if (is_null($key)) { | |
5c412626 | 2588 | $joins['wn' . $sub] = PlSqlJoin::left('watch_nonins', '$ME.ni_id = $UID'); |
4e7bf1e0 | 2589 | } else { |
5c412626 | 2590 | $joins['wn' . $sub] = PlSqlJoin::left('watch_nonins', '$ME.uid = {?} AND $ME.ni_id = $UID', substr($key, 5)); |
4e7bf1e0 FB |
2591 | } |
2592 | } | |
2593 | foreach ($this->wn as $sub=>$key) { | |
2594 | if (is_null($key)) { | |
5c412626 | 2595 | $joins['wn' . $sub] = PlSqlJoin::left('watch_nonins', '$ME.ni_id = $UID'); |
4e7bf1e0 | 2596 | } else { |
5c412626 | 2597 | $joins['wn' . $sub] = PlSqlJoin::left('watch_nonins', '$ME.uid = {?} AND $ME.ni_id = $UID', substr($key, 5)); |
4e7bf1e0 FB |
2598 | } |
2599 | } | |
2600 | foreach ($this->wp as $sub=>$key) { | |
2601 | if (is_null($key)) { | |
5c412626 | 2602 | $joins['wp' . $sub] = PlSqlJoin::left('watch_promo'); |
4e7bf1e0 | 2603 | } else { |
5c412626 | 2604 | $joins['wp' . $sub] = PlSqlJoin::left('watch_promo', '$ME.uid = {?}', substr($key, 5)); |
4e7bf1e0 FB |
2605 | } |
2606 | } | |
2607 | return $joins; | |
2608 | } | |
48885bbe FB |
2609 | |
2610 | ||
470d14f6 FB |
2611 | /** PHOTOS |
2612 | */ | |
2613 | private $with_photo; | |
2614 | public function addPhotoFilter() | |
2615 | { | |
2616 | $this->requireProfiles(); | |
2617 | $this->with_photo = true; | |
2618 | } | |
2619 | ||
2620 | protected function photoJoins() | |
2621 | { | |
2622 | if ($this->with_photo) { | |
2623 | return array('photo' => PlSqlJoin::left('profile_photos', '$ME.pid = $PID')); | |
2624 | } else { | |
2625 | return array(); | |
2626 | } | |
2627 | } | |
2628 | ||
2629 | ||
48885bbe FB |
2630 | /** MARKETING |
2631 | */ | |
2632 | private $with_rm; | |
2633 | public function addMarketingHash() | |
2634 | { | |
2635 | $this->requireAccounts(); | |
2636 | $this->with_rm = true; | |
2637 | } | |
2638 | ||
2639 | protected function marketingJoins() | |
2640 | { | |
2641 | if ($this->with_rm) { | |
5c412626 | 2642 | return array('rm' => PlSqlJoin::left('register_marketing', '$ME.uid = $UID')); |
48885bbe FB |
2643 | } else { |
2644 | return array(); | |
2645 | } | |
2646 | } | |
a087cc8d | 2647 | } |
8363588b | 2648 | // }}} |
3f42a6ad | 2649 | |
a7d9ab89 RB |
2650 | // {{{ class ProfileFilter |
2651 | class ProfileFilter extends UserFilter | |
2652 | { | |
434570c4 | 2653 | public function get($limit = null) |
a7d9ab89 RB |
2654 | { |
2655 | return $this->getProfiles($limit); | |
2656 | } | |
2657 | } | |
2658 | // }}} | |
2659 | ||
a087cc8d FB |
2660 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
2661 | ?> |