Fix advanced search when soundex is activated.
[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 // {{{ class UserFilterBuilder
23 class UserFilterBuilder
24 {
25 private $envprefix;
26 private $fields;
27 private $valid = true;
28 private $ufc = null;
29 private $orders = array();
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
63 public function addOrder(PlFilterOrder &$order)
64 {
65 $this->order[] = $order;
66 }
67
68 public function isValid()
69 {
70 $this->buildUFC();
71 return $this->valid;
72 }
73
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
85 /** Returns the built UFC
86 * @return The UFC, or PFC_False() if an error happened
87 */
88 public function getUFC()
89 {
90 $this->buildUFC();
91 if ($this->valid) {
92 return $this->ufc;
93 } else {
94 return new PFC_False();
95 }
96 }
97
98 /** Returns adequate orders
99 */
100 public function getOrders()
101 {
102 $this->buildUFC();
103 return $this->orders;
104 }
105
106 /** Wrappers around Env::i/s/..., to add envprefix
107 */
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);
116 }
117
118 public function i($key, $def = 0)
119 {
120 return Env::i($this->envprefix . $key, $def);
121 }
122
123 public function v($key, $def = null)
124 {
125 return Env::v($this->envprefix . $key, $def);
126 }
127
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);
141 }
142
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
155 public function isOn($key)
156 {
157 return $this->has($key) && $this->t($key) == 'on';
158 }
159 }
160 // }}}
161
162 // {{{ class UFB_QuickSearch
163 class 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
175 // {{{ class UFB_AdvancedSearch
176 class 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'),
193 new UFBF_JobDescription('jobdescription', 'Fonction'),
194 new UFBF_JobCv('cv', 'CV'),
195 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
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
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"),
205
206 new UFBF_Comment('free', 'Commentaire'),
207 new UFBF_Phone('phone_number', 'Téléphone'),
208 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
209
210 new UFBF_Mentor('only_referent', 'Référent'),
211 );
212 parent::__construct($fields, $envprefix);
213 }
214 }
215 // }}}
216
217 // {{{ class UFB_MentorSearch
218 class UFB_MentorSearch extends UserFilterBuilder
219 {
220 public function __construct($envprefix = '')
221 {
222 $fields = array(
223 new UFBF_MentorCountry('country'),
224 new UFBF_MentorTerm('jobterm', 'jobtermText'),
225 new UFBF_MentorExpertise('expertise'),
226 );
227 parent::__construct($fields, $envprefix);
228 }
229 }
230 // }}}
231
232 // {{{ class UFB_Field
233 abstract 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
280 public function isEmpty()
281 {
282 return $this->empty;
283 }
284
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 }
297 // }}}
298
299 // {{{ class UFBF_Text
300 abstract class UFBF_Text extends UFB_Field
301 {
302 private $minlength;
303 private $maxlength;
304
305 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
306 {
307 parent::__construct($envfield, $formtext);
308 $this->minlength = $minlength;
309 $this->maxlength = $maxlength;
310 }
311
312 protected function check(UserFilterBuilder &$ufb)
313 {
314 if ($ufb->blank($this->envfield)) {
315 $this->empty = true;
316 return true;
317 }
318
319 $this->val = $ufb->t($this->envfield);
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}).");
324 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) {
325 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
326 }
327
328 return true;
329 }
330 }
331 // }}}
332
333 // {{{ class UFBF_Range
334 /** Subclass to use for fields which only allow integers within a range
335 */
336 abstract 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 {
351 if ($ufb->blank($this->envfield)) {
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 }
365 // }}}
366
367 // {{{ class UFBF_Index
368 /** Subclass to use for indexed fields
369 */
370 abstract class UFBF_Index extends UFB_Field
371 {
372 protected function check(UserFilterBuilder &$ufb)
373 {
374 if ($ufb->blank($this->envfield)) {
375 $this->empty = true;
376 }
377 $this->val = $ufb->i($this->envfield);
378 return true;
379 }
380 }
381 // }}}
382
383 // {{{ class UFBF_Enum
384 /** Subclass to use for fields whose value must belong to a specific set of values
385 */
386 abstract class UFBF_Enum extends UFB_Field
387 {
388 protected $allowedvalues;
389
390 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
391 {
392 parent::__construct($envfield, $formtext);
393 $this->allowedvalues = $allowedvalues;
394 $this->strict = $strict;
395 }
396
397 protected function check(UserFilterBuilder &$ufb)
398 {
399 if ($ufb->blank($this->envfield)) {
400 $this->empty = true;
401 return true;
402 }
403
404 $this->val = $ufb->v($this->envfield);
405 if (! in_array($this->val, $this->allowedvalues)) {
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 }
411 }
412 return true;
413 }
414 }
415 // }}}
416
417 // {{{ class UFBF_Bool
418 abstract class UFBF_Bool extends UFB_Field
419 {
420 protected function check(UserFilterBuilder &$ufb)
421 {
422 if ($ufb->blank($this->envfield)) {
423 $this->empty = true;
424 return true;
425 }
426
427 $this->val = $ufb->b($this->envfield);
428 return true;
429 }
430 }
431 // }}}
432
433 // {{{ class UFBF_Mixed
434 /** A class for building UFBFs when the user can input either a text or an ID
435 */
436 abstract 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 = '')
445 {
446 parent::__construct($envfieldtext, $formtext);
447 $this->envfieldindex = $envfieldindex;
448 }
449
450 protected function check(UserFilterBuilder &$ufb)
451 {
452 if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) {
453 $this->empty = true;
454 return true;
455 }
456
457 if (!$ufb->blank($this->envfieldindex)) {
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);
465 } else {
466 $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield),
467 $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS);
468 if (count($indexes) == 0) {
469 return false;
470 }
471 $this->val = $indexes;
472 }
473 return true;
474 }
475 }
476 // }}}
477
478 // {{{ class UFBF_Quick
479 class UFBF_Quick extends UFB_Field
480 {
481 protected function check(UserFilterBuilder &$ufb)
482 {
483 if ($ufb->blank($this->envfield)) {
484 $this->empty = true;
485 return true;
486 }
487
488 $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
489
490 return true;
491 }
492
493 protected function buildUFC(UserFilterBuilder &$ufb)
494 {
495
496 $r = $s = $this->val;
497
498 /** Admin: Email, IP
499 */
500 if (S::admin() && strpos($s, '@') !== false) {
501 return new UFC_Email($s);
502 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
503 return new UFC_Ip($s);
504 }
505
506 $conds = new PFC_And();
507
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 }
523 $exact =$ufb->b('exact');
524 $conds->addChild(new UFC_NameTokens($st, $flags, $ufb->b('with_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 = $ufb->i($this->envfield);
610 $this->comp = $ufb->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::GRADE_ING, $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(new 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(new 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, XDB::WILDCARD_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_Index
771 {
772 protected $direnum = DirEnum::ADMINAREAS;
773 protected $onlycurrentfield;
774
775 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
776 {
777 parent::__construct($envfield, $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_JobTerms
826 class 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
835 // {{{ class UFBF_JobDescription
836 class UFBF_JobDescription extends UFBF_Text
837 {
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
846 protected function buildUFC(UserFilterBuilder &$ufb)
847 {
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 }
853 }
854 }
855 // }}}
856
857 // {{{ class UFBF_JobCv
858 class UFBF_JobCv extends UFBF_Text
859 {
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
868 protected function buildUFC(UserFilterBuilder &$ufb)
869 {
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 }
875 }
876 }
877 // }}}
878
879 // {{{ class UFBF_Nationality
880 class 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
892 class 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
904 class 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
924 class UFBF_Section extends UFBF_Mixed
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
935 // {{{ class UFBF_EducationSchool
936 class UFBF_EducationSchool extends UFBF_Mixed
937 {
938 protected $direnum = DirEnum::EDUSCHOOLS;
939
940 protected function buildUFC(UserFilterBuilder &$ufb)
941 {
942 return new UFC_EducationSchool($this->val);
943 }
944 }
945 // }}}
946
947 // {{{ class UFBF_EducationDegree
948 class UFBF_EducationDegree extends UFBF_Mixed
949 {
950 protected $direnum = DirEnum::EDUDEGREES;
951
952 protected function buildUFC(UserFilterBuilder &$ufb)
953 {
954 return new UFC_EducationDegree($this->val);
955 }
956 }
957 // }}}
958
959 // {{{ class UFBF_EducationField
960 class UFBF_EducationField extends UFBF_Mixed
961 {
962 protected $direnum = DirEnum::EDUFIELDS;
963
964 protected function buildUFC(UserFilterBuilder &$ufb)
965 {
966 return new UFC_EducationField($this->val);
967 }
968 }
969 // }}}
970
971 // {{{ class UFBF_Comment
972 class UFBF_Comment extends UFBF_Text
973 {
974 protected function buildUFC(UserFilterBuilder &$ufb)
975 {
976 return new UFC_Comment($this->val);
977 }
978 }
979 // }}}
980
981 // {{{ class UFBF_Phone
982 class 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
992 class 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 // }}}
1019
1020 // {{{ class UFBF_Mentor
1021 class UFBF_Mentor extends UFBF_Bool
1022 {
1023 protected function buildUFC(UserFilterBuilder &$ufb)
1024 {
1025 return new UFC_Mentor();
1026 }
1027 }
1028 // }}}
1029
1030 // {{{ class UFBF_MentorCountry
1031 class UFBF_MentorCountry extends UFBF_Text
1032 {
1033 protected function buildUFC(UserFilterBuilder &$ufb)
1034 {
1035 return new UFC_Mentor_Country($this->val);
1036 }
1037 }
1038 // }}}
1039
1040 // {{{ class UFBF_Mentorterm
1041 class 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
1050 // {{{ class UFBF_MentorExpertise
1051 class UFBF_MentorExpertise extends UFBF_Text
1052 {
1053 protected function buildUFC(UserFilterBuilder &$ufb)
1054 {
1055 return new UFC_Mentor_Expertise($this->val);
1056 }
1057 }
1058 // }}}
1059
1060 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1061 ?>