Remove ThrowError
[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{
d9b3d712
RB
239 private $minlength;
240 private $maxlength;
241
f3f800d8 242 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
d9b3d712
RB
243 {
244 parent::__construct($envfield, $formtext);
d9b3d712
RB
245 $this->minlength = $minlength;
246 $this->maxlength = $maxlength;
247 }
248
249 protected function check(UserFilterBuilder &$ufb)
250 {
251 if (!$ufb->has($this->envfield)) {
252 $this->empty = true;
253 return true;
254 }
255
256 $this->val = $ufb->s($this->envfield);
257 if (strlen($this->val) < $this->minlength) {
258 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
259 } else if (strlen($this->val) > $this->maxlength) {
260 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
f3f800d8
RB
261 } else if (preg_match(":[\]\[<>{}~/§_`|%$^=+]|\*\*:u", $this->val)) {
262 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
d9b3d712 263 }
f3f800d8 264
d9b3d712
RB
265 return true;
266 }
267}
21b67462 268// }}}
d9b3d712 269
21b67462 270// {{{ class UFBF_Range
d9b3d712
RB
271/** Subclass to use for fields which only allow integers within a range
272 */
273abstract class UFBF_Range extends UFB_Field
274{
275
276 private $min;
277 private $max;
278
279 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
280 {
281 parent::__construct($envfield, $formtext);
282 $this->min = $min;
283 $this->max = $max;
284 }
285
286 protected function check(UserFilterBuilder &$ufb)
287 {
288 if (!$ufb->has($this->envfield)) {
289 $this->empty = true;
290 return true;
291 }
292
293 $this->val = $ufb->i($this->envfield);
294 if ($this->val < $this->min) {
295 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
296 } else if ($this->val > $this->max) {
297 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
298 }
299 return true;
300 }
301}
21b67462 302// }}}
d9b3d712 303
21b67462 304// {{{ class UFBF_Index
d9b3d712
RB
305/** Subclass to use for indexed fields
306 */
307abstract class UFBF_Index extends UFB_Field
308{
309 protected function check(UserFilterBuilder &$ufb)
310 {
311 if (!$ufb->has($this->envfield)) {
312 $this->empty = true;
313 }
314 return true;
315 }
316}
21b67462 317// }}}
d9b3d712 318
21b67462 319// {{{ class UFBF_Enum
d9b3d712
RB
320/** Subclass to use for fields whose value must belong to a specific set of values
321 */
322abstract class UFBF_Enum extends UFB_Field
323{
21b67462
RB
324 protected $allowedvalues;
325
326 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
327 {
328 parent::__construct($envfield, $formtext);
329 $this->allowedvalues = $allowedvalues;
21b67462 330 $this->strict = $strict;
d9b3d712
RB
331 }
332
333 protected function check(UserFilterBuilder &$ufb)
334 {
335 if (!$ufb->has($this->envfield)) {
336 $this->empty = true;
337 return true;
338 }
339
340 $this->val = $ufb->v($this->envfield);
341 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
342 if ($this->strict) {
343 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
344 } else {
345 $this->empty = true;
346 }
d9b3d712
RB
347 }
348 return true;
349 }
350}
21b67462 351// }}}
d9b3d712 352
21b67462
RB
353// {{{ class UFBF_Bool
354abstract class UFBF_Bool extends UFB_Field
d9b3d712 355{
21b67462
RB
356 protected function check(UserFilterBuilder &$ufb)
357 {
358 if (!$ufb->has($this->envfield)) {
359 $this->empty = true;
360 return true;
361 }
362
363 $this->val = ($ufb->i($this->envfield) != 0);
364 return true;
365 }
366}
367// }}}
d9b3d712 368
21b67462
RB
369// {{{ class UFBF_Mixed
370/** A class for building UFBFs when the user can input either a text or an ID
371 */
372abstract class UFBF_Mixed extends UFB_Field
373{
374 /** Name of the DirEnum on which class is based
375 */
376 protected $direnum;
377
378 protected $envfieldindex;
379
380 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 381 {
21b67462
RB
382 parent::__construct($envfieldtext, $formtext);
383 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
384 }
385
21b67462 386 protected function check(UserFilterBuilder &$ufb)
d9b3d712 387 {
21b67462
RB
388 if (!$ufb->has($this->envfieldindex) && !$ufb->has($this->envfield)) {
389 $this->empty = true;
390 return true;
391 }
392
393 if ($ufb->has($this->envfieldindex)) {
394 $index = $ufb->v($this->envfieldindex);
395 if (is_int($index)) {
396 $index = intval($index);
397 } else {
398 $index = strtoupper($index);
399 }
400 $this->val = array($index);
d9b3d712 401 } else {
21b67462
RB
402 $indexes = DirEnum::getIDs($this->direnum, $ufb->s($this->envfield),
403 $ufb->i('exact') ? DirEnumeration::MODE_EXACT : DirEnumeration::MODE_CONTAINS);
404 if (count($indexes) == 0) {
405 return false;
406 }
407 $this->val = $indexes;
d9b3d712 408 }
21b67462 409 return true;
d9b3d712
RB
410 }
411}
21b67462 412// }}}
d9b3d712 413
f3f800d8 414// {{{ class UFBF_Quick
59c6cb70
RB
415class UFBF_Quick extends UFB_Field
416{
417 protected function check(UserFilterBuilder &$ufb)
418 {
419 if (!$ufb->has($this->envfield)) {
420 $this->empty = true;
421 return true;
422 }
423
424 $this->val = str_replace('*', '%', replace_accent($ufb->s($this->envfield)));
425 }
426
427 protected function buildUFC(UserFilterBuilder &$ufb)
428 {
429 $conds = new PFC_And();
430
431 $s = $this->val;
432
433 /** Admin: Email, IP
434 */
435 if (S::admin() && strpos($s, '@') !== false) {
436 $conds->addChild(new UFC_Email($s));
437 return $conds;
438 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
439 // TODO: create UFC_Ip
440// $this->conds->addChild(new UFC_Ip($s));
441 return $conds;
442 }
443
444 /** Name
445 */
446 $s = preg_replace('!\d+!', ' ', $s);
447 $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY);
448 if (count($strings) > 5) {
449 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
450 $strings = array_slice($strings, 0, 5);
451 }
452
453 if (count($strings)) {
454 if (S::logged()) {
455 $flags = array();
456 } else {
457 $flags = array('public');
458 }
459 if ($ufb->i('soundex')) {
460 $soundex = true;
461 $st = array();
462 foreach ($strings as $string) {
463 $st[] = soundex_fr($string);
464 }
465 } else {
466 $soundex = false;
467 $st = $strings;
468 }
469 if ($ufb->i('exact')) {
470 $exact = true;
471 } else {
472 $exact = false;
473 }
474 $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact));
475
476 $ufb->addSort(new UFO_Score());
477 }
478
479 /** Promo ranges
480 */
481 $s = preg_replace('! *- *!', '-', $r);
482 $s = preg_replace('!([<>]) *!', ' \1', $s);
483 $s = preg_replace('![^0-9\-><]!', ' ', $s);
484 $s = preg_replace('![<>\-] !', '', $s);
485 $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY);
486 foreach ($ranges as $r) {
487 if (preg_match('!^\d{4}$!', $r)) {
488 $conds->addChild(new UFC_Promo('=', UserFilter::DISPLAY, 'X' . $r));
489 } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
490 $p1=min(intval($matches[1]), intval($matches[2]));
491 $p2=max(intval($matches[1]), intval($matches[2]));
492 $conds->addChild(new PFC_And(
493 new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $p1),
494 new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $p2)
495 ));
496 } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
497 $conds->addChild(new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $matches[1]));
498 } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
499 $this->conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1]));
500 }
501 }
502
503 /** Phone number
504 */
505 $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
506 $t = preg_replace('![<>\- ]!', '', $t);
507 if (strlen($t) > 4) {
508 $conds->addChild(new UFC_Phone($t));
509 }
510
511 return $conds;
512 }
513}
514// }}}
515
21b67462
RB
516// {{{ class UFBF_Name
517class UFBF_Name extends UFBF_Text
518{
519 protected function check(UserFilterBuilder &$ufb)
520 {
521 if (!parent::check($ufb)) {
522 return false;
523 }
524
525 $this->val = preg_split('/[[:space:]]/', $this->val);
526 if (count($this->val) == 0) {
527 $this->empty = true;
528 }
529 return true;
530 }
531
532 protected function buildUFC(UserFilterBuilder &$ufb)
533 {
534 return new UFC_NameTokens($this->val, array(), $ufb->i('with_soundex'), $ufb->i('exact'));
535 }
536}
537// }}}
538
539// {{{ class UFBF_Promo
d9b3d712
RB
540class UFBF_Promo extends UFB_Field
541{
542 private static $validcomps = array('<', '<=', '=', '>=', '>');
543 private $comp;
544 private $envfieldcomp;
545
546 public function __construct($envfield, $fromtext = '', $envfieldcomp)
547 {
548 parent::__construct($envfield, $fromtext);
549 $this->envfieldcomp = $envfieldcomp;
550 }
551
552 protected function check(UserFilterBuilder &$ufb)
553 {
554 if (!$ufb->has($this->envfield) || !$ufb->has($this->envfieldcomp)) {
555 $this->empty = true;
556 return true;
557 }
558
559 $this->val = $ubf->i($this->envfield);
560 $this->comp = $ubf->v($this->envfieldcomp);
561
562 if (!in_array($this->comp, self::$validcomps)) {
563 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
564 }
565
566 if (preg_match('/^[0-9]{2}$/', $this->val)) {
567 $this->val += 1900;
568 }
569 if ($this->val < 1900 || $this->val > 9999) {
570 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
571 }
572 return true;
573 }
574
575 protected function buildUFC(UserFilterBuilder &$ufb) {
576 return new UFC_Promo($this->comp, UserFilter::DISPLAY, 'X' . $this->val);
577 }
578}
21b67462
RB
579// }}}
580
581// {{{ class UFBF_Sex
582class UFBF_Sex extends UFBF_Enum
583{
584 public function __construct($envfield, $formtext = '')
585 {
586 parent::__construct($envfield, $formtext, array(1, 2));
587 }
588
589 private static function getVal($id)
590 {
591 switch($id) {
592 case 1:
593 return User::GENDER_MALE;
594 break;
595 case 2:
596 return User::GENDER_FEMALE;
597 break;
598 }
599 }
600
601 protected function buildUFC(UserFilterBuilder &$ufb)
602 {
603 return new UFC_Sex(self::getVal($this->val));
604 }
605}
606// }}}
607
608// {{{ class UFBF_Registered
609class UFBF_Registered extends UFBF_Enum
610{
611 public function __construct($envfield, $formtext = '')
612 {
613 parent::__construct($envfield, $formtext, array(1, 2));
614 }
615
616 protected function buildUFC(UserFilterBuilder &$ufb)
617 {
618 if ($this->val == 1) {
619 return new UFC_Registered();
620 } else if ($this->val == 2) {
621 return new PFC_Not(UFC_Registered());
622 }
623 }
624}
625// }}}
d9b3d712 626
21b67462
RB
627// {{{ class UFBF_Dead
628class UFBF_Dead extends UFBF_Enum
629{
630 public function __construct($envfield, $formtext = '')
631 {
632 parent::__construct($envfield, $formtext, array(1, 2));
633 }
634
635 protected function buildUFC(UserFilterBuilder &$ufb)
636 {
637 if ($this->val == 1) {
638 return new PFC_Not(UFC_Dead());
639 } else if ($this->val == 2) {
640 return new UFC_Dead();
641 }
642 }
643}
644// }}}
645
646// {{{ class UFBF_Town
647/** Retrieves a town, either from a postal code or a town name
648 */
649class UFBF_Town extends UFBF_Text
650{
651 const TYPE_TEXT = 1;
652 const TYPE_ZIP = 2;
653 const TYPE_ANY = 3;
654
655 private $type;
d9696b0a
RB
656 private $onlycurrentfield;
657
658 public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current')
21b67462
RB
659 {
660 $this->type = $type;
d9696b0a 661 $this->onlycurrentfield = $onlycurrentfield;
f3f800d8 662 parent::__construct($envfield, $formtext, 2, 30);
21b67462
RB
663 }
664
665 protected function buildUFC(UserFilterBuilder &$ufb)
666 {
d9696b0a
RB
667 if ($ufb->isOn($this->onlycurrentfield)) {
668 $flags = UFC_Address::FLAG_CURRENT;
669 } else {
670 $flags = UFC_Address::FLAG_ANY;
671 }
672
21b67462
RB
673 if (preg_match('/[0-9]/', $this->val)) {
674 if ($this->type & self::TYPE_ZIP) {
d9696b0a 675 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
676 } else {
677 return new PFC_False();
678 }
679 } else {
d9696b0a
RB
680 $byname = new UFC_AddressText(null, UFC_Address::CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val);
681 $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
682 if ($this->type & self::TYPE_ANY) {
683 return new PFC_Or($byname, $byzip);
684 } else if ($this->type & self::TYPE_TEXT) {
685 return $byname;
686 } else {
687 return $byzip;
688 }
689 }
690 }
691}
692// }}}
693
694// {{{ class UFBF_Country
695class UFBF_Country extends UFBF_Mixed
696{
697 protected $direnum = DirEnum::COUNTRIES;
d9696b0a
RB
698 protected $onlycurrentfield;
699
700 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
701 {
702 parent::__construct($envfieldtext, $envfieldindex, $formtext);
703 $this->onlycurrentfield = $onlycurrentfield;
704 }
21b67462
RB
705
706 protected function buildUFC(UserFilterBuilder &$ufb)
707 {
d9696b0a
RB
708 if ($ufb->isOn($this->onlycurrentfield)) {
709 $flags = UFC_Address::FLAG_CURRENT;
710 } else {
711 $flags = UFC_Address::FLAG_ANY;
712 }
713
714 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
715 }
716}
717// }}}
718
719// {{{ class UFBF_AdminArea
720class UFBF_AdminArea extends UFBF_Mixed
721{
722 protected $direnum = DirEnum::ADMINAREAS;
d9696b0a
RB
723 protected $onlycurrentfield;
724
725 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
726 {
727 parent::__construct($envfieldtext, $envfieldindex, $formtext);
728 $this->onlycurrentfield = $onlycurrentfield;
729 }
730
21b67462
RB
731
732 protected function buildUFC(UserFilterBuilder &$ufb)
733 {
d9696b0a
RB
734 if ($ufb->isOn($this->onlycurrentfield)) {
735 $flags = UFC_Address::FLAG_CURRENT;
736 } else {
737 $flags = UFC_Address::FLAG_ANY;
738 }
739
740 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ADMAREA, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
741 }
742}
743// }}}
744
745// {{{ class UFBF_JobCompany
746class UFBF_JobCompany extends UFBF_Text
747{
d9696b0a
RB
748 private $onlymentorfield;
749
750 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
751 {
752 parent::__construct($envfield, $formtext);
753 $this->onlymentorfield = $onlymentorfield;
754 }
755
756 public function check(UserFilterBuilder &$ufb) {
757 if (parent::check($ufb)) {
758 # No company check for mentors
759 if ($ufb->isOn($this->onlymentorfield)) {
760 $this->empty = true;
761 }
762 return true;
763 } else {
764 return false;
765 }
766 }
767
21b67462
RB
768 protected function buildUFC(UserFilterBuilder &$ufb)
769 {
770 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
771 }
772}
773// }}}
774
775// {{{ class UFBF_JobSector
776class UFBF_JobSector extends UFBF_Mixed
777{
778 protected $direnum = DirEnum::SECTORS;
d9696b0a
RB
779 private $onlymentorfield;
780
781 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlymentorfield = 'only_referent')
782 {
783 parent::__construct($envfieldtext, $envfieldindex, $formtext);
784 $this->onlymentorfield = $onlymentorfield;
785 }
21b67462
RB
786
787 protected function buildUFC(UserFilterBuilder &$ufb)
788 {
d9696b0a
RB
789 if ($ufb->isOn($this->onlymentorfield)) {
790 return new UFC_Mentor_Sectorization($this->val, UserFilter::JOB_SUBSECTOR);
791 } else {
792 return new UFC_Job_Sectorization($this->val, UserFilter::JOB_SUBSUBSECTOR);
793 }
21b67462
RB
794 }
795}
796// }}}
797
798// {{{ class UFBF_JobDescription
799class UFBF_JobDescription extends UFBF_Text
800{
d9696b0a
RB
801 private $onlymentorfield;
802
803 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
804 {
805 parent::__construct($envfield, $formtext);
806 $this->onlymentorfield = $onlymentorfield;
807 }
808
21b67462
RB
809 protected function buildUFC(UserFilterBuilder &$ufb)
810 {
d9696b0a
RB
811 if ($ufb->isOn($this->onlymentorfield)) {
812 return new UFC_Mentor_Expertise($this->val);
813 } else {
814 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
815 }
21b67462
RB
816 }
817}
818// }}}
819
820// {{{ class UFBF_JobCv
821class UFBF_JobCv extends UFBF_Text
822{
d9696b0a
RB
823 private $onlymentorfield;
824
825 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
826 {
827 parent::__construct($envfield, $formtext);
828 $this->onlymentorfield = $onlymentorfield;
829 }
830
21b67462
RB
831 protected function buildUFC(UserFilterBuilder &$ufb)
832 {
d9696b0a
RB
833 if ($ufb->isOn($this->onlymentorfield)) {
834 return new UFC_Mentor_Expertise($this->val);
835 } else {
836 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
837 }
21b67462
RB
838 }
839}
840// }}}
841
842// {{{ class UFBF_Nationality
843class UFBF_Nationality extends UFBF_Mixed
844{
845 protected $direnum = DirEnum::NATIONALITIES;
846
847 protected function buildUFC(UserFilterBuilder &$ufb)
848 {
849 return new UFC_Nationality($this->val);
850 }
851}
852// }}}
853
854// {{{ class UFBF_Binet
855class UFBF_Binet extends UFBF_Mixed
856{
857 protected $direnum = DirEnum::BINETS;
858
859 protected function buildUFC(UserFilterBuilder &$ufb)
860 {
861 return new UFC_Binet($this->val);
862 }
863}
864// }}}
865
866// {{{ class UFBF_Group
867class UFBF_Group extends UFBF_Mixed
868{
869 protected $direnum = DirEnum::GROUPESX;
870
871 protected function buildUFC(UserFilterBuilder &$ufb)
872 {
873 if (count($this->val) == 1) {
874 return new UFC_Group($this->val[0]);
875 }
876
877 $or = new PFC_Or();
878 foreach ($this->val as $grp) {
879 $or->addChild(new UFC_Group($grp));
880 }
881 return $or;
882 }
883}
884// }}}
885
886// {{{ class UFBF_Section
887class UFBF_Section extends UFBF_Index
888{
889 protected $direnum = DirEnum::SECTIONS;
890
891 protected function buildUFC(UserFilterBuilder &$ufb)
892 {
893 return new UFC_Section($this->val);
894 }
895}
896// }}}
897
898// {{{ class UFBF_Formation
899class UFBF_Formation extends UFBF_Mixed
900{
901 protected $direnum = DirEnum::SCHOOLS;
902
903 protected function buildUFC(UserFilterBuilder &$ufb)
904 {
905 return new UFC_Formation($this->val);
906 }
907}
908// }}}
909
910// {{{ class UFBF_Diploma
911class UFBF_Diploma extends UFBF_Mixed
912{
913 protected $direnum = DirEnum::DEGREES;
914
915 protected function buildUFC(UserFilterBuilder &$ufb)
916 {
917 return new UFC_Diploma($this->val);
918 }
919}
920// }}}
921
922// {{{ class UFBF_StudiesDomain
923class UFBF_StudiesDomain extends UFBF_Mixed
924{
925 protected $direnum = DirEnum::STUDIESDOMAINS;
926
927 protected function buildUFC(UserFilterBuilder &$ufb)
928 {
929 return new UFC_StudyField($this->val);
930 }
931}
932// }}}
933
934// {{{ class UFBF_Comment
935class UFBF_Comment extends UFBF_Text
936{
937 protected function buildUFC(UserFilterBuilder &$ufb)
938 {
939 return new UFC_Comment($this->val);
940 }
941}
942// }}}
3ed7556a
RB
943
944// {{{ class UFBF_Phone
945class UFBF_Phone extends UFBF_Text
946{
947 protected function buildUFC(UserFilterBuilder &$ufb)
948 {
949 return new UFC_Phone($this->val);
950 }
951}
952// }}}
953
954// {{{ class UFBF_Networking
955class UFBF_Networking extends UFBF_Text
956{
957 private $networktypefield;
958 private $nwtype;
959
960 public function __construct($envfield, $networktypefield, $formtext = '')
961 {
962 parent::__construct($envfield, $formtext);
963 $this->networktypefield = $networktypefield;
964 }
965
966 public function check(UserFilterBuilder &$ufb)
967 {
968 if (parent::check($ufb)) {
969 $this->nwtype = $ufb->i($this->networktypefield);
970 return true;
971 } else {
972 return false;
973 }
974 }
975
976 public function buildUFC(UserFilterBuilder &$ufb)
977 {
978 return new UFC_Networking($this->nwtype, $this->val);
979 }
980}
981// }}}
d9b3d712 982?>