Adapts advanced search on addresses to our new geocoding engine (gmaps v3).
[platal.git] / include / ufbuilder.inc.php
CommitLineData
d9b3d712
RB
1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 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
e21504a3
RB
22// {{{ class StoredUserFilterBuilder
23class StoredUserFilterBuilder
24{
25 // Possible stored types (currently only 'ufb' exists)
26 const TYPE_UFB = 'ufb';
27
28 protected $ufb;
29 protected $env;
30 protected $ufc;
31
26ba053e 32 public function __construct(UserFilterBuilder $ufb, PlFilterCondition $ufc = null, array $env = array())
e21504a3
RB
33 {
34 $this->ufb = $ufb;
35 $this->ufc = $ufc;
36 $this->env = $env;
37 }
38
39 public function export()
40 {
41 $export = new PlDict();
42 $export->set('type', self::TYPE_UFB);
43 $export->set('condition', $this->ufc->export());
44 $export->set('env', $this->env);
45 return $export;
46 }
47
48 public function getEnv()
49 {
50 return $this->env;
51 }
52
53 public function fillFromExport($export)
54 {
55 $export = new PlDict($export);
56 if (!$export->has('type')) {
57 throw new Exception("Missing 'type' field in export.");
58 }
59 if ($export->s('type') != self::TYPE_UFB) {
60 throw new Exception("Unknown type '$type' in export.");
61 }
62 $this->ufc = UserFilterCondition::fromExport($export->v('condition'));
63 $this->env = $export->v('env', array());
64 }
65
66 public function updateFromEnv($env)
67 {
68 $this->ufb->setFakeEnv($env);
69 if ($this->ufb->isValid()) {
70 $this->env = $env;
71 $this->ufc = $this->ufb->getUFC();
72 return true;
73 } else {
74 $this->ufb->clearFakeEnv();
75 return false;
76 }
77 }
78
79 public function refresh()
80 {
81 if ($this->isValid()) {
82 $this->ufc = $this->ufb->getUFC();
83 }
84 }
85
86 public function getUFC()
87 {
88 return $this->ufc;
89 }
90
91 public function isValid()
92 {
93 $this->ufb->setFakeEnv($this->env);
94 return $this->ufb->isValid();
95 }
96
97 public function isEmpty()
98 {
99 $this->ufb->setFakeEnv($this->env);
100 return $this->ufb->isEmpty();
101 }
102}
103// }}}
104
21b67462 105// {{{ class UserFilterBuilder
d9b3d712
RB
106class UserFilterBuilder
107{
108 private $envprefix;
109 private $fields;
110 private $valid = true;
111 private $ufc = null;
59c6cb70 112 private $orders = array();
e21504a3 113 private $fake_env = null;
d9b3d712
RB
114
115 /** Constructor
116 * @param $fields An array of UFB_Field objects
117 * @param $envprefix Prefix to use for parts of the query
118 */
119 public function __construct($fields, $envprefix = '')
120 {
121 $this->fields = $fields;
122 $this->envprefix = $envprefix;
123 }
124
e21504a3
RB
125 public function setFakeEnv($env)
126 {
127 $this->fake_env = new PlDict($env);
128 }
129
130 public function clearFakeEnv()
131 {
132 $this->fake_env = null;
133 }
134
d9b3d712
RB
135 /** Builds the UFC; returns as soon as a field says it is invalid
136 */
137 private function buildUFC()
138 {
139 if ($this->ufc != null) {
140 return;
141 }
142 $this->ufc = new PFC_And();
143
144 foreach ($this->fields as $field) {
26ba053e 145 $this->valid = $field->apply($this);
d9b3d712
RB
146 if (!$this->valid) {
147 return;
148 }
149 }
150 }
151
26ba053e 152 public function addCond(PlFilterCondition $cond)
d9b3d712
RB
153 {
154 $this->ufc->addChild($cond);
155 }
156
26ba053e 157 public function addOrder(PlFilterOrder $order)
59c6cb70
RB
158 {
159 $this->order[] = $order;
160 }
161
d9b3d712
RB
162 public function isValid()
163 {
164 $this->buildUFC();
165 return $this->valid;
166 }
167
6faa0186
RB
168 public function isEmpty()
169 {
170 $this->buildUFC();
171 foreach ($this->fields as $field) {
172 if (! $field->isEmpty()) {
173 return false;
174 }
175 }
176 return true;
177 }
178
d9b3d712
RB
179 /** Returns the built UFC
180 * @return The UFC, or PFC_False() if an error happened
181 */
3314838e 182 public function getUFC()
d9b3d712
RB
183 {
184 $this->buildUFC();
185 if ($this->valid) {
0476a1e7
RB
186 if ($this->isEmpty()) {
187 return new PFC_True();
188 } else {
189 return $this->ufc;
190 }
d9b3d712
RB
191 } else {
192 return new PFC_False();
193 }
194 }
195
59c6cb70
RB
196 /** Returns adequate orders
197 */
198 public function getOrders()
199 {
200 $this->buildUFC();
201 return $this->orders;
202 }
203
e21504a3
RB
204 public function getEnvFieldNames()
205 {
206 $fields = array();
207 foreach ($this->fields as $ufbf) {
208 $fields = array_merge($fields, $ufbf->getEnvFieldNames());
209 }
210 return array_unique($fields);
211 }
212
213 public function getEnv()
214 {
215 $values = array();
216 foreach ($this->getEnvFieldNames() as $field) {
217 if ($this->has($field)) {
218 $values[$field] = $this->v($field);
219 }
220 }
221 return $values;
222 }
223
224 public function setEnv($values)
225 {
226 foreach ($this->getEnvFieldNames() as $field) {
227 if (array_key_exists($field, $values)) {
228 Env::set($this->envprefix . $field, $values[$field]);
229 }
230 }
231 }
232
d9b3d712
RB
233 /** Wrappers around Env::i/s/..., to add envprefix
234 */
0f17825b
FB
235 public function s($key, $def = '')
236 {
e21504a3
RB
237 if ($this->fake_env) {
238 return $this->fake_env->s($key, $def);
239 } else {
240 return Env::s($this->envprefix . $key, $def);
241 }
0f17825b
FB
242 }
243
244 public function t($key, $def = '')
245 {
e21504a3
RB
246 if ($this->fake_env) {
247 return $this->fake_env->t($key, $def);
248 } else {
249 return Env::t($this->envprefix . $key, $def);
250 }
d9b3d712
RB
251 }
252
0f17825b
FB
253 public function i($key, $def = 0)
254 {
e21504a3
RB
255 if ($this->fake_env) {
256 return $this->fake_env->i($key, $def);
257 } else {
258 return Env::i($this->envprefix . $key, $def);
259 }
d9b3d712
RB
260 }
261
0f17825b
FB
262 public function v($key, $def = null)
263 {
e21504a3
RB
264 if ($this->fake_env) {
265 return $this->fake_env->v($key, $def);
266 } else {
267 return Env::v($this->envprefix . $key, $def);
268 }
d9b3d712
RB
269 }
270
0f17825b
FB
271 public function b($key, $def = false)
272 {
e21504a3
RB
273 if ($this->fake_env) {
274 return $this->fake_env->b($key, $def);
275 } else {
276 return Env::b($this->envprefix . $key, $def);
277 }
0f17825b
FB
278 }
279
280 public function has($key)
281 {
e21504a3
RB
282 if ($this->fake_env) {
283 return $this->fake_env->has($key);
284 } else {
285 return Env::has($this->envprefix . $key);
286 }
0f17825b
FB
287 }
288
289 public function blank($key, $strict = false)
290 {
e21504a3
RB
291 if ($this->fake_env) {
292 return $this->fake_env->blank($key, $strict);
293 } else {
294 return Env::blank($key, $strict);
295 }
d9b3d712 296 }
d9696b0a 297
78be0329
FB
298 public function hasAlnum($key)
299 {
300 $str = $this->s($key);
301 return preg_match('/[a-z0-9]/i', $str);
302 }
303
304 public function hasAlpha($key)
305 {
306 $str = $this->s($key);
307 return preg_match('/[a-z]/i', $str);
308 }
309
0f17825b
FB
310 public function isOn($key)
311 {
312 return $this->has($key) && $this->t($key) == 'on';
d9696b0a 313 }
d9b3d712 314}
21b67462 315// }}}
d9b3d712 316
59c6cb70
RB
317// {{{ class UFB_QuickSearch
318class UFB_QuickSearch extends UserFilterBuilder
319{
320 public function __construct($envprefix = '')
321 {
322 $fields = array(
323 new UFBF_Quick('quick', 'Recherche rapide'),
78a47eb4 324 new UFBF_NotRegistered('nonins', 'Non inscrits'),
59c6cb70
RB
325 );
326 parent::__construct($fields, $envprefix);
327 }
328}
329// }}}
330
21b67462
RB
331// {{{ class UFB_AdvancedSearch
332class UFB_AdvancedSearch extends UserFilterBuilder
333{
0f567f55
RB
334 /** Create a UFB_AdvancedSearch.
335 * @param $include_admin Whether to include 'admin-only' fields
336 * @param $include_ax Whether to include 'ax-only' fields
337 * @param $envprefix Optional prefix for form field names.
338 */
339 public function __construct($include_admin = false, $include_ax = false, $envprefix = '')
21b67462
RB
340 {
341 $fields = array(
5600b2fe 342 new UFBF_Name('name', 'Nom', 'name_type'),
e4937ecc
SJ
343 new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type'),
344 new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type'),
21b67462
RB
345 new UFBF_Sex('woman', 'Sexe'),
346 new UFBF_Registered('subscriber', 'Inscrit'),
c10e9a24 347 new UFBF_HasEmailRedirect('has_email_redirect', 'A une redirection active'),
21b67462
RB
348 new UFBF_Dead('alive', 'En vie'),
349
3a2985f9
SJ
350 new UFBF_AddressIndex('sublocality', 'Arrondissement', 'SUBLOCALITIES'),
351 new UFBF_AddressIndex('administrative_area_level_3', 'Canton', 'ADMNISTRATIVEAREAS3'),
352 new UFBF_AddressIndex('administrative_area_level_2', 'Département', 'ADMNISTRATIVEAREAS2'),
353 new UFBF_AddressIndex('administrative_area_level_1', 'Région', 'ADMNISTRATIVEAREAS1'),
354 new UFBF_AddressMixed('localityTxt', 'locality', 'Ville', 'LOCALITIES'),
355 new UFBF_AddressMixed('countryTxt', 'country', 'Pays', 'COUNTRIES'),
21b67462
RB
356
357 new UFBF_JobCompany('entreprise', 'Entreprise'),
21b67462
RB
358 new UFBF_JobDescription('jobdescription', 'Fonction'),
359 new UFBF_JobCv('cv', 'CV'),
3ac45f10 360 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
21b67462 361
00f25ab1
SJ
362 new UFBF_OriginCorps('origin_corps', 'Corps d\'origine'),
363 new UFBF_CurrentCorps('current_corps', 'Corps actuel'),
364 new UFBF_CorpsRank('corps_rank', 'Grade'),
365
21b67462
RB
366 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
367 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
368 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
369 new UFBF_Section('sectionTxt', 'section', 'Section'),
370
fb3b6547
RB
371 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
372 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
373 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
21b67462
RB
374
375 new UFBF_Comment('free', 'Commentaire'),
3ed7556a
RB
376 new UFBF_Phone('phone_number', 'Téléphone'),
377 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
96f01fba
RB
378
379 new UFBF_Mentor('only_referent', 'Référent'),
21b67462 380 );
0f567f55
RB
381
382 if ($include_admin || $include_ax) {
383 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId::AX);
384 }
385
21b67462
RB
386 parent::__construct($fields, $envprefix);
387 }
388}
389// }}}
390
6faa0186
RB
391// {{{ class UFB_MentorSearch
392class UFB_MentorSearch extends UserFilterBuilder
393{
394 public function __construct($envprefix = '')
395 {
396 $fields = array(
459e6f81
PC
397 new UFBF_MentorCountry('country'),
398 new UFBF_MentorTerm('jobterm', 'jobtermText'),
6faa0186
RB
399 new UFBF_MentorExpertise('expertise'),
400 );
401 parent::__construct($fields, $envprefix);
402 }
403}
404// }}}
405
e21504a3
RB
406// {{{ class UFB_NewsLetter
407class UFB_NewsLetter extends UserFilterBuilder
408{
409 const FIELDS_PROMO = 'promo';
410 const FIELDS_AXID = 'axid';
411 const FIELDS_GEO = 'geo';
412
413 public function __construct($flags, $envprefix = '')
414 {
415 $fields = array();
416 if ($flags->hasFlag(self::FIELDS_PROMO)) {
417 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
418 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
419 }
420 if ($flags->hasFlag(self::FIELDS_AXID)) {
421 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId::AX);
422 }
423 parent::__construct($fields, $envprefix);
424 }
425}
426// }}}
427
21b67462 428// {{{ class UFB_Field
d9b3d712
RB
429abstract class UFB_Field
430{
431 protected $envfield;
432 protected $formtext;
433
434 protected $empty = false;
435 protected $val = null;
436
437 /** Constructor
438 * @param $envfield Name of the field in the environment
439 * @param $formtext User-friendly name of that field
440 */
441 public function __construct($envfield, $formtext = '')
442 {
443 $this->envfield = $envfield;
444 if ($formtext != '') {
445 $this->formtext = $formtext;
446 } else {
447 $formtext = ucfirst($envfield);
448 }
449 }
450
451 /** Prints the given error message to the user, and returns false
452 * in order to be used as return $this->raise('ERROR');
453 *
454 * All %s in the $msg will be replaced with the formtext.
455 */
456 protected function raise($msg)
457 {
458 Platal::page()->trigError(str_replace('%s', $this->formtext, $msg));
459 return false;
460 }
461
26ba053e 462 public function apply(UserFilterBuilder $ufb) {
d9b3d712
RB
463 if (!$this->check($ufb)) {
464 return false;
465 }
466
1d364832 467 if (!$this->isEmpty()) {
d9b3d712
RB
468 $ufc = $this->buildUFC($ufb);
469 if ($ufc != null) {
470 $ufb->addCond($ufc);
471 }
472 }
473 return true;
474 }
475
6faa0186
RB
476 public function isEmpty()
477 {
478 return $this->empty;
479 }
480
d9b3d712
RB
481 /** Create the UFC associated to the field; won't be called
482 * if the field is "empty"
26ba053e 483 * @param $ufb UFB to which fields must be added
d9b3d712
RB
484 * @return UFC
485 */
26ba053e 486 abstract protected function buildUFC(UserFilterBuilder $ufb);
d9b3d712
RB
487
488 /** This function is intended to run consistency checks on the value
489 * @return boolean Whether the input is valid
490 */
26ba053e 491 abstract protected function check(UserFilterBuilder $ufb);
e21504a3
RB
492
493 // Simple form interface
494
495 /** Retrieve a list of env field names used by that field
496 * their values will be recorded when saving the 'search' and used to prefill the form
497 * when needed.
498 */
499 public function getEnvFieldNames()
500 {
501 return array($this->envfield);
502 }
d9b3d712 503}
21b67462 504// }}}
d9b3d712 505
21b67462 506// {{{ class UFBF_Text
d9b3d712
RB
507abstract class UFBF_Text extends UFB_Field
508{
d9b3d712
RB
509 private $minlength;
510 private $maxlength;
511
f3f800d8 512 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
d9b3d712
RB
513 {
514 parent::__construct($envfield, $formtext);
d9b3d712
RB
515 $this->minlength = $minlength;
516 $this->maxlength = $maxlength;
517 }
518
26ba053e 519 protected function check(UserFilterBuilder $ufb)
d9b3d712 520 {
0f17825b 521 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
522 $this->empty = true;
523 return true;
524 }
525
0f17825b 526 $this->val = $ufb->t($this->envfield);
d9b3d712
RB
527 if (strlen($this->val) < $this->minlength) {
528 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
529 } else if (strlen($this->val) > $this->maxlength) {
530 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
5a0b9531 531 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) {
f3f800d8 532 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
d9b3d712 533 }
f3f800d8 534
d9b3d712
RB
535 return true;
536 }
537}
21b67462 538// }}}
d9b3d712 539
21b67462 540// {{{ class UFBF_Range
d9b3d712
RB
541/** Subclass to use for fields which only allow integers within a range
542 */
543abstract class UFBF_Range extends UFB_Field
544{
545
546 private $min;
547 private $max;
548
549 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
550 {
551 parent::__construct($envfield, $formtext);
552 $this->min = $min;
553 $this->max = $max;
554 }
555
26ba053e 556 protected function check(UserFilterBuilder $ufb)
d9b3d712 557 {
0f17825b 558 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
559 $this->empty = true;
560 return true;
561 }
562
563 $this->val = $ufb->i($this->envfield);
564 if ($this->val < $this->min) {
565 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
566 } else if ($this->val > $this->max) {
567 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
568 }
569 return true;
570 }
571}
21b67462 572// }}}
d9b3d712 573
21b67462 574// {{{ class UFBF_Index
d9b3d712
RB
575/** Subclass to use for indexed fields
576 */
577abstract class UFBF_Index extends UFB_Field
578{
26ba053e 579 protected function check(UserFilterBuilder $ufb)
d9b3d712 580 {
0f17825b 581 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
582 $this->empty = true;
583 }
6faa0186 584 $this->val = $ufb->i($this->envfield);
d9b3d712
RB
585 return true;
586 }
587}
21b67462 588// }}}
d9b3d712 589
21b67462 590// {{{ class UFBF_Enum
d9b3d712
RB
591/** Subclass to use for fields whose value must belong to a specific set of values
592 */
593abstract class UFBF_Enum extends UFB_Field
594{
21b67462
RB
595 protected $allowedvalues;
596
597 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
598 {
599 parent::__construct($envfield, $formtext);
600 $this->allowedvalues = $allowedvalues;
21b67462 601 $this->strict = $strict;
d9b3d712
RB
602 }
603
26ba053e 604 protected function check(UserFilterBuilder $ufb)
d9b3d712 605 {
0f17825b 606 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
607 $this->empty = true;
608 return true;
609 }
610
611 $this->val = $ufb->v($this->envfield);
612 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
613 if ($this->strict) {
614 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
615 } else {
616 $this->empty = true;
617 }
d9b3d712
RB
618 }
619 return true;
620 }
621}
21b67462 622// }}}
d9b3d712 623
21b67462
RB
624// {{{ class UFBF_Bool
625abstract class UFBF_Bool extends UFB_Field
d9b3d712 626{
26ba053e 627 protected function check(UserFilterBuilder $ufb)
21b67462 628 {
0f17825b 629 if ($ufb->blank($this->envfield)) {
21b67462
RB
630 $this->empty = true;
631 return true;
632 }
633
0f17825b 634 $this->val = $ufb->b($this->envfield);
21b67462
RB
635 return true;
636 }
637}
638// }}}
d9b3d712 639
21b67462
RB
640// {{{ class UFBF_Mixed
641/** A class for building UFBFs when the user can input either a text or an ID
642 */
643abstract class UFBF_Mixed extends UFB_Field
644{
645 /** Name of the DirEnum on which class is based
646 */
647 protected $direnum;
648
649 protected $envfieldindex;
650
651 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 652 {
21b67462
RB
653 parent::__construct($envfieldtext, $formtext);
654 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
655 }
656
26ba053e 657 protected function check(UserFilterBuilder $ufb)
d9b3d712 658 {
78be0329 659 if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) {
21b67462
RB
660 $this->empty = true;
661 return true;
662 }
663
0f17825b 664 if (!$ufb->blank($this->envfieldindex)) {
21b67462
RB
665 $index = $ufb->v($this->envfieldindex);
666 if (is_int($index)) {
667 $index = intval($index);
668 } else {
669 $index = strtoupper($index);
670 }
671 $this->val = array($index);
d9b3d712 672 } else {
aab2ffdd 673 $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield),
0f17825b 674 $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS);
21b67462
RB
675 if (count($indexes) == 0) {
676 return false;
677 }
678 $this->val = $indexes;
d9b3d712 679 }
21b67462 680 return true;
d9b3d712 681 }
e21504a3
RB
682
683 public function getEnvFieldNames()
684 {
685 return array($this->envfieldindex, $this->envfield);
686 }
d9b3d712 687}
21b67462 688// }}}
d9b3d712 689
f3f800d8 690// {{{ class UFBF_Quick
59c6cb70
RB
691class UFBF_Quick extends UFB_Field
692{
26ba053e 693 protected function check(UserFilterBuilder $ufb)
59c6cb70 694 {
0f17825b 695 if ($ufb->blank($this->envfield)) {
59c6cb70
RB
696 $this->empty = true;
697 return true;
698 }
699
0f17825b 700 $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
4b2e2074
RB
701
702 return true;
59c6cb70
RB
703 }
704
26ba053e 705 protected function buildUFC(UserFilterBuilder $ufb)
59c6cb70 706 {
59c6cb70 707
4b2e2074 708 $r = $s = $this->val;
59c6cb70
RB
709
710 /** Admin: Email, IP
711 */
712 if (S::admin() && strpos($s, '@') !== false) {
4b2e2074 713 return new UFC_Email($s);
59c6cb70 714 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
0c457792 715 return new UFC_Ip($s);
59c6cb70
RB
716 }
717
4b2e2074
RB
718 $conds = new PFC_And();
719
59c6cb70
RB
720 /** Name
721 */
722 $s = preg_replace('!\d+!', ' ', $s);
67c3a227 723 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY);
99e44215
SJ
724 foreach ($strings as $key => $string) {
725 if (strlen($string) < 2) {
726 unset($strings[$key]);
727 }
728 }
59c6cb70
RB
729 if (count($strings) > 5) {
730 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
731 $strings = array_slice($strings, 0, 5);
732 }
733
734 if (count($strings)) {
d91f8a50 735 if (S::user() != null && S::user()->checkPerms('directory_private')) {
59c6cb70
RB
736 $flags = array();
737 } else {
738 $flags = array('public');
739 }
0f17825b 740 $exact =$ufb->b('exact');
9d590571 741 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
59c6cb70 742
4b2e2074 743 $ufb->addOrder(new UFO_Score());
59c6cb70
RB
744 }
745
746 /** Promo ranges
747 */
748 $s = preg_replace('! *- *!', '-', $r);
749 $s = preg_replace('!([<>]) *!', ' \1', $s);
67c3a227 750 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
59c6cb70 751 $s = preg_replace('![<>\-] !', '', $s);
936feeaf
SJ
752 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY);
753 $grades = array('' => UserFilter::GRADE_ING, 'x' => UserFilter::GRADE_ING, 'm' => UserFilter::GRADE_MST, 'd' => UserFilter::GRADE_PHD);
59c6cb70 754 foreach ($ranges as $r) {
67c3a227 755 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
936feeaf 756 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
67c3a227
SJ
757 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
758 $p1 = min(intval($matches[2]), intval($matches[3]));
759 $p2 = max(intval($matches[2]), intval($matches[3]));
760 $conds->addChild(new PFC_And(
761 new UFC_Promo('>=', $grades[$matches[1]], $p1),
762 new UFC_Promo('<=', $grades[$matches[1]], $p2)
763 ));
764 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 765 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
67c3a227 766 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 767 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
59c6cb70
RB
768 }
769 }
770
771 /** Phone number
772 */
67c3a227 773 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
59c6cb70 774 $t = preg_replace('![<>\- ]!', '', $t);
67c3a227 775 if (strlen($t) > 4) {
59c6cb70
RB
776 $conds->addChild(new UFC_Phone($t));
777 }
778
779 return $conds;
780 }
781}
782// }}}
783
0f567f55
RB
784// {{{ class UFBF_SchoolIds
785class UFBF_SchoolIds extends UFB_Field
786{
787 // One of UFC_SchoolId types
788 protected $type;
e21504a3
RB
789 protected $reversed_envfield;
790 protected $reversed = false;
0f567f55 791
e21504a3 792 public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX, $reversed_envfield = '')
0f567f55
RB
793 {
794 parent::__construct($envfield, $formtext);
795 $this->type = $type;
e21504a3
RB
796 if ($reversed_envfield == '') {
797 $reversed_envfield = $envfield . '_reversed';
798 }
799 $this->reversed_envfield = $reversed_envfield;
0f567f55
RB
800 }
801
26ba053e 802 protected function check(UserFilterBuilder $ufb)
0f567f55
RB
803 {
804 if ($ufb->blank($this->envfield)) {
805 $this->empty = true;
806 return true;
807 }
808
809 $value = $ufb->t($this->envfield);
91b9255b 810 $values = explode("\r\n", $value);
0f567f55
RB
811 $ids = array();
812 foreach ($values as $val) {
813 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
814 $ids[] = $val;
815 }
816 }
817 if (count($ids) == 0) {
818 return $this->raise("Le champ %s ne contient aucune valeur valide.");
819 }
820
e21504a3 821 $this->reversed = $ufb->b($this->reversed_envfield);
0f567f55
RB
822 $this->val = $ids;
823 return true;
824 }
825
26ba053e 826 protected function buildUFC(UserFilterBuilder $ufb)
0f567f55 827 {
e21504a3
RB
828 $ufc = new UFC_SchoolId($this->type, $this->val);
829 if ($this->reversed) {
830 return new PFC_Not($ufc);
831 } else {
832 return $ufc;
833 }
0f567f55
RB
834 }
835}
836// }}}
837
21b67462
RB
838// {{{ class UFBF_Name
839class UFBF_Name extends UFBF_Text
840{
5600b2fe
SJ
841 private $envfieldtype;
842 private $type;
843
844 public function __construct($envfield, $formtext = '', $envfieldtype)
845 {
846 parent::__construct($envfield, $formtext);
847 $this->envfieldtype = $envfieldtype;
848 }
849
26ba053e 850 protected function check(UserFilterBuilder $ufb)
21b67462
RB
851 {
852 if (!parent::check($ufb)) {
853 return false;
854 }
855
5ed1cce8
RB
856 require_once 'name.func.inc.php';
857
858 $this->val = split_name_for_search($this->val);
21b67462
RB
859 if (count($this->val) == 0) {
860 $this->empty = true;
861 }
5600b2fe
SJ
862 $this->type = $ufb->v($this->envfieldtype);
863 if (!in_array($this->type, array('', 'lastname', 'firstname', 'nickname'))) {
864 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
865 }
21b67462
RB
866 return true;
867 }
868
26ba053e 869 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 870 {
5600b2fe
SJ
871 return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type);
872 }
873
874 public function getEnvFieldNames()
875 {
876 return array($this->envfield, $this->envfieldtype);
21b67462
RB
877 }
878}
879// }}}
880
881// {{{ class UFBF_Promo
d9b3d712
RB
882class UFBF_Promo extends UFB_Field
883{
884 private static $validcomps = array('<', '<=', '=', '>=', '>');
e4937ecc 885 private static $validtypes = array(UserFilter::GRADE_ING, UserFilter::GRADE_PHD, UserFilter::GRADE_MST);
d9b3d712 886 private $comp;
e4937ecc 887 private $type;
d9b3d712 888 private $envfieldcomp;
e4937ecc 889 private $envfieldtype;
d9b3d712 890
e4937ecc 891 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
d9b3d712 892 {
e21504a3 893 parent::__construct($envfield, $formtext);
d9b3d712 894 $this->envfieldcomp = $envfieldcomp;
e4937ecc 895 $this->envfieldtype = $envfieldtype;
d9b3d712
RB
896 }
897
26ba053e 898 protected function check(UserFilterBuilder $ufb)
d9b3d712 899 {
e4937ecc 900 if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp) || $ufb->blank($this->envfieldtype)) {
d9b3d712
RB
901 $this->empty = true;
902 return true;
903 }
904
9e6b7376
RB
905 $this->val = $ufb->i($this->envfield);
906 $this->comp = $ufb->v($this->envfieldcomp);
e4937ecc
SJ
907 $this->type = $ufb->v($this->envfieldtype);
908
909 if (!in_array($this->type, self::$validtypes)) {
910 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
911 }
d9b3d712
RB
912
913 if (!in_array($this->comp, self::$validcomps)) {
914 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
915 }
916
917 if (preg_match('/^[0-9]{2}$/', $this->val)) {
918 $this->val += 1900;
919 }
920 if ($this->val < 1900 || $this->val > 9999) {
921 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
922 }
923 return true;
924 }
925
26ba053e 926 protected function buildUFC(UserFilterBuilder $ufb) {
e4937ecc 927 return new UFC_Promo($this->comp, $this->type, $this->val);
d9b3d712 928 }
e21504a3
RB
929
930 public function getEnvFieldNames()
931 {
e4937ecc 932 return array($this->envfield, $this->envfieldcomp, $this->envfieldtype);
e21504a3 933 }
d9b3d712 934}
21b67462
RB
935// }}}
936
937// {{{ class UFBF_Sex
938class UFBF_Sex extends UFBF_Enum
939{
940 public function __construct($envfield, $formtext = '')
941 {
942 parent::__construct($envfield, $formtext, array(1, 2));
943 }
944
945 private static function getVal($id)
946 {
947 switch($id) {
948 case 1:
949 return User::GENDER_MALE;
950 break;
951 case 2:
952 return User::GENDER_FEMALE;
953 break;
954 }
955 }
956
26ba053e 957 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
958 {
959 return new UFC_Sex(self::getVal($this->val));
960 }
961}
962// }}}
963
78a47eb4
RB
964// {{{ class UFBF_NotRegistered
965// Simple field for selecting only alive, not registered users (for quick search)
966class UFBF_NotRegistered extends UFBF_Bool
967{
26ba053e 968 protected function buildUFC(UserFilterBuilder $ufb)
78a47eb4
RB
969 {
970 if ($this->val) {
971 return new PFC_And(
972 new PFC_Not(new UFC_Dead()),
973 new PFC_Not(new UFC_Registered())
974 );
975 }
976 }
977}
978// }}}
979
21b67462
RB
980// {{{ class UFBF_Registered
981class UFBF_Registered extends UFBF_Enum
982{
983 public function __construct($envfield, $formtext = '')
984 {
985 parent::__construct($envfield, $formtext, array(1, 2));
986 }
987
26ba053e 988 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
989 {
990 if ($this->val == 1) {
991 return new UFC_Registered();
992 } else if ($this->val == 2) {
e637cb69 993 return new PFC_Not(new UFC_Registered());
21b67462
RB
994 }
995 }
996}
997// }}}
d9b3d712 998
c10e9a24
SJ
999// {{{ class UFBF_HasEmailRedirect
1000class UFBF_HasEmailRedirect extends UFBF_Enum
1001{
1002 public function __construct($envfield, $formtext = '')
1003 {
1004 parent::__construct($envfield, $formtext, array(1, 2));
1005 }
1006
1007 protected function buildUFC(UserFilterBuilder $ufb)
1008 {
1009 if ($this->val == 1) {
1010 return new UFC_HasEmailRedirect();
1011 } else if ($this->val == 2) {
1012 return new PFC_Not(new UFC_HasEmailRedirect());
1013 }
1014 }
1015}
1016// }}}
1017
21b67462
RB
1018// {{{ class UFBF_Dead
1019class UFBF_Dead extends UFBF_Enum
1020{
1021 public function __construct($envfield, $formtext = '')
1022 {
1023 parent::__construct($envfield, $formtext, array(1, 2));
1024 }
1025
26ba053e 1026 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1027 {
1028 if ($this->val == 1) {
2d9951d8 1029 return new PFC_Not(new UFC_Dead());
21b67462
RB
1030 } else if ($this->val == 2) {
1031 return new UFC_Dead();
1032 }
1033 }
1034}
1035// }}}
1036
3a2985f9
SJ
1037// {{{ class UFBF_AddressMixed
1038class UFBF_AddressMixed extends UFBF_Mixed
21b67462 1039{
d9696b0a
RB
1040 protected $onlycurrentfield;
1041
3a2985f9 1042 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
d9696b0a
RB
1043 {
1044 parent::__construct($envfieldtext, $envfieldindex, $formtext);
1045 $this->onlycurrentfield = $onlycurrentfield;
3a2985f9 1046 $this->direnum = constant('DirEnum::' . $addressfield);
d9696b0a 1047 }
21b67462 1048
26ba053e 1049 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1050 {
d9696b0a
RB
1051 if ($ufb->isOn($this->onlycurrentfield)) {
1052 $flags = UFC_Address::FLAG_CURRENT;
1053 } else {
1054 $flags = UFC_Address::FLAG_ANY;
1055 }
1056
3a2985f9 1057 return new UFC_AddressComponent($this->val, $this->envfieldindex, UFC_Address::TYPE_NON_HQ, $flags);
21b67462 1058 }
e21504a3
RB
1059
1060 public function getEnvFieldNames()
1061 {
1062 return array($this->envfield, $this->envfieldindex, $this->onlycurrentfield);
1063 }
21b67462
RB
1064}
1065// }}}
1066
3a2985f9
SJ
1067// {{{ class UFBF_AddressIndex
1068class UFBF_AddressIndex extends UFBF_Index
86ab1c8f 1069{
3a2985f9 1070 protected $direnum;
86ab1c8f
SJ
1071 protected $onlycurrentfield;
1072
3a2985f9 1073 public function __construct($envfield, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
86ab1c8f
SJ
1074 {
1075 parent::__construct($envfield, $formtext);
1076 $this->onlycurrentfield = $onlycurrentfield;
3a2985f9 1077 $this->direnum = constant('DirEnum::' . $addressfield);
86ab1c8f
SJ
1078 }
1079
1080
26ba053e 1081 protected function buildUFC(UserFilterBuilder $ufb)
86ab1c8f
SJ
1082 {
1083 if ($ufb->isOn($this->onlycurrentfield)) {
1084 $flags = UFC_Address::FLAG_CURRENT;
1085 } else {
1086 $flags = UFC_Address::FLAG_ANY;
1087 }
1088
3a2985f9 1089 return new UFC_AddressComponent($this->val, $this->envfield, UFC_Address::TYPE_NON_HQ, $flags);
21b67462 1090 }
e21504a3
RB
1091
1092 public function getEnvFieldNames()
1093 {
1094 return array($this->envfield, $this->onlycurrentfield);
1095 }
21b67462
RB
1096}
1097// }}}
1098
1099// {{{ class UFBF_JobCompany
1100class UFBF_JobCompany extends UFBF_Text
1101{
d9696b0a
RB
1102 private $onlymentorfield;
1103
1104 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1105 {
1106 parent::__construct($envfield, $formtext);
1107 $this->onlymentorfield = $onlymentorfield;
1108 }
1109
26ba053e 1110 public function check(UserFilterBuilder $ufb) {
d9696b0a
RB
1111 if (parent::check($ufb)) {
1112 # No company check for mentors
1113 if ($ufb->isOn($this->onlymentorfield)) {
1114 $this->empty = true;
1115 }
1116 return true;
1117 } else {
1118 return false;
1119 }
1120 }
1121
26ba053e 1122 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1123 {
1124 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
1125 }
e21504a3
RB
1126
1127 public function getEnvFieldNames()
1128 {
1129 return array($this->envfield, $this->onlymentorfield);
1130 }
21b67462
RB
1131}
1132// }}}
1133
3ac45f10
PC
1134// {{{ class UFBF_JobTerms
1135class UFBF_JobTerms extends UFBF_Index
1136{
26ba053e 1137 protected function buildUFC(UserFilterBuilder $ufb)
3ac45f10
PC
1138 {
1139 return new UFC_Job_Terms($this->val);
1140 }
1141}
1142// }}}
1143
21b67462
RB
1144// {{{ class UFBF_JobDescription
1145class UFBF_JobDescription extends UFBF_Text
1146{
d9696b0a
RB
1147 private $onlymentorfield;
1148
1149 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1150 {
1151 parent::__construct($envfield, $formtext);
1152 $this->onlymentorfield = $onlymentorfield;
1153 }
1154
26ba053e 1155 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1156 {
d9696b0a
RB
1157 if ($ufb->isOn($this->onlymentorfield)) {
1158 return new UFC_Mentor_Expertise($this->val);
1159 } else {
1160 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
1161 }
21b67462 1162 }
e21504a3
RB
1163
1164 public function getEnvFieldNames()
1165 {
1166 return array($this->envfield, $this->onlymentorfield);
1167 }
21b67462
RB
1168}
1169// }}}
1170
1171// {{{ class UFBF_JobCv
1172class UFBF_JobCv extends UFBF_Text
1173{
d9696b0a
RB
1174 private $onlymentorfield;
1175
1176 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1177 {
1178 parent::__construct($envfield, $formtext);
1179 $this->onlymentorfield = $onlymentorfield;
1180 }
1181
26ba053e 1182 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1183 {
d9696b0a
RB
1184 if ($ufb->isOn($this->onlymentorfield)) {
1185 return new UFC_Mentor_Expertise($this->val);
1186 } else {
1187 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
1188 }
21b67462 1189 }
e21504a3
RB
1190
1191 public function getEnvFieldNames()
1192 {
1193 return array($this->envfield, $this->onlymentorfield);
1194 }
21b67462
RB
1195}
1196// }}}
1197
1198// {{{ class UFBF_Nationality
1199class UFBF_Nationality extends UFBF_Mixed
1200{
1201 protected $direnum = DirEnum::NATIONALITIES;
1202
26ba053e 1203 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1204 {
1205 return new UFC_Nationality($this->val);
1206 }
1207}
1208// }}}
1209
1210// {{{ class UFBF_Binet
1211class UFBF_Binet extends UFBF_Mixed
1212{
1213 protected $direnum = DirEnum::BINETS;
1214
26ba053e 1215 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1216 {
1217 return new UFC_Binet($this->val);
1218 }
1219}
1220// }}}
1221
1222// {{{ class UFBF_Group
1223class UFBF_Group extends UFBF_Mixed
1224{
1225 protected $direnum = DirEnum::GROUPESX;
1226
26ba053e 1227 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1228 {
1229 if (count($this->val) == 1) {
1230 return new UFC_Group($this->val[0]);
1231 }
1232
1233 $or = new PFC_Or();
1234 foreach ($this->val as $grp) {
1235 $or->addChild(new UFC_Group($grp));
1236 }
1237 return $or;
1238 }
1239}
1240// }}}
1241
1242// {{{ class UFBF_Section
442f967f 1243class UFBF_Section extends UFBF_Mixed
21b67462
RB
1244{
1245 protected $direnum = DirEnum::SECTIONS;
1246
26ba053e 1247 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1248 {
1249 return new UFC_Section($this->val);
1250 }
1251}
1252// }}}
1253
fb3b6547
RB
1254// {{{ class UFBF_EducationSchool
1255class UFBF_EducationSchool extends UFBF_Mixed
21b67462 1256{
fb3b6547 1257 protected $direnum = DirEnum::EDUSCHOOLS;
21b67462 1258
26ba053e 1259 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1260 {
fb3b6547 1261 return new UFC_EducationSchool($this->val);
21b67462
RB
1262 }
1263}
1264// }}}
1265
fb3b6547
RB
1266// {{{ class UFBF_EducationDegree
1267class UFBF_EducationDegree extends UFBF_Mixed
21b67462 1268{
fb3b6547 1269 protected $direnum = DirEnum::EDUDEGREES;
21b67462 1270
26ba053e 1271 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1272 {
fb3b6547 1273 return new UFC_EducationDegree($this->val);
21b67462
RB
1274 }
1275}
1276// }}}
1277
fb3b6547
RB
1278// {{{ class UFBF_EducationField
1279class UFBF_EducationField extends UFBF_Mixed
21b67462 1280{
fb3b6547 1281 protected $direnum = DirEnum::EDUFIELDS;
21b67462 1282
26ba053e 1283 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1284 {
fb3b6547 1285 return new UFC_EducationField($this->val);
21b67462
RB
1286 }
1287}
1288// }}}
1289
00f25ab1
SJ
1290// {{{ class UFBF_OriginCorps
1291class UFBF_OriginCorps extends UFBF_Index
1292{
1293 protected $direnum = DirEnum::ORIGINCORPS;
1294
1295 protected function buildUFC(UserFilterBuilder $ufb)
1296 {
1297 return new UFC_Corps(null, $this->val, UFC_Corps::ORIGIN);
1298 }
1299}
1300// }}}
1301
1302// {{{ class UFBF_CurrentCorps
1303class UFBF_CurrentCorps extends UFBF_Index
1304{
1305 protected $direnum = DirEnum::CURRENTCORPS;
1306
1307 protected function buildUFC(UserFilterBuilder $ufb)
1308 {
1309 return new UFC_Corps(null, $this->val, UFC_Corps::CURRENT);
1310 }
1311}
1312// }}}
1313
1314// {{{ class UFBF_CorpsRank
1315class UFBF_CorpsRank extends UFBF_Index
1316{
1317 protected $direnum = DirEnum::CORPSRANKS;
1318
1319 protected function buildUFC(UserFilterBuilder $ufb)
1320 {
1321 return new UFC_Corps_Rank(null, $this->val);
1322 }
1323}
1324// }}}
1325
21b67462
RB
1326// {{{ class UFBF_Comment
1327class UFBF_Comment extends UFBF_Text
1328{
26ba053e 1329 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1330 {
1331 return new UFC_Comment($this->val);
1332 }
1333}
1334// }}}
3ed7556a
RB
1335
1336// {{{ class UFBF_Phone
1337class UFBF_Phone extends UFBF_Text
1338{
26ba053e 1339 protected function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1340 {
1341 return new UFC_Phone($this->val);
1342 }
1343}
1344// }}}
1345
1346// {{{ class UFBF_Networking
1347class UFBF_Networking extends UFBF_Text
1348{
1349 private $networktypefield;
1350 private $nwtype;
1351
1352 public function __construct($envfield, $networktypefield, $formtext = '')
1353 {
1354 parent::__construct($envfield, $formtext);
1355 $this->networktypefield = $networktypefield;
1356 }
1357
26ba053e 1358 public function check(UserFilterBuilder $ufb)
3ed7556a
RB
1359 {
1360 if (parent::check($ufb)) {
1361 $this->nwtype = $ufb->i($this->networktypefield);
1362 return true;
1363 } else {
1364 return false;
1365 }
1366 }
1367
1d364832
RB
1368 public function isEmpty()
1369 {
1370 return parent::isEmpty() || $this->nwtype == 0;
1371 }
1372
26ba053e 1373 public function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1374 {
1375 return new UFC_Networking($this->nwtype, $this->val);
1376 }
e21504a3
RB
1377
1378 public function getEnvFieldNames()
1379 {
1380 return array($this->envfield, $this->networktypefield);
1381 }
3ed7556a
RB
1382}
1383// }}}
6faa0186 1384
96f01fba
RB
1385// {{{ class UFBF_Mentor
1386class UFBF_Mentor extends UFBF_Bool
1387{
26ba053e 1388 protected function buildUFC(UserFilterBuilder $ufb)
96f01fba
RB
1389 {
1390 return new UFC_Mentor();
1391 }
1392}
1393// }}}
1394
6faa0186 1395// {{{ class UFBF_MentorCountry
459e6f81 1396class UFBF_MentorCountry extends UFBF_Text
6faa0186 1397{
26ba053e 1398 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1399 {
1400 return new UFC_Mentor_Country($this->val);
1401 }
1402}
1403// }}}
1404
459e6f81
PC
1405// {{{ class UFBF_Mentorterm
1406class UFBF_MentorTerm extends UFBF_Index
1407{
26ba053e 1408 protected function buildUFC(UserFilterBuilder $ufb)
459e6f81
PC
1409 {
1410 return new UFC_Mentor_Terms($this->val);
1411 }
1412}
1413// }}}
1414
6faa0186
RB
1415// {{{ class UFBF_MentorExpertise
1416class UFBF_MentorExpertise extends UFBF_Text
1417{
26ba053e 1418 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1419 {
1420 return new UFC_Mentor_Expertise($this->val);
1421 }
1422}
1423// }}}
05fa89a5
FB
1424
1425// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
d9b3d712 1426?>