24a285756bc99e5c87b5180a1fc89ad516673912
[platal.git] / classes / userfilter / conditions.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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
22 // {{{ abstract class UserFilterCondition
23 /** This class describe objects which filter users based
24 * on various parameters.
25 * The parameters of the filter must be given to the constructor.
26 * The buildCondition function is called by UserFilter when
27 * actually building the query. That function must call
28 * $uf->addWheteverFilter so that the UserFilter makes
29 * adequate joins. It must return the 'WHERE' condition to use
30 * with the filter.
31 */
32 abstract class UserFilterCondition implements PlFilterCondition
33 {
34 const OP_EQUALS = '==';
35 const OP_GREATER = '>';
36 const OP_NOTGREATER = '<=';
37 const OP_LESSER = '<';
38 const OP_NOTLESSER = '>=';
39 const OP_NULL = 'null';
40 const OP_NOTNULL = 'not null';
41 const OP_CONTAINS = 'contains';
42 const OP_PREFIX = 'prefix';
43 const OP_SUFFIX = 'suffix';
44
45 protected function buildExport($type)
46 {
47 $export = array('type' => $type);
48 return $export;
49 }
50
51 public function export()
52 {
53 throw new Exception("This class is not exportable");
54 }
55
56 public static function comparisonFromXDBWildcard($wildcard)
57 {
58 switch ($wildcard) {
59 case XDB::WILDCARD_EXACT:
60 return self::OP_EQUALS;
61 case XDB::WILDCARD_PREFIX:
62 return self::OP_PREFIX;
63 case XDB::WILDCARD_SUFFIX:
64 return self::OP_SUFFIX;
65 case XDB::WILDCARD_CONTAINS:
66 return self::OP_CONTAINS;
67 }
68 throw new Exception("Unknown wildcard mode: $wildcard");
69 }
70
71 public static function xdbWildcardFromComparison($comparison)
72 {
73 if (!self::isStringComparison($comparison)) {
74 throw new Exception("Unknown string coparison: $comparison");
75 }
76 switch ($comparison) {
77 case self::OP_EQUALS:
78 return XDB::WILDCARD_EXACT;
79 case self::OP_PREFIX:
80 return XDB::WILDCARD_PREFIX;
81 case self::OP_SUFFIX:
82 return XDB::WILDCARD_SUFFIX;
83 case self::OP_CONTAINS:
84 return XDB::WILDCARD_CONTAINS;
85 }
86 }
87
88 private static function isNumericComparison($comparison)
89 {
90 return $comparison == self::OP_EQUALS
91 || $comparison == self::OP_GREATER
92 || $comparison == self::OP_NOTGREATER
93 || $comparison == self::OP_LESSER
94 || $comparison == self::OP_NOTLESSER;
95 }
96
97 private static function isStringComparison($comparison)
98 {
99 return $comparison == self::OP_EQUALS
100 || $comparison == self::OP_CONTAINS
101 || $comparison == self::OP_PREFIX
102 || $comparison == self::OP_SUFFIX;
103 }
104
105 public static function fromExport(array $export)
106 {
107 $export = new PlDict($export);
108 if (!$export->has('type')) {
109 throw new Exception("Missing type in export");
110 }
111 $type = $export->s('type');
112 $cond = null;
113 switch ($type) {
114 case 'and':
115 case 'or':
116 case 'not':
117 case 'true':
118 case 'false':
119 $class = 'pfc_' . $type;
120 $cond = new $class();
121 break;
122
123 case 'host':
124 if ($export->has('ip')) {
125 $cond = new UFC_Ip($export->s('ip'));
126 }
127 break;
128
129 case 'comment':
130 if ($export->has('text') && $export->s('comparison') == self::OP_CONTAINS) {
131 $cond = new UFC_Comment($export->s('text'));
132 }
133 break;
134
135 case 'promo':
136 if ($export->has('promo') && self::isNumericComparison($export->s('comparison'))) {
137 $cond = new UFC_Promo($export->s('comparison'),
138 $export->s('grade', UserFilter::DISPLAY),
139 $export->s('promo'));
140 }
141 break;
142
143 case 'lastname':
144 case 'name':
145 case 'firstname':
146 case 'nickname':
147 case 'pseudonym':
148 if ($export->has('text')) {
149 $flag = self::xdbWildcardFromComparison($export->s('comparison'));
150 if ($export->b('search_in_variants')) {
151 $flag |= UFC_Name::VARIANTS;
152 }
153 if ($export->b('search_in_particle')) {
154 $flag |= UFC_Name::PARTICLE;
155 }
156 $cond = new UFC_Name($type, $export->s('text'), $flag);
157 }
158 break;
159
160 case 'account_type':
161 case 'account_perm':
162 case 'hrpid':
163 case 'hruid':
164 $values = $export->v('values', array());
165 $class = 'ufc_' . str_replace('_', '', $type);
166 $cond = new $class($values);
167 break;
168
169 case 'has_profile':
170 $class = 'ufc_' . str_replace('_', '', $type);
171 $cond = new $class();
172 break;
173
174 default:
175 throw new Exception("Unknown condition type: $type");
176 }
177 if (is_null($cond)) {
178 throw new Exception("Unsupported $type definition");
179 }
180 if ($cond instanceof PFC_NChildren) {
181 $children = $export->v('children', array());
182 foreach ($children as $child) {
183 $cond->addChild(self::fromExport($child));
184 }
185 } else if ($cond instanceof PFC_OneChild) {
186 if ($export->has('child')) {
187 $cond->setChild(self::fromExport($export->v('child')));
188 }
189 }
190 return $cond;
191 }
192 }
193 // }}}
194 // {{{ class UFC_HasProfile
195 /** Filters users who have a profile
196 */
197 class UFC_HasProfile extends UserFilterCondition
198 {
199 public function buildCondition(PlFilter $uf)
200 {
201 $uf->requireProfiles();
202 return '$PID IS NOT NULL';
203 }
204
205 public function export()
206 {
207 return $this->buildExport('has_profile');
208 }
209 }
210 // }}}
211 // {{{ class UFC_AccountType
212 /** Filters users who have one of the given account types
213 */
214 class UFC_AccountType extends UserFilterCondition
215 {
216 private $types;
217
218 public function __construct()
219 {
220 $this->types = pl_flatten(func_get_args());
221 }
222
223 public function buildCondition(PlFilter $uf)
224 {
225 $uf->requireAccounts();
226 return XDB::format('a.type IN {?}', $this->types);
227 }
228
229 public function export()
230 {
231 $export = $this->buildExport('account_type');
232 $export['values'] = $this->types;
233 return $export;
234 }
235 }
236 // }}}
237 // {{{ class UFC_AccountPerm
238 /** Filters users who have one of the given permissions
239 */
240 class UFC_AccountPerm extends UserFilterCondition
241 {
242 private $perms;
243
244 public function __construct()
245 {
246 $this->perms = pl_flatten(func_get_args());
247 }
248
249 public function buildCondition(PlFilter $uf)
250 {
251 $uf->requirePerms();
252 $conds = array();
253 foreach ($this->perms as $perm) {
254 $conds[] = XDB::format('FIND_IN_SET({?}, IF(a.user_perms IS NULL, at.perms,
255 CONCAT(at.perms, \',\', a.user_perms)))',
256 $perm);
257 }
258 if (empty($conds)) {
259 return self::COND_TRUE;
260 } else {
261 return implode(' OR ', $conds);
262 }
263 }
264
265 public function export()
266 {
267 $export = $this->buildExport('account_perm');
268 $export['values'] = $this->perms;
269 return $export;
270 }
271 }
272 // }}}
273 // {{{ class UFC_Hruid
274 /** Filters users based on their hruid
275 * @param $val Either an hruid, or a list of those
276 */
277 class UFC_Hruid extends UserFilterCondition
278 {
279 private $hruids;
280
281 public function __construct()
282 {
283 $this->hruids = pl_flatten(func_get_args());
284 }
285
286 public function buildCondition(PlFilter $uf)
287 {
288 $uf->requireAccounts();
289 return XDB::format('a.hruid IN {?}', $this->hruids);
290 }
291
292 public function export()
293 {
294 $export = $this->buildExport('hruid');
295 $export['values'] = $this->hruids;
296 return $export;
297 }
298 }
299 // }}}
300 // {{{ class UFC_Hrpid
301 /** Filters users based on the hrpid of their profiles
302 * @param $val Either an hrpid, or a list of those
303 */
304 class UFC_Hrpid extends UserFilterCondition
305 {
306 private $hrpids;
307
308 public function __construct()
309 {
310 $this->hrpids = pl_flatten(func_get_args());
311 }
312
313 public function buildCondition(PlFilter $uf)
314 {
315 $uf->requireProfiles();
316 return XDB::format('p.hrpid IN {?}', $this->hrpids);
317 }
318
319 public function export()
320 {
321 $export = $this->buildExport('hrpid');
322 $export['values'] = $this->hrpids;
323 return $export;
324 }
325 }
326 // }}}
327 // {{{ class UFC_Ip
328 /** Filters users based on one of their last IPs
329 * @param $ip IP from which connection are checked
330 */
331 class UFC_Ip extends UserFilterCondition
332 {
333 private $ip;
334
335 public function __construct($ip)
336 {
337 $this->ip = $ip;
338 }
339
340 public function buildCondition(PlFilter $uf)
341 {
342 $sub = $uf->addLoggerFilter();
343 $ip = ip_to_uint($this->ip);
344 return XDB::format($sub . '.ip = {?} OR ' . $sub . '.forward_ip = {?}', $ip, $ip);
345 }
346
347 public function export()
348 {
349 $export = $this->buildExport('host');
350 $export['ip'] = $this->ip;
351 return $export;
352 }
353 }
354 // }}}
355 // {{{ class UFC_Comment
356 class UFC_Comment extends UserFilterCondition
357 {
358 private $text;
359
360 public function __construct($text)
361 {
362 $this->text = $text;
363 }
364
365 public function buildCondition(PlFilter $uf)
366 {
367 $uf->requireProfiles();
368 return $uf->getVisibilityCondition('p.freetext_pub') . ' AND p.freetext ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->text);
369 }
370
371 public function export()
372 {
373 $export = $this->buildExport('comment');
374 $export['comparison'] = self::OP_CONTAINS;
375 $export['text'] = $this->text;
376 return $export;
377 }
378 }
379 // }}}
380 // {{{ class UFC_Promo
381 /** Filters users based on promotion
382 * @param $comparison Comparison operator (>, =, ...)
383 * @param $grade Formation on which to restrict, UserFilter::DISPLAY for "any formation"
384 * @param $promo Promotion on which the filter is based
385 */
386 class UFC_Promo extends UserFilterCondition
387 {
388
389 private $grade;
390 private $promo;
391 private $comparison;
392
393 public function __construct($comparison, $grade, $promo)
394 {
395 $this->grade = $grade;
396 $this->comparison = $comparison;
397 $this->promo = $promo;
398 if ($this->grade != UserFilter::DISPLAY) {
399 UserFilter::assertGrade($this->grade);
400 }
401 if ($this->grade == UserFilter::DISPLAY && $this->comparison != '=') {
402 // XXX: we might try to guess the grade from the first char of the promo and forbid only '<= 2004', but allow '<= X2004'
403 Platal::page()->killError("Il n'est pas possible d'appliquer la comparaison '" . $this->comparison . "' aux promotions sans spécifier de formation (X/M/D)");
404 }
405 }
406
407 public function buildCondition(PlFilter $uf)
408 {
409 if ($this->grade == UserFilter::DISPLAY) {
410 $sub = $uf->addDisplayFilter();
411 return XDB::format('pd' . $sub . '.promo ' . $this->comparison . ' {?}', $this->promo);
412 } else {
413 $sub = $uf->addEducationFilter(true, $this->grade);
414 $field = 'pe' . $sub . '.' . UserFilter::promoYear($this->grade);
415 return $field . ' IS NOT NULL AND ' . $field . ' ' . $this->comparison . ' ' . XDB::format('{?}', $this->promo);
416 }
417 }
418
419 public function export()
420 {
421 $export['comparison'] = $this->comparison;
422 if ($this->grade != UserFilter::DISPLAY) {
423 $export['grade'] = $this->grade;
424 }
425 $export['promo'] = $this->promo;
426 return $export;
427 }
428 }
429 // }}}
430 // {{{ class UFC_SchoolId
431 /** Filters users based on their shoold identifier
432 * @param type Parameter type (Xorg, AX, School)
433 * @param value School id value
434 */
435 class UFC_SchoolId extends UserFilterCondition
436 {
437 const AX = 'ax';
438 const Xorg = 'xorg';
439 const School = 'school';
440
441 private $type;
442 private $id;
443
444 static public function assertType($type)
445 {
446 if ($type != self::AX && $type != self::Xorg && $type != self::School) {
447 Platal::page()->killError("Type de matricule invalide: $type");
448 }
449 }
450
451 public function __construct($type, $id)
452 {
453 $this->type = $type;
454 $this->id = $id;
455 self::assertType($type);
456 }
457
458 public function buildCondition(PlFilter $uf)
459 {
460 $uf->requireProfiles();
461 $id = $this->id;
462 $type = $this->type;
463 if ($type == self::School) {
464 $type = self::Xorg;
465 $id = Profile::getXorgId($id);
466 }
467 return XDB::format('p.' . $type . '_id = {?}', $id);
468 }
469 }
470 // }}}
471 // {{{ class UFC_EducationSchool
472 /** Filters users by formation
473 * @param $val The formation to search (either ID or array of IDs)
474 */
475 class UFC_EducationSchool extends UserFilterCondition
476 {
477 private $val;
478
479 public function __construct()
480 {
481 $this->val = pl_flatten(func_get_args());
482 }
483
484 public function buildCondition(PlFilter $uf)
485 {
486 $sub = $uf->addEducationFilter();
487 return XDB::format('pe' . $sub . '.eduid IN {?}', $this->val);
488 }
489 }
490 // }}}
491 // {{{ class UFC_EducationDegree
492 class UFC_EducationDegree extends UserFilterCondition
493 {
494 private $diploma;
495
496 public function __construct()
497 {
498 $this->diploma = pl_flatten(func_get_args());
499 }
500
501 public function buildCondition(PlFilter $uf)
502 {
503 $sub = $uf->addEducationFilter();
504 return XDB::format('pe' . $sub . '.degreeid IN {?}', $this->diploma);
505 }
506 }
507 // }}}
508 // {{{ class UFC_EducationField
509 class UFC_EducationField extends UserFilterCondition
510 {
511 private $val;
512
513 public function __construct()
514 {
515 $this->val = pl_flatten(func_get_args());
516 }
517
518 public function buildCondition(PlFilter $uf)
519 {
520 $sub = $uf->addEducationFilter();
521 return XDB::format('pe' . $sub . '.fieldid IN {?}', $this->val);
522 }
523 }
524 // }}}
525 // {{{ class UFC_Name
526 /** Filters users based on name
527 * @param $type Type of name field on which filtering is done (firstname, lastname...)
528 * @param $text Text on which to filter
529 * @param $mode Flag indicating search type (prefix, suffix, with particule...)
530 */
531 class UFC_Name extends UserFilterCondition
532 {
533 const EXACT = XDB::WILDCARD_EXACT; // 0x000
534 const PREFIX = XDB::WILDCARD_PREFIX; // 0x001
535 const SUFFIX = XDB::WILDCARD_SUFFIX; // 0x002
536 const CONTAINS = XDB::WILDCARD_CONTAINS; // 0x003
537 const PARTICLE = 0x004;
538 const VARIANTS = 0x008;
539
540 private $type;
541 private $text;
542 private $mode;
543
544 public function __construct($type, $text, $mode)
545 {
546 $this->type = $type;
547 $this->text = $text;
548 $this->mode = $mode;
549 }
550
551 private function buildNameQuery($type, $variant, $where, UserFilter $uf)
552 {
553 $sub = $uf->addNameFilter($type, $variant);
554 return str_replace('$ME', 'pn' . $sub, $where);
555 }
556
557 public function buildCondition(PlFilter $uf)
558 {
559 $left = '$ME.name';
560 if (($this->mode & self::PARTICLE) == self::PARTICLE) {
561 $left = 'CONCAT($ME.particle, \' \', $ME.name)';
562 }
563 $right = XDB::formatWildcards($this->mode & self::CONTAINS, $this->text);
564
565 $cond = $left . $right;
566 $conds = array($this->buildNameQuery($this->type, null, $cond, $uf));
567 if (($this->mode & self::VARIANTS) != 0 && isset(Profile::$name_variants[$this->type])) {
568 foreach (Profile::$name_variants[$this->type] as $var) {
569 $conds[] = $this->buildNameQuery($this->type, $var, $cond, $uf);
570 }
571 }
572 return implode(' OR ', $conds);
573 }
574
575 public function export()
576 {
577 $export = $this->buildExport($this->type);
578 if ($this->mode & self::VARIANTS) {
579 $export['search_in_variants'] = true;
580 }
581 if ($this->mode & self::PARTICLE) {
582 $export['search_in_particle'] = true;
583 }
584 $export['comparison'] = self::comparisonFromXDBWildcard($this->mode & 0x3);
585 $export['text'] = $this->text;
586 return $export;
587 }
588 }
589 // }}}
590 // {{{ class UFC_NameTokens
591 /** Selects users based on tokens in their name (for quicksearch)
592 * @param $tokens An array of tokens to search
593 * @param $flags Flags the tokens must have (e.g 'public' for public search)
594 * @param $soundex (bool) Whether those tokens are fulltext or soundex
595 */
596 class UFC_NameTokens extends UserFilterCondition
597 {
598 /* Flags */
599 const FLAG_PUBLIC = 'public';
600
601 private $tokens;
602 private $flags;
603 private $soundex;
604 private $exact;
605
606 public function __construct($tokens, $flags = array(), $soundex = false, $exact = false)
607 {
608 if (is_array($tokens)) {
609 $this->tokens = $tokens;
610 } else {
611 $this->tokens = array($tokens);
612 }
613 if (is_array($flags)) {
614 $this->flags = $flags;
615 } else {
616 $this->flags = array($flags);
617 }
618 $this->soundex = $soundex;
619 $this->exact = $exact;
620 }
621
622 public function buildCondition(PlFilter $uf)
623 {
624 $conds = array();
625 foreach ($this->tokens as $i => $token) {
626 $sub = $uf->addNameTokensFilter($token);
627 if ($this->soundex) {
628 $c = XDB::format($sub . '.soundex = {?}', soundex_fr($token));
629 } else if ($this->exact) {
630 $c = XDB::format($sub . '.token = {?}', $token);
631 } else {
632 $c = $sub . '.token ' . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $token);
633 }
634 if ($this->flags != null) {
635 $c .= XDB::format(' AND ' . $sub . '.flags IN {?}', $this->flags);
636 }
637 $conds[] = $c;
638 }
639
640 return implode(' AND ', $conds);
641 }
642 }
643 // }}}
644 // {{{ class UFC_Nationality
645 class UFC_Nationality extends UserFilterCondition
646 {
647 private $val;
648
649 public function __construct()
650 {
651 $this->val = pl_flatten(func_get_args());
652 }
653
654 public function buildCondition(PlFilter $uf)
655 {
656 $uf->requireProfiles();
657 $nat = XDB::formatArray($this->val);
658 $conds = array(
659 'p.nationality1 IN ' . $nat,
660 'p.nationality2 IN ' . $nat,
661 'p.nationality3 IN ' . $nat,
662 );
663 return implode(' OR ', $conds);
664 }
665 }
666 // }}}
667 // {{{ class UFC_Dead
668 /** Filters users based on death date
669 * @param $comparison Comparison operator
670 * @param $date Date to which death date should be compared (DateTime object, string or timestamp)
671 */
672 class UFC_Dead extends UserFilterCondition
673 {
674 private $comparison;
675 private $date;
676
677 public function __construct($comparison = null, $date = null)
678 {
679 $this->comparison = $comparison;
680 $this->date = make_datetime($date);
681 }
682
683 public function buildCondition(PlFilter $uf)
684 {
685 $uf->requireProfiles();
686 $str = 'p.deathdate IS NOT NULL';
687 if (!is_null($this->comparison)) {
688 $str .= ' AND p.deathdate ' . $this->comparison . ' ' . XDB::format('{?}', $this->date->format('Y-m-d'));
689 }
690 return $str;
691 }
692 }
693 // }}}
694 // {{{ class UFC_Registered
695 /** Filters users based on registration state
696 * @param $active Whether we want to use only "active" users (i.e with a valid redirection)
697 * @param $comparison Comparison operator
698 * @param $date Date to which users registration date should be compared
699 */
700 class UFC_Registered extends UserFilterCondition
701 {
702 private $active;
703 private $comparison;
704 private $date;
705
706 public function __construct($active = false, $comparison = null, $date = null)
707 {
708 $this->active = $active;
709 $this->comparison = $comparison;
710 $this->date = make_datetime($date);
711 }
712
713 public function buildCondition(PlFilter $uf)
714 {
715 $uf->requireAccounts();
716 if ($this->active) {
717 $date = '$UID IS NOT NULL AND a.state = \'active\'';
718 } else {
719 $date = '$UID IS NOT NULL AND a.state != \'pending\'';
720 }
721 if (!is_null($this->comparison)) {
722 $date .= ' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date ' . $this->comparison . ' ' . XDB::format('{?}', $this->date->format('Y-m-d'));
723 }
724 return $date;
725 }
726 }
727 // }}}
728 // {{{ class UFC_ProfileUpdated
729 /** Filters users based on profile update date
730 * @param $comparison Comparison operator
731 * @param $date Date to which profile update date must be compared
732 */
733 class UFC_ProfileUpdated extends UserFilterCondition
734 {
735 private $comparison;
736 private $date;
737
738 public function __construct($comparison = null, $date = null)
739 {
740 $this->comparison = $comparison;
741 $this->date = $date;
742 }
743
744 public function buildCondition(PlFilter $uf)
745 {
746 $uf->requireProfiles();
747 return 'p.last_change ' . $this->comparison . XDB::format(' {?}', date('Y-m-d H:i:s', $this->date));
748 }
749 }
750 // }}}
751 // {{{ class UFC_Birthday
752 /** Filters users based on next birthday date
753 * @param $comparison Comparison operator
754 * @param $date Date to which users next birthday date should be compared
755 */
756 class UFC_Birthday extends UserFilterCondition
757 {
758 private $comparison;
759 private $date;
760
761 public function __construct($comparison = null, $date = null)
762 {
763 $this->comparison = $comparison;
764 $this->date = $date;
765 }
766
767 public function buildCondition(PlFilter $uf)
768 {
769 $uf->requireProfiles();
770 return 'p.next_birthday ' . $this->comparison . XDB::format(' {?}', date('Y-m-d', $this->date));
771 }
772 }
773 // }}}
774 // {{{ class UFC_Sex
775 /** Filters users based on sex
776 * @parm $sex One of User::GENDER_MALE or User::GENDER_FEMALE, for selecting users
777 */
778 class UFC_Sex extends UserFilterCondition
779 {
780 private $sex;
781 public function __construct($sex)
782 {
783 $this->sex = $sex;
784 }
785
786 public function buildCondition(PlFilter $uf)
787 {
788 if ($this->sex != User::GENDER_MALE && $this->sex != User::GENDER_FEMALE) {
789 return self::COND_FALSE;
790 } else {
791 $uf->requireProfiles();
792 return XDB::format('p.sex = {?}', $this->sex == User::GENDER_FEMALE ? 'female' : 'male');
793 }
794 }
795 }
796 // }}}
797 // {{{ class UFC_Group
798 /** Filters users based on group membership
799 * @param $group Group whose members we are selecting
800 * @param $anim Whether to restrict selection to animators of that group
801 */
802 class UFC_Group extends UserFilterCondition
803 {
804 private $group;
805 private $anim;
806 public function __construct($group, $anim = false)
807 {
808 $this->group = $group;
809 $this->anim = $anim;
810 }
811
812 public function buildCondition(PlFilter $uf)
813 {
814 // Groups have AX visibility.
815 if ($uf->getVisibilityLevel() == ProfileVisibility::VIS_PUBLIC) {
816 return self::COND_TRUE;
817 }
818 $sub = $uf->addGroupFilter($this->group);
819 $where = 'gpm' . $sub . '.perms IS NOT NULL';
820 if ($this->anim) {
821 $where .= ' AND gpm' . $sub . '.perms = \'admin\'';
822 }
823 return $where;
824 }
825 }
826 // }}}
827 // {{{ class UFC_Binet
828 /** Selects users based on their belonging to a given (list of) binet
829 * @param $binet either a binet_id or an array of binet_ids
830 */
831 class UFC_Binet extends UserFilterCondition
832 {
833 private $val;
834
835 public function __construct()
836 {
837 $this->val = pl_flatten(func_get_args());
838 }
839
840 public function buildCondition(PlFilter $uf)
841 {
842 // Binets are private.
843 if ($uf->getVisibilityLevel() != ProfileVisibility::VIS_PRIVATE) {
844 return self::CONF_TRUE;
845 }
846 $sub = $uf->addBinetsFilter();
847 return XDB::format($sub . '.binet_id IN {?}', $this->val);
848 }
849 }
850 // }}}
851 // {{{ class UFC_Section
852 /** Selects users based on section
853 * @param $section ID of the section
854 */
855 class UFC_Section extends UserFilterCondition
856 {
857 private $section;
858
859 public function __construct()
860 {
861 $this->section = pl_flatten(func_get_args());
862 }
863
864 public function buildCondition(PlFilter $uf)
865 {
866 // Sections are private.
867 if ($uf->getVisibilityLevel() != ProfileVisibility::VIS_PRIVATE) {
868 return self::CONF_TRUE;
869 }
870 $uf->requireProfiles();
871 return XDB::format('p.section IN {?}', $this->section);
872 }
873 }
874 // }}}
875 // {{{ class UFC_Email
876 /** Filters users based on an email or a list of emails
877 * @param $emails List of emails whose owner must be selected
878 */
879 class UFC_Email extends UserFilterCondition
880 {
881 private $emails;
882 public function __construct()
883 {
884 $this->emails = pl_flatten(func_get_args());
885 }
886
887 public function buildCondition(PlFilter $uf)
888 {
889 $foreign = array();
890 $virtual = array();
891 $aliases = array();
892 $cond = array();
893
894 if (count($this->emails) == 0) {
895 return PlFilterCondition::COND_TRUE;
896 }
897
898 foreach ($this->emails as $entry) {
899 if (User::isForeignEmailAddress($entry)) {
900 $foreign[] = $entry;
901 } else if (User::isVirtualEmailAddress($entry)) {
902 $virtual[] = $entry;
903 } else {
904 @list($user, $domain) = explode('@', $entry);
905 $aliases[] = $user;
906 }
907 }
908
909 if (count($foreign) > 0) {
910 $sub = $uf->addEmailRedirectFilter($foreign);
911 $cond[] = XDB::format('e' . $sub . '.email IS NOT NULL OR a.email IN {?}', $foreign);
912 }
913 if (count($virtual) > 0) {
914 $sub = $uf->addVirtualEmailFilter($virtual);
915 $cond[] = 'vr' . $sub . '.redirect IS NOT NULL';
916 }
917 if (count($aliases) > 0) {
918 $sub = $uf->addAliasFilter($aliases);
919 $cond[] = 'al' . $sub . '.alias IS NOT NULL';
920 }
921 return '(' . implode(') OR (', $cond) . ')';
922 }
923 }
924 // }}}
925 // {{{ class UFC_Address
926 abstract class UFC_Address extends UserFilterCondition
927 {
928 /** Valid address type ('hq' is reserved for company addresses)
929 */
930 const TYPE_HOME = 1;
931 const TYPE_PRO = 2;
932 const TYPE_ANY = 3;
933
934 /** Text for these types
935 */
936 protected static $typetexts = array(
937 self::TYPE_HOME => 'home',
938 self::TYPE_PRO => 'pro',
939 );
940
941 protected $type;
942
943 /** Flags for addresses
944 */
945 const FLAG_CURRENT = 0x0001;
946 const FLAG_TEMP = 0x0002;
947 const FLAG_SECOND = 0x0004;
948 const FLAG_MAIL = 0x0008;
949 const FLAG_CEDEX = 0x0010;
950
951 // Binary OR of those flags
952 const FLAG_ANY = 0x001F;
953
954 /** Text of these flags
955 */
956 protected static $flagtexts = array(
957 self::FLAG_CURRENT => 'current',
958 self::FLAG_TEMP => 'temporary',
959 self::FLAG_SECOND => 'secondary',
960 self::FLAG_MAIL => 'mail',
961 self::FLAG_CEDEX => 'cedex',
962 );
963
964 protected $flags;
965
966 public function __construct($type = null, $flags = null)
967 {
968 $this->type = $type;
969 $this->flags = $flags;
970 }
971
972 protected function initConds($sub, $vis_cond)
973 {
974 $conds = array($vis_cond);
975
976 $types = array();
977 foreach (self::$typetexts as $flag => $type) {
978 if ($flag & $this->type) {
979 $types[] = $type;
980 }
981 }
982 if (count($types)) {
983 $conds[] = XDB::format($sub . '.type IN {?}', $types);
984 }
985
986 if ($this->flags != self::FLAG_ANY) {
987 foreach(self::$flagtexts as $flag => $text) {
988 if ($flag & $this->flags) {
989 $conds[] = 'FIND_IN_SET(' . XDB::format('{?}', $text) . ', ' . $sub . '.flags)';
990 }
991 }
992 }
993 return $conds;
994 }
995
996 }
997 // }}}
998 // {{{ class UFC_AddressText
999 /** Select users based on their address, using full text search
1000 * @param $text Text for filter in fulltext search
1001 * @param $textSearchMode Mode for search (one of XDB::WILDCARD_*)
1002 * @param $type Filter on address type
1003 * @param $flags Filter on address flags
1004 * @param $country Filter on address country
1005 * @param $locality Filter on address locality
1006 */
1007 class UFC_AddressText extends UFC_Address
1008 {
1009
1010 private $text;
1011 private $textSearchMode;
1012
1013 public function __construct($text = null, $textSearchMode = XDB::WILDCARD_CONTAINS,
1014 $type = null, $flags = self::FLAG_ANY, $country = null, $locality = null)
1015 {
1016 parent::__construct($type, $flags);
1017 $this->text = $text;
1018 $this->textSearchMode = $textSearchMode;
1019 $this->country = $country;
1020 $this->locality = $locality;
1021 }
1022
1023 private function mkMatch($txt)
1024 {
1025 return XDB::formatWildcards($this->textSearchMode, $txt);
1026 }
1027
1028 public function buildCondition(PlFilter $uf)
1029 {
1030 $sub = $uf->addAddressFilter();
1031 $conds = $this->initConds($sub, $uf->getVisibilityCondition($sub . '.pub'));
1032 if ($this->text != null) {
1033 $conds[] = $sub . '.text' . $this->mkMatch($this->text);
1034 }
1035
1036 if ($this->country != null) {
1037 $subc = $uf->addAddressCountryFilter();
1038 $subconds = array();
1039 $subconds[] = $subc . '.country' . $this->mkMatch($this->country);
1040 $subconds[] = $subc . '.countryFR' . $this->mkMatch($this->country);
1041 $conds[] = implode(' OR ', $subconds);
1042 }
1043
1044 if ($this->locality != null) {
1045 $subl = $uf->addAddressLocalityFilter();
1046 $conds[] = $subl . '.name' . $this->mkMatch($this->locality);
1047 }
1048
1049 return implode(' AND ', $conds);
1050 }
1051 }
1052 // }}}
1053 // {{{ class UFC_AddressField
1054 /** Filters users based on their address,
1055 * @param $val Either a code for one of the fields, or an array of such codes
1056 * @param $fieldtype The type of field to look for
1057 * @param $type Filter on address type
1058 * @param $flags Filter on address flags
1059 */
1060 class UFC_AddressField extends UFC_Address
1061 {
1062 const FIELD_COUNTRY = 1;
1063 const FIELD_ADMAREA = 2;
1064 const FIELD_SUBADMAREA = 3;
1065 const FIELD_LOCALITY = 4;
1066 const FIELD_ZIPCODE = 5;
1067
1068 /** Data of the filter
1069 */
1070 private $val;
1071 private $fieldtype;
1072
1073 public function __construct($val, $fieldtype, $type = null, $flags = self::FLAG_ANY)
1074 {
1075 parent::__construct($type, $flags);
1076
1077 if (!is_array($val)) {
1078 $val = array($val);
1079 }
1080 $this->val = $val;
1081 $this->fieldtype = $fieldtype;
1082 }
1083
1084 public function buildCondition(PlFilter $uf)
1085 {
1086 $sub = $uf->addAddressFilter();
1087 $conds = $this->initConds($sub, $uf->getVisibilityCondition($sub . '.pub'));
1088
1089 switch ($this->fieldtype) {
1090 case self::FIELD_COUNTRY:
1091 $field = 'countryId';
1092 break;
1093 case self::FIELD_ADMAREA:
1094 $field = 'administrativeAreaId';
1095 break;
1096 case self::FIELD_SUBADMAREA:
1097 $field = 'subAdministrativeAreaId';
1098 break;
1099 case self::FIELD_LOCALITY:
1100 $field = 'localityId';
1101 break;
1102 case self::FIELD_ZIPCODE:
1103 $field = 'postalCode';
1104 break;
1105 default:
1106 Platal::page()->killError('Invalid address field type: ' . $this->fieldtype);
1107 }
1108 $conds[] = XDB::format($sub . '.' . $field . ' IN {?}', $this->val);
1109
1110 return implode(' AND ', $conds);
1111 }
1112 }
1113 // }}}
1114 // {{{ class UFC_Corps
1115 /** Filters users based on the corps they belong to
1116 * @param $corps Corps we are looking for (abbreviation)
1117 * @param $type Whether we search for original or current corps
1118 */
1119 class UFC_Corps extends UserFilterCondition
1120 {
1121 const CURRENT = 1;
1122 const ORIGIN = 2;
1123
1124 private $corps;
1125 private $type;
1126
1127 public function __construct($corps, $type = self::CURRENT)
1128 {
1129 $this->corps = $corps;
1130 $this->type = $type;
1131 }
1132
1133 public function buildCondition(PlFilter $uf)
1134 {
1135 /** Tables shortcuts:
1136 * pc for profile_corps,
1137 * pceo for profile_corps_enum - orginal
1138 * pcec for profile_corps_enum - current
1139 */
1140 $sub = $uf->addCorpsFilter($this->type);
1141 $cond = $sub . '.abbreviation = ' . $corps;
1142 $cond .= ' AND ' . $uf->getVisibilityCondition($sub . '.corps_pub');
1143 return $cond;
1144 }
1145 }
1146 // }}}
1147 // {{{ class UFC_Corps_Rank
1148 /** Filters users based on their rank in the corps
1149 * @param $rank Rank we are looking for (abbreviation)
1150 */
1151 class UFC_Corps_Rank extends UserFilterCondition
1152 {
1153 private $rank;
1154 public function __construct($rank)
1155 {
1156 $this->rank = $rank;
1157 }
1158
1159 public function buildCondition(PlFilter $uf)
1160 {
1161 /** Tables shortcuts:
1162 * pc for profile_corps
1163 * pcr for profile_corps_rank
1164 */
1165 $sub = $uf->addCorpsRankFilter();
1166 $cond = $sub . '.abbreviation = ' . $rank;
1167 // XXX(x2006barrois): find a way to get rid of that hardcoded
1168 // reference to 'pc'.
1169 $cond .= ' AND ' . $uf->getVisibilityCondition('pc.corps_pub');
1170 return $cond;
1171 }
1172 }
1173 // }}}
1174 // {{{ class UFC_Job_Company
1175 /** Filters users based on the company they belong to
1176 * @param $type The field being searched (self::JOBID, self::JOBNAME or self::JOBACRONYM)
1177 * @param $value The searched value
1178 */
1179 class UFC_Job_Company extends UserFilterCondition
1180 {
1181 const JOBID = 'id';
1182 const JOBNAME = 'name';
1183 const JOBACRONYM = 'acronym';
1184
1185 private $type;
1186 private $value;
1187
1188 public function __construct($type, $value)
1189 {
1190 $this->assertType($type);
1191 $this->type = $type;
1192 $this->value = $value;
1193 }
1194
1195 private function assertType($type)
1196 {
1197 if ($type != self::JOBID && $type != self::JOBNAME && $type != self::JOBACRONYM) {
1198 Platal::page()->killError("Type de recherche non valide.");
1199 }
1200 }
1201
1202 public function buildCondition(PlFilter $uf)
1203 {
1204 $sub = $uf->addJobCompanyFilter();
1205 $cond = $sub . '.' . $this->type . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
1206 $jsub = $uf->addJobFilter();
1207 $cond .= ' AND ' . $uf->getVisibilityCondition($jsub . '.pub');
1208 return $cond;
1209 }
1210 }
1211 // }}}
1212 // {{{ class UFC_Job_Terms
1213 /** Filters users based on the job terms they assigned to one of their
1214 * jobs.
1215 * @param $val The ID of the job term, or an array of such IDs
1216 */
1217 class UFC_Job_Terms extends UserFilterCondition
1218 {
1219 private $val;
1220
1221 public function __construct($val)
1222 {
1223 if (!is_array($val)) {
1224 $val = array($val);
1225 }
1226 $this->val = $val;
1227 }
1228
1229 public function buildCondition(PlFilter $uf)
1230 {
1231 $sub = $uf->addJobTermsFilter(count($this->val));
1232 $conditions = array();
1233 foreach ($this->val as $i => $jtid) {
1234 $conditions[] = $sub[$i] . '.jtid_1 = ' . XDB::escape($jtid);
1235 }
1236 $jsub = $uf->addJobFilter();
1237 $conditions[] = $uf->getVisibilityCondition($jsub . '.pub');
1238 return implode(' AND ', $conditions);
1239 }
1240 }
1241 // }}}
1242 // {{{ class UFC_Job_Description
1243 /** Filters users based on their job description
1244 * @param $description The text being searched for
1245 * @param $fields The fields to search for (CV, user-defined)
1246 */
1247 class UFC_Job_Description extends UserFilterCondition
1248 {
1249
1250 private $description;
1251 private $fields;
1252
1253 public function __construct($description, $fields)
1254 {
1255 $this->fields = $fields;
1256 $this->description = $description;
1257 }
1258
1259 public function buildCondition(PlFilter $uf)
1260 {
1261 $conds = array();
1262
1263 $jsub = $uf->addJobFilter();
1264 // CV is private => if only CV requested, and not private,
1265 // don't do anything. Otherwise restrict to standard job visibility.
1266 if ($this->fields == UserFilter::JOB_CV) {
1267 if ($uf->getVisibilityLevel() != ProfileVisibility::VIS_PRIVATE) {
1268 return self::CONF_TRUE;
1269 }
1270 } else {
1271 $conds[] = $uf->getVisibilityCondition($jsub . '.pub');
1272 }
1273
1274 if ($this->fields & UserFilter::JOB_USERDEFINED) {
1275 $conds[] = $jsub . '.description ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description);
1276 }
1277 if ($this->fields & UserFilter::JOB_CV && $uf->getVisibilityLevel() == ProfileVisibility::VIS_PRIVATE) {
1278 $uf->requireProfiles();
1279 $conds[] = 'p.cv ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->description);
1280 }
1281 return implode(' OR ', $conds);
1282 }
1283 }
1284 // }}}
1285 // {{{ class UFC_Networking
1286 /** Filters users based on network identity (IRC, ...)
1287 * @param $type Type of network (-1 for any)
1288 * @param $value Value to search
1289 */
1290 class UFC_Networking extends UserFilterCondition
1291 {
1292 private $type;
1293 private $value;
1294
1295 public function __construct($type, $value)
1296 {
1297 $this->type = $type;
1298 $this->value = $value;
1299 }
1300
1301 public function buildCondition(PlFilter $uf)
1302 {
1303 $sub = $uf->addNetworkingFilter();
1304 $conds = array();
1305 $conds[] = $uf->getVisibilityCondition($sub . '.pub');
1306 $conds[] = $sub . '.address ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
1307 if ($this->type != -1) {
1308 $conds[] = $sub . '.nwid = ' . XDB::format('{?}', $this->type);
1309 }
1310 return implode(' AND ', $conds);
1311 }
1312 }
1313 // }}}
1314 // {{{ class UFC_Phone
1315 /** Filters users based on their phone number
1316 * @param $num_type Type of number (pro/user/home)
1317 * @param $phone_type Type of phone (fixed/mobile/fax)
1318 * @param $number Phone number
1319 */
1320 class UFC_Phone extends UserFilterCondition
1321 {
1322 const NUM_PRO = 'pro';
1323 const NUM_USER = 'user';
1324 const NUM_HOME = 'address';
1325 const NUM_ANY = 'any';
1326
1327 const PHONE_FIXED = 'fixed';
1328 const PHONE_MOBILE = 'mobile';
1329 const PHONE_FAX = 'fax';
1330 const PHONE_ANY = 'any';
1331
1332 private $num_type;
1333 private $phone_type;
1334 private $number;
1335
1336 public function __construct($number, $num_type = self::NUM_ANY, $phone_type = self::PHONE_ANY)
1337 {
1338 $phone = new Phone(array('display' => $number));
1339 $phone->format();
1340 $this->number = $phone->search();
1341 $this->num_type = $num_type;
1342 $this->phone_type = $phone_type;
1343 }
1344
1345 public function buildCondition(PlFilter $uf)
1346 {
1347 $sub = $uf->addPhoneFilter();
1348 $conds = array();
1349
1350 $conds[] = $uf->getVisibilityCondition($sub . '.pub');
1351
1352 $conds[] = $sub . '.search_tel = ' . XDB::format('{?}', $this->number);
1353 if ($this->num_type != self::NUM_ANY) {
1354 $conds[] = $sub . '.link_type = ' . XDB::format('{?}', $this->num_type);
1355 }
1356 if ($this->phone_type != self::PHONE_ANY) {
1357 $conds[] = $sub . '.tel_type = ' . XDB::format('{?}', $this->phone_type);
1358 }
1359 return implode(' AND ', $conds);
1360 }
1361 }
1362 // }}}
1363 // {{{ class UFC_Medal
1364 /** Filters users based on their medals
1365 * @param $medal ID of the medal
1366 * @param $grade Grade of the medal (null for 'any')
1367 */
1368 class UFC_Medal extends UserFilterCondition
1369 {
1370 private $medal;
1371 private $grade;
1372
1373 public function __construct($medal, $grade = null)
1374 {
1375 $this->medal = $medal;
1376 $this->grade = $grade;
1377 }
1378
1379 public function buildCondition(PlFilter $uf)
1380 {
1381 $conds = array();
1382
1383 // This will require profiles => table 'p' will be available.
1384 $sub = $uf->addMedalFilter();
1385
1386 $conds[] = $uf->getVisibilityCondition('p.medals_pub');
1387
1388 $conds[] = $sub . '.mid = ' . XDB::format('{?}', $this->medal);
1389 if ($this->grade != null) {
1390 $conds[] = $sub . '.gid = ' . XDB::format('{?}', $this->grade);
1391 }
1392 return implode(' AND ', $conds);
1393 }
1394 }
1395 // }}}
1396 // {{{ class UFC_Photo
1397 /** Filters profiles with photo
1398 */
1399 class UFC_Photo extends UserFilterCondition
1400 {
1401 public function buildCondition(PlFilter $uf)
1402 {
1403 $sub = $uf->addPhotoFilter();
1404 return $sub . '.attach IS NOT NULL AND ' . $uf->getVisibilityCondition($sub . '.pub');
1405 }
1406 }
1407 // }}}
1408 // {{{ class UFC_Mentor
1409 class UFC_Mentor extends UserFilterCondition
1410 {
1411 public function buildCondition(PlFilter $uf)
1412 {
1413 $sub = $uf->addMentorFilter(UserFilter::MENTOR);
1414 return $sub . '.expertise IS NOT NULL';
1415 }
1416 }
1417 // }}}
1418 // {{{ class UFC_Mentor_Expertise
1419 /** Filters users by mentoring expertise
1420 * @param $expertise Domain of expertise
1421 */
1422 class UFC_Mentor_Expertise extends UserFilterCondition
1423 {
1424 private $expertise;
1425
1426 public function __construct($expertise)
1427 {
1428 $this->expertise = $expertise;
1429 }
1430
1431 public function buildCondition(PlFilter $uf)
1432 {
1433 $sub = $uf->addMentorFilter(UserFilter::MENTOR_EXPERTISE);
1434 return $sub . '.expertise ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->expertise);
1435 }
1436 }
1437 // }}}
1438 // {{{ class UFC_Mentor_Country
1439 /** Filters users by mentoring country
1440 * @param $country Two-letters code of country being searched
1441 */
1442 class UFC_Mentor_Country extends UserFilterCondition
1443 {
1444 private $country;
1445
1446 public function __construct()
1447 {
1448 $this->country = pl_flatten(func_get_args());
1449 }
1450
1451 public function buildCondition(PlFilter $uf)
1452 {
1453 $sub = $uf->addMentorFilter(UserFilter::MENTOR_COUNTRY);
1454 return $sub . '.country IN ' . XDB::format('{?}', $this->country);
1455 }
1456 }
1457 // }}}
1458 // {{{ class UFC_Mentor_Terms
1459 /** Filters users based on the job terms they used in mentoring.
1460 * @param $val The ID of the job term, or an array of such IDs
1461 */
1462 class UFC_Mentor_Terms extends UserFilterCondition
1463 {
1464 private $val;
1465
1466 public function __construct($val)
1467 {
1468 $this->val = $val;
1469 }
1470
1471 public function buildCondition(PlFilter $uf)
1472 {
1473 $sub = $uf->addMentorFilter(UserFilter::MENTOR_TERM);
1474 return $sub . '.jtid_1 = ' . XDB::escape($this->val);
1475 }
1476 }
1477 // }}}
1478 // {{{ class UFC_UserRelated
1479 /** Filters users based on a relation toward a user
1480 * @param $user User to which searched users are related
1481 */
1482 abstract class UFC_UserRelated extends UserFilterCondition
1483 {
1484 protected $user;
1485 public function __construct(PlUser &$user)
1486 {
1487 $this->user =& $user;
1488 }
1489 }
1490 // }}}
1491 // {{{ class UFC_Contact
1492 /** Filters users who belong to selected user's contacts
1493 */
1494 class UFC_Contact extends UFC_UserRelated
1495 {
1496 public function buildCondition(PlFilter $uf)
1497 {
1498 $sub = $uf->addContactFilter($this->user->id());
1499 return 'c' . $sub . '.contact IS NOT NULL';
1500 }
1501 }
1502 // }}}
1503 // {{{ class UFC_WatchRegistration
1504 /** Filters users being watched by selected user
1505 */
1506 class UFC_WatchRegistration extends UFC_UserRelated
1507 {
1508 public function buildCondition(PlFilter $uf)
1509 {
1510 if (!$this->user->watchType('registration')) {
1511 return PlFilterCondition::COND_FALSE;
1512 }
1513 $uids = $this->user->watchUsers();
1514 if (count($uids) == 0) {
1515 return PlFilterCondition::COND_FALSE;
1516 } else {
1517 return XDB::format('$UID IN {?}', $uids);
1518 }
1519 }
1520 }
1521 // }}}
1522 // {{{ class UFC_WatchPromo
1523 /** Filters users belonging to a promo watched by selected user
1524 * @param $user Selected user (the one watching promo)
1525 * @param $grade Formation the user is watching
1526 */
1527 class UFC_WatchPromo extends UFC_UserRelated
1528 {
1529 private $grade;
1530 public function __construct(PlUser &$user, $grade = UserFilter::GRADE_ING)
1531 {
1532 parent::__construct($user);
1533 $this->grade = $grade;
1534 }
1535
1536 public function buildCondition(PlFilter $uf)
1537 {
1538 $promos = $this->user->watchPromos();
1539 if (count($promos) == 0) {
1540 return PlFilterCondition::COND_FALSE;
1541 } else {
1542 $sube = $uf->addEducationFilter(true, $this->grade);
1543 $field = 'pe' . $sube . '.' . UserFilter::promoYear($this->grade);
1544 return XDB::format($field . ' IN {?}', $promos);
1545 }
1546 }
1547 }
1548 // }}}
1549 // {{{ class UFC_WatchContact
1550 /** Filters users watched by selected user
1551 */
1552 class UFC_WatchContact extends UFC_Contact
1553 {
1554 public function buildCondition(PlFilter $uf)
1555 {
1556 if (!$this->user->watchContacts()) {
1557 return PlFilterCondition::COND_FALSE;
1558 }
1559 return parent::buildCondition($uf);
1560 }
1561 }
1562 // }}}
1563 // {{{ class UFC_MarketingHash
1564 /** Filters users using the hash generated
1565 * to send marketing emails to him.
1566 */
1567 class UFC_MarketingHash extends UserFilterCondition
1568 {
1569 private $hash;
1570
1571 public function __construct($hash)
1572 {
1573 $this->hash = $hash;
1574 }
1575
1576 public function buildCondition(PlFilter $uf)
1577 {
1578 $table = $uf->addMarketingHash();
1579 return XDB::format('rm.hash = {?}', $this->hash);
1580 }
1581 }
1582 // }}}
1583
1584 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1585 ?>