84f354a6e90e16b188460044e2240da361f3b6ed
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class StoredUserFilterBuilder
23 class StoredUserFilterBuilder
25 // Possible stored types (currently only 'ufb' exists)
26 const TYPE_UFB
= 'ufb';
32 public function __construct(UserFilterBuilder
$ufb, PlFilterCondition
$ufc = null
, array $env = array())
39 public function export()
41 $export = new PlDict();
42 $export->set('type', self
::TYPE_UFB
);
43 $export->set('condition', $this->ufc
->export());
44 $export->set('env', $this->env
);
48 public function getEnv()
53 public function fillFromExport($export)
55 $export = new PlDict($export);
56 if (!$export->has('type')) {
57 throw new Exception("Missing 'type' field in export.");
59 if ($export->s('type') != self
::TYPE_UFB
) {
60 throw new Exception("Unknown type '$type' in export.");
62 $this->ufc
= UserFilterCondition
::fromExport($export->v('condition'));
63 $this->env
= $export->v('env', array());
66 public function updateFromEnv($env)
68 $this->ufb
->setFakeEnv($env);
69 if ($this->ufb
->isValid()) {
71 $this->ufc
= $this->ufb
->getUFC();
74 $this->ufb
->clearFakeEnv();
79 public function refresh()
81 if ($this->isValid()) {
82 $this->ufc
= $this->ufb
->getUFC();
86 public function getUFC()
91 public function isValid()
93 $this->ufb
->setFakeEnv($this->env
);
94 return $this->ufb
->isValid();
97 public function isEmpty()
99 $this->ufb
->setFakeEnv($this->env
);
100 return $this->ufb
->isEmpty();
105 // {{{ class UserFilterBuilder
106 class UserFilterBuilder
110 private $valid = true
;
112 private $orders = array();
113 private $fake_env = null
;
116 * @param $fields An array of UFB_Field objects
117 * @param $envprefix Prefix to use for parts of the query
119 public function __construct($fields, $envprefix = '')
121 $this->fields
= $fields;
122 $this->envprefix
= $envprefix;
125 public function setFakeEnv($env)
127 $this->fake_env
= new PlDict($env);
130 public function clearFakeEnv()
132 $this->fake_env
= null
;
135 /** Builds the UFC; returns as soon as a field says it is invalid
137 private function buildUFC()
139 if ($this->ufc
!= null
) {
142 $this->ufc
= new PFC_And();
144 foreach ($this->fields
as $field) {
145 $this->valid
= $field->apply($this);
152 public function addCond(PlFilterCondition
$cond)
154 $this->ufc
->addChild($cond);
157 public function addOrder(PlFilterOrder
$order)
159 $this->order
[] = $order;
162 public function isValid()
168 public function isEmpty()
171 foreach ($this->fields
as $field) {
172 if (! $field->isEmpty()) {
179 /** Returns the built UFC
180 * @return The UFC, or PFC_False() if an error happened
182 public function getUFC()
186 if ($this->isEmpty()) {
187 return new PFC_True();
192 return new PFC_False();
196 /** Returns adequate orders
198 public function getOrders()
201 return $this->orders
;
204 public function getEnvFieldNames()
207 foreach ($this->fields
as $ufbf) {
208 $fields = array_merge($fields, $ufbf->getEnvFieldNames());
210 return array_unique($fields);
213 public function getEnv()
216 foreach ($this->getEnvFieldNames() as $field) {
217 if ($this->has($field)) {
218 $values[$field] = $this->v($field);
224 public function setEnv($values)
226 foreach ($this->getEnvFieldNames() as $field) {
227 if (array_key_exists($field, $values)) {
228 Env
::set($this->envprefix
. $field, $values[$field]);
233 /** Wrappers around Env::i/s/..., to add envprefix
235 public function s($key, $def = '')
237 if ($this->fake_env
) {
238 return $this->fake_env
->s($key, $def);
240 return Env
::s($this->envprefix
. $key, $def);
244 public function t($key, $def = '')
246 if ($this->fake_env
) {
247 return $this->fake_env
->t($key, $def);
249 return Env
::t($this->envprefix
. $key, $def);
253 public function i($key, $def = 0)
255 if ($this->fake_env
) {
256 return $this->fake_env
->i($key, $def);
258 return Env
::i($this->envprefix
. $key, $def);
262 public function v($key, $def = null
)
264 if ($this->fake_env
) {
265 return $this->fake_env
->v($key, $def);
267 return Env
::v($this->envprefix
. $key, $def);
271 public function b($key, $def = false
)
273 if ($this->fake_env
) {
274 return $this->fake_env
->b($key, $def);
276 return Env
::b($this->envprefix
. $key, $def);
280 public function has($key)
282 if ($this->fake_env
) {
283 return $this->fake_env
->has($key);
285 return Env
::has($this->envprefix
. $key);
289 public function blank($key, $strict = false
)
291 if ($this->fake_env
) {
292 return $this->fake_env
->blank($key, $strict);
294 return Env
::blank($key, $strict);
298 public function hasAlnum($key)
300 $str = $this->s($key);
301 return preg_match('/[a-z0-9]/i', $str);
304 public function hasAlpha($key)
306 $str = $this->s($key);
307 return preg_match('/[a-z]/i', $str);
310 public function isOn($key)
312 return $this->has($key) && $this->t($key) == 'on';
317 // {{{ class UFB_QuickSearch
318 class UFB_QuickSearch
extends UserFilterBuilder
320 public function __construct($envprefix = '')
323 new UFBF_Quick('quick', 'Recherche rapide'),
324 new UFBF_NotRegistered('nonins', 'Non inscrits'),
326 parent
::__construct($fields, $envprefix);
331 // {{{ class UFB_AdvancedSearch
332 class UFB_AdvancedSearch
extends UserFilterBuilder
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.
339 public function __construct($include_admin = false
, $include_ax = false
, $envprefix = '')
342 new UFBF_Name('name', 'Nom', 'name_type'),
343 new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type'),
344 new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type'),
345 new UFBF_Sex('woman', 'Sexe'),
346 new UFBF_Registered('subscriber', 'Inscrit'),
347 new UFBF_HasEmailRedirect('has_email_redirect', 'A une redirection active'),
348 new UFBF_Dead('alive', 'En vie'),
350 new UFBF_AddressIndex('sublocality', 'Arrondissement', 'SUBLOCALITIES'),
351 new UFBF_AddressIndex('administrative_area_level_3', 'Canton', 'ADMNISTRATIVEAREAS3'),
352 new UFBF_AddressIndex('administrative_area_level_2', 'Département', 'ADMNISTRATIVEAREAS2'),
353 new UFBF_AddressIndex('administrative_area_level_1', 'Région', 'ADMNISTRATIVEAREAS1'),
354 new UFBF_AddressMixed('localityTxt', 'locality', 'Ville', 'LOCALITIES'),
355 new UFBF_AddressMixed('countryTxt', 'country', 'Pays', 'COUNTRIES'),
357 new UFBF_JobCompany('entreprise', 'Entreprise'),
358 new UFBF_JobDescription('jobdescription', 'Fonction'),
359 new UFBF_JobCv('cv', 'CV'),
360 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
362 new UFBF_OriginCorps('origin_corps', 'Corps d\'origine'),
363 new UFBF_CurrentCorps('current_corps', 'Corps actuel'),
364 new UFBF_CorpsRank('corps_rank', 'Grade'),
366 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
367 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
368 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
369 new UFBF_Section('sectionTxt', 'section', 'Section'),
371 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
372 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
373 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
375 new UFBF_Comment('free', 'Commentaire'),
376 new UFBF_Phone('phone_number', 'Téléphone'),
377 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
379 new UFBF_Mentor('only_referent', 'Référent'),
382 if ($include_admin ||
$include_ax) {
383 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId
::AX
);
386 parent
::__construct($fields, $envprefix);
391 // {{{ class UFB_MentorSearch
392 class UFB_MentorSearch
extends UserFilterBuilder
394 public function __construct($envprefix = '')
397 new UFBF_MentorCountry('country'),
398 new UFBF_MentorTerm('jobterm', 'jobtermText'),
399 new UFBF_MentorExpertise('expertise'),
401 parent
::__construct($fields, $envprefix);
406 // {{{ class UFB_DeltaTenSearch
407 class UFB_DeltaTenSearch
extends UserFilterBuilder
409 public function __construct($envprefix = '')
412 new UFBF_DeltaTenMessage('deltaten_message'),
414 new UFBF_Town('city', 'Ville / Code Postal'),
415 new UFBF_Country('countryTxt', 'country', 'Pays'),
416 new UFBF_AdminArea('administrativearea', 'Région'),
417 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
420 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
421 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
422 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
424 new UFBF_JobCompany('entreprise', 'Entreprise'),
425 new UFBF_JobDescription('jobdescription', 'Fonction'),
426 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
428 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
429 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
430 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
431 new UFBF_Section('sectionTxt', 'section', 'Section'),
432 new UFBF_Sex('woman', 'Sexe'),
434 parent
::__construct($fields, $envprefix);
439 // {{{ class UFB_NewsLetter
440 class UFB_NewsLetter
extends UserFilterBuilder
442 const FIELDS_PROMO
= 'promo';
443 const FIELDS_AXID
= 'axid';
444 const FIELDS_GEO
= 'geo';
446 public function __construct($flags, $envprefix = '')
449 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
450 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type');
451 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type');
453 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
454 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
456 parent
::__construct($fields, $envprefix);
461 // {{{ class UFB_Field
462 abstract class UFB_Field
467 protected $empty = false
;
468 protected $val = null
;
471 * @param $envfield Name of the field in the environment
472 * @param $formtext User-friendly name of that field
474 public function __construct($envfield, $formtext = '')
476 $this->envfield
= $envfield;
477 if ($formtext != '') {
478 $this->formtext
= $formtext;
480 $formtext = ucfirst($envfield);
484 /** Prints the given error message to the user, and returns false
485 * in order to be used as return $this->raise('ERROR');
487 * All %s in the $msg will be replaced with the formtext.
489 protected function raise($msg)
491 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
495 public function apply(UserFilterBuilder
$ufb) {
496 if (!$this->check($ufb)) {
500 if (!$this->isEmpty()) {
501 $ufc = $this->buildUFC($ufb);
509 public function isEmpty()
514 /** Create the UFC associated to the field; won't be called
515 * if the field is "empty"
516 * @param $ufb UFB to which fields must be added
519 abstract protected function buildUFC(UserFilterBuilder
$ufb);
521 /** This function is intended to run consistency checks on the value
522 * @return boolean Whether the input is valid
524 abstract protected function check(UserFilterBuilder
$ufb);
526 // Simple form interface
528 /** Retrieve a list of env field names used by that field
529 * their values will be recorded when saving the 'search' and used to prefill the form
532 public function getEnvFieldNames()
534 return array($this->envfield
);
539 // {{{ class UFBF_Text
540 abstract class UFBF_Text
extends UFB_Field
545 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
547 parent
::__construct($envfield, $formtext);
548 $this->minlength
= $minlength;
549 $this->maxlength
= $maxlength;
552 protected function check(UserFilterBuilder
$ufb)
554 if ($ufb->blank($this->envfield
)) {
559 $this->val
= $ufb->t($this->envfield
);
560 if (strlen($this->val
) < $this->minlength
) {
561 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
562 } else if (strlen($this->val
) > $this->maxlength
) {
563 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
564 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
565 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
573 // {{{ class UFBF_Range
574 /** Subclass to use for fields which only allow integers within a range
576 abstract class UFBF_Range
extends UFB_Field
582 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
584 parent
::__construct($envfield, $formtext);
589 protected function check(UserFilterBuilder
$ufb)
591 if ($ufb->blank($this->envfield
)) {
596 $this->val
= $ufb->i($this->envfield
);
597 if ($this->val
< $this->min
) {
598 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
599 } else if ($this->val
> $this->max
) {
600 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
607 // {{{ class UFBF_Index
608 /** Subclass to use for indexed fields
610 abstract class UFBF_Index
extends UFB_Field
612 protected function check(UserFilterBuilder
$ufb)
614 if ($ufb->blank($this->envfield
)) {
617 $this->val
= $ufb->i($this->envfield
);
623 // {{{ class UFBF_Enum
624 /** Subclass to use for fields whose value must belong to a specific set of values
626 abstract class UFBF_Enum
extends UFB_Field
628 protected $allowedvalues;
630 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
632 parent
::__construct($envfield, $formtext);
633 $this->allowedvalues
= $allowedvalues;
634 $this->strict
= $strict;
637 protected function check(UserFilterBuilder
$ufb)
639 if ($ufb->blank($this->envfield
)) {
644 $this->val
= $ufb->v($this->envfield
);
645 if (! in_array($this->val
, $this->allowedvalues
)) {
647 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
657 // {{{ class UFBF_Bool
658 abstract class UFBF_Bool
extends UFB_Field
660 protected function check(UserFilterBuilder
$ufb)
662 if ($ufb->blank($this->envfield
)) {
667 $this->val
= $ufb->b($this->envfield
);
673 // {{{ class UFBF_Mixed
674 /** A class for building UFBFs when the user can input either a text or an ID
676 abstract class UFBF_Mixed
extends UFB_Field
678 /** Name of the DirEnum on which class is based
682 protected $envfieldindex;
684 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
686 parent
::__construct($envfieldtext, $formtext);
687 $this->envfieldindex
= $envfieldindex;
690 protected function check(UserFilterBuilder
$ufb)
692 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
697 if (!$ufb->blank($this->envfieldindex
)) {
698 $index = $ufb->v($this->envfieldindex
);
699 if (is_int($index)) {
700 $index = intval($index);
702 $index = strtoupper($index);
704 $this->val
= array($index);
706 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
707 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
708 if (count($indexes) == 0) {
711 $this->val
= $indexes;
716 public function getEnvFieldNames()
718 return array($this->envfieldindex
, $this->envfield
);
723 // {{{ class UFBF_Quick
724 class UFBF_Quick
extends UFB_Field
726 protected function check(UserFilterBuilder
$ufb)
728 if ($ufb->blank($this->envfield
)) {
733 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
738 protected function buildUFC(UserFilterBuilder
$ufb)
741 $r = $s = $this->val
;
745 if (S
::admin() && strpos($s, '@') !== false
) {
746 return new UFC_Email($s);
747 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
748 return new UFC_Ip($s);
751 $conds = new PFC_And();
755 $s = preg_replace('!\d+!', ' ', $s);
756 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY
);
757 foreach ($strings as $key => $string) {
758 if (strlen($string) < 2) {
759 unset($strings[$key]);
762 if (count($strings) > 5) {
763 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
764 $strings = array_slice($strings, 0, 5);
767 if (count($strings)) {
768 if (S
::user() != null
&& S
::user()->checkPerms('directory_private')) {
771 $flags = array('public');
773 $exact =$ufb->b('exact');
774 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
776 $ufb->addOrder(new UFO_Score());
781 $s = preg_replace('! *- *!', '-', $r);
782 $s = preg_replace('!([<>]) *!', ' \1', $s);
783 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
784 $s = preg_replace('![<>\-] !', '', $s);
785 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY
);
786 $grades = array('' => UserFilter
::GRADE_ING
, 'x' => UserFilter
::GRADE_ING
, 'm' => UserFilter
::GRADE_MST
, 'd' => UserFilter
::GRADE_PHD
);
787 foreach ($ranges as $r) {
788 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
789 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
790 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
791 $p1 = min(intval($matches[2]), intval($matches[3]));
792 $p2 = max(intval($matches[2]), intval($matches[3]));
793 $conds->addChild(new PFC_And(
794 new UFC_Promo('>=', $grades[$matches[1]], $p1),
795 new UFC_Promo('<=', $grades[$matches[1]], $p2)
797 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
798 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
799 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
800 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
806 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
807 $t = preg_replace('![<>\- ]!', '', $t);
808 if (strlen($t) > 4) {
809 $conds->addChild(new UFC_Phone($t));
817 // {{{ class UFBF_SchoolIds
818 class UFBF_SchoolIds
extends UFB_Field
820 // One of UFC_SchoolId types
822 protected $reversed_envfield;
823 protected $reversed = false
;
825 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
827 parent
::__construct($envfield, $formtext);
829 if ($reversed_envfield == '') {
830 $reversed_envfield = $envfield . '_reversed';
832 $this->reversed_envfield
= $reversed_envfield;
835 protected function check(UserFilterBuilder
$ufb)
837 if ($ufb->blank($this->envfield
)) {
842 $value = $ufb->t($this->envfield
);
843 $values = explode("\r\n", $value);
845 foreach ($values as $val) {
846 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
850 if (count($ids) == 0) {
851 return $this->raise("Le champ %s ne contient aucune valeur valide.");
854 $this->reversed
= $ufb->b($this->reversed_envfield
);
859 protected function buildUFC(UserFilterBuilder
$ufb)
861 $ufc = new UFC_SchoolId($this->type
, $this->val
);
862 if ($this->reversed
) {
863 return new PFC_Not($ufc);
871 // {{{ class UFBF_Name
872 class UFBF_Name
extends UFBF_Text
874 private $envfieldtype;
877 public function __construct($envfield, $formtext = '', $envfieldtype)
879 parent
::__construct($envfield, $formtext);
880 $this->envfieldtype
= $envfieldtype;
883 protected function check(UserFilterBuilder
$ufb)
885 if (!parent
::check($ufb)) {
889 require_once 'name.func.inc.php';
891 $this->val
= split_name_for_search($this->val
);
892 if (count($this->val
) == 0) {
895 $this->type
= $ufb->v($this->envfieldtype
);
896 if (!in_array($this->type
, array('', 'lastname', 'firstname', 'nickname'))) {
897 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
902 protected function buildUFC(UserFilterBuilder
$ufb)
904 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type
);
907 public function getEnvFieldNames()
909 return array($this->envfield
, $this->envfieldtype
);
914 // {{{ class UFBF_Promo
915 class UFBF_Promo
extends UFB_Field
917 private static $validcomps = array('<', '<=', '=', '>=', '>');
918 private static $validtypes = array(UserFilter
::GRADE_ING
, UserFilter
::GRADE_PHD
, UserFilter
::GRADE_MST
);
921 private $envfieldcomp;
922 private $envfieldtype;
924 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
926 parent
::__construct($envfield, $formtext);
927 $this->envfieldcomp
= $envfieldcomp;
928 $this->envfieldtype
= $envfieldtype;
931 protected function check(UserFilterBuilder
$ufb)
933 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
) ||
$ufb->blank($this->envfieldtype
)) {
938 $this->val
= $ufb->i($this->envfield
);
939 $this->comp
= $ufb->v($this->envfieldcomp
);
940 $this->type
= $ufb->v($this->envfieldtype
);
942 if (!in_array($this->type
, self
::$validtypes)) {
943 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
946 if (!in_array($this->comp
, self
::$validcomps)) {
947 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
950 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
953 if ($this->val
< 1900 ||
$this->val
> 9999) {
954 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
959 protected function buildUFC(UserFilterBuilder
$ufb) {
960 return new UFC_Promo($this->comp
, $this->type
, $this->val
);
963 public function getEnvFieldNames()
965 return array($this->envfield
, $this->envfieldcomp
, $this->envfieldtype
);
970 // {{{ class UFBF_Sex
971 class UFBF_Sex
extends UFBF_Enum
973 public function __construct($envfield, $formtext = '')
975 parent
::__construct($envfield, $formtext, array(1, 2));
978 private static function getVal($id)
982 return User
::GENDER_MALE
;
985 return User
::GENDER_FEMALE
;
990 protected function buildUFC(UserFilterBuilder
$ufb)
992 return new UFC_Sex(self
::getVal($this->val
));
997 // {{{ class UFBF_NotRegistered
998 // Simple field for selecting only alive, not registered users (for quick search)
999 class UFBF_NotRegistered
extends UFBF_Bool
1001 protected function buildUFC(UserFilterBuilder
$ufb)
1005 new PFC_Not(new UFC_Dead()),
1006 new PFC_Not(new UFC_Registered())
1013 // {{{ class UFBF_Registered
1014 class UFBF_Registered
extends UFBF_Enum
1016 public function __construct($envfield, $formtext = '')
1018 parent
::__construct($envfield, $formtext, array(1, 2));
1021 protected function buildUFC(UserFilterBuilder
$ufb)
1023 if ($this->val
== 1) {
1024 return new UFC_Registered();
1025 } else if ($this->val
== 2) {
1026 return new PFC_Not(new UFC_Registered());
1032 // {{{ class UFBF_HasEmailRedirect
1033 class UFBF_HasEmailRedirect
extends UFBF_Enum
1035 public function __construct($envfield, $formtext = '')
1037 parent
::__construct($envfield, $formtext, array(1, 2));
1040 protected function buildUFC(UserFilterBuilder
$ufb)
1042 if ($this->val
== 1) {
1043 return new UFC_HasEmailRedirect();
1044 } else if ($this->val
== 2) {
1045 return new PFC_Not(new UFC_HasEmailRedirect());
1051 // {{{ class UFBF_Dead
1052 class UFBF_Dead
extends UFBF_Enum
1054 public function __construct($envfield, $formtext = '')
1056 parent
::__construct($envfield, $formtext, array(1, 2));
1059 protected function buildUFC(UserFilterBuilder
$ufb)
1061 if ($this->val
== 1) {
1062 return new PFC_Not(new UFC_Dead());
1063 } else if ($this->val
== 2) {
1064 return new UFC_Dead();
1070 // {{{ class UFBF_AddressMixed
1071 class UFBF_AddressMixed
extends UFBF_Mixed
1073 protected $onlycurrentfield;
1075 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
1077 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1078 $this->onlycurrentfield
= $onlycurrentfield;
1079 $this->direnum
= constant('DirEnum::' . $addressfield);
1082 protected function buildUFC(UserFilterBuilder
$ufb)
1084 if ($ufb->isOn($this->onlycurrentfield
)) {
1085 $flags = UFC_Address
::FLAG_CURRENT
;
1087 $flags = UFC_Address
::FLAG_ANY
;
1090 return new UFC_AddressComponent($this->val
, $this->envfieldindex
, UFC_Address
::TYPE_NON_HQ
, $flags);
1093 public function getEnvFieldNames()
1095 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1100 // {{{ class UFBF_AddressIndex
1101 class UFBF_AddressIndex
extends UFBF_Index
1104 protected $onlycurrentfield;
1106 public function __construct($envfield, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
1108 parent
::__construct($envfield, $formtext);
1109 $this->onlycurrentfield
= $onlycurrentfield;
1110 $this->direnum
= constant('DirEnum::' . $addressfield);
1114 protected function buildUFC(UserFilterBuilder
$ufb)
1116 if ($ufb->isOn($this->onlycurrentfield
)) {
1117 $flags = UFC_Address
::FLAG_CURRENT
;
1119 $flags = UFC_Address
::FLAG_ANY
;
1122 return new UFC_AddressComponent($this->val
, $this->envfield
, UFC_Address
::TYPE_NON_HQ
, $flags);
1125 public function getEnvFieldNames()
1127 return array($this->envfield
, $this->onlycurrentfield
);
1132 // {{{ class UFBF_JobCompany
1133 class UFBF_JobCompany
extends UFBF_Text
1135 private $onlymentorfield;
1137 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1139 parent
::__construct($envfield, $formtext);
1140 $this->onlymentorfield
= $onlymentorfield;
1143 public function check(UserFilterBuilder
$ufb) {
1144 if (parent
::check($ufb)) {
1145 # No company check for mentors
1146 if ($ufb->isOn($this->onlymentorfield
)) {
1147 $this->empty = true
;
1155 protected function buildUFC(UserFilterBuilder
$ufb)
1157 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1160 public function getEnvFieldNames()
1162 return array($this->envfield
, $this->onlymentorfield
);
1167 // {{{ class UFBF_JobTerms
1168 class UFBF_JobTerms
extends UFBF_Index
1170 protected function buildUFC(UserFilterBuilder
$ufb)
1172 return new UFC_Job_Terms($this->val
);
1177 // {{{ class UFBF_JobDescription
1178 class UFBF_JobDescription
extends UFBF_Text
1180 private $onlymentorfield;
1182 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1184 parent
::__construct($envfield, $formtext);
1185 $this->onlymentorfield
= $onlymentorfield;
1188 protected function buildUFC(UserFilterBuilder
$ufb)
1190 if ($ufb->isOn($this->onlymentorfield
)) {
1191 return new UFC_Mentor_Expertise($this->val
);
1193 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1197 public function getEnvFieldNames()
1199 return array($this->envfield
, $this->onlymentorfield
);
1204 // {{{ class UFBF_JobCv
1205 class UFBF_JobCv
extends UFBF_Text
1207 private $onlymentorfield;
1209 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1211 parent
::__construct($envfield, $formtext);
1212 $this->onlymentorfield
= $onlymentorfield;
1215 protected function buildUFC(UserFilterBuilder
$ufb)
1217 if ($ufb->isOn($this->onlymentorfield
)) {
1218 return new UFC_Mentor_Expertise($this->val
);
1220 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1224 public function getEnvFieldNames()
1226 return array($this->envfield
, $this->onlymentorfield
);
1231 // {{{ class UFBF_Nationality
1232 class UFBF_Nationality
extends UFBF_Mixed
1234 protected $direnum = DirEnum
::NATIONALITIES
;
1236 protected function buildUFC(UserFilterBuilder
$ufb)
1238 return new UFC_Nationality($this->val
);
1243 // {{{ class UFBF_Binet
1244 class UFBF_Binet
extends UFBF_Mixed
1246 protected $direnum = DirEnum
::BINETS
;
1248 protected function buildUFC(UserFilterBuilder
$ufb)
1250 return new UFC_Binet($this->val
);
1255 // {{{ class UFBF_Group
1256 class UFBF_Group
extends UFBF_Mixed
1258 protected $direnum = DirEnum
::GROUPESX
;
1260 protected function buildUFC(UserFilterBuilder
$ufb)
1262 if (count($this->val
) == 1) {
1263 return new UFC_Group($this->val
[0]);
1267 foreach ($this->val
as $grp) {
1268 $or->addChild(new UFC_Group($grp));
1275 // {{{ class UFBF_Section
1276 class UFBF_Section
extends UFBF_Mixed
1278 protected $direnum = DirEnum
::SECTIONS
;
1280 protected function buildUFC(UserFilterBuilder
$ufb)
1282 return new UFC_Section($this->val
);
1287 // {{{ class UFBF_EducationSchool
1288 class UFBF_EducationSchool
extends UFBF_Mixed
1290 protected $direnum = DirEnum
::EDUSCHOOLS
;
1292 protected function buildUFC(UserFilterBuilder
$ufb)
1294 return new UFC_EducationSchool($this->val
);
1299 // {{{ class UFBF_EducationDegree
1300 class UFBF_EducationDegree
extends UFBF_Mixed
1302 protected $direnum = DirEnum
::EDUDEGREES
;
1304 protected function buildUFC(UserFilterBuilder
$ufb)
1306 return new UFC_EducationDegree($this->val
);
1311 // {{{ class UFBF_EducationField
1312 class UFBF_EducationField
extends UFBF_Mixed
1314 protected $direnum = DirEnum
::EDUFIELDS
;
1316 protected function buildUFC(UserFilterBuilder
$ufb)
1318 return new UFC_EducationField($this->val
);
1323 // {{{ class UFBF_OriginCorps
1324 class UFBF_OriginCorps
extends UFBF_Index
1326 protected $direnum = DirEnum
::ORIGINCORPS
;
1328 protected function buildUFC(UserFilterBuilder
$ufb)
1330 return new UFC_Corps(null
, $this->val
, UFC_Corps
::ORIGIN
);
1335 // {{{ class UFBF_CurrentCorps
1336 class UFBF_CurrentCorps
extends UFBF_Index
1338 protected $direnum = DirEnum
::CURRENTCORPS
;
1340 protected function buildUFC(UserFilterBuilder
$ufb)
1342 return new UFC_Corps(null
, $this->val
, UFC_Corps
::CURRENT
);
1347 // {{{ class UFBF_CorpsRank
1348 class UFBF_CorpsRank
extends UFBF_Index
1350 protected $direnum = DirEnum
::CORPSRANKS
;
1352 protected function buildUFC(UserFilterBuilder
$ufb)
1354 return new UFC_Corps_Rank(null
, $this->val
);
1359 // {{{ class UFBF_Comment
1360 class UFBF_Comment
extends UFBF_Text
1362 protected function buildUFC(UserFilterBuilder
$ufb)
1364 return new UFC_Comment($this->val
);
1369 // {{{ class UFBF_Phone
1370 class UFBF_Phone
extends UFBF_Text
1372 protected function buildUFC(UserFilterBuilder
$ufb)
1374 return new UFC_Phone($this->val
);
1379 // {{{ class UFBF_Networking
1380 class UFBF_Networking
extends UFBF_Text
1382 private $networktypefield;
1385 public function __construct($envfield, $networktypefield, $formtext = '')
1387 parent
::__construct($envfield, $formtext);
1388 $this->networktypefield
= $networktypefield;
1391 public function check(UserFilterBuilder
$ufb)
1393 if (parent
::check($ufb)) {
1394 $this->nwtype
= $ufb->i($this->networktypefield
);
1401 public function isEmpty()
1403 return parent
::isEmpty() ||
$this->nwtype
== 0;
1406 public function buildUFC(UserFilterBuilder
$ufb)
1408 return new UFC_Networking($this->nwtype
, $this->val
);
1411 public function getEnvFieldNames()
1413 return array($this->envfield
, $this->networktypefield
);
1418 // {{{ class UFBF_Mentor
1419 class UFBF_Mentor
extends UFBF_Bool
1421 protected function buildUFC(UserFilterBuilder
$ufb)
1423 return new UFC_Mentor();
1428 // {{{ class UFBF_MentorCountry
1429 class UFBF_MentorCountry
extends UFBF_Text
1431 protected function buildUFC(UserFilterBuilder
$ufb)
1433 return new UFC_Mentor_Country($this->val
);
1438 // {{{ class UFBF_Mentorterm
1439 class UFBF_MentorTerm
extends UFBF_Index
1441 protected function buildUFC(UserFilterBuilder
$ufb)
1443 return new UFC_Mentor_Terms($this->val
);
1448 // {{{ class UFBF_MentorExpertise
1449 class UFBF_MentorExpertise
extends UFBF_Text
1451 protected function buildUFC(UserFilterBuilder
$ufb)
1453 return new UFC_Mentor_Expertise($this->val
);
1458 // {{{ class UFBF_DeltaTenMessage
1459 class UFBF_DeltaTenMessage
extends UFBF_Text
1461 protected function buildUFC(UserFilterBuilder
$ufb)
1463 return new UFC_DeltaTen_Message($this->val
);
1468 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: