Add UFBF_QuickSearch, add support for orders
[platal.git] / include / ufbuilder.inc.php
CommitLineData
d9b3d712
RB
1<?php
2/***************************************************************************
21b67462 3 * Copyright (C) 2003-2010 Polytechnique.org *
d9b3d712
RB
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
21b67462
RB
22require_once 'directory.enums.inc.php';
23
24// {{{ class UserFilterBuilder
d9b3d712
RB
25class UserFilterBuilder
26{
27 private $envprefix;
28 private $fields;
29 private $valid = true;
30 private $ufc = null;
59c6cb70 31 private $orders = array();
d9b3d712
RB
32
33 /** Constructor
34 * @param $fields An array of UFB_Field objects
35 * @param $envprefix Prefix to use for parts of the query
36 */
37 public function __construct($fields, $envprefix = '')
38 {
39 $this->fields = $fields;
40 $this->envprefix = $envprefix;
41 }
42
43 /** Builds the UFC; returns as soon as a field says it is invalid
44 */
45 private function buildUFC()
46 {
47 if ($this->ufc != null) {
48 return;
49 }
50 $this->ufc = new PFC_And();
51
52 foreach ($this->fields as $field) {
53 $this->valid = $field->apply(&$this);
54 if (!$this->valid) {
55 return;
56 }
57 }
58 }
59
60 public function addCond(PlFilterCondition &$cond)
61 {
62 $this->ufc->addChild($cond);
63 }
64
59c6cb70
RB
65 public function addOrder(PlFilterOrder &$order)
66 {
67 $this->order[] = $order;
68 }
69
d9b3d712
RB
70 public function isValid()
71 {
72 $this->buildUFC();
73 return $this->valid;
74 }
75
76 /** Returns the built UFC
77 * @return The UFC, or PFC_False() if an error happened
78 */
79 public function &getUFC()
80 {
81 $this->buildUFC();
82 if ($this->valid) {
83 return $this->ufc;
84 } else {
85 return new PFC_False();
86 }
87 }
88
59c6cb70
RB
89 /** Returns adequate orders
90 */
91 public function getOrders()
92 {
93 $this->buildUFC();
94 return $this->orders;
95 }
96
d9b3d712
RB
97 /** Wrappers around Env::i/s/..., to add envprefix
98 */
21b67462 99 public function s($key, $def = '') {
d9b3d712
RB
100 return trim(Env::s($this->envprefix . $key, $def));
101 }
102
21b67462 103 public function i($key, $def = 0) {
d9b3d712
RB
104 return intval(trim(Env::i($this->envprefix . $key, $def)));
105 }
106
21b67462 107 public function v($key, $def = null) {
d9b3d712
RB
108 return Env::v($this->envprefix . $key, $def);
109 }
110
111 public function has($key) {
21b67462 112 return (Env::has($this->envprefix . $key) && strlen($this->s($key, '')) > 0);
d9b3d712 113 }
d9696b0a
RB
114
115 public function isOn($key) {
116 return (Env::has($this->envprefix . $key) && $this->s($key) == 'on');
117 }
d9b3d712 118}
21b67462 119// }}}
d9b3d712 120
59c6cb70
RB
121// {{{ class UFB_QuickSearch
122class UFB_QuickSearch extends UserFilterBuilder
123{
124 public function __construct($envprefix = '')
125 {
126 $fields = array(
127 new UFBF_Quick('quick', 'Recherche rapide'),
128 );
129 parent::__construct($fields, $envprefix);
130 }
131}
132// }}}
133
21b67462
RB
134// {{{ class UFB_AdvancedSearch
135class UFB_AdvancedSearch extends UserFilterBuilder
136{
137 public function __construct($envprefix = '')
138 {
139 $fields = array(
140 new UFBF_Name('name', 'Nom'),
141 new UFBF_Promo('promo1', 'Promotion', 'egal1'),
142 new UFBF_Promo('promo2', 'Promotion', 'egal2'),
143 new UFBF_Sex('woman', 'Sexe'),
144 new UFBF_Registered('subscriber', 'Inscrit'),
145 new UFBF_Dead('alive', 'En vie'),
146
147 new UFBF_Town('city', 'Ville / Code Postal'),
148 new UFBF_Country('countryTxt', 'country', 'Pays'),
149 new UFBF_AdminArea('region', 'Région'),
150
151 new UFBF_JobCompany('entreprise', 'Entreprise'),
152 new UFBF_JobSector('sector', 'Poste'),
153 new UFBF_JobDescription('jobdescription', 'Fonction'),
154 new UFBF_JobCv('cv', 'CV'),
155
156 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
157 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
158 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
159 new UFBF_Section('sectionTxt', 'section', 'Section'),
160
161 new UFBF_Formation('schoolTxt', 'school', "École d'application"),
162 new UFBF_Diploma('diplomaTxt', 'diploma', 'Diplôme'),
163 new UFBF_StudiesDomain('fieldTxt', 'field', "Domaine d'études"),
164
165 new UFBF_Comment('free', 'Commentaire'),
3ed7556a
RB
166 new UFBF_Phone('phone_number', 'Téléphone'),
167 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
21b67462
RB
168 );
169 parent::__construct($fields, $envprefix);
170 }
171}
172// }}}
173
174// {{{ class UFB_Field
d9b3d712
RB
175abstract class UFB_Field
176{
177 protected $envfield;
178 protected $formtext;
179
180 protected $empty = false;
181 protected $val = null;
182
183 /** Constructor
184 * @param $envfield Name of the field in the environment
185 * @param $formtext User-friendly name of that field
186 */
187 public function __construct($envfield, $formtext = '')
188 {
189 $this->envfield = $envfield;
190 if ($formtext != '') {
191 $this->formtext = $formtext;
192 } else {
193 $formtext = ucfirst($envfield);
194 }
195 }
196
197 /** Prints the given error message to the user, and returns false
198 * in order to be used as return $this->raise('ERROR');
199 *
200 * All %s in the $msg will be replaced with the formtext.
201 */
202 protected function raise($msg)
203 {
204 Platal::page()->trigError(str_replace('%s', $this->formtext, $msg));
205 return false;
206 }
207
208 public function apply(UserFilterBuilder &$ufb) {
209 if (!$this->check($ufb)) {
210 return false;
211 }
212
213 if (!$this->empty) {
214 $ufc = $this->buildUFC($ufb);
215 if ($ufc != null) {
216 $ufb->addCond($ufc);
217 }
218 }
219 return true;
220 }
221
222 /** Create the UFC associated to the field; won't be called
223 * if the field is "empty"
224 * @param &$ufb UFB to which fields must be added
225 * @return UFC
226 */
227 abstract protected function buildUFC(UserFilterBuilder &$ufb);
228
229 /** This function is intended to run consistency checks on the value
230 * @return boolean Whether the input is valid
231 */
232 abstract protected function check(UserFilterBuilder &$ufb);
233}
21b67462 234// }}}
d9b3d712 235
21b67462 236// {{{ class UFBF_Text
d9b3d712
RB
237abstract class UFBF_Text extends UFB_Field
238{
239 private $forbiddenchars;
240 private $minlength;
241 private $maxlength;
242
243 public function __construct($envfield, $formtext = '', $forbiddenchars = '', $minlength = 2, $maxlength = 255)
244 {
245 parent::__construct($envfield, $formtext);
246 $this->forbiddenchars = $forbiddenchars;
247 $this->minlength = $minlength;
248 $this->maxlength = $maxlength;
249 }
250
251 protected function check(UserFilterBuilder &$ufb)
252 {
253 if (!$ufb->has($this->envfield)) {
254 $this->empty = true;
255 return true;
256 }
257
258 $this->val = $ufb->s($this->envfield);
259 if (strlen($this->val) < $this->minlength) {
260 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
261 } else if (strlen($this->val) > $this->maxlength) {
262 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
263 }
264 return true;
265 }
266}
21b67462 267// }}}
d9b3d712 268
21b67462 269// {{{ class UFBF_Range
d9b3d712
RB
270/** Subclass to use for fields which only allow integers within a range
271 */
272abstract class UFBF_Range extends UFB_Field
273{
274
275 private $min;
276 private $max;
277
278 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
279 {
280 parent::__construct($envfield, $formtext);
281 $this->min = $min;
282 $this->max = $max;
283 }
284
285 protected function check(UserFilterBuilder &$ufb)
286 {
287 if (!$ufb->has($this->envfield)) {
288 $this->empty = true;
289 return true;
290 }
291
292 $this->val = $ufb->i($this->envfield);
293 if ($this->val < $this->min) {
294 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
295 } else if ($this->val > $this->max) {
296 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
297 }
298 return true;
299 }
300}
21b67462 301// }}}
d9b3d712 302
21b67462 303// {{{ class UFBF_Index
d9b3d712
RB
304/** Subclass to use for indexed fields
305 */
306abstract class UFBF_Index extends UFB_Field
307{
308 protected function check(UserFilterBuilder &$ufb)
309 {
310 if (!$ufb->has($this->envfield)) {
311 $this->empty = true;
312 }
313 return true;
314 }
315}
21b67462 316// }}}
d9b3d712 317
21b67462 318// {{{ class UFBF_Enum
d9b3d712
RB
319/** Subclass to use for fields whose value must belong to a specific set of values
320 */
321abstract class UFBF_Enum extends UFB_Field
322{
21b67462
RB
323 protected $allowedvalues;
324
325 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
326 {
327 parent::__construct($envfield, $formtext);
328 $this->allowedvalues = $allowedvalues;
21b67462 329 $this->strict = $strict;
d9b3d712
RB
330 }
331
332 protected function check(UserFilterBuilder &$ufb)
333 {
334 if (!$ufb->has($this->envfield)) {
335 $this->empty = true;
336 return true;
337 }
338
339 $this->val = $ufb->v($this->envfield);
340 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
341 if ($this->strict) {
342 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
343 } else {
344 $this->empty = true;
345 }
d9b3d712
RB
346 }
347 return true;
348 }
349}
21b67462 350// }}}
d9b3d712 351
21b67462
RB
352// {{{ class UFBF_Bool
353abstract class UFBF_Bool extends UFB_Field
d9b3d712 354{
21b67462
RB
355 protected function check(UserFilterBuilder &$ufb)
356 {
357 if (!$ufb->has($this->envfield)) {
358 $this->empty = true;
359 return true;
360 }
361
362 $this->val = ($ufb->i($this->envfield) != 0);
363 return true;
364 }
365}
366// }}}
d9b3d712 367
21b67462
RB
368// {{{ class UFBF_Mixed
369/** A class for building UFBFs when the user can input either a text or an ID
370 */
371abstract class UFBF_Mixed extends UFB_Field
372{
373 /** Name of the DirEnum on which class is based
374 */
375 protected $direnum;
376
377 protected $envfieldindex;
378
379 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 380 {
21b67462
RB
381 parent::__construct($envfieldtext, $formtext);
382 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
383 }
384
21b67462 385 protected function check(UserFilterBuilder &$ufb)
d9b3d712 386 {
21b67462
RB
387 if (!$ufb->has($this->envfieldindex) && !$ufb->has($this->envfield)) {
388 $this->empty = true;
389 return true;
390 }
391
392 if ($ufb->has($this->envfieldindex)) {
393 $index = $ufb->v($this->envfieldindex);
394 if (is_int($index)) {
395 $index = intval($index);
396 } else {
397 $index = strtoupper($index);
398 }
399 $this->val = array($index);
d9b3d712 400 } else {
21b67462
RB
401 $indexes = DirEnum::getIDs($this->direnum, $ufb->s($this->envfield),
402 $ufb->i('exact') ? DirEnumeration::MODE_EXACT : DirEnumeration::MODE_CONTAINS);
403 if (count($indexes) == 0) {
404 return false;
405 }
406 $this->val = $indexes;
d9b3d712 407 }
21b67462 408 return true;
d9b3d712
RB
409 }
410}
21b67462 411// }}}
d9b3d712 412
59c6cb70
RB
413// {{{ UFBF_Quick
414class UFBF_Quick extends UFB_Field
415{
416 protected function check(UserFilterBuilder &$ufb)
417 {
418 if (!$ufb->has($this->envfield)) {
419 $this->empty = true;
420 return true;
421 }
422
423 $this->val = str_replace('*', '%', replace_accent($ufb->s($this->envfield)));
424 }
425
426 protected function buildUFC(UserFilterBuilder &$ufb)
427 {
428 $conds = new PFC_And();
429
430 $s = $this->val;
431
432 /** Admin: Email, IP
433 */
434 if (S::admin() && strpos($s, '@') !== false) {
435 $conds->addChild(new UFC_Email($s));
436 return $conds;
437 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
438 // TODO: create UFC_Ip
439// $this->conds->addChild(new UFC_Ip($s));
440 return $conds;
441 }
442
443 /** Name
444 */
445 $s = preg_replace('!\d+!', ' ', $s);
446 $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY);
447 if (count($strings) > 5) {
448 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
449 $strings = array_slice($strings, 0, 5);
450 }
451
452 if (count($strings)) {
453 if (S::logged()) {
454 $flags = array();
455 } else {
456 $flags = array('public');
457 }
458 if ($ufb->i('soundex')) {
459 $soundex = true;
460 $st = array();
461 foreach ($strings as $string) {
462 $st[] = soundex_fr($string);
463 }
464 } else {
465 $soundex = false;
466 $st = $strings;
467 }
468 if ($ufb->i('exact')) {
469 $exact = true;
470 } else {
471 $exact = false;
472 }
473 $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact));
474
475 $ufb->addSort(new UFO_Score());
476 }
477
478 /** Promo ranges
479 */
480 $s = preg_replace('! *- *!', '-', $r);
481 $s = preg_replace('!([<>]) *!', ' \1', $s);
482 $s = preg_replace('![^0-9\-><]!', ' ', $s);
483 $s = preg_replace('![<>\-] !', '', $s);
484 $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY);
485 foreach ($ranges as $r) {
486 if (preg_match('!^\d{4}$!', $r)) {
487 $conds->addChild(new UFC_Promo('=', UserFilter::DISPLAY, 'X' . $r));
488 } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
489 $p1=min(intval($matches[1]), intval($matches[2]));
490 $p2=max(intval($matches[1]), intval($matches[2]));
491 $conds->addChild(new PFC_And(
492 new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $p1),
493 new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $p2)
494 ));
495 } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
496 $conds->addChild(new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $matches[1]));
497 } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
498 $this->conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1]));
499 }
500 }
501
502 /** Phone number
503 */
504 $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
505 $t = preg_replace('![<>\- ]!', '', $t);
506 if (strlen($t) > 4) {
507 $conds->addChild(new UFC_Phone($t));
508 }
509
510 return $conds;
511 }
512}
513// }}}
514
21b67462
RB
515// {{{ class UFBF_Name
516class UFBF_Name extends UFBF_Text
517{
518 protected function check(UserFilterBuilder &$ufb)
519 {
520 if (!parent::check($ufb)) {
521 return false;
522 }
523
524 $this->val = preg_split('/[[:space:]]/', $this->val);
525 if (count($this->val) == 0) {
526 $this->empty = true;
527 }
528 return true;
529 }
530
531 protected function buildUFC(UserFilterBuilder &$ufb)
532 {
533 return new UFC_NameTokens($this->val, array(), $ufb->i('with_soundex'), $ufb->i('exact'));
534 }
535}
536// }}}
537
538// {{{ class UFBF_Promo
d9b3d712
RB
539class UFBF_Promo extends UFB_Field
540{
541 private static $validcomps = array('<', '<=', '=', '>=', '>');
542 private $comp;
543 private $envfieldcomp;
544
545 public function __construct($envfield, $fromtext = '', $envfieldcomp)
546 {
547 parent::__construct($envfield, $fromtext);
548 $this->envfieldcomp = $envfieldcomp;
549 }
550
551 protected function check(UserFilterBuilder &$ufb)
552 {
553 if (!$ufb->has($this->envfield) || !$ufb->has($this->envfieldcomp)) {
554 $this->empty = true;
555 return true;
556 }
557
558 $this->val = $ubf->i($this->envfield);
559 $this->comp = $ubf->v($this->envfieldcomp);
560
561 if (!in_array($this->comp, self::$validcomps)) {
562 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
563 }
564
565 if (preg_match('/^[0-9]{2}$/', $this->val)) {
566 $this->val += 1900;
567 }
568 if ($this->val < 1900 || $this->val > 9999) {
569 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
570 }
571 return true;
572 }
573
574 protected function buildUFC(UserFilterBuilder &$ufb) {
575 return new UFC_Promo($this->comp, UserFilter::DISPLAY, 'X' . $this->val);
576 }
577}
21b67462
RB
578// }}}
579
580// {{{ class UFBF_Sex
581class UFBF_Sex extends UFBF_Enum
582{
583 public function __construct($envfield, $formtext = '')
584 {
585 parent::__construct($envfield, $formtext, array(1, 2));
586 }
587
588 private static function getVal($id)
589 {
590 switch($id) {
591 case 1:
592 return User::GENDER_MALE;
593 break;
594 case 2:
595 return User::GENDER_FEMALE;
596 break;
597 }
598 }
599
600 protected function buildUFC(UserFilterBuilder &$ufb)
601 {
602 return new UFC_Sex(self::getVal($this->val));
603 }
604}
605// }}}
606
607// {{{ class UFBF_Registered
608class UFBF_Registered extends UFBF_Enum
609{
610 public function __construct($envfield, $formtext = '')
611 {
612 parent::__construct($envfield, $formtext, array(1, 2));
613 }
614
615 protected function buildUFC(UserFilterBuilder &$ufb)
616 {
617 if ($this->val == 1) {
618 return new UFC_Registered();
619 } else if ($this->val == 2) {
620 return new PFC_Not(UFC_Registered());
621 }
622 }
623}
624// }}}
d9b3d712 625
21b67462
RB
626// {{{ class UFBF_Dead
627class UFBF_Dead extends UFBF_Enum
628{
629 public function __construct($envfield, $formtext = '')
630 {
631 parent::__construct($envfield, $formtext, array(1, 2));
632 }
633
634 protected function buildUFC(UserFilterBuilder &$ufb)
635 {
636 if ($this->val == 1) {
637 return new PFC_Not(UFC_Dead());
638 } else if ($this->val == 2) {
639 return new UFC_Dead();
640 }
641 }
642}
643// }}}
644
645// {{{ class UFBF_Town
646/** Retrieves a town, either from a postal code or a town name
647 */
648class UFBF_Town extends UFBF_Text
649{
650 const TYPE_TEXT = 1;
651 const TYPE_ZIP = 2;
652 const TYPE_ANY = 3;
653
654 private $type;
d9696b0a
RB
655 private $onlycurrentfield;
656
657 public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current')
21b67462
RB
658 {
659 $this->type = $type;
d9696b0a 660 $this->onlycurrentfield = $onlycurrentfield;
21b67462
RB
661 parent::__construct($envfield, $formtext, '', 2, 30);
662 }
663
664 protected function buildUFC(UserFilterBuilder &$ufb)
665 {
d9696b0a
RB
666 if ($ufb->isOn($this->onlycurrentfield)) {
667 $flags = UFC_Address::FLAG_CURRENT;
668 } else {
669 $flags = UFC_Address::FLAG_ANY;
670 }
671
21b67462
RB
672 if (preg_match('/[0-9]/', $this->val)) {
673 if ($this->type & self::TYPE_ZIP) {
d9696b0a 674 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
675 } else {
676 return new PFC_False();
677 }
678 } else {
d9696b0a
RB
679 $byname = new UFC_AddressText(null, UFC_Address::CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val);
680 $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
681 if ($this->type & self::TYPE_ANY) {
682 return new PFC_Or($byname, $byzip);
683 } else if ($this->type & self::TYPE_TEXT) {
684 return $byname;
685 } else {
686 return $byzip;
687 }
688 }
689 }
690}
691// }}}
692
693// {{{ class UFBF_Country
694class UFBF_Country extends UFBF_Mixed
695{
696 protected $direnum = DirEnum::COUNTRIES;
d9696b0a
RB
697 protected $onlycurrentfield;
698
699 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
700 {
701 parent::__construct($envfieldtext, $envfieldindex, $formtext);
702 $this->onlycurrentfield = $onlycurrentfield;
703 }
21b67462
RB
704
705 protected function buildUFC(UserFilterBuilder &$ufb)
706 {
d9696b0a
RB
707 if ($ufb->isOn($this->onlycurrentfield)) {
708 $flags = UFC_Address::FLAG_CURRENT;
709 } else {
710 $flags = UFC_Address::FLAG_ANY;
711 }
712
713 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
714 }
715}
716// }}}
717
718// {{{ class UFBF_AdminArea
719class UFBF_AdminArea extends UFBF_Mixed
720{
721 protected $direnum = DirEnum::ADMINAREAS;
d9696b0a
RB
722 protected $onlycurrentfield;
723
724 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
725 {
726 parent::__construct($envfieldtext, $envfieldindex, $formtext);
727 $this->onlycurrentfield = $onlycurrentfield;
728 }
729
21b67462
RB
730
731 protected function buildUFC(UserFilterBuilder &$ufb)
732 {
d9696b0a
RB
733 if ($ufb->isOn($this->onlycurrentfield)) {
734 $flags = UFC_Address::FLAG_CURRENT;
735 } else {
736 $flags = UFC_Address::FLAG_ANY;
737 }
738
739 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ADMAREA, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
740 }
741}
742// }}}
743
744// {{{ class UFBF_JobCompany
745class UFBF_JobCompany extends UFBF_Text
746{
d9696b0a
RB
747 private $onlymentorfield;
748
749 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
750 {
751 parent::__construct($envfield, $formtext);
752 $this->onlymentorfield = $onlymentorfield;
753 }
754
755 public function check(UserFilterBuilder &$ufb) {
756 if (parent::check($ufb)) {
757 # No company check for mentors
758 if ($ufb->isOn($this->onlymentorfield)) {
759 $this->empty = true;
760 }
761 return true;
762 } else {
763 return false;
764 }
765 }
766
21b67462
RB
767 protected function buildUFC(UserFilterBuilder &$ufb)
768 {
769 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
770 }
771}
772// }}}
773
774// {{{ class UFBF_JobSector
775class UFBF_JobSector extends UFBF_Mixed
776{
777 protected $direnum = DirEnum::SECTORS;
d9696b0a
RB
778 private $onlymentorfield;
779
780 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlymentorfield = 'only_referent')
781 {
782 parent::__construct($envfieldtext, $envfieldindex, $formtext);
783 $this->onlymentorfield = $onlymentorfield;
784 }
21b67462
RB
785
786 protected function buildUFC(UserFilterBuilder &$ufb)
787 {
d9696b0a
RB
788 if ($ufb->isOn($this->onlymentorfield)) {
789 return new UFC_Mentor_Sectorization($this->val, UserFilter::JOB_SUBSECTOR);
790 } else {
791 return new UFC_Job_Sectorization($this->val, UserFilter::JOB_SUBSUBSECTOR);
792 }
21b67462
RB
793 }
794}
795// }}}
796
797// {{{ class UFBF_JobDescription
798class UFBF_JobDescription extends UFBF_Text
799{
d9696b0a
RB
800 private $onlymentorfield;
801
802 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
803 {
804 parent::__construct($envfield, $formtext);
805 $this->onlymentorfield = $onlymentorfield;
806 }
807
21b67462
RB
808 protected function buildUFC(UserFilterBuilder &$ufb)
809 {
d9696b0a
RB
810 if ($ufb->isOn($this->onlymentorfield)) {
811 return new UFC_Mentor_Expertise($this->val);
812 } else {
813 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
814 }
21b67462
RB
815 }
816}
817// }}}
818
819// {{{ class UFBF_JobCv
820class UFBF_JobCv extends UFBF_Text
821{
d9696b0a
RB
822 private $onlymentorfield;
823
824 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
825 {
826 parent::__construct($envfield, $formtext);
827 $this->onlymentorfield = $onlymentorfield;
828 }
829
21b67462
RB
830 protected function buildUFC(UserFilterBuilder &$ufb)
831 {
d9696b0a
RB
832 if ($ufb->isOn($this->onlymentorfield)) {
833 return new UFC_Mentor_Expertise($this->val);
834 } else {
835 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
836 }
21b67462
RB
837 }
838}
839// }}}
840
841// {{{ class UFBF_Nationality
842class UFBF_Nationality extends UFBF_Mixed
843{
844 protected $direnum = DirEnum::NATIONALITIES;
845
846 protected function buildUFC(UserFilterBuilder &$ufb)
847 {
848 return new UFC_Nationality($this->val);
849 }
850}
851// }}}
852
853// {{{ class UFBF_Binet
854class UFBF_Binet extends UFBF_Mixed
855{
856 protected $direnum = DirEnum::BINETS;
857
858 protected function buildUFC(UserFilterBuilder &$ufb)
859 {
860 return new UFC_Binet($this->val);
861 }
862}
863// }}}
864
865// {{{ class UFBF_Group
866class UFBF_Group extends UFBF_Mixed
867{
868 protected $direnum = DirEnum::GROUPESX;
869
870 protected function buildUFC(UserFilterBuilder &$ufb)
871 {
872 if (count($this->val) == 1) {
873 return new UFC_Group($this->val[0]);
874 }
875
876 $or = new PFC_Or();
877 foreach ($this->val as $grp) {
878 $or->addChild(new UFC_Group($grp));
879 }
880 return $or;
881 }
882}
883// }}}
884
885// {{{ class UFBF_Section
886class UFBF_Section extends UFBF_Index
887{
888 protected $direnum = DirEnum::SECTIONS;
889
890 protected function buildUFC(UserFilterBuilder &$ufb)
891 {
892 return new UFC_Section($this->val);
893 }
894}
895// }}}
896
897// {{{ class UFBF_Formation
898class UFBF_Formation extends UFBF_Mixed
899{
900 protected $direnum = DirEnum::SCHOOLS;
901
902 protected function buildUFC(UserFilterBuilder &$ufb)
903 {
904 return new UFC_Formation($this->val);
905 }
906}
907// }}}
908
909// {{{ class UFBF_Diploma
910class UFBF_Diploma extends UFBF_Mixed
911{
912 protected $direnum = DirEnum::DEGREES;
913
914 protected function buildUFC(UserFilterBuilder &$ufb)
915 {
916 return new UFC_Diploma($this->val);
917 }
918}
919// }}}
920
921// {{{ class UFBF_StudiesDomain
922class UFBF_StudiesDomain extends UFBF_Mixed
923{
924 protected $direnum = DirEnum::STUDIESDOMAINS;
925
926 protected function buildUFC(UserFilterBuilder &$ufb)
927 {
928 return new UFC_StudyField($this->val);
929 }
930}
931// }}}
932
933// {{{ class UFBF_Comment
934class UFBF_Comment extends UFBF_Text
935{
936 protected function buildUFC(UserFilterBuilder &$ufb)
937 {
938 return new UFC_Comment($this->val);
939 }
940}
941// }}}
3ed7556a
RB
942
943// {{{ class UFBF_Phone
944class UFBF_Phone extends UFBF_Text
945{
946 protected function buildUFC(UserFilterBuilder &$ufb)
947 {
948 return new UFC_Phone($this->val);
949 }
950}
951// }}}
952
953// {{{ class UFBF_Networking
954class UFBF_Networking extends UFBF_Text
955{
956 private $networktypefield;
957 private $nwtype;
958
959 public function __construct($envfield, $networktypefield, $formtext = '')
960 {
961 parent::__construct($envfield, $formtext);
962 $this->networktypefield = $networktypefield;
963 }
964
965 public function check(UserFilterBuilder &$ufb)
966 {
967 if (parent::check($ufb)) {
968 $this->nwtype = $ufb->i($this->networktypefield);
969 return true;
970 } else {
971 return false;
972 }
973 }
974
975 public function buildUFC(UserFilterBuilder &$ufb)
976 {
977 return new UFC_Networking($this->nwtype, $this->val);
978 }
979}
980// }}}
d9b3d712 981?>