Update core
[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
78be0329
FB
143 public function hasAlnum($key)
144 {
145 $str = $this->s($key);
146 return preg_match('/[a-z0-9]/i', $str);
147 }
148
149 public function hasAlpha($key)
150 {
151 $str = $this->s($key);
152 return preg_match('/[a-z]/i', $str);
153 }
154
0f17825b
FB
155 public function isOn($key)
156 {
157 return $this->has($key) && $this->t($key) == 'on';
d9696b0a 158 }
d9b3d712 159}
21b67462 160// }}}
d9b3d712 161
59c6cb70
RB
162// {{{ class UFB_QuickSearch
163class UFB_QuickSearch extends UserFilterBuilder
164{
165 public function __construct($envprefix = '')
166 {
167 $fields = array(
168 new UFBF_Quick('quick', 'Recherche rapide'),
169 );
170 parent::__construct($fields, $envprefix);
171 }
172}
173// }}}
174
21b67462
RB
175// {{{ class UFB_AdvancedSearch
176class UFB_AdvancedSearch extends UserFilterBuilder
177{
178 public function __construct($envprefix = '')
179 {
180 $fields = array(
181 new UFBF_Name('name', 'Nom'),
182 new UFBF_Promo('promo1', 'Promotion', 'egal1'),
183 new UFBF_Promo('promo2', 'Promotion', 'egal2'),
184 new UFBF_Sex('woman', 'Sexe'),
185 new UFBF_Registered('subscriber', 'Inscrit'),
186 new UFBF_Dead('alive', 'En vie'),
187
188 new UFBF_Town('city', 'Ville / Code Postal'),
189 new UFBF_Country('countryTxt', 'country', 'Pays'),
190 new UFBF_AdminArea('region', 'Région'),
191
192 new UFBF_JobCompany('entreprise', 'Entreprise'),
21b67462
RB
193 new UFBF_JobDescription('jobdescription', 'Fonction'),
194 new UFBF_JobCv('cv', 'CV'),
3ac45f10 195 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
21b67462
RB
196
197 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
198 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
199 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
200 new UFBF_Section('sectionTxt', 'section', 'Section'),
201
fb3b6547
RB
202 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
203 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
204 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
21b67462
RB
205
206 new UFBF_Comment('free', 'Commentaire'),
3ed7556a
RB
207 new UFBF_Phone('phone_number', 'Téléphone'),
208 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
96f01fba
RB
209
210 new UFBF_Mentor('only_referent', 'Référent'),
21b67462
RB
211 );
212 parent::__construct($fields, $envprefix);
213 }
214}
215// }}}
216
6faa0186
RB
217// {{{ class UFB_MentorSearch
218class UFB_MentorSearch extends UserFilterBuilder
219{
220 public function __construct($envprefix = '')
221 {
222 $fields = array(
459e6f81
PC
223 new UFBF_MentorCountry('country'),
224 new UFBF_MentorTerm('jobterm', 'jobtermText'),
6faa0186
RB
225 new UFBF_MentorExpertise('expertise'),
226 );
227 parent::__construct($fields, $envprefix);
228 }
229}
230// }}}
231
21b67462 232// {{{ class UFB_Field
d9b3d712
RB
233abstract class UFB_Field
234{
235 protected $envfield;
236 protected $formtext;
237
238 protected $empty = false;
239 protected $val = null;
240
241 /** Constructor
242 * @param $envfield Name of the field in the environment
243 * @param $formtext User-friendly name of that field
244 */
245 public function __construct($envfield, $formtext = '')
246 {
247 $this->envfield = $envfield;
248 if ($formtext != '') {
249 $this->formtext = $formtext;
250 } else {
251 $formtext = ucfirst($envfield);
252 }
253 }
254
255 /** Prints the given error message to the user, and returns false
256 * in order to be used as return $this->raise('ERROR');
257 *
258 * All %s in the $msg will be replaced with the formtext.
259 */
260 protected function raise($msg)
261 {
262 Platal::page()->trigError(str_replace('%s', $this->formtext, $msg));
263 return false;
264 }
265
266 public function apply(UserFilterBuilder &$ufb) {
267 if (!$this->check($ufb)) {
268 return false;
269 }
270
271 if (!$this->empty) {
272 $ufc = $this->buildUFC($ufb);
273 if ($ufc != null) {
274 $ufb->addCond($ufc);
275 }
276 }
277 return true;
278 }
279
6faa0186
RB
280 public function isEmpty()
281 {
282 return $this->empty;
283 }
284
d9b3d712
RB
285 /** Create the UFC associated to the field; won't be called
286 * if the field is "empty"
287 * @param &$ufb UFB to which fields must be added
288 * @return UFC
289 */
290 abstract protected function buildUFC(UserFilterBuilder &$ufb);
291
292 /** This function is intended to run consistency checks on the value
293 * @return boolean Whether the input is valid
294 */
295 abstract protected function check(UserFilterBuilder &$ufb);
296}
21b67462 297// }}}
d9b3d712 298
21b67462 299// {{{ class UFBF_Text
d9b3d712
RB
300abstract class UFBF_Text extends UFB_Field
301{
d9b3d712
RB
302 private $minlength;
303 private $maxlength;
304
f3f800d8 305 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
d9b3d712
RB
306 {
307 parent::__construct($envfield, $formtext);
d9b3d712
RB
308 $this->minlength = $minlength;
309 $this->maxlength = $maxlength;
310 }
311
312 protected function check(UserFilterBuilder &$ufb)
313 {
0f17825b 314 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
315 $this->empty = true;
316 return true;
317 }
318
0f17825b 319 $this->val = $ufb->t($this->envfield);
d9b3d712
RB
320 if (strlen($this->val) < $this->minlength) {
321 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
322 } else if (strlen($this->val) > $this->maxlength) {
323 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
5a0b9531 324 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) {
f3f800d8 325 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
d9b3d712 326 }
f3f800d8 327
d9b3d712
RB
328 return true;
329 }
330}
21b67462 331// }}}
d9b3d712 332
21b67462 333// {{{ class UFBF_Range
d9b3d712
RB
334/** Subclass to use for fields which only allow integers within a range
335 */
336abstract class UFBF_Range extends UFB_Field
337{
338
339 private $min;
340 private $max;
341
342 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
343 {
344 parent::__construct($envfield, $formtext);
345 $this->min = $min;
346 $this->max = $max;
347 }
348
349 protected function check(UserFilterBuilder &$ufb)
350 {
0f17825b 351 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
352 $this->empty = true;
353 return true;
354 }
355
356 $this->val = $ufb->i($this->envfield);
357 if ($this->val < $this->min) {
358 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
359 } else if ($this->val > $this->max) {
360 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
361 }
362 return true;
363 }
364}
21b67462 365// }}}
d9b3d712 366
21b67462 367// {{{ class UFBF_Index
d9b3d712
RB
368/** Subclass to use for indexed fields
369 */
370abstract class UFBF_Index extends UFB_Field
371{
372 protected function check(UserFilterBuilder &$ufb)
373 {
0f17825b 374 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
375 $this->empty = true;
376 }
6faa0186 377 $this->val = $ufb->i($this->envfield);
d9b3d712
RB
378 return true;
379 }
380}
21b67462 381// }}}
d9b3d712 382
21b67462 383// {{{ class UFBF_Enum
d9b3d712
RB
384/** Subclass to use for fields whose value must belong to a specific set of values
385 */
386abstract class UFBF_Enum extends UFB_Field
387{
21b67462
RB
388 protected $allowedvalues;
389
390 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
391 {
392 parent::__construct($envfield, $formtext);
393 $this->allowedvalues = $allowedvalues;
21b67462 394 $this->strict = $strict;
d9b3d712
RB
395 }
396
397 protected function check(UserFilterBuilder &$ufb)
398 {
0f17825b 399 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
400 $this->empty = true;
401 return true;
402 }
403
404 $this->val = $ufb->v($this->envfield);
405 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
406 if ($this->strict) {
407 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
408 } else {
409 $this->empty = true;
410 }
d9b3d712
RB
411 }
412 return true;
413 }
414}
21b67462 415// }}}
d9b3d712 416
21b67462
RB
417// {{{ class UFBF_Bool
418abstract class UFBF_Bool extends UFB_Field
d9b3d712 419{
21b67462
RB
420 protected function check(UserFilterBuilder &$ufb)
421 {
0f17825b 422 if ($ufb->blank($this->envfield)) {
21b67462
RB
423 $this->empty = true;
424 return true;
425 }
426
0f17825b 427 $this->val = $ufb->b($this->envfield);
21b67462
RB
428 return true;
429 }
430}
431// }}}
d9b3d712 432
21b67462
RB
433// {{{ class UFBF_Mixed
434/** A class for building UFBFs when the user can input either a text or an ID
435 */
436abstract class UFBF_Mixed extends UFB_Field
437{
438 /** Name of the DirEnum on which class is based
439 */
440 protected $direnum;
441
442 protected $envfieldindex;
443
444 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 445 {
21b67462
RB
446 parent::__construct($envfieldtext, $formtext);
447 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
448 }
449
21b67462 450 protected function check(UserFilterBuilder &$ufb)
d9b3d712 451 {
78be0329 452 if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) {
21b67462
RB
453 $this->empty = true;
454 return true;
455 }
456
0f17825b 457 if (!$ufb->blank($this->envfieldindex)) {
21b67462
RB
458 $index = $ufb->v($this->envfieldindex);
459 if (is_int($index)) {
460 $index = intval($index);
461 } else {
462 $index = strtoupper($index);
463 }
464 $this->val = array($index);
d9b3d712 465 } else {
aab2ffdd 466 $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield),
0f17825b 467 $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS);
21b67462
RB
468 if (count($indexes) == 0) {
469 return false;
470 }
471 $this->val = $indexes;
d9b3d712 472 }
21b67462 473 return true;
d9b3d712
RB
474 }
475}
21b67462 476// }}}
d9b3d712 477
f3f800d8 478// {{{ class UFBF_Quick
59c6cb70
RB
479class UFBF_Quick extends UFB_Field
480{
481 protected function check(UserFilterBuilder &$ufb)
482 {
0f17825b 483 if ($ufb->blank($this->envfield)) {
59c6cb70
RB
484 $this->empty = true;
485 return true;
486 }
487
0f17825b 488 $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
4b2e2074
RB
489
490 return true;
59c6cb70
RB
491 }
492
493 protected function buildUFC(UserFilterBuilder &$ufb)
494 {
59c6cb70 495
4b2e2074 496 $r = $s = $this->val;
59c6cb70
RB
497
498 /** Admin: Email, IP
499 */
500 if (S::admin() && strpos($s, '@') !== false) {
4b2e2074 501 return new UFC_Email($s);
59c6cb70 502 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
0c457792 503 return new UFC_Ip($s);
59c6cb70
RB
504 }
505
4b2e2074
RB
506 $conds = new PFC_And();
507
59c6cb70
RB
508 /** Name
509 */
510 $s = preg_replace('!\d+!', ' ', $s);
511 $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY);
512 if (count($strings) > 5) {
513 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
514 $strings = array_slice($strings, 0, 5);
515 }
516
517 if (count($strings)) {
518 if (S::logged()) {
519 $flags = array();
520 } else {
521 $flags = array('public');
522 }
0f17825b 523 $exact =$ufb->b('exact');
71886016 524 $conds->addChild(new UFC_NameTokens($st, $flags, $ufb->b('with_soundex'), $exact));
59c6cb70 525
4b2e2074 526 $ufb->addOrder(new UFO_Score());
59c6cb70
RB
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)) {
4b2e2074 549 $conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1]));
59c6cb70
RB
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
21b67462
RB
566// {{{ class UFBF_Name
567class 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 {
0f17825b 584 return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact'));
21b67462
RB
585 }
586}
587// }}}
588
589// {{{ class UFBF_Promo
d9b3d712
RB
590class 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 {
0f17825b 604 if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp)) {
d9b3d712
RB
605 $this->empty = true;
606 return true;
607 }
608
9e6b7376
RB
609 $this->val = $ufb->i($this->envfield);
610 $this->comp = $ufb->v($this->envfieldcomp);
d9b3d712
RB
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) {
999db5aa 626 return new UFC_Promo($this->comp, UserFilter::GRADE_ING, $this->val);
d9b3d712
RB
627 }
628}
21b67462
RB
629// }}}
630
631// {{{ class UFBF_Sex
632class 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
659class 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) {
e637cb69 671 return new PFC_Not(new UFC_Registered());
21b67462
RB
672 }
673 }
674}
675// }}}
d9b3d712 676
21b67462
RB
677// {{{ class UFBF_Dead
678class 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) {
2d9951d8 688 return new PFC_Not(new UFC_Dead());
21b67462
RB
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 */
699class 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;
d9696b0a
RB
706 private $onlycurrentfield;
707
708 public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current')
21b67462
RB
709 {
710 $this->type = $type;
d9696b0a 711 $this->onlycurrentfield = $onlycurrentfield;
f3f800d8 712 parent::__construct($envfield, $formtext, 2, 30);
21b67462
RB
713 }
714
715 protected function buildUFC(UserFilterBuilder &$ufb)
716 {
d9696b0a
RB
717 if ($ufb->isOn($this->onlycurrentfield)) {
718 $flags = UFC_Address::FLAG_CURRENT;
719 } else {
720 $flags = UFC_Address::FLAG_ANY;
721 }
722
21b67462
RB
723 if (preg_match('/[0-9]/', $this->val)) {
724 if ($this->type & self::TYPE_ZIP) {
d9696b0a 725 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
726 } else {
727 return new PFC_False();
728 }
729 } else {
1f8dfc60 730 $byname = new UFC_AddressText(null, XDB::WILDCARD_CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val);
d9696b0a 731 $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
21b67462
RB
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
745class UFBF_Country extends UFBF_Mixed
746{
747 protected $direnum = DirEnum::COUNTRIES;
d9696b0a
RB
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 }
21b67462
RB
755
756 protected function buildUFC(UserFilterBuilder &$ufb)
757 {
d9696b0a
RB
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);
21b67462
RB
765 }
766}
767// }}}
768
769// {{{ class UFBF_AdminArea
32283a1a 770class UFBF_AdminArea extends UFBF_Index
21b67462
RB
771{
772 protected $direnum = DirEnum::ADMINAREAS;
d9696b0a
RB
773 protected $onlycurrentfield;
774
32283a1a 775 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
d9696b0a 776 {
32283a1a 777 parent::__construct($envfield, $formtext);
d9696b0a
RB
778 $this->onlycurrentfield = $onlycurrentfield;
779 }
780
21b67462
RB
781
782 protected function buildUFC(UserFilterBuilder &$ufb)
783 {
d9696b0a
RB
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);
21b67462
RB
791 }
792}
793// }}}
794
795// {{{ class UFBF_JobCompany
796class UFBF_JobCompany extends UFBF_Text
797{
d9696b0a
RB
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
21b67462
RB
818 protected function buildUFC(UserFilterBuilder &$ufb)
819 {
820 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
821 }
822}
823// }}}
824
3ac45f10
PC
825// {{{ class UFBF_JobTerms
826class UFBF_JobTerms extends UFBF_Index
827{
828 protected function buildUFC(UserFilterBuilder &$ufb)
829 {
830 return new UFC_Job_Terms($this->val);
831 }
832}
833// }}}
834
21b67462
RB
835// {{{ class UFBF_JobDescription
836class UFBF_JobDescription extends UFBF_Text
837{
d9696b0a
RB
838 private $onlymentorfield;
839
840 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
841 {
842 parent::__construct($envfield, $formtext);
843 $this->onlymentorfield = $onlymentorfield;
844 }
845
21b67462
RB
846 protected function buildUFC(UserFilterBuilder &$ufb)
847 {
d9696b0a
RB
848 if ($ufb->isOn($this->onlymentorfield)) {
849 return new UFC_Mentor_Expertise($this->val);
850 } else {
851 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
852 }
21b67462
RB
853 }
854}
855// }}}
856
857// {{{ class UFBF_JobCv
858class UFBF_JobCv extends UFBF_Text
859{
d9696b0a
RB
860 private $onlymentorfield;
861
862 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
863 {
864 parent::__construct($envfield, $formtext);
865 $this->onlymentorfield = $onlymentorfield;
866 }
867
21b67462
RB
868 protected function buildUFC(UserFilterBuilder &$ufb)
869 {
d9696b0a
RB
870 if ($ufb->isOn($this->onlymentorfield)) {
871 return new UFC_Mentor_Expertise($this->val);
872 } else {
873 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
874 }
21b67462
RB
875 }
876}
877// }}}
878
879// {{{ class UFBF_Nationality
880class UFBF_Nationality extends UFBF_Mixed
881{
882 protected $direnum = DirEnum::NATIONALITIES;
883
884 protected function buildUFC(UserFilterBuilder &$ufb)
885 {
886 return new UFC_Nationality($this->val);
887 }
888}
889// }}}
890
891// {{{ class UFBF_Binet
892class UFBF_Binet extends UFBF_Mixed
893{
894 protected $direnum = DirEnum::BINETS;
895
896 protected function buildUFC(UserFilterBuilder &$ufb)
897 {
898 return new UFC_Binet($this->val);
899 }
900}
901// }}}
902
903// {{{ class UFBF_Group
904class UFBF_Group extends UFBF_Mixed
905{
906 protected $direnum = DirEnum::GROUPESX;
907
908 protected function buildUFC(UserFilterBuilder &$ufb)
909 {
910 if (count($this->val) == 1) {
911 return new UFC_Group($this->val[0]);
912 }
913
914 $or = new PFC_Or();
915 foreach ($this->val as $grp) {
916 $or->addChild(new UFC_Group($grp));
917 }
918 return $or;
919 }
920}
921// }}}
922
923// {{{ class UFBF_Section
442f967f 924class UFBF_Section extends UFBF_Mixed
21b67462
RB
925{
926 protected $direnum = DirEnum::SECTIONS;
927
928 protected function buildUFC(UserFilterBuilder &$ufb)
929 {
930 return new UFC_Section($this->val);
931 }
932}
933// }}}
934
fb3b6547
RB
935// {{{ class UFBF_EducationSchool
936class UFBF_EducationSchool extends UFBF_Mixed
21b67462 937{
fb3b6547 938 protected $direnum = DirEnum::EDUSCHOOLS;
21b67462
RB
939
940 protected function buildUFC(UserFilterBuilder &$ufb)
941 {
fb3b6547 942 return new UFC_EducationSchool($this->val);
21b67462
RB
943 }
944}
945// }}}
946
fb3b6547
RB
947// {{{ class UFBF_EducationDegree
948class UFBF_EducationDegree extends UFBF_Mixed
21b67462 949{
fb3b6547 950 protected $direnum = DirEnum::EDUDEGREES;
21b67462
RB
951
952 protected function buildUFC(UserFilterBuilder &$ufb)
953 {
fb3b6547 954 return new UFC_EducationDegree($this->val);
21b67462
RB
955 }
956}
957// }}}
958
fb3b6547
RB
959// {{{ class UFBF_EducationField
960class UFBF_EducationField extends UFBF_Mixed
21b67462 961{
fb3b6547 962 protected $direnum = DirEnum::EDUFIELDS;
21b67462
RB
963
964 protected function buildUFC(UserFilterBuilder &$ufb)
965 {
fb3b6547 966 return new UFC_EducationField($this->val);
21b67462
RB
967 }
968}
969// }}}
970
971// {{{ class UFBF_Comment
972class UFBF_Comment extends UFBF_Text
973{
974 protected function buildUFC(UserFilterBuilder &$ufb)
975 {
976 return new UFC_Comment($this->val);
977 }
978}
979// }}}
3ed7556a
RB
980
981// {{{ class UFBF_Phone
982class UFBF_Phone extends UFBF_Text
983{
984 protected function buildUFC(UserFilterBuilder &$ufb)
985 {
986 return new UFC_Phone($this->val);
987 }
988}
989// }}}
990
991// {{{ class UFBF_Networking
992class UFBF_Networking extends UFBF_Text
993{
994 private $networktypefield;
995 private $nwtype;
996
997 public function __construct($envfield, $networktypefield, $formtext = '')
998 {
999 parent::__construct($envfield, $formtext);
1000 $this->networktypefield = $networktypefield;
1001 }
1002
1003 public function check(UserFilterBuilder &$ufb)
1004 {
1005 if (parent::check($ufb)) {
1006 $this->nwtype = $ufb->i($this->networktypefield);
1007 return true;
1008 } else {
1009 return false;
1010 }
1011 }
1012
1013 public function buildUFC(UserFilterBuilder &$ufb)
1014 {
1015 return new UFC_Networking($this->nwtype, $this->val);
1016 }
1017}
1018// }}}
6faa0186 1019
96f01fba
RB
1020// {{{ class UFBF_Mentor
1021class UFBF_Mentor extends UFBF_Bool
1022{
1023 protected function buildUFC(UserFilterBuilder &$ufb)
1024 {
1025 return new UFC_Mentor();
1026 }
1027}
1028// }}}
1029
6faa0186 1030// {{{ class UFBF_MentorCountry
459e6f81 1031class UFBF_MentorCountry extends UFBF_Text
6faa0186
RB
1032{
1033 protected function buildUFC(UserFilterBuilder &$ufb)
1034 {
1035 return new UFC_Mentor_Country($this->val);
1036 }
1037}
1038// }}}
1039
459e6f81
PC
1040// {{{ class UFBF_Mentorterm
1041class UFBF_MentorTerm extends UFBF_Index
1042{
1043 protected function buildUFC(UserFilterBuilder &$ufb)
1044 {
1045 return new UFC_Mentor_Terms($this->val);
1046 }
1047}
1048// }}}
1049
6faa0186
RB
1050// {{{ class UFBF_MentorExpertise
1051class UFBF_MentorExpertise extends UFBF_Text
1052{
1053 protected function buildUFC(UserFilterBuilder &$ufb)
1054 {
1055 return new UFC_Mentor_Expertise($this->val);
1056 }
1057}
1058// }}}
05fa89a5
FB
1059
1060// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
d9b3d712 1061?>