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