Fixes search on country modification.
[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'),
82f06260
SJ
354 new UFBF_AddressMixed('locality_text', 'locality', 'Ville', 'LOCALITIES'),
355 new UFBF_AddressMixed('country_text', '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
82f06260
SJ
366 new UFBF_Nationality('nationalite_text', 'nationalite', 'Nationalité'),
367 new UFBF_Binet('binet_text', 'binet', 'Binet'),
368 new UFBF_Group('groupex_text', 'groupex', 'Groupe X'),
369 new UFBF_Section('section_text', 'section', 'Section'),
21b67462 370
82f06260
SJ
371 new UFBF_EducationSchool('school_text', 'school', "École d'application"),
372 new UFBF_EducationDegree('diploma_text', 'diploma', 'Diplôme'),
373 new UFBF_EducationField('field_text', '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
95a24b8d
RB
406// {{{ class UFB_DeltaTenSearch
407class UFB_DeltaTenSearch extends UserFilterBuilder
408{
409 public function __construct($envprefix = '')
410 {
411 $fields = array(
412 new UFBF_DeltaTenMessage('deltaten_message'),
413
414 new UFBF_Town('city', 'Ville / Code Postal'),
415 new UFBF_Country('countryTxt', 'country', 'Pays'),
416 new UFBF_AdminArea('administrativearea', 'Région'),
417 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
418
419
420 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
421 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
422 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
423
424 new UFBF_JobCompany('entreprise', 'Entreprise'),
425 new UFBF_JobDescription('jobdescription', 'Fonction'),
426 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
427
428 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
429 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
430 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
431 new UFBF_Section('sectionTxt', 'section', 'Section'),
432 new UFBF_Sex('woman', 'Sexe'),
433 );
434 parent::__construct($fields, $envprefix);
435 }
436}
437// }}}
438
e21504a3
RB
439// {{{ class UFB_NewsLetter
440class UFB_NewsLetter extends UserFilterBuilder
441{
442 const FIELDS_PROMO = 'promo';
443 const FIELDS_AXID = 'axid';
444 const FIELDS_GEO = 'geo';
445
446 public function __construct($flags, $envprefix = '')
447 {
448 $fields = array();
449 if ($flags->hasFlag(self::FIELDS_PROMO)) {
99f1bdfd
SJ
450 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type');
451 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type');
e21504a3
RB
452 }
453 if ($flags->hasFlag(self::FIELDS_AXID)) {
454 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId::AX);
455 }
456 parent::__construct($fields, $envprefix);
457 }
458}
459// }}}
460
21b67462 461// {{{ class UFB_Field
d9b3d712
RB
462abstract class UFB_Field
463{
464 protected $envfield;
465 protected $formtext;
466
467 protected $empty = false;
468 protected $val = null;
469
470 /** Constructor
471 * @param $envfield Name of the field in the environment
472 * @param $formtext User-friendly name of that field
473 */
474 public function __construct($envfield, $formtext = '')
475 {
476 $this->envfield = $envfield;
477 if ($formtext != '') {
478 $this->formtext = $formtext;
479 } else {
480 $formtext = ucfirst($envfield);
481 }
482 }
483
484 /** Prints the given error message to the user, and returns false
485 * in order to be used as return $this->raise('ERROR');
486 *
487 * All %s in the $msg will be replaced with the formtext.
488 */
489 protected function raise($msg)
490 {
491 Platal::page()->trigError(str_replace('%s', $this->formtext, $msg));
492 return false;
493 }
494
26ba053e 495 public function apply(UserFilterBuilder $ufb) {
d9b3d712
RB
496 if (!$this->check($ufb)) {
497 return false;
498 }
499
1d364832 500 if (!$this->isEmpty()) {
d9b3d712
RB
501 $ufc = $this->buildUFC($ufb);
502 if ($ufc != null) {
503 $ufb->addCond($ufc);
504 }
505 }
506 return true;
507 }
508
6faa0186
RB
509 public function isEmpty()
510 {
511 return $this->empty;
512 }
513
d9b3d712
RB
514 /** Create the UFC associated to the field; won't be called
515 * if the field is "empty"
26ba053e 516 * @param $ufb UFB to which fields must be added
d9b3d712
RB
517 * @return UFC
518 */
26ba053e 519 abstract protected function buildUFC(UserFilterBuilder $ufb);
d9b3d712
RB
520
521 /** This function is intended to run consistency checks on the value
522 * @return boolean Whether the input is valid
523 */
26ba053e 524 abstract protected function check(UserFilterBuilder $ufb);
e21504a3
RB
525
526 // Simple form interface
527
528 /** Retrieve a list of env field names used by that field
529 * their values will be recorded when saving the 'search' and used to prefill the form
530 * when needed.
531 */
532 public function getEnvFieldNames()
533 {
534 return array($this->envfield);
535 }
d9b3d712 536}
21b67462 537// }}}
d9b3d712 538
21b67462 539// {{{ class UFBF_Text
d9b3d712
RB
540abstract class UFBF_Text extends UFB_Field
541{
d9b3d712
RB
542 private $minlength;
543 private $maxlength;
544
f3f800d8 545 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
d9b3d712
RB
546 {
547 parent::__construct($envfield, $formtext);
d9b3d712
RB
548 $this->minlength = $minlength;
549 $this->maxlength = $maxlength;
550 }
551
26ba053e 552 protected function check(UserFilterBuilder $ufb)
d9b3d712 553 {
0f17825b 554 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
555 $this->empty = true;
556 return true;
557 }
558
0f17825b 559 $this->val = $ufb->t($this->envfield);
d9b3d712
RB
560 if (strlen($this->val) < $this->minlength) {
561 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
562 } else if (strlen($this->val) > $this->maxlength) {
563 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
5a0b9531 564 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val)) {
f3f800d8 565 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
d9b3d712 566 }
f3f800d8 567
d9b3d712
RB
568 return true;
569 }
570}
21b67462 571// }}}
d9b3d712 572
21b67462 573// {{{ class UFBF_Range
d9b3d712
RB
574/** Subclass to use for fields which only allow integers within a range
575 */
576abstract class UFBF_Range extends UFB_Field
577{
578
579 private $min;
580 private $max;
581
582 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
583 {
584 parent::__construct($envfield, $formtext);
585 $this->min = $min;
586 $this->max = $max;
587 }
588
26ba053e 589 protected function check(UserFilterBuilder $ufb)
d9b3d712 590 {
0f17825b 591 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
592 $this->empty = true;
593 return true;
594 }
595
596 $this->val = $ufb->i($this->envfield);
597 if ($this->val < $this->min) {
598 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
599 } else if ($this->val > $this->max) {
600 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
601 }
602 return true;
603 }
604}
21b67462 605// }}}
d9b3d712 606
21b67462 607// {{{ class UFBF_Index
d9b3d712
RB
608/** Subclass to use for indexed fields
609 */
610abstract class UFBF_Index extends UFB_Field
611{
26ba053e 612 protected function check(UserFilterBuilder $ufb)
d9b3d712 613 {
0f17825b 614 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
615 $this->empty = true;
616 }
6faa0186 617 $this->val = $ufb->i($this->envfield);
d9b3d712
RB
618 return true;
619 }
620}
21b67462 621// }}}
d9b3d712 622
21b67462 623// {{{ class UFBF_Enum
d9b3d712
RB
624/** Subclass to use for fields whose value must belong to a specific set of values
625 */
626abstract class UFBF_Enum extends UFB_Field
627{
21b67462
RB
628 protected $allowedvalues;
629
630 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false)
d9b3d712
RB
631 {
632 parent::__construct($envfield, $formtext);
633 $this->allowedvalues = $allowedvalues;
21b67462 634 $this->strict = $strict;
d9b3d712
RB
635 }
636
26ba053e 637 protected function check(UserFilterBuilder $ufb)
d9b3d712 638 {
0f17825b 639 if ($ufb->blank($this->envfield)) {
d9b3d712
RB
640 $this->empty = true;
641 return true;
642 }
643
644 $this->val = $ufb->v($this->envfield);
645 if (! in_array($this->val, $this->allowedvalues)) {
21b67462
RB
646 if ($this->strict) {
647 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
648 } else {
649 $this->empty = true;
650 }
d9b3d712
RB
651 }
652 return true;
653 }
654}
21b67462 655// }}}
d9b3d712 656
21b67462
RB
657// {{{ class UFBF_Bool
658abstract class UFBF_Bool extends UFB_Field
d9b3d712 659{
26ba053e 660 protected function check(UserFilterBuilder $ufb)
21b67462 661 {
0f17825b 662 if ($ufb->blank($this->envfield)) {
21b67462
RB
663 $this->empty = true;
664 return true;
665 }
666
0f17825b 667 $this->val = $ufb->b($this->envfield);
21b67462
RB
668 return true;
669 }
670}
671// }}}
d9b3d712 672
21b67462
RB
673// {{{ class UFBF_Mixed
674/** A class for building UFBFs when the user can input either a text or an ID
675 */
676abstract class UFBF_Mixed extends UFB_Field
677{
678 /** Name of the DirEnum on which class is based
679 */
680 protected $direnum;
681
682 protected $envfieldindex;
683
684 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
d9b3d712 685 {
21b67462
RB
686 parent::__construct($envfieldtext, $formtext);
687 $this->envfieldindex = $envfieldindex;
d9b3d712
RB
688 }
689
26ba053e 690 protected function check(UserFilterBuilder $ufb)
d9b3d712 691 {
78be0329 692 if ($ufb->blank($this->envfieldindex) && !$ufb->hasAlnum($this->envfield)) {
21b67462
RB
693 $this->empty = true;
694 return true;
695 }
696
0f17825b 697 if (!$ufb->blank($this->envfieldindex)) {
21b67462
RB
698 $index = $ufb->v($this->envfieldindex);
699 if (is_int($index)) {
700 $index = intval($index);
701 } else {
702 $index = strtoupper($index);
703 }
704 $this->val = array($index);
d9b3d712 705 } else {
aab2ffdd 706 $indexes = DirEnum::getIDs($this->direnum, $ufb->t($this->envfield),
0f17825b 707 $ufb->b('exact') ? XDB::WILDCARD_EXACT : XDB::WILDCARD_CONTAINS);
21b67462
RB
708 if (count($indexes) == 0) {
709 return false;
710 }
711 $this->val = $indexes;
d9b3d712 712 }
21b67462 713 return true;
d9b3d712 714 }
e21504a3
RB
715
716 public function getEnvFieldNames()
717 {
718 return array($this->envfieldindex, $this->envfield);
719 }
d9b3d712 720}
21b67462 721// }}}
d9b3d712 722
f3f800d8 723// {{{ class UFBF_Quick
59c6cb70
RB
724class UFBF_Quick extends UFB_Field
725{
26ba053e 726 protected function check(UserFilterBuilder $ufb)
59c6cb70 727 {
0f17825b 728 if ($ufb->blank($this->envfield)) {
59c6cb70
RB
729 $this->empty = true;
730 return true;
731 }
732
0f17825b 733 $this->val = str_replace('*', '%', replace_accent($ufb->t($this->envfield)));
4b2e2074
RB
734
735 return true;
59c6cb70
RB
736 }
737
26ba053e 738 protected function buildUFC(UserFilterBuilder $ufb)
59c6cb70 739 {
59c6cb70 740
4b2e2074 741 $r = $s = $this->val;
59c6cb70
RB
742
743 /** Admin: Email, IP
744 */
745 if (S::admin() && strpos($s, '@') !== false) {
4b2e2074 746 return new UFC_Email($s);
59c6cb70 747 } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
0c457792 748 return new UFC_Ip($s);
59c6cb70
RB
749 }
750
4b2e2074
RB
751 $conds = new PFC_And();
752
59c6cb70
RB
753 /** Name
754 */
755 $s = preg_replace('!\d+!', ' ', $s);
67c3a227 756 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY);
99e44215
SJ
757 foreach ($strings as $key => $string) {
758 if (strlen($string) < 2) {
759 unset($strings[$key]);
760 }
761 }
59c6cb70
RB
762 if (count($strings) > 5) {
763 Platal::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
764 $strings = array_slice($strings, 0, 5);
765 }
766
767 if (count($strings)) {
d91f8a50 768 if (S::user() != null && S::user()->checkPerms('directory_private')) {
59c6cb70
RB
769 $flags = array();
770 } else {
771 $flags = array('public');
772 }
0f17825b 773 $exact =$ufb->b('exact');
9d590571 774 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
59c6cb70 775
4b2e2074 776 $ufb->addOrder(new UFO_Score());
59c6cb70
RB
777 }
778
779 /** Promo ranges
780 */
781 $s = preg_replace('! *- *!', '-', $r);
782 $s = preg_replace('!([<>]) *!', ' \1', $s);
67c3a227 783 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
59c6cb70 784 $s = preg_replace('![<>\-] !', '', $s);
936feeaf
SJ
785 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY);
786 $grades = array('' => UserFilter::GRADE_ING, 'x' => UserFilter::GRADE_ING, 'm' => UserFilter::GRADE_MST, 'd' => UserFilter::GRADE_PHD);
59c6cb70 787 foreach ($ranges as $r) {
67c3a227 788 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
936feeaf 789 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
67c3a227
SJ
790 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
791 $p1 = min(intval($matches[2]), intval($matches[3]));
792 $p2 = max(intval($matches[2]), intval($matches[3]));
793 $conds->addChild(new PFC_And(
794 new UFC_Promo('>=', $grades[$matches[1]], $p1),
795 new UFC_Promo('<=', $grades[$matches[1]], $p2)
796 ));
797 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 798 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
67c3a227 799 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
936feeaf 800 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
59c6cb70
RB
801 }
802 }
803
804 /** Phone number
805 */
67c3a227 806 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
59c6cb70 807 $t = preg_replace('![<>\- ]!', '', $t);
67c3a227 808 if (strlen($t) > 4) {
59c6cb70
RB
809 $conds->addChild(new UFC_Phone($t));
810 }
811
812 return $conds;
813 }
814}
815// }}}
816
0f567f55
RB
817// {{{ class UFBF_SchoolIds
818class UFBF_SchoolIds extends UFB_Field
819{
820 // One of UFC_SchoolId types
821 protected $type;
e21504a3
RB
822 protected $reversed_envfield;
823 protected $reversed = false;
0f567f55 824
e21504a3 825 public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX, $reversed_envfield = '')
0f567f55
RB
826 {
827 parent::__construct($envfield, $formtext);
828 $this->type = $type;
e21504a3
RB
829 if ($reversed_envfield == '') {
830 $reversed_envfield = $envfield . '_reversed';
831 }
832 $this->reversed_envfield = $reversed_envfield;
0f567f55
RB
833 }
834
26ba053e 835 protected function check(UserFilterBuilder $ufb)
0f567f55
RB
836 {
837 if ($ufb->blank($this->envfield)) {
838 $this->empty = true;
839 return true;
840 }
841
842 $value = $ufb->t($this->envfield);
91b9255b 843 $values = explode("\r\n", $value);
0f567f55
RB
844 $ids = array();
845 foreach ($values as $val) {
846 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
847 $ids[] = $val;
848 }
849 }
850 if (count($ids) == 0) {
851 return $this->raise("Le champ %s ne contient aucune valeur valide.");
852 }
853
e21504a3 854 $this->reversed = $ufb->b($this->reversed_envfield);
0f567f55
RB
855 $this->val = $ids;
856 return true;
857 }
858
26ba053e 859 protected function buildUFC(UserFilterBuilder $ufb)
0f567f55 860 {
e21504a3
RB
861 $ufc = new UFC_SchoolId($this->type, $this->val);
862 if ($this->reversed) {
863 return new PFC_Not($ufc);
864 } else {
865 return $ufc;
866 }
0f567f55
RB
867 }
868}
869// }}}
870
21b67462
RB
871// {{{ class UFBF_Name
872class UFBF_Name extends UFBF_Text
873{
5600b2fe
SJ
874 private $envfieldtype;
875 private $type;
876
877 public function __construct($envfield, $formtext = '', $envfieldtype)
878 {
879 parent::__construct($envfield, $formtext);
880 $this->envfieldtype = $envfieldtype;
881 }
882
26ba053e 883 protected function check(UserFilterBuilder $ufb)
21b67462
RB
884 {
885 if (!parent::check($ufb)) {
886 return false;
887 }
888
5ed1cce8
RB
889 require_once 'name.func.inc.php';
890
891 $this->val = split_name_for_search($this->val);
21b67462
RB
892 if (count($this->val) == 0) {
893 $this->empty = true;
894 }
5600b2fe
SJ
895 $this->type = $ufb->v($this->envfieldtype);
896 if (!in_array($this->type, array('', 'lastname', 'firstname', 'nickname'))) {
897 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
898 }
21b67462
RB
899 return true;
900 }
901
26ba053e 902 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 903 {
5600b2fe
SJ
904 return new UFC_NameTokens($this->val, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type);
905 }
906
907 public function getEnvFieldNames()
908 {
909 return array($this->envfield, $this->envfieldtype);
21b67462
RB
910 }
911}
912// }}}
913
914// {{{ class UFBF_Promo
d9b3d712
RB
915class UFBF_Promo extends UFB_Field
916{
917 private static $validcomps = array('<', '<=', '=', '>=', '>');
e4937ecc 918 private static $validtypes = array(UserFilter::GRADE_ING, UserFilter::GRADE_PHD, UserFilter::GRADE_MST);
d9b3d712 919 private $comp;
e4937ecc 920 private $type;
d9b3d712 921 private $envfieldcomp;
e4937ecc 922 private $envfieldtype;
d9b3d712 923
e4937ecc 924 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
d9b3d712 925 {
e21504a3 926 parent::__construct($envfield, $formtext);
d9b3d712 927 $this->envfieldcomp = $envfieldcomp;
e4937ecc 928 $this->envfieldtype = $envfieldtype;
d9b3d712
RB
929 }
930
26ba053e 931 protected function check(UserFilterBuilder $ufb)
d9b3d712 932 {
e4937ecc 933 if ($ufb->blank($this->envfield) || $ufb->blank($this->envfieldcomp) || $ufb->blank($this->envfieldtype)) {
d9b3d712
RB
934 $this->empty = true;
935 return true;
936 }
937
9e6b7376
RB
938 $this->val = $ufb->i($this->envfield);
939 $this->comp = $ufb->v($this->envfieldcomp);
e4937ecc
SJ
940 $this->type = $ufb->v($this->envfieldtype);
941
942 if (!in_array($this->type, self::$validtypes)) {
943 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
944 }
d9b3d712
RB
945
946 if (!in_array($this->comp, self::$validcomps)) {
947 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
948 }
949
950 if (preg_match('/^[0-9]{2}$/', $this->val)) {
951 $this->val += 1900;
952 }
953 if ($this->val < 1900 || $this->val > 9999) {
954 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
955 }
956 return true;
957 }
958
26ba053e 959 protected function buildUFC(UserFilterBuilder $ufb) {
e4937ecc 960 return new UFC_Promo($this->comp, $this->type, $this->val);
d9b3d712 961 }
e21504a3
RB
962
963 public function getEnvFieldNames()
964 {
e4937ecc 965 return array($this->envfield, $this->envfieldcomp, $this->envfieldtype);
e21504a3 966 }
d9b3d712 967}
21b67462
RB
968// }}}
969
970// {{{ class UFBF_Sex
971class UFBF_Sex extends UFBF_Enum
972{
973 public function __construct($envfield, $formtext = '')
974 {
975 parent::__construct($envfield, $formtext, array(1, 2));
976 }
977
978 private static function getVal($id)
979 {
980 switch($id) {
981 case 1:
982 return User::GENDER_MALE;
983 break;
984 case 2:
985 return User::GENDER_FEMALE;
986 break;
987 }
988 }
989
26ba053e 990 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
991 {
992 return new UFC_Sex(self::getVal($this->val));
993 }
994}
995// }}}
996
78a47eb4
RB
997// {{{ class UFBF_NotRegistered
998// Simple field for selecting only alive, not registered users (for quick search)
999class UFBF_NotRegistered extends UFBF_Bool
1000{
26ba053e 1001 protected function buildUFC(UserFilterBuilder $ufb)
78a47eb4
RB
1002 {
1003 if ($this->val) {
1004 return new PFC_And(
1005 new PFC_Not(new UFC_Dead()),
1006 new PFC_Not(new UFC_Registered())
1007 );
1008 }
1009 }
1010}
1011// }}}
1012
21b67462
RB
1013// {{{ class UFBF_Registered
1014class UFBF_Registered extends UFBF_Enum
1015{
1016 public function __construct($envfield, $formtext = '')
1017 {
1018 parent::__construct($envfield, $formtext, array(1, 2));
1019 }
1020
26ba053e 1021 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1022 {
1023 if ($this->val == 1) {
1024 return new UFC_Registered();
1025 } else if ($this->val == 2) {
e637cb69 1026 return new PFC_Not(new UFC_Registered());
21b67462
RB
1027 }
1028 }
1029}
1030// }}}
d9b3d712 1031
c10e9a24
SJ
1032// {{{ class UFBF_HasEmailRedirect
1033class UFBF_HasEmailRedirect extends UFBF_Enum
1034{
1035 public function __construct($envfield, $formtext = '')
1036 {
1037 parent::__construct($envfield, $formtext, array(1, 2));
1038 }
1039
1040 protected function buildUFC(UserFilterBuilder $ufb)
1041 {
1042 if ($this->val == 1) {
1043 return new UFC_HasEmailRedirect();
1044 } else if ($this->val == 2) {
1045 return new PFC_Not(new UFC_HasEmailRedirect());
1046 }
1047 }
1048}
1049// }}}
1050
21b67462
RB
1051// {{{ class UFBF_Dead
1052class UFBF_Dead extends UFBF_Enum
1053{
1054 public function __construct($envfield, $formtext = '')
1055 {
1056 parent::__construct($envfield, $formtext, array(1, 2));
1057 }
1058
26ba053e 1059 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1060 {
1061 if ($this->val == 1) {
2d9951d8 1062 return new PFC_Not(new UFC_Dead());
21b67462
RB
1063 } else if ($this->val == 2) {
1064 return new UFC_Dead();
1065 }
1066 }
1067}
1068// }}}
1069
3a2985f9
SJ
1070// {{{ class UFBF_AddressMixed
1071class UFBF_AddressMixed extends UFBF_Mixed
21b67462 1072{
d9696b0a
RB
1073 protected $onlycurrentfield;
1074
3a2985f9 1075 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
d9696b0a
RB
1076 {
1077 parent::__construct($envfieldtext, $envfieldindex, $formtext);
1078 $this->onlycurrentfield = $onlycurrentfield;
3a2985f9 1079 $this->direnum = constant('DirEnum::' . $addressfield);
d9696b0a 1080 }
21b67462 1081
26ba053e 1082 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1083 {
d9696b0a
RB
1084 if ($ufb->isOn($this->onlycurrentfield)) {
1085 $flags = UFC_Address::FLAG_CURRENT;
1086 } else {
1087 $flags = UFC_Address::FLAG_ANY;
1088 }
1089
3a2985f9 1090 return new UFC_AddressComponent($this->val, $this->envfieldindex, UFC_Address::TYPE_NON_HQ, $flags);
21b67462 1091 }
e21504a3
RB
1092
1093 public function getEnvFieldNames()
1094 {
1095 return array($this->envfield, $this->envfieldindex, $this->onlycurrentfield);
1096 }
21b67462
RB
1097}
1098// }}}
1099
3a2985f9
SJ
1100// {{{ class UFBF_AddressIndex
1101class UFBF_AddressIndex extends UFBF_Index
86ab1c8f 1102{
3a2985f9 1103 protected $direnum;
86ab1c8f
SJ
1104 protected $onlycurrentfield;
1105
3a2985f9 1106 public function __construct($envfield, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
86ab1c8f
SJ
1107 {
1108 parent::__construct($envfield, $formtext);
1109 $this->onlycurrentfield = $onlycurrentfield;
3a2985f9 1110 $this->direnum = constant('DirEnum::' . $addressfield);
86ab1c8f
SJ
1111 }
1112
1113
26ba053e 1114 protected function buildUFC(UserFilterBuilder $ufb)
86ab1c8f
SJ
1115 {
1116 if ($ufb->isOn($this->onlycurrentfield)) {
1117 $flags = UFC_Address::FLAG_CURRENT;
1118 } else {
1119 $flags = UFC_Address::FLAG_ANY;
1120 }
1121
3a2985f9 1122 return new UFC_AddressComponent($this->val, $this->envfield, UFC_Address::TYPE_NON_HQ, $flags);
21b67462 1123 }
e21504a3
RB
1124
1125 public function getEnvFieldNames()
1126 {
1127 return array($this->envfield, $this->onlycurrentfield);
1128 }
21b67462
RB
1129}
1130// }}}
1131
1132// {{{ class UFBF_JobCompany
1133class UFBF_JobCompany extends UFBF_Text
1134{
d9696b0a
RB
1135 private $onlymentorfield;
1136
1137 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1138 {
1139 parent::__construct($envfield, $formtext);
1140 $this->onlymentorfield = $onlymentorfield;
1141 }
1142
26ba053e 1143 public function check(UserFilterBuilder $ufb) {
d9696b0a
RB
1144 if (parent::check($ufb)) {
1145 # No company check for mentors
1146 if ($ufb->isOn($this->onlymentorfield)) {
1147 $this->empty = true;
1148 }
1149 return true;
1150 } else {
1151 return false;
1152 }
1153 }
1154
26ba053e 1155 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1156 {
1157 return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val);
1158 }
e21504a3
RB
1159
1160 public function getEnvFieldNames()
1161 {
1162 return array($this->envfield, $this->onlymentorfield);
1163 }
21b67462
RB
1164}
1165// }}}
1166
3ac45f10
PC
1167// {{{ class UFBF_JobTerms
1168class UFBF_JobTerms extends UFBF_Index
1169{
26ba053e 1170 protected function buildUFC(UserFilterBuilder $ufb)
3ac45f10
PC
1171 {
1172 return new UFC_Job_Terms($this->val);
1173 }
1174}
1175// }}}
1176
21b67462
RB
1177// {{{ class UFBF_JobDescription
1178class UFBF_JobDescription extends UFBF_Text
1179{
d9696b0a
RB
1180 private $onlymentorfield;
1181
1182 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1183 {
1184 parent::__construct($envfield, $formtext);
1185 $this->onlymentorfield = $onlymentorfield;
1186 }
1187
26ba053e 1188 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1189 {
d9696b0a
RB
1190 if ($ufb->isOn($this->onlymentorfield)) {
1191 return new UFC_Mentor_Expertise($this->val);
1192 } else {
1193 return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED);
1194 }
21b67462 1195 }
e21504a3
RB
1196
1197 public function getEnvFieldNames()
1198 {
1199 return array($this->envfield, $this->onlymentorfield);
1200 }
21b67462
RB
1201}
1202// }}}
1203
1204// {{{ class UFBF_JobCv
1205class UFBF_JobCv extends UFBF_Text
1206{
d9696b0a
RB
1207 private $onlymentorfield;
1208
1209 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1210 {
1211 parent::__construct($envfield, $formtext);
1212 $this->onlymentorfield = $onlymentorfield;
1213 }
1214
26ba053e 1215 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1216 {
d9696b0a
RB
1217 if ($ufb->isOn($this->onlymentorfield)) {
1218 return new UFC_Mentor_Expertise($this->val);
1219 } else {
1220 return new UFC_Job_Description($this->val, UserFilter::JOB_CV);
1221 }
21b67462 1222 }
e21504a3
RB
1223
1224 public function getEnvFieldNames()
1225 {
1226 return array($this->envfield, $this->onlymentorfield);
1227 }
21b67462
RB
1228}
1229// }}}
1230
1231// {{{ class UFBF_Nationality
1232class UFBF_Nationality extends UFBF_Mixed
1233{
1234 protected $direnum = DirEnum::NATIONALITIES;
1235
26ba053e 1236 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1237 {
1238 return new UFC_Nationality($this->val);
1239 }
1240}
1241// }}}
1242
1243// {{{ class UFBF_Binet
1244class UFBF_Binet extends UFBF_Mixed
1245{
1246 protected $direnum = DirEnum::BINETS;
1247
26ba053e 1248 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1249 {
1250 return new UFC_Binet($this->val);
1251 }
1252}
1253// }}}
1254
1255// {{{ class UFBF_Group
1256class UFBF_Group extends UFBF_Mixed
1257{
1258 protected $direnum = DirEnum::GROUPESX;
1259
26ba053e 1260 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1261 {
1262 if (count($this->val) == 1) {
1263 return new UFC_Group($this->val[0]);
1264 }
1265
1266 $or = new PFC_Or();
1267 foreach ($this->val as $grp) {
1268 $or->addChild(new UFC_Group($grp));
1269 }
1270 return $or;
1271 }
1272}
1273// }}}
1274
1275// {{{ class UFBF_Section
442f967f 1276class UFBF_Section extends UFBF_Mixed
21b67462
RB
1277{
1278 protected $direnum = DirEnum::SECTIONS;
1279
26ba053e 1280 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1281 {
1282 return new UFC_Section($this->val);
1283 }
1284}
1285// }}}
1286
fb3b6547
RB
1287// {{{ class UFBF_EducationSchool
1288class UFBF_EducationSchool extends UFBF_Mixed
21b67462 1289{
fb3b6547 1290 protected $direnum = DirEnum::EDUSCHOOLS;
21b67462 1291
26ba053e 1292 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1293 {
fb3b6547 1294 return new UFC_EducationSchool($this->val);
21b67462
RB
1295 }
1296}
1297// }}}
1298
fb3b6547
RB
1299// {{{ class UFBF_EducationDegree
1300class UFBF_EducationDegree extends UFBF_Mixed
21b67462 1301{
fb3b6547 1302 protected $direnum = DirEnum::EDUDEGREES;
21b67462 1303
26ba053e 1304 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1305 {
fb3b6547 1306 return new UFC_EducationDegree($this->val);
21b67462
RB
1307 }
1308}
1309// }}}
1310
fb3b6547
RB
1311// {{{ class UFBF_EducationField
1312class UFBF_EducationField extends UFBF_Mixed
21b67462 1313{
fb3b6547 1314 protected $direnum = DirEnum::EDUFIELDS;
21b67462 1315
26ba053e 1316 protected function buildUFC(UserFilterBuilder $ufb)
21b67462 1317 {
fb3b6547 1318 return new UFC_EducationField($this->val);
21b67462
RB
1319 }
1320}
1321// }}}
1322
00f25ab1
SJ
1323// {{{ class UFBF_OriginCorps
1324class UFBF_OriginCorps extends UFBF_Index
1325{
1326 protected $direnum = DirEnum::ORIGINCORPS;
1327
1328 protected function buildUFC(UserFilterBuilder $ufb)
1329 {
1330 return new UFC_Corps(null, $this->val, UFC_Corps::ORIGIN);
1331 }
1332}
1333// }}}
1334
1335// {{{ class UFBF_CurrentCorps
1336class UFBF_CurrentCorps extends UFBF_Index
1337{
1338 protected $direnum = DirEnum::CURRENTCORPS;
1339
1340 protected function buildUFC(UserFilterBuilder $ufb)
1341 {
1342 return new UFC_Corps(null, $this->val, UFC_Corps::CURRENT);
1343 }
1344}
1345// }}}
1346
1347// {{{ class UFBF_CorpsRank
1348class UFBF_CorpsRank extends UFBF_Index
1349{
1350 protected $direnum = DirEnum::CORPSRANKS;
1351
1352 protected function buildUFC(UserFilterBuilder $ufb)
1353 {
1354 return new UFC_Corps_Rank(null, $this->val);
1355 }
1356}
1357// }}}
1358
21b67462
RB
1359// {{{ class UFBF_Comment
1360class UFBF_Comment extends UFBF_Text
1361{
26ba053e 1362 protected function buildUFC(UserFilterBuilder $ufb)
21b67462
RB
1363 {
1364 return new UFC_Comment($this->val);
1365 }
1366}
1367// }}}
3ed7556a
RB
1368
1369// {{{ class UFBF_Phone
1370class UFBF_Phone extends UFBF_Text
1371{
26ba053e 1372 protected function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1373 {
1374 return new UFC_Phone($this->val);
1375 }
1376}
1377// }}}
1378
1379// {{{ class UFBF_Networking
1380class UFBF_Networking extends UFBF_Text
1381{
1382 private $networktypefield;
1383 private $nwtype;
1384
1385 public function __construct($envfield, $networktypefield, $formtext = '')
1386 {
1387 parent::__construct($envfield, $formtext);
1388 $this->networktypefield = $networktypefield;
1389 }
1390
26ba053e 1391 public function check(UserFilterBuilder $ufb)
3ed7556a
RB
1392 {
1393 if (parent::check($ufb)) {
1394 $this->nwtype = $ufb->i($this->networktypefield);
1395 return true;
1396 } else {
1397 return false;
1398 }
1399 }
1400
1d364832
RB
1401 public function isEmpty()
1402 {
1403 return parent::isEmpty() || $this->nwtype == 0;
1404 }
1405
26ba053e 1406 public function buildUFC(UserFilterBuilder $ufb)
3ed7556a
RB
1407 {
1408 return new UFC_Networking($this->nwtype, $this->val);
1409 }
e21504a3
RB
1410
1411 public function getEnvFieldNames()
1412 {
1413 return array($this->envfield, $this->networktypefield);
1414 }
3ed7556a
RB
1415}
1416// }}}
6faa0186 1417
96f01fba
RB
1418// {{{ class UFBF_Mentor
1419class UFBF_Mentor extends UFBF_Bool
1420{
26ba053e 1421 protected function buildUFC(UserFilterBuilder $ufb)
96f01fba
RB
1422 {
1423 return new UFC_Mentor();
1424 }
1425}
1426// }}}
1427
6faa0186 1428// {{{ class UFBF_MentorCountry
459e6f81 1429class UFBF_MentorCountry extends UFBF_Text
6faa0186 1430{
26ba053e 1431 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1432 {
1433 return new UFC_Mentor_Country($this->val);
1434 }
1435}
1436// }}}
1437
459e6f81
PC
1438// {{{ class UFBF_Mentorterm
1439class UFBF_MentorTerm extends UFBF_Index
1440{
26ba053e 1441 protected function buildUFC(UserFilterBuilder $ufb)
459e6f81
PC
1442 {
1443 return new UFC_Mentor_Terms($this->val);
1444 }
1445}
1446// }}}
1447
6faa0186
RB
1448// {{{ class UFBF_MentorExpertise
1449class UFBF_MentorExpertise extends UFBF_Text
1450{
26ba053e 1451 protected function buildUFC(UserFilterBuilder $ufb)
6faa0186
RB
1452 {
1453 return new UFC_Mentor_Expertise($this->val);
1454 }
1455}
1456// }}}
05fa89a5 1457
95a24b8d
RB
1458// {{{ class UFBF_DeltaTenMessage
1459class UFBF_DeltaTenMessage extends UFBF_Text
1460{
1461 protected function buildUFC(UserFilterBuilder $ufb)
1462 {
1463 return new UFC_DeltaTen_Message($this->val);
1464 }
1465}
1466// }}}
1467
05fa89a5 1468// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
d9b3d712 1469?>