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