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