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