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