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_Town('city', 'Ville / Code Postal'),
351 new UFBF_Country('countryTxt', 'country', 'Pays'),
352 new UFBF_AdminArea('administrativearea', 'Région'),
353 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
355 new UFBF_JobCompany('entreprise', 'Entreprise'),
356 new UFBF_JobDescription('jobdescription', 'Fonction'),
357 new UFBF_JobCv('cv', 'CV'),
358 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
360 new UFBF_OriginCorps('origin_corps', 'Corps d\'origine'),
361 new UFBF_CurrentCorps('current_corps', 'Corps actuel'),
362 new UFBF_CorpsRank('corps_rank', 'Grade'),
364 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
365 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
366 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
367 new UFBF_Section('sectionTxt', 'section', 'Section'),
369 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
370 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
371 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
373 new UFBF_Comment('free', 'Commentaire'),
374 new UFBF_Phone('phone_number', 'Téléphone'),
375 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
377 new UFBF_Mentor('only_referent', 'Référent'),
380 if ($include_admin ||
$include_ax) {
381 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId
::AX
);
384 parent
::__construct($fields, $envprefix);
389 // {{{ class UFB_MentorSearch
390 class UFB_MentorSearch
extends UserFilterBuilder
392 public function __construct($envprefix = '')
395 new UFBF_MentorCountry('country'),
396 new UFBF_MentorTerm('jobterm', 'jobtermText'),
397 new UFBF_MentorExpertise('expertise'),
399 parent
::__construct($fields, $envprefix);
404 // {{{ class UFB_NewsLetter
405 class UFB_NewsLetter
extends UserFilterBuilder
407 const FIELDS_PROMO
= 'promo';
408 const FIELDS_AXID
= 'axid';
409 const FIELDS_GEO
= 'geo';
411 public function __construct($flags, $envprefix = '')
414 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
415 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
416 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
418 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
419 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
421 parent
::__construct($fields, $envprefix);
426 // {{{ class UFB_Field
427 abstract class UFB_Field
432 protected $empty = false
;
433 protected $val = null
;
436 * @param $envfield Name of the field in the environment
437 * @param $formtext User-friendly name of that field
439 public function __construct($envfield, $formtext = '')
441 $this->envfield
= $envfield;
442 if ($formtext != '') {
443 $this->formtext
= $formtext;
445 $formtext = ucfirst($envfield);
449 /** Prints the given error message to the user, and returns false
450 * in order to be used as return $this->raise('ERROR');
452 * All %s in the $msg will be replaced with the formtext.
454 protected function raise($msg)
456 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
460 public function apply(UserFilterBuilder
$ufb) {
461 if (!$this->check($ufb)) {
465 if (!$this->isEmpty()) {
466 $ufc = $this->buildUFC($ufb);
474 public function isEmpty()
479 /** Create the UFC associated to the field; won't be called
480 * if the field is "empty"
481 * @param $ufb UFB to which fields must be added
484 abstract protected function buildUFC(UserFilterBuilder
$ufb);
486 /** This function is intended to run consistency checks on the value
487 * @return boolean Whether the input is valid
489 abstract protected function check(UserFilterBuilder
$ufb);
491 // Simple form interface
493 /** Retrieve a list of env field names used by that field
494 * their values will be recorded when saving the 'search' and used to prefill the form
497 public function getEnvFieldNames()
499 return array($this->envfield
);
504 // {{{ class UFBF_Text
505 abstract class UFBF_Text
extends UFB_Field
510 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
512 parent
::__construct($envfield, $formtext);
513 $this->minlength
= $minlength;
514 $this->maxlength
= $maxlength;
517 protected function check(UserFilterBuilder
$ufb)
519 if ($ufb->blank($this->envfield
)) {
524 $this->val
= $ufb->t($this->envfield
);
525 if (strlen($this->val
) < $this->minlength
) {
526 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
527 } else if (strlen($this->val
) > $this->maxlength
) {
528 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
529 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
530 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
538 // {{{ class UFBF_Range
539 /** Subclass to use for fields which only allow integers within a range
541 abstract class UFBF_Range
extends UFB_Field
547 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
549 parent
::__construct($envfield, $formtext);
554 protected function check(UserFilterBuilder
$ufb)
556 if ($ufb->blank($this->envfield
)) {
561 $this->val
= $ufb->i($this->envfield
);
562 if ($this->val
< $this->min
) {
563 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
564 } else if ($this->val
> $this->max
) {
565 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
572 // {{{ class UFBF_Index
573 /** Subclass to use for indexed fields
575 abstract class UFBF_Index
extends UFB_Field
577 protected function check(UserFilterBuilder
$ufb)
579 if ($ufb->blank($this->envfield
)) {
582 $this->val
= $ufb->i($this->envfield
);
588 // {{{ class UFBF_Enum
589 /** Subclass to use for fields whose value must belong to a specific set of values
591 abstract class UFBF_Enum
extends UFB_Field
593 protected $allowedvalues;
595 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
597 parent
::__construct($envfield, $formtext);
598 $this->allowedvalues
= $allowedvalues;
599 $this->strict
= $strict;
602 protected function check(UserFilterBuilder
$ufb)
604 if ($ufb->blank($this->envfield
)) {
609 $this->val
= $ufb->v($this->envfield
);
610 if (! in_array($this->val
, $this->allowedvalues
)) {
612 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
622 // {{{ class UFBF_Bool
623 abstract class UFBF_Bool
extends UFB_Field
625 protected function check(UserFilterBuilder
$ufb)
627 if ($ufb->blank($this->envfield
)) {
632 $this->val
= $ufb->b($this->envfield
);
638 // {{{ class UFBF_Mixed
639 /** A class for building UFBFs when the user can input either a text or an ID
641 abstract class UFBF_Mixed
extends UFB_Field
643 /** Name of the DirEnum on which class is based
647 protected $envfieldindex;
649 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
651 parent
::__construct($envfieldtext, $formtext);
652 $this->envfieldindex
= $envfieldindex;
655 protected function check(UserFilterBuilder
$ufb)
657 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
662 if (!$ufb->blank($this->envfieldindex
)) {
663 $index = $ufb->v($this->envfieldindex
);
664 if (is_int($index)) {
665 $index = intval($index);
667 $index = strtoupper($index);
669 $this->val
= array($index);
671 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
672 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
673 if (count($indexes) == 0) {
676 $this->val
= $indexes;
681 public function getEnvFieldNames()
683 return array($this->envfieldindex
, $this->envfield
);
688 // {{{ class UFBF_Quick
689 class UFBF_Quick
extends UFB_Field
691 protected function check(UserFilterBuilder
$ufb)
693 if ($ufb->blank($this->envfield
)) {
698 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
703 protected function buildUFC(UserFilterBuilder
$ufb)
706 $r = $s = $this->val
;
710 if (S
::admin() && strpos($s, '@') !== false
) {
711 return new UFC_Email($s);
712 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
713 return new UFC_Ip($s);
716 $conds = new PFC_And();
720 $s = preg_replace('!\d+!', ' ', $s);
721 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY
);
722 foreach ($strings as $key => $string) {
723 if (strlen($string) < 2) {
724 unset($strings[$key]);
727 if (count($strings) > 5) {
728 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
729 $strings = array_slice($strings, 0, 5);
732 if (count($strings)) {
733 if (S
::user() != null
&& S
::user()->checkPerms('directory_private')) {
736 $flags = array('public');
738 $exact =$ufb->b('exact');
739 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
741 $ufb->addOrder(new UFO_Score());
746 $s = preg_replace('! *- *!', '-', $r);
747 $s = preg_replace('!([<>]) *!', ' \1', $s);
748 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
749 $s = preg_replace('![<>\-] !', '', $s);
750 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY
);
751 $grades = array('' => UserFilter
::GRADE_ING
, 'x' => UserFilter
::GRADE_ING
, 'm' => UserFilter
::GRADE_MST
, 'd' => UserFilter
::GRADE_PHD
);
752 foreach ($ranges as $r) {
753 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
754 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
755 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
756 $p1 = min(intval($matches[2]), intval($matches[3]));
757 $p2 = max(intval($matches[2]), intval($matches[3]));
758 $conds->addChild(new PFC_And(
759 new UFC_Promo('>=', $grades[$matches[1]], $p1),
760 new UFC_Promo('<=', $grades[$matches[1]], $p2)
762 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
763 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
764 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
765 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
771 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
772 $t = preg_replace('![<>\- ]!', '', $t);
773 if (strlen($t) > 4) {
774 $conds->addChild(new UFC_Phone($t));
782 // {{{ class UFBF_SchoolIds
783 class UFBF_SchoolIds
extends UFB_Field
785 // One of UFC_SchoolId types
787 protected $reversed_envfield;
788 protected $reversed = false
;
790 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
792 parent
::__construct($envfield, $formtext);
794 if ($reversed_envfield == '') {
795 $reversed_envfield = $envfield . '_reversed';
797 $this->reversed_envfield
= $reversed_envfield;
800 protected function check(UserFilterBuilder
$ufb)
802 if ($ufb->blank($this->envfield
)) {
807 $value = $ufb->t($this->envfield
);
808 $values = explode("\r\n", $value);
810 foreach ($values as $val) {
811 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
815 if (count($ids) == 0) {
816 return $this->raise("Le champ %s ne contient aucune valeur valide.");
819 $this->reversed
= $ufb->b($this->reversed_envfield
);
824 protected function buildUFC(UserFilterBuilder
$ufb)
826 $ufc = new UFC_SchoolId($this->type
, $this->val
);
827 if ($this->reversed
) {
828 return new PFC_Not($ufc);
836 // {{{ class UFBF_Name
837 class UFBF_Name
extends UFBF_Text
839 private $envfieldtype;
842 public function __construct($envfield, $formtext = '', $envfieldtype)
844 parent
::__construct($envfield, $formtext);
845 $this->envfieldtype
= $envfieldtype;
848 protected function check(UserFilterBuilder
$ufb)
850 if (!parent
::check($ufb)) {
854 require_once 'name.func.inc.php';
856 $this->val
= split_name_for_search($this->val
);
857 if (count($this->val
) == 0) {
860 $this->type
= $ufb->v($this->envfieldtype
);
861 if (!in_array($this->type
, array('', 'lastname', 'firstname', 'nickname'))) {
862 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
867 protected function buildUFC(UserFilterBuilder
$ufb)
869 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type
);
872 public function getEnvFieldNames()
874 return array($this->envfield
, $this->envfieldtype
);
879 // {{{ class UFBF_Promo
880 class UFBF_Promo
extends UFB_Field
882 private static $validcomps = array('<', '<=', '=', '>=', '>');
883 private static $validtypes = array(UserFilter
::GRADE_ING
, UserFilter
::GRADE_PHD
, UserFilter
::GRADE_MST
);
886 private $envfieldcomp;
887 private $envfieldtype;
889 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
891 parent
::__construct($envfield, $formtext);
892 $this->envfieldcomp
= $envfieldcomp;
893 $this->envfieldtype
= $envfieldtype;
896 protected function check(UserFilterBuilder
$ufb)
898 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
) ||
$ufb->blank($this->envfieldtype
)) {
903 $this->val
= $ufb->i($this->envfield
);
904 $this->comp
= $ufb->v($this->envfieldcomp
);
905 $this->type
= $ufb->v($this->envfieldtype
);
907 if (!in_array($this->type
, self
::$validtypes)) {
908 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
911 if (!in_array($this->comp
, self
::$validcomps)) {
912 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
915 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
918 if ($this->val
< 1900 ||
$this->val
> 9999) {
919 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
924 protected function buildUFC(UserFilterBuilder
$ufb) {
925 return new UFC_Promo($this->comp
, $this->type
, $this->val
);
928 public function getEnvFieldNames()
930 return array($this->envfield
, $this->envfieldcomp
, $this->envfieldtype
);
935 // {{{ class UFBF_Sex
936 class UFBF_Sex
extends UFBF_Enum
938 public function __construct($envfield, $formtext = '')
940 parent
::__construct($envfield, $formtext, array(1, 2));
943 private static function getVal($id)
947 return User
::GENDER_MALE
;
950 return User
::GENDER_FEMALE
;
955 protected function buildUFC(UserFilterBuilder
$ufb)
957 return new UFC_Sex(self
::getVal($this->val
));
962 // {{{ class UFBF_NotRegistered
963 // Simple field for selecting only alive, not registered users (for quick search)
964 class UFBF_NotRegistered
extends UFBF_Bool
966 protected function buildUFC(UserFilterBuilder
$ufb)
970 new PFC_Not(new UFC_Dead()),
971 new PFC_Not(new UFC_Registered())
978 // {{{ class UFBF_Registered
979 class UFBF_Registered
extends UFBF_Enum
981 public function __construct($envfield, $formtext = '')
983 parent
::__construct($envfield, $formtext, array(1, 2));
986 protected function buildUFC(UserFilterBuilder
$ufb)
988 if ($this->val
== 1) {
989 return new UFC_Registered();
990 } else if ($this->val
== 2) {
991 return new PFC_Not(new UFC_Registered());
997 // {{{ class UFBF_HasEmailRedirect
998 class UFBF_HasEmailRedirect
extends UFBF_Enum
1000 public function __construct($envfield, $formtext = '')
1002 parent
::__construct($envfield, $formtext, array(1, 2));
1005 protected function buildUFC(UserFilterBuilder
$ufb)
1007 if ($this->val
== 1) {
1008 return new UFC_HasEmailRedirect();
1009 } else if ($this->val
== 2) {
1010 return new PFC_Not(new UFC_HasEmailRedirect());
1016 // {{{ class UFBF_Dead
1017 class UFBF_Dead
extends UFBF_Enum
1019 public function __construct($envfield, $formtext = '')
1021 parent
::__construct($envfield, $formtext, array(1, 2));
1024 protected function buildUFC(UserFilterBuilder
$ufb)
1026 if ($this->val
== 1) {
1027 return new PFC_Not(new UFC_Dead());
1028 } else if ($this->val
== 2) {
1029 return new UFC_Dead();
1035 // {{{ class UFBF_Town
1036 /** Retrieves a town, either from a postal code or a town name
1038 class UFBF_Town
extends UFBF_Text
1040 const TYPE_TEXT
= 1;
1045 private $onlycurrentfield;
1047 public function __construct($envfield, $formtext = '', $type = self
::TYPE_ANY
, $onlycurrentfield = 'only_current')
1049 $this->type
= $type;
1050 $this->onlycurrentfield
= $onlycurrentfield;
1051 parent
::__construct($envfield, $formtext, 2, 30);
1054 protected function buildUFC(UserFilterBuilder
$ufb)
1056 if ($ufb->isOn($this->onlycurrentfield
)) {
1057 $flags = UFC_Address
::FLAG_CURRENT
;
1059 $flags = UFC_Address
::FLAG_ANY
;
1062 if (preg_match('/[0-9]/', $this->val
)) {
1063 if ($this->type
& self
::TYPE_ZIP
) {
1064 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1066 return new PFC_False();
1069 $byname = new UFC_AddressText(null
, XDB
::WILDCARD_CONTAINS
, UFC_Address
::TYPE_ANY
, $flags, null
, $this->val
);
1070 $byzip = new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1071 if ($this->type
& self
::TYPE_ANY
) {
1072 return new PFC_Or($byname, $byzip);
1073 } else if ($this->type
& self
::TYPE_TEXT
) {
1081 public function getEnvFieldNames()
1083 return array($this->envfield
, $this->onlycurrentfield
);
1088 // {{{ class UFBF_Country
1089 class UFBF_Country
extends UFBF_Mixed
1091 protected $direnum = DirEnum
::COUNTRIES
;
1092 protected $onlycurrentfield;
1094 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
1096 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1097 $this->onlycurrentfield
= $onlycurrentfield;
1100 protected function buildUFC(UserFilterBuilder
$ufb)
1102 if ($ufb->isOn($this->onlycurrentfield
)) {
1103 $flags = UFC_Address
::FLAG_CURRENT
;
1105 $flags = UFC_Address
::FLAG_ANY
;
1108 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_COUNTRY
, UFC_Address
::TYPE_ANY
, $flags);
1111 public function getEnvFieldNames()
1113 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1118 // {{{ class UFBF_AdminArea
1119 class UFBF_AdminArea
extends UFBF_Index
1121 protected $direnum = DirEnum
::ADMINAREAS
;
1122 protected $onlycurrentfield;
1124 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1126 parent
::__construct($envfield, $formtext);
1127 $this->onlycurrentfield
= $onlycurrentfield;
1131 protected function buildUFC(UserFilterBuilder
$ufb)
1133 if ($ufb->isOn($this->onlycurrentfield
)) {
1134 $flags = UFC_Address
::FLAG_CURRENT
;
1136 $flags = UFC_Address
::FLAG_ANY
;
1139 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1142 public function getEnvFieldNames()
1144 return array($this->envfield
, $this->onlycurrentfield
);
1149 // {{{ class UFBF_SubAdminArea
1150 class UFBF_SubAdminArea
extends UFBF_Index
1152 protected $direnum = DirEnum
::SUBADMINAREAS
;
1153 protected $onlycurrentfield;
1155 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1157 parent
::__construct($envfield, $formtext);
1158 $this->onlycurrentfield
= $onlycurrentfield;
1162 protected function buildUFC(UserFilterBuilder
$ufb)
1164 if ($ufb->isOn($this->onlycurrentfield
)) {
1165 $flags = UFC_Address
::FLAG_CURRENT
;
1167 $flags = UFC_Address
::FLAG_ANY
;
1170 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_SUBADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1173 public function getEnvFieldNames()
1175 return array($this->envfield
, $this->onlycurrentfield
);
1180 // {{{ class UFBF_JobCompany
1181 class UFBF_JobCompany
extends UFBF_Text
1183 private $onlymentorfield;
1185 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1187 parent
::__construct($envfield, $formtext);
1188 $this->onlymentorfield
= $onlymentorfield;
1191 public function check(UserFilterBuilder
$ufb) {
1192 if (parent
::check($ufb)) {
1193 # No company check for mentors
1194 if ($ufb->isOn($this->onlymentorfield
)) {
1195 $this->empty = true
;
1203 protected function buildUFC(UserFilterBuilder
$ufb)
1205 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1208 public function getEnvFieldNames()
1210 return array($this->envfield
, $this->onlymentorfield
);
1215 // {{{ class UFBF_JobTerms
1216 class UFBF_JobTerms
extends UFBF_Index
1218 protected function buildUFC(UserFilterBuilder
$ufb)
1220 return new UFC_Job_Terms($this->val
);
1225 // {{{ class UFBF_JobDescription
1226 class UFBF_JobDescription
extends UFBF_Text
1228 private $onlymentorfield;
1230 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1232 parent
::__construct($envfield, $formtext);
1233 $this->onlymentorfield
= $onlymentorfield;
1236 protected function buildUFC(UserFilterBuilder
$ufb)
1238 if ($ufb->isOn($this->onlymentorfield
)) {
1239 return new UFC_Mentor_Expertise($this->val
);
1241 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1245 public function getEnvFieldNames()
1247 return array($this->envfield
, $this->onlymentorfield
);
1252 // {{{ class UFBF_JobCv
1253 class UFBF_JobCv
extends UFBF_Text
1255 private $onlymentorfield;
1257 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1259 parent
::__construct($envfield, $formtext);
1260 $this->onlymentorfield
= $onlymentorfield;
1263 protected function buildUFC(UserFilterBuilder
$ufb)
1265 if ($ufb->isOn($this->onlymentorfield
)) {
1266 return new UFC_Mentor_Expertise($this->val
);
1268 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1272 public function getEnvFieldNames()
1274 return array($this->envfield
, $this->onlymentorfield
);
1279 // {{{ class UFBF_Nationality
1280 class UFBF_Nationality
extends UFBF_Mixed
1282 protected $direnum = DirEnum
::NATIONALITIES
;
1284 protected function buildUFC(UserFilterBuilder
$ufb)
1286 return new UFC_Nationality($this->val
);
1291 // {{{ class UFBF_Binet
1292 class UFBF_Binet
extends UFBF_Mixed
1294 protected $direnum = DirEnum
::BINETS
;
1296 protected function buildUFC(UserFilterBuilder
$ufb)
1298 return new UFC_Binet($this->val
);
1303 // {{{ class UFBF_Group
1304 class UFBF_Group
extends UFBF_Mixed
1306 protected $direnum = DirEnum
::GROUPESX
;
1308 protected function buildUFC(UserFilterBuilder
$ufb)
1310 if (count($this->val
) == 1) {
1311 return new UFC_Group($this->val
[0]);
1315 foreach ($this->val
as $grp) {
1316 $or->addChild(new UFC_Group($grp));
1323 // {{{ class UFBF_Section
1324 class UFBF_Section
extends UFBF_Mixed
1326 protected $direnum = DirEnum
::SECTIONS
;
1328 protected function buildUFC(UserFilterBuilder
$ufb)
1330 return new UFC_Section($this->val
);
1335 // {{{ class UFBF_EducationSchool
1336 class UFBF_EducationSchool
extends UFBF_Mixed
1338 protected $direnum = DirEnum
::EDUSCHOOLS
;
1340 protected function buildUFC(UserFilterBuilder
$ufb)
1342 return new UFC_EducationSchool($this->val
);
1347 // {{{ class UFBF_EducationDegree
1348 class UFBF_EducationDegree
extends UFBF_Mixed
1350 protected $direnum = DirEnum
::EDUDEGREES
;
1352 protected function buildUFC(UserFilterBuilder
$ufb)
1354 return new UFC_EducationDegree($this->val
);
1359 // {{{ class UFBF_EducationField
1360 class UFBF_EducationField
extends UFBF_Mixed
1362 protected $direnum = DirEnum
::EDUFIELDS
;
1364 protected function buildUFC(UserFilterBuilder
$ufb)
1366 return new UFC_EducationField($this->val
);
1371 // {{{ class UFBF_OriginCorps
1372 class UFBF_OriginCorps
extends UFBF_Index
1374 protected $direnum = DirEnum
::ORIGINCORPS
;
1376 protected function buildUFC(UserFilterBuilder
$ufb)
1378 return new UFC_Corps(null
, $this->val
, UFC_Corps
::ORIGIN
);
1383 // {{{ class UFBF_CurrentCorps
1384 class UFBF_CurrentCorps
extends UFBF_Index
1386 protected $direnum = DirEnum
::CURRENTCORPS
;
1388 protected function buildUFC(UserFilterBuilder
$ufb)
1390 return new UFC_Corps(null
, $this->val
, UFC_Corps
::CURRENT
);
1395 // {{{ class UFBF_CorpsRank
1396 class UFBF_CorpsRank
extends UFBF_Index
1398 protected $direnum = DirEnum
::CORPSRANKS
;
1400 protected function buildUFC(UserFilterBuilder
$ufb)
1402 return new UFC_Corps_Rank(null
, $this->val
);
1407 // {{{ class UFBF_Comment
1408 class UFBF_Comment
extends UFBF_Text
1410 protected function buildUFC(UserFilterBuilder
$ufb)
1412 return new UFC_Comment($this->val
);
1417 // {{{ class UFBF_Phone
1418 class UFBF_Phone
extends UFBF_Text
1420 protected function buildUFC(UserFilterBuilder
$ufb)
1422 return new UFC_Phone($this->val
);
1427 // {{{ class UFBF_Networking
1428 class UFBF_Networking
extends UFBF_Text
1430 private $networktypefield;
1433 public function __construct($envfield, $networktypefield, $formtext = '')
1435 parent
::__construct($envfield, $formtext);
1436 $this->networktypefield
= $networktypefield;
1439 public function check(UserFilterBuilder
$ufb)
1441 if (parent
::check($ufb)) {
1442 $this->nwtype
= $ufb->i($this->networktypefield
);
1449 public function isEmpty()
1451 return parent
::isEmpty() ||
$this->nwtype
== 0;
1454 public function buildUFC(UserFilterBuilder
$ufb)
1456 return new UFC_Networking($this->nwtype
, $this->val
);
1459 public function getEnvFieldNames()
1461 return array($this->envfield
, $this->networktypefield
);
1466 // {{{ class UFBF_Mentor
1467 class UFBF_Mentor
extends UFBF_Bool
1469 protected function buildUFC(UserFilterBuilder
$ufb)
1471 return new UFC_Mentor();
1476 // {{{ class UFBF_MentorCountry
1477 class UFBF_MentorCountry
extends UFBF_Text
1479 protected function buildUFC(UserFilterBuilder
$ufb)
1481 return new UFC_Mentor_Country($this->val
);
1486 // {{{ class UFBF_Mentorterm
1487 class UFBF_MentorTerm
extends UFBF_Index
1489 protected function buildUFC(UserFilterBuilder
$ufb)
1491 return new UFC_Mentor_Terms($this->val
);
1496 // {{{ class UFBF_MentorExpertise
1497 class UFBF_MentorExpertise
extends UFBF_Text
1499 protected function buildUFC(UserFilterBuilder
$ufb)
1501 return new UFC_Mentor_Expertise($this->val
);
1506 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: