Deletes all references to sectors as they have been replaced by jobterms.
[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 if ($ufb->b('with_soundex')) {
524 $soundex = true;
525 $st = array();
526 foreach ($strings as $string) {
527 $st[] = soundex_fr($string);
528 }
529 } else {
530 $soundex = false;
531 $st = $strings;
532 }
533 $exact =$ufb->b('exact');
534 $conds->addChild(new UFC_NameTokens($st, $flags, $soundex, $exact));
535
536 $ufb->addOrder(new UFO_Score());
537 }
538
539 /** Promo ranges
540 */
541 $s = preg_replace('! *- *!', '-', $r);
542 $s = preg_replace('!([<>]) *!', ' \1', $s);
543 $s = preg_replace('![^0-9\-><]!', ' ', $s);
544 $s = preg_replace('![<>\-] !', '', $s);
545 $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY);
546 foreach ($ranges as $r) {
547 if (preg_match('!^\d{4}$!', $r)) {
548 $conds->addChild(new UFC_Promo('=', UserFilter::DISPLAY, 'X' . $r));
549 } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
550 $p1=min(intval($matches[1]), intval($matches[2]));
551 $p2=max(intval($matches[1]), intval($matches[2]));
552 $conds->addChild(new PFC_And(
553 new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $p1),
554 new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $p2)
555 ));
556 } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
557 $conds->addChild(new UFC_Promo('<=', UserFilter::DISPLAY, 'X' . $matches[1]));
558 } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
559 $conds->addChild(new UFC_Promo('>=', UserFilter::DISPLAY, 'X' . $matches[1]));
560 }
561 }
562
563 /** Phone number
564 */
565 $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
566 $t = preg_replace('![<>\- ]!', '', $t);
567 if (strlen($t) > 4) {
568 $conds->addChild(new UFC_Phone($t));
569 }
570
571 return $conds;
572 }
573 }
574 // }}}
575
576 // {{{ class UFBF_Name
577 class UFBF_Name extends UFBF_Text
578 {
579 protected function check(UserFilterBuilder &$ufb)
580 {
581 if (!parent::check($ufb)) {
582 return false;
583 }
584
585 $this->val = preg_split('/[[:space:]]/', $this->val);
586 if (count($this->val) == 0) {
587 $this->empty = true;
588 }
589 return true;
590 }
591
592 protected function buildUFC(UserFilterBuilder &$ufb)
593 {
594 return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact'));
595 }
596 }
597 // }}}
598
599 // {{{ class UFBF_Promo
600 class UFBF_Promo extends UFB_Field
601 {
602 private static $validcomps = array('<', '<=', '=', '>=', '>');
603 private $comp;
604 private $envfieldcomp;
605
606 public function __construct($envfield, $fromtext = '', $envfieldcomp)
607 {
608 parent::__construct($envfield, $fromtext);
609 $this->envfieldcomp = $envfieldcomp;
610 }
611
612 protected function check(UserFilterBuilder &$ufb)
613 {
614 if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp)) {
615 $this->empty = true;
616 return true;
617 }
618
619 $this->val = $ufb->i($this->envfield);
620 $this->comp = $ufb->v($this->envfieldcomp);
621
622 if (!in_array($this->comp, self::$validcomps)) {
623 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
624 }
625
626 if (preg_match('/^[0-9]{2}$/', $this->val)) {
627 $this->val += 1900;
628 }
629 if ($this->val < 1900 || $this->val > 9999) {
630 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
631 }
632 return true;
633 }
634
635 protected function buildUFC(UserFilterBuilder &$ufb) {
636 return new UFC_Promo($this->comp, UserFilter::GRADE_ING, $this->val);
637 }
638 }
639 // }}}
640
641 // {{{ class UFBF_Sex
642 class UFBF_Sex extends UFBF_Enum
643 {
644 public function __construct($envfield, $formtext = '')
645 {
646 parent::__construct($envfield, $formtext, array(1, 2));
647 }
648
649 private static function getVal($id)
650 {
651 switch($id) {
652 case 1:
653 return User::GENDER_MALE;
654 break;
655 case 2:
656 return User::GENDER_FEMALE;
657 break;
658 }
659 }
660
661 protected function buildUFC(UserFilterBuilder &$ufb)
662 {
663 return new UFC_Sex(self::getVal($this->val));
664 }
665 }
666 // }}}
667
668 // {{{ class UFBF_Registered
669 class UFBF_Registered extends UFBF_Enum
670 {
671 public function __construct($envfield, $formtext = '')
672 {
673 parent::__construct($envfield, $formtext, array(1, 2));
674 }
675
676 protected function buildUFC(UserFilterBuilder &$ufb)
677 {
678 if ($this->val == 1) {
679 return new UFC_Registered();
680 } else if ($this->val == 2) {
681 return new PFC_Not(new UFC_Registered());
682 }
683 }
684 }
685 // }}}
686
687 // {{{ class UFBF_Dead
688 class UFBF_Dead extends UFBF_Enum
689 {
690 public function __construct($envfield, $formtext = '')
691 {
692 parent::__construct($envfield, $formtext, array(1, 2));
693 }
694
695 protected function buildUFC(UserFilterBuilder &$ufb)
696 {
697 if ($this->val == 1) {
698 return new PFC_Not(new UFC_Dead());
699 } else if ($this->val == 2) {
700 return new UFC_Dead();
701 }
702 }
703 }
704 // }}}
705
706 // {{{ class UFBF_Town
707 /** Retrieves a town, either from a postal code or a town name
708 */
709 class UFBF_Town extends UFBF_Text
710 {
711 const TYPE_TEXT = 1;
712 const TYPE_ZIP = 2;
713 const TYPE_ANY = 3;
714
715 private $type;
716 private $onlycurrentfield;
717
718 public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current')
719 {
720 $this->type = $type;
721 $this->onlycurrentfield = $onlycurrentfield;
722 parent::__construct($envfield, $formtext, 2, 30);
723 }
724
725 protected function buildUFC(UserFilterBuilder &$ufb)
726 {
727 if ($ufb->isOn($this->onlycurrentfield)) {
728 $flags = UFC_Address::FLAG_CURRENT;
729 } else {
730 $flags = UFC_Address::FLAG_ANY;
731 }
732
733 if (preg_match('/[0-9]/', $this->val)) {
734 if ($this->type & self::TYPE_ZIP) {
735 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
736 } else {
737 return new PFC_False();
738 }
739 } else {
740 $byname = new UFC_AddressText(null, XDB::WILDCARD_CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val);
741 $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags);
742 if ($this->type & self::TYPE_ANY) {
743 return new PFC_Or($byname, $byzip);
744 } else if ($this->type & self::TYPE_TEXT) {
745 return $byname;
746 } else {
747 return $byzip;
748 }
749 }
750 }
751 }
752 // }}}
753
754 // {{{ class UFBF_Country
755 class UFBF_Country extends UFBF_Mixed
756 {
757 protected $direnum = DirEnum::COUNTRIES;
758 protected $onlycurrentfield;
759
760 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
761 {
762 parent::__construct($envfieldtext, $envfieldindex, $formtext);
763 $this->onlycurrentfield = $onlycurrentfield;
764 }
765
766 protected function buildUFC(UserFilterBuilder &$ufb)
767 {
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_COUNTRY, UFC_Address::TYPE_ANY, $flags);
775 }
776 }
777 // }}}
778
779 // {{{ class UFBF_AdminArea
780 class UFBF_AdminArea extends UFBF_Mixed
781 {
782 protected $direnum = DirEnum::ADMINAREAS;
783 protected $onlycurrentfield;
784
785 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
786 {
787 parent::__construct($envfieldtext, $envfieldindex, $formtext);
788 $this->onlycurrentfield = $onlycurrentfield;
789 }
790
791
792 protected function buildUFC(UserFilterBuilder &$ufb)
793 {
794 if ($ufb->isOn($this->onlycurrentfield)) {
795 $flags = UFC_Address::FLAG_CURRENT;
796 } else {
797 $flags = UFC_Address::FLAG_ANY;
798 }
799
800 return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ADMAREA, UFC_Address::TYPE_ANY, $flags);
801 }
802 }
803 // }}}
804
805 // {{{ class UFBF_JobCompany
806 class UFBF_JobCompany extends UFBF_Text
807 {
808 private $onlymentorfield;
809
810 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
811 {
812 parent::__construct($envfield, $formtext);
813 $this->onlymentorfield = $onlymentorfield;
814 }
815
816 public function check(UserFilterBuilder &$ufb) {
817 if (parent::check($ufb)) {
818 # No company check for mentors
819 if ($ufb->isOn($this->onlymentorfield)) {
820 $this->empty = true;
821 }
822 return true;
823 } else {
824 return false;
825 }
826 }
827
828 protected function buildUFC(UserFilterBuilder &$ufb)
829 {
830 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
831 }
832 }
833 // }}}
834
835 // {{{ class UFBF_JobTerms
836 class UFBF_JobTerms extends UFBF_Index
837 {
838 protected function buildUFC(UserFilterBuilder &$ufb)
839 {
840 return new UFC_Job_Terms($this->val);
841 }
842 }
843 // }}}
844
845 // {{{ class UFBF_JobDescription
846 class UFBF_JobDescription extends UFBF_Text
847 {
848 private $onlymentorfield;
849
850 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
851 {
852 parent::__construct($envfield, $formtext);
853 $this->onlymentorfield = $onlymentorfield;
854 }
855
856 protected function buildUFC(UserFilterBuilder &$ufb)
857 {
858 if ($ufb->isOn($this->onlymentorfield)) {
859 return new UFC_Mentor_Expertise($this->val);
860 } else {
861 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
862 }
863 }
864 }
865 // }}}
866
867 // {{{ class UFBF_JobCv
868 class UFBF_JobCv extends UFBF_Text
869 {
870 private $onlymentorfield;
871
872 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
873 {
874 parent::__construct($envfield, $formtext);
875 $this->onlymentorfield = $onlymentorfield;
876 }
877
878 protected function buildUFC(UserFilterBuilder &$ufb)
879 {
880 if ($ufb->isOn($this->onlymentorfield)) {
881 return new UFC_Mentor_Expertise($this->val);
882 } else {
883 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
884 }
885 }
886 }
887 // }}}
888
889 // {{{ class UFBF_Nationality
890 class UFBF_Nationality extends UFBF_Mixed
891 {
892 protected $direnum = DirEnum::NATIONALITIES;
893
894 protected function buildUFC(UserFilterBuilder &$ufb)
895 {
896 return new UFC_Nationality($this->val);
897 }
898 }
899 // }}}
900
901 // {{{ class UFBF_Binet
902 class UFBF_Binet extends UFBF_Mixed
903 {
904 protected $direnum = DirEnum::BINETS;
905
906 protected function buildUFC(UserFilterBuilder &$ufb)
907 {
908 return new UFC_Binet($this->val);
909 }
910 }
911 // }}}
912
913 // {{{ class UFBF_Group
914 class UFBF_Group extends UFBF_Mixed
915 {
916 protected $direnum = DirEnum::GROUPESX;
917
918 protected function buildUFC(UserFilterBuilder &$ufb)
919 {
920 if (count($this->val) == 1) {
921 return new UFC_Group($this->val[0]);
922 }
923
924 $or = new PFC_Or();
925 foreach ($this->val as $grp) {
926 $or->addChild(new UFC_Group($grp));
927 }
928 return $or;
929 }
930 }
931 // }}}
932
933 // {{{ class UFBF_Section
934 class UFBF_Section extends UFBF_Index
935 {
936 protected $direnum = DirEnum::SECTIONS;
937
938 protected function buildUFC(UserFilterBuilder &$ufb)
939 {
940 return new UFC_Section($this->val);
941 }
942 }
943 // }}}
944
945 // {{{ class UFBF_EducationSchool
946 class UFBF_EducationSchool extends UFBF_Mixed
947 {
948 protected $direnum = DirEnum::EDUSCHOOLS;
949
950 protected function buildUFC(UserFilterBuilder &$ufb)
951 {
952 return new UFC_EducationSchool($this->val);
953 }
954 }
955 // }}}
956
957 // {{{ class UFBF_EducationDegree
958 class UFBF_EducationDegree extends UFBF_Mixed
959 {
960 protected $direnum = DirEnum::EDUDEGREES;
961
962 protected function buildUFC(UserFilterBuilder &$ufb)
963 {
964 return new UFC_EducationDegree($this->val);
965 }
966 }
967 // }}}
968
969 // {{{ class UFBF_EducationField
970 class UFBF_EducationField extends UFBF_Mixed
971 {
972 protected $direnum = DirEnum::EDUFIELDS;
973
974 protected function buildUFC(UserFilterBuilder &$ufb)
975 {
976 return new UFC_EducationField($this->val);
977 }
978 }
979 // }}}
980
981 // {{{ class UFBF_Comment
982 class UFBF_Comment extends UFBF_Text
983 {
984 protected function buildUFC(UserFilterBuilder &$ufb)
985 {
986 return new UFC_Comment($this->val);
987 }
988 }
989 // }}}
990
991 // {{{ class UFBF_Phone
992 class UFBF_Phone extends UFBF_Text
993 {
994 protected function buildUFC(UserFilterBuilder &$ufb)
995 {
996 return new UFC_Phone($this->val);
997 }
998 }
999 // }}}
1000
1001 // {{{ class UFBF_Networking
1002 class UFBF_Networking extends UFBF_Text
1003 {
1004 private $networktypefield;
1005 private $nwtype;
1006
1007 public function __construct($envfield, $networktypefield, $formtext = '')
1008 {
1009 parent::__construct($envfield, $formtext);
1010 $this->networktypefield = $networktypefield;
1011 }
1012
1013 public function check(UserFilterBuilder &$ufb)
1014 {
1015 if (parent::check($ufb)) {
1016 $this->nwtype = $ufb->i($this->networktypefield);
1017 return true;
1018 } else {
1019 return false;
1020 }
1021 }
1022
1023 public function buildUFC(UserFilterBuilder &$ufb)
1024 {
1025 return new UFC_Networking($this->nwtype, $this->val);
1026 }
1027 }
1028 // }}}
1029
1030 // {{{ class UFBF_Mentor
1031 class UFBF_Mentor extends UFBF_Bool
1032 {
1033 protected function buildUFC(UserFilterBuilder &$ufb)
1034 {
1035 return new UFC_Mentor();
1036 }
1037 }
1038 // }}}
1039
1040 // {{{ class UFBF_MentorCountry
1041 class UFBF_MentorCountry extends UFBF_Text
1042 {
1043 protected function buildUFC(UserFilterBuilder &$ufb)
1044 {
1045 return new UFC_Mentor_Country($this->val);
1046 }
1047 }
1048 // }}}
1049
1050 // {{{ class UFBF_Mentorterm
1051 class UFBF_MentorTerm extends UFBF_Index
1052 {
1053 protected function buildUFC(UserFilterBuilder &$ufb)
1054 {
1055 return new UFC_Mentor_Terms($this->val);
1056 }
1057 }
1058 // }}}
1059
1060 // {{{ class UFBF_MentorExpertise
1061 class UFBF_MentorExpertise extends UFBF_Text
1062 {
1063 protected function buildUFC(UserFilterBuilder &$ufb)
1064 {
1065 return new UFC_Mentor_Expertise($this->val);
1066 }
1067 }
1068 // }}}
1069
1070 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
1071 ?>