Commit | Line | Data |
---|---|---|
d9b3d712 RB |
1 | <?php |
2 | /*************************************************************************** | |
21b67462 | 3 | * Copyright (C) 2003-2010 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 | ||
21b67462 RB |
22 | require_once 'directory.enums.inc.php'; |
23 | ||
24 | // {{{ class UserFilterBuilder | |
d9b3d712 RB |
25 | class UserFilterBuilder |
26 | { | |
27 | private $envprefix; | |
28 | private $fields; | |
29 | private $valid = true; | |
30 | private $ufc = null; | |
31 | ||
32 | /** Constructor | |
33 | * @param $fields An array of UFB_Field objects | |
34 | * @param $envprefix Prefix to use for parts of the query | |
35 | */ | |
36 | public function __construct($fields, $envprefix = '') | |
37 | { | |
38 | $this->fields = $fields; | |
39 | $this->envprefix = $envprefix; | |
40 | } | |
41 | ||
42 | /** Builds the UFC; returns as soon as a field says it is invalid | |
43 | */ | |
44 | private function buildUFC() | |
45 | { | |
46 | if ($this->ufc != null) { | |
47 | return; | |
48 | } | |
49 | $this->ufc = new PFC_And(); | |
50 | ||
51 | foreach ($this->fields as $field) { | |
52 | $this->valid = $field->apply(&$this); | |
53 | if (!$this->valid) { | |
54 | return; | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | public function addCond(PlFilterCondition &$cond) | |
60 | { | |
61 | $this->ufc->addChild($cond); | |
62 | } | |
63 | ||
64 | public function isValid() | |
65 | { | |
66 | $this->buildUFC(); | |
67 | return $this->valid; | |
68 | } | |
69 | ||
70 | /** Returns the built UFC | |
71 | * @return The UFC, or PFC_False() if an error happened | |
72 | */ | |
73 | public function &getUFC() | |
74 | { | |
75 | $this->buildUFC(); | |
76 | if ($this->valid) { | |
77 | return $this->ufc; | |
78 | } else { | |
79 | return new PFC_False(); | |
80 | } | |
81 | } | |
82 | ||
83 | /** Wrappers around Env::i/s/..., to add envprefix | |
84 | */ | |
21b67462 | 85 | public function s($key, $def = '') { |
d9b3d712 RB |
86 | return trim(Env::s($this->envprefix . $key, $def)); |
87 | } | |
88 | ||
21b67462 | 89 | public function i($key, $def = 0) { |
d9b3d712 RB |
90 | return intval(trim(Env::i($this->envprefix . $key, $def))); |
91 | } | |
92 | ||
21b67462 | 93 | public function v($key, $def = null) { |
d9b3d712 RB |
94 | return Env::v($this->envprefix . $key, $def); |
95 | } | |
96 | ||
97 | public function has($key) { | |
21b67462 | 98 | return (Env::has($this->envprefix . $key) && strlen($this->s($key, '')) > 0); |
d9b3d712 | 99 | } |
d9696b0a RB |
100 | |
101 | public function isOn($key) { | |
102 | return (Env::has($this->envprefix . $key) && $this->s($key) == 'on'); | |
103 | } | |
d9b3d712 | 104 | } |
21b67462 | 105 | // }}} |
d9b3d712 | 106 | |
21b67462 RB |
107 | // {{{ class UFB_AdvancedSearch |
108 | class UFB_AdvancedSearch extends UserFilterBuilder | |
109 | { | |
110 | public function __construct($envprefix = '') | |
111 | { | |
112 | $fields = array( | |
113 | new UFBF_Name('name', 'Nom'), | |
114 | new UFBF_Promo('promo1', 'Promotion', 'egal1'), | |
115 | new UFBF_Promo('promo2', 'Promotion', 'egal2'), | |
116 | new UFBF_Sex('woman', 'Sexe'), | |
117 | new UFBF_Registered('subscriber', 'Inscrit'), | |
118 | new UFBF_Dead('alive', 'En vie'), | |
119 | ||
120 | new UFBF_Town('city', 'Ville / Code Postal'), | |
121 | new UFBF_Country('countryTxt', 'country', 'Pays'), | |
122 | new UFBF_AdminArea('region', 'Région'), | |
123 | ||
124 | new UFBF_JobCompany('entreprise', 'Entreprise'), | |
125 | new UFBF_JobSector('sector', 'Poste'), | |
126 | new UFBF_JobDescription('jobdescription', 'Fonction'), | |
127 | new UFBF_JobCv('cv', 'CV'), | |
128 | ||
129 | new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'), | |
130 | new UFBF_Binet('binetTxt', 'binet', 'Binet'), | |
131 | new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'), | |
132 | new UFBF_Section('sectionTxt', 'section', 'Section'), | |
133 | ||
134 | new UFBF_Formation('schoolTxt', 'school', "École d'application"), | |
135 | new UFBF_Diploma('diplomaTxt', 'diploma', 'Diplôme'), | |
136 | new UFBF_StudiesDomain('fieldTxt', 'field', "Domaine d'études"), | |
137 | ||
138 | new UFBF_Comment('free', 'Commentaire'), | |
139 | ); | |
140 | parent::__construct($fields, $envprefix); | |
141 | } | |
142 | } | |
143 | // }}} | |
144 | ||
145 | // {{{ class UFB_Field | |
d9b3d712 RB |
146 | abstract class UFB_Field |
147 | { | |
148 | protected $envfield; | |
149 | protected $formtext; | |
150 | ||
151 | protected $empty = false; | |
152 | protected $val = null; | |
153 | ||
154 | /** Constructor | |
155 | * @param $envfield Name of the field in the environment | |
156 | * @param $formtext User-friendly name of that field | |
157 | */ | |
158 | public function __construct($envfield, $formtext = '') | |
159 | { | |
160 | $this->envfield = $envfield; | |
161 | if ($formtext != '') { | |
162 | $this->formtext = $formtext; | |
163 | } else { | |
164 | $formtext = ucfirst($envfield); | |
165 | } | |
166 | } | |
167 | ||
168 | /** Prints the given error message to the user, and returns false | |
169 | * in order to be used as return $this->raise('ERROR'); | |
170 | * | |
171 | * All %s in the $msg will be replaced with the formtext. | |
172 | */ | |
173 | protected function raise($msg) | |
174 | { | |
175 | Platal::page()->trigError(str_replace('%s', $this->formtext, $msg)); | |
176 | return false; | |
177 | } | |
178 | ||
179 | public function apply(UserFilterBuilder &$ufb) { | |
180 | if (!$this->check($ufb)) { | |
181 | return false; | |
182 | } | |
183 | ||
184 | if (!$this->empty) { | |
185 | $ufc = $this->buildUFC($ufb); | |
186 | if ($ufc != null) { | |
187 | $ufb->addCond($ufc); | |
188 | } | |
189 | } | |
190 | return true; | |
191 | } | |
192 | ||
193 | /** Create the UFC associated to the field; won't be called | |
194 | * if the field is "empty" | |
195 | * @param &$ufb UFB to which fields must be added | |
196 | * @return UFC | |
197 | */ | |
198 | abstract protected function buildUFC(UserFilterBuilder &$ufb); | |
199 | ||
200 | /** This function is intended to run consistency checks on the value | |
201 | * @return boolean Whether the input is valid | |
202 | */ | |
203 | abstract protected function check(UserFilterBuilder &$ufb); | |
204 | } | |
21b67462 | 205 | // }}} |
d9b3d712 | 206 | |
21b67462 | 207 | // {{{ class UFBF_Text |
d9b3d712 RB |
208 | abstract class UFBF_Text extends UFB_Field |
209 | { | |
210 | private $forbiddenchars; | |
211 | private $minlength; | |
212 | private $maxlength; | |
213 | ||
214 | public function __construct($envfield, $formtext = '', $forbiddenchars = '', $minlength = 2, $maxlength = 255) | |
215 | { | |
216 | parent::__construct($envfield, $formtext); | |
217 | $this->forbiddenchars = $forbiddenchars; | |
218 | $this->minlength = $minlength; | |
219 | $this->maxlength = $maxlength; | |
220 | } | |
221 | ||
222 | protected function check(UserFilterBuilder &$ufb) | |
223 | { | |
224 | if (!$ufb->has($this->envfield)) { | |
225 | $this->empty = true; | |
226 | return true; | |
227 | } | |
228 | ||
229 | $this->val = $ufb->s($this->envfield); | |
230 | if (strlen($this->val) < $this->minlength) { | |
231 | return $this->raise("Le champ %s est trop court (minimum {$this->minlength})."); | |
232 | } else if (strlen($this->val) > $this->maxlength) { | |
233 | return $this->raise("Le champ %s est trop long (maximum {$this->maxlength})."); | |
234 | } | |
235 | return true; | |
236 | } | |
237 | } | |
21b67462 | 238 | // }}} |
d9b3d712 | 239 | |
21b67462 | 240 | // {{{ class UFBF_Range |
d9b3d712 RB |
241 | /** Subclass to use for fields which only allow integers within a range |
242 | */ | |
243 | abstract class UFBF_Range extends UFB_Field | |
244 | { | |
245 | ||
246 | private $min; | |
247 | private $max; | |
248 | ||
249 | public function __construct($envfield, $formtext = '', $min = 0, $max = 65535) | |
250 | { | |
251 | parent::__construct($envfield, $formtext); | |
252 | $this->min = $min; | |
253 | $this->max = $max; | |
254 | } | |
255 | ||
256 | protected function check(UserFilterBuilder &$ufb) | |
257 | { | |
258 | if (!$ufb->has($this->envfield)) { | |
259 | $this->empty = true; | |
260 | return true; | |
261 | } | |
262 | ||
263 | $this->val = $ufb->i($this->envfield); | |
264 | if ($this->val < $this->min) { | |
265 | return $this->raise("Le champs %s est inférieur au minimum ({$this->min})."); | |
266 | } else if ($this->val > $this->max) { | |
267 | return $this->raise("Le champ %s est supérieur au maximum ({$this->max})."); | |
268 | } | |
269 | return true; | |
270 | } | |
271 | } | |
21b67462 | 272 | // }}} |
d9b3d712 | 273 | |
21b67462 | 274 | // {{{ class UFBF_Index |
d9b3d712 RB |
275 | /** Subclass to use for indexed fields |
276 | */ | |
277 | abstract class UFBF_Index extends UFB_Field | |
278 | { | |
279 | protected function check(UserFilterBuilder &$ufb) | |
280 | { | |
281 | if (!$ufb->has($this->envfield)) { | |
282 | $this->empty = true; | |
283 | } | |
284 | return true; | |
285 | } | |
286 | } | |
21b67462 | 287 | // }}} |
d9b3d712 | 288 | |
21b67462 | 289 | // {{{ class UFBF_Enum |
d9b3d712 RB |
290 | /** Subclass to use for fields whose value must belong to a specific set of values |
291 | */ | |
292 | abstract class UFBF_Enum extends UFB_Field | |
293 | { | |
21b67462 RB |
294 | protected $allowedvalues; |
295 | ||
296 | public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false) | |
d9b3d712 RB |
297 | { |
298 | parent::__construct($envfield, $formtext); | |
299 | $this->allowedvalues = $allowedvalues; | |
21b67462 | 300 | $this->strict = $strict; |
d9b3d712 RB |
301 | } |
302 | ||
303 | protected function check(UserFilterBuilder &$ufb) | |
304 | { | |
305 | if (!$ufb->has($this->envfield)) { | |
306 | $this->empty = true; | |
307 | return true; | |
308 | } | |
309 | ||
310 | $this->val = $ufb->v($this->envfield); | |
311 | if (! in_array($this->val, $this->allowedvalues)) { | |
21b67462 RB |
312 | if ($this->strict) { |
313 | return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s."); | |
314 | } else { | |
315 | $this->empty = true; | |
316 | } | |
d9b3d712 RB |
317 | } |
318 | return true; | |
319 | } | |
320 | } | |
21b67462 | 321 | // }}} |
d9b3d712 | 322 | |
21b67462 RB |
323 | // {{{ class UFBF_Bool |
324 | abstract class UFBF_Bool extends UFB_Field | |
d9b3d712 | 325 | { |
21b67462 RB |
326 | protected function check(UserFilterBuilder &$ufb) |
327 | { | |
328 | if (!$ufb->has($this->envfield)) { | |
329 | $this->empty = true; | |
330 | return true; | |
331 | } | |
332 | ||
333 | $this->val = ($ufb->i($this->envfield) != 0); | |
334 | return true; | |
335 | } | |
336 | } | |
337 | // }}} | |
d9b3d712 | 338 | |
21b67462 RB |
339 | // {{{ class UFBF_Mixed |
340 | /** A class for building UFBFs when the user can input either a text or an ID | |
341 | */ | |
342 | abstract class UFBF_Mixed extends UFB_Field | |
343 | { | |
344 | /** Name of the DirEnum on which class is based | |
345 | */ | |
346 | protected $direnum; | |
347 | ||
348 | protected $envfieldindex; | |
349 | ||
350 | public function __construct($envfieldtext, $envfieldindex, $formtext = '') | |
d9b3d712 | 351 | { |
21b67462 RB |
352 | parent::__construct($envfieldtext, $formtext); |
353 | $this->envfieldindex = $envfieldindex; | |
d9b3d712 RB |
354 | } |
355 | ||
21b67462 | 356 | protected function check(UserFilterBuilder &$ufb) |
d9b3d712 | 357 | { |
21b67462 RB |
358 | if (!$ufb->has($this->envfieldindex) && !$ufb->has($this->envfield)) { |
359 | $this->empty = true; | |
360 | return true; | |
361 | } | |
362 | ||
363 | if ($ufb->has($this->envfieldindex)) { | |
364 | $index = $ufb->v($this->envfieldindex); | |
365 | if (is_int($index)) { | |
366 | $index = intval($index); | |
367 | } else { | |
368 | $index = strtoupper($index); | |
369 | } | |
370 | $this->val = array($index); | |
d9b3d712 | 371 | } else { |
21b67462 RB |
372 | $indexes = DirEnum::getIDs($this->direnum, $ufb->s($this->envfield), |
373 | $ufb->i('exact') ? DirEnumeration::MODE_EXACT : DirEnumeration::MODE_CONTAINS); | |
374 | if (count($indexes) == 0) { | |
375 | return false; | |
376 | } | |
377 | $this->val = $indexes; | |
d9b3d712 | 378 | } |
21b67462 | 379 | return true; |
d9b3d712 RB |
380 | } |
381 | } | |
21b67462 | 382 | // }}} |
d9b3d712 | 383 | |
21b67462 RB |
384 | // {{{ class UFBF_Name |
385 | class UFBF_Name extends UFBF_Text | |
386 | { | |
387 | protected function check(UserFilterBuilder &$ufb) | |
388 | { | |
389 | if (!parent::check($ufb)) { | |
390 | return false; | |
391 | } | |
392 | ||
393 | $this->val = preg_split('/[[:space:]]/', $this->val); | |
394 | if (count($this->val) == 0) { | |
395 | $this->empty = true; | |
396 | } | |
397 | return true; | |
398 | } | |
399 | ||
400 | protected function buildUFC(UserFilterBuilder &$ufb) | |
401 | { | |
402 | return new UFC_NameTokens($this->val, array(), $ufb->i('with_soundex'), $ufb->i('exact')); | |
403 | } | |
404 | } | |
405 | // }}} | |
406 | ||
407 | // {{{ class UFBF_Promo | |
d9b3d712 RB |
408 | class UFBF_Promo extends UFB_Field |
409 | { | |
410 | private static $validcomps = array('<', '<=', '=', '>=', '>'); | |
411 | private $comp; | |
412 | private $envfieldcomp; | |
413 | ||
414 | public function __construct($envfield, $fromtext = '', $envfieldcomp) | |
415 | { | |
416 | parent::__construct($envfield, $fromtext); | |
417 | $this->envfieldcomp = $envfieldcomp; | |
418 | } | |
419 | ||
420 | protected function check(UserFilterBuilder &$ufb) | |
421 | { | |
422 | if (!$ufb->has($this->envfield) || !$ufb->has($this->envfieldcomp)) { | |
423 | $this->empty = true; | |
424 | return true; | |
425 | } | |
426 | ||
427 | $this->val = $ubf->i($this->envfield); | |
428 | $this->comp = $ubf->v($this->envfieldcomp); | |
429 | ||
430 | if (!in_array($this->comp, self::$validcomps)) { | |
431 | return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s"); | |
432 | } | |
433 | ||
434 | if (preg_match('/^[0-9]{2}$/', $this->val)) { | |
435 | $this->val += 1900; | |
436 | } | |
437 | if ($this->val < 1900 || $this->val > 9999) { | |
438 | return $this->raise("Le champ %s doit être une année à 4 chiffres."); | |
439 | } | |
440 | return true; | |
441 | } | |
442 | ||
443 | protected function buildUFC(UserFilterBuilder &$ufb) { | |
444 | return new UFC_Promo($this->comp, UserFilter::DISPLAY, 'X' . $this->val); | |
445 | } | |
446 | } | |
21b67462 RB |
447 | // }}} |
448 | ||
449 | // {{{ class UFBF_Sex | |
450 | class UFBF_Sex extends UFBF_Enum | |
451 | { | |
452 | public function __construct($envfield, $formtext = '') | |
453 | { | |
454 | parent::__construct($envfield, $formtext, array(1, 2)); | |
455 | } | |
456 | ||
457 | private static function getVal($id) | |
458 | { | |
459 | switch($id) { | |
460 | case 1: | |
461 | return User::GENDER_MALE; | |
462 | break; | |
463 | case 2: | |
464 | return User::GENDER_FEMALE; | |
465 | break; | |
466 | } | |
467 | } | |
468 | ||
469 | protected function buildUFC(UserFilterBuilder &$ufb) | |
470 | { | |
471 | return new UFC_Sex(self::getVal($this->val)); | |
472 | } | |
473 | } | |
474 | // }}} | |
475 | ||
476 | // {{{ class UFBF_Registered | |
477 | class UFBF_Registered extends UFBF_Enum | |
478 | { | |
479 | public function __construct($envfield, $formtext = '') | |
480 | { | |
481 | parent::__construct($envfield, $formtext, array(1, 2)); | |
482 | } | |
483 | ||
484 | protected function buildUFC(UserFilterBuilder &$ufb) | |
485 | { | |
486 | if ($this->val == 1) { | |
487 | return new UFC_Registered(); | |
488 | } else if ($this->val == 2) { | |
489 | return new PFC_Not(UFC_Registered()); | |
490 | } | |
491 | } | |
492 | } | |
493 | // }}} | |
d9b3d712 | 494 | |
21b67462 RB |
495 | // {{{ class UFBF_Dead |
496 | class UFBF_Dead extends UFBF_Enum | |
497 | { | |
498 | public function __construct($envfield, $formtext = '') | |
499 | { | |
500 | parent::__construct($envfield, $formtext, array(1, 2)); | |
501 | } | |
502 | ||
503 | protected function buildUFC(UserFilterBuilder &$ufb) | |
504 | { | |
505 | if ($this->val == 1) { | |
506 | return new PFC_Not(UFC_Dead()); | |
507 | } else if ($this->val == 2) { | |
508 | return new UFC_Dead(); | |
509 | } | |
510 | } | |
511 | } | |
512 | // }}} | |
513 | ||
514 | // {{{ class UFBF_Town | |
515 | /** Retrieves a town, either from a postal code or a town name | |
516 | */ | |
517 | class UFBF_Town extends UFBF_Text | |
518 | { | |
519 | const TYPE_TEXT = 1; | |
520 | const TYPE_ZIP = 2; | |
521 | const TYPE_ANY = 3; | |
522 | ||
523 | private $type; | |
d9696b0a RB |
524 | private $onlycurrentfield; |
525 | ||
526 | public function __construct($envfield, $formtext = '', $type = self::TYPE_ANY, $onlycurrentfield = 'only_current') | |
21b67462 RB |
527 | { |
528 | $this->type = $type; | |
d9696b0a | 529 | $this->onlycurrentfield = $onlycurrentfield; |
21b67462 RB |
530 | parent::__construct($envfield, $formtext, '', 2, 30); |
531 | } | |
532 | ||
533 | protected function buildUFC(UserFilterBuilder &$ufb) | |
534 | { | |
d9696b0a RB |
535 | if ($ufb->isOn($this->onlycurrentfield)) { |
536 | $flags = UFC_Address::FLAG_CURRENT; | |
537 | } else { | |
538 | $flags = UFC_Address::FLAG_ANY; | |
539 | } | |
540 | ||
21b67462 RB |
541 | if (preg_match('/[0-9]/', $this->val)) { |
542 | if ($this->type & self::TYPE_ZIP) { | |
d9696b0a | 543 | return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags); |
21b67462 RB |
544 | } else { |
545 | return new PFC_False(); | |
546 | } | |
547 | } else { | |
d9696b0a RB |
548 | $byname = new UFC_AddressText(null, UFC_Address::CONTAINS, UFC_Address::TYPE_ANY, $flags, null, $this->val); |
549 | $byzip = new UFC_AddressField($this->val, UFC_AddressField::FIELD_ZIPCODE, UFC_Address::TYPE_ANY, $flags); | |
21b67462 RB |
550 | if ($this->type & self::TYPE_ANY) { |
551 | return new PFC_Or($byname, $byzip); | |
552 | } else if ($this->type & self::TYPE_TEXT) { | |
553 | return $byname; | |
554 | } else { | |
555 | return $byzip; | |
556 | } | |
557 | } | |
558 | } | |
559 | } | |
560 | // }}} | |
561 | ||
562 | // {{{ class UFBF_Country | |
563 | class UFBF_Country extends UFBF_Mixed | |
564 | { | |
565 | protected $direnum = DirEnum::COUNTRIES; | |
d9696b0a RB |
566 | protected $onlycurrentfield; |
567 | ||
568 | public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current') | |
569 | { | |
570 | parent::__construct($envfieldtext, $envfieldindex, $formtext); | |
571 | $this->onlycurrentfield = $onlycurrentfield; | |
572 | } | |
21b67462 RB |
573 | |
574 | protected function buildUFC(UserFilterBuilder &$ufb) | |
575 | { | |
d9696b0a RB |
576 | if ($ufb->isOn($this->onlycurrentfield)) { |
577 | $flags = UFC_Address::FLAG_CURRENT; | |
578 | } else { | |
579 | $flags = UFC_Address::FLAG_ANY; | |
580 | } | |
581 | ||
582 | return new UFC_AddressField($this->val, UFC_AddressField::FIELD_COUNTRY, UFC_Address::TYPE_ANY, $flags); | |
21b67462 RB |
583 | } |
584 | } | |
585 | // }}} | |
586 | ||
587 | // {{{ class UFBF_AdminArea | |
588 | class UFBF_AdminArea extends UFBF_Mixed | |
589 | { | |
590 | protected $direnum = DirEnum::ADMINAREAS; | |
d9696b0a RB |
591 | protected $onlycurrentfield; |
592 | ||
593 | public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current') | |
594 | { | |
595 | parent::__construct($envfieldtext, $envfieldindex, $formtext); | |
596 | $this->onlycurrentfield = $onlycurrentfield; | |
597 | } | |
598 | ||
21b67462 RB |
599 | |
600 | protected function buildUFC(UserFilterBuilder &$ufb) | |
601 | { | |
d9696b0a RB |
602 | if ($ufb->isOn($this->onlycurrentfield)) { |
603 | $flags = UFC_Address::FLAG_CURRENT; | |
604 | } else { | |
605 | $flags = UFC_Address::FLAG_ANY; | |
606 | } | |
607 | ||
608 | return new UFC_AddressField($this->val, UFC_AddressField::FIELD_ADMAREA, UFC_Address::TYPE_ANY, $flags); | |
21b67462 RB |
609 | } |
610 | } | |
611 | // }}} | |
612 | ||
613 | // {{{ class UFBF_JobCompany | |
614 | class UFBF_JobCompany extends UFBF_Text | |
615 | { | |
d9696b0a RB |
616 | private $onlymentorfield; |
617 | ||
618 | public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent') | |
619 | { | |
620 | parent::__construct($envfield, $formtext); | |
621 | $this->onlymentorfield = $onlymentorfield; | |
622 | } | |
623 | ||
624 | public function check(UserFilterBuilder &$ufb) { | |
625 | if (parent::check($ufb)) { | |
626 | # No company check for mentors | |
627 | if ($ufb->isOn($this->onlymentorfield)) { | |
628 | $this->empty = true; | |
629 | } | |
630 | return true; | |
631 | } else { | |
632 | return false; | |
633 | } | |
634 | } | |
635 | ||
21b67462 RB |
636 | protected function buildUFC(UserFilterBuilder &$ufb) |
637 | { | |
638 | return new UFC_Job_Company(UFC_Job_Company::JOBNAME, $this->val); | |
639 | } | |
640 | } | |
641 | // }}} | |
642 | ||
643 | // {{{ class UFBF_JobSector | |
644 | class UFBF_JobSector extends UFBF_Mixed | |
645 | { | |
646 | protected $direnum = DirEnum::SECTORS; | |
d9696b0a RB |
647 | private $onlymentorfield; |
648 | ||
649 | public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlymentorfield = 'only_referent') | |
650 | { | |
651 | parent::__construct($envfieldtext, $envfieldindex, $formtext); | |
652 | $this->onlymentorfield = $onlymentorfield; | |
653 | } | |
21b67462 RB |
654 | |
655 | protected function buildUFC(UserFilterBuilder &$ufb) | |
656 | { | |
d9696b0a RB |
657 | if ($ufb->isOn($this->onlymentorfield)) { |
658 | return new UFC_Mentor_Sectorization($this->val, UserFilter::JOB_SUBSECTOR); | |
659 | } else { | |
660 | return new UFC_Job_Sectorization($this->val, UserFilter::JOB_SUBSUBSECTOR); | |
661 | } | |
21b67462 RB |
662 | } |
663 | } | |
664 | // }}} | |
665 | ||
666 | // {{{ class UFBF_JobDescription | |
667 | class UFBF_JobDescription extends UFBF_Text | |
668 | { | |
d9696b0a RB |
669 | private $onlymentorfield; |
670 | ||
671 | public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent') | |
672 | { | |
673 | parent::__construct($envfield, $formtext); | |
674 | $this->onlymentorfield = $onlymentorfield; | |
675 | } | |
676 | ||
21b67462 RB |
677 | protected function buildUFC(UserFilterBuilder &$ufb) |
678 | { | |
d9696b0a RB |
679 | if ($ufb->isOn($this->onlymentorfield)) { |
680 | return new UFC_Mentor_Expertise($this->val); | |
681 | } else { | |
682 | return new UFC_Job_Description($this->val, UserFilter::JOB_USERDEFINED); | |
683 | } | |
21b67462 RB |
684 | } |
685 | } | |
686 | // }}} | |
687 | ||
688 | // {{{ class UFBF_JobCv | |
689 | class UFBF_JobCv extends UFBF_Text | |
690 | { | |
d9696b0a RB |
691 | private $onlymentorfield; |
692 | ||
693 | public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent') | |
694 | { | |
695 | parent::__construct($envfield, $formtext); | |
696 | $this->onlymentorfield = $onlymentorfield; | |
697 | } | |
698 | ||
21b67462 RB |
699 | protected function buildUFC(UserFilterBuilder &$ufb) |
700 | { | |
d9696b0a RB |
701 | if ($ufb->isOn($this->onlymentorfield)) { |
702 | return new UFC_Mentor_Expertise($this->val); | |
703 | } else { | |
704 | return new UFC_Job_Description($this->val, UserFilter::JOB_CV); | |
705 | } | |
21b67462 RB |
706 | } |
707 | } | |
708 | // }}} | |
709 | ||
710 | // {{{ class UFBF_Nationality | |
711 | class UFBF_Nationality extends UFBF_Mixed | |
712 | { | |
713 | protected $direnum = DirEnum::NATIONALITIES; | |
714 | ||
715 | protected function buildUFC(UserFilterBuilder &$ufb) | |
716 | { | |
717 | return new UFC_Nationality($this->val); | |
718 | } | |
719 | } | |
720 | // }}} | |
721 | ||
722 | // {{{ class UFBF_Binet | |
723 | class UFBF_Binet extends UFBF_Mixed | |
724 | { | |
725 | protected $direnum = DirEnum::BINETS; | |
726 | ||
727 | protected function buildUFC(UserFilterBuilder &$ufb) | |
728 | { | |
729 | return new UFC_Binet($this->val); | |
730 | } | |
731 | } | |
732 | // }}} | |
733 | ||
734 | // {{{ class UFBF_Group | |
735 | class UFBF_Group extends UFBF_Mixed | |
736 | { | |
737 | protected $direnum = DirEnum::GROUPESX; | |
738 | ||
739 | protected function buildUFC(UserFilterBuilder &$ufb) | |
740 | { | |
741 | if (count($this->val) == 1) { | |
742 | return new UFC_Group($this->val[0]); | |
743 | } | |
744 | ||
745 | $or = new PFC_Or(); | |
746 | foreach ($this->val as $grp) { | |
747 | $or->addChild(new UFC_Group($grp)); | |
748 | } | |
749 | return $or; | |
750 | } | |
751 | } | |
752 | // }}} | |
753 | ||
754 | // {{{ class UFBF_Section | |
755 | class UFBF_Section extends UFBF_Index | |
756 | { | |
757 | protected $direnum = DirEnum::SECTIONS; | |
758 | ||
759 | protected function buildUFC(UserFilterBuilder &$ufb) | |
760 | { | |
761 | return new UFC_Section($this->val); | |
762 | } | |
763 | } | |
764 | // }}} | |
765 | ||
766 | // {{{ class UFBF_Formation | |
767 | class UFBF_Formation extends UFBF_Mixed | |
768 | { | |
769 | protected $direnum = DirEnum::SCHOOLS; | |
770 | ||
771 | protected function buildUFC(UserFilterBuilder &$ufb) | |
772 | { | |
773 | return new UFC_Formation($this->val); | |
774 | } | |
775 | } | |
776 | // }}} | |
777 | ||
778 | // {{{ class UFBF_Diploma | |
779 | class UFBF_Diploma extends UFBF_Mixed | |
780 | { | |
781 | protected $direnum = DirEnum::DEGREES; | |
782 | ||
783 | protected function buildUFC(UserFilterBuilder &$ufb) | |
784 | { | |
785 | return new UFC_Diploma($this->val); | |
786 | } | |
787 | } | |
788 | // }}} | |
789 | ||
790 | // {{{ class UFBF_StudiesDomain | |
791 | class UFBF_StudiesDomain extends UFBF_Mixed | |
792 | { | |
793 | protected $direnum = DirEnum::STUDIESDOMAINS; | |
794 | ||
795 | protected function buildUFC(UserFilterBuilder &$ufb) | |
796 | { | |
797 | return new UFC_StudyField($this->val); | |
798 | } | |
799 | } | |
800 | // }}} | |
801 | ||
802 | // {{{ class UFBF_Comment | |
803 | class UFBF_Comment extends UFBF_Text | |
804 | { | |
805 | protected function buildUFC(UserFilterBuilder &$ufb) | |
806 | { | |
807 | return new UFC_Comment($this->val); | |
808 | } | |
809 | } | |
810 | // }}} | |
d9b3d712 | 811 | ?> |