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