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