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