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_NewsLetter
407 class UFB_NewsLetter
extends UserFilterBuilder
409 const FIELDS_PROMO
= 'promo';
410 const FIELDS_AXID
= 'axid';
411 const FIELDS_GEO
= 'geo';
413 public function __construct($flags, $envprefix = '')
416 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
417 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
418 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
420 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
421 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
423 parent
::__construct($fields, $envprefix);
428 // {{{ class UFB_Field
429 abstract class UFB_Field
434 protected $empty = false
;
435 protected $val = null
;
438 * @param $envfield Name of the field in the environment
439 * @param $formtext User-friendly name of that field
441 public function __construct($envfield, $formtext = '')
443 $this->envfield
= $envfield;
444 if ($formtext != '') {
445 $this->formtext
= $formtext;
447 $formtext = ucfirst($envfield);
451 /** Prints the given error message to the user, and returns false
452 * in order to be used as return $this->raise('ERROR');
454 * All %s in the $msg will be replaced with the formtext.
456 protected function raise($msg)
458 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
462 public function apply(UserFilterBuilder
$ufb) {
463 if (!$this->check($ufb)) {
467 if (!$this->isEmpty()) {
468 $ufc = $this->buildUFC($ufb);
476 public function isEmpty()
481 /** Create the UFC associated to the field; won't be called
482 * if the field is "empty"
483 * @param $ufb UFB to which fields must be added
486 abstract protected function buildUFC(UserFilterBuilder
$ufb);
488 /** This function is intended to run consistency checks on the value
489 * @return boolean Whether the input is valid
491 abstract protected function check(UserFilterBuilder
$ufb);
493 // Simple form interface
495 /** Retrieve a list of env field names used by that field
496 * their values will be recorded when saving the 'search' and used to prefill the form
499 public function getEnvFieldNames()
501 return array($this->envfield
);
506 // {{{ class UFBF_Text
507 abstract class UFBF_Text
extends UFB_Field
512 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
514 parent
::__construct($envfield, $formtext);
515 $this->minlength
= $minlength;
516 $this->maxlength
= $maxlength;
519 protected function check(UserFilterBuilder
$ufb)
521 if ($ufb->blank($this->envfield
)) {
526 $this->val
= $ufb->t($this->envfield
);
527 if (strlen($this->val
) < $this->minlength
) {
528 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
529 } else if (strlen($this->val
) > $this->maxlength
) {
530 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
531 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
532 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
540 // {{{ class UFBF_Range
541 /** Subclass to use for fields which only allow integers within a range
543 abstract class UFBF_Range
extends UFB_Field
549 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
551 parent
::__construct($envfield, $formtext);
556 protected function check(UserFilterBuilder
$ufb)
558 if ($ufb->blank($this->envfield
)) {
563 $this->val
= $ufb->i($this->envfield
);
564 if ($this->val
< $this->min
) {
565 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
566 } else if ($this->val
> $this->max
) {
567 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
574 // {{{ class UFBF_Index
575 /** Subclass to use for indexed fields
577 abstract class UFBF_Index
extends UFB_Field
579 protected function check(UserFilterBuilder
$ufb)
581 if ($ufb->blank($this->envfield
)) {
584 $this->val
= $ufb->i($this->envfield
);
590 // {{{ class UFBF_Enum
591 /** Subclass to use for fields whose value must belong to a specific set of values
593 abstract class UFBF_Enum
extends UFB_Field
595 protected $allowedvalues;
597 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
599 parent
::__construct($envfield, $formtext);
600 $this->allowedvalues
= $allowedvalues;
601 $this->strict
= $strict;
604 protected function check(UserFilterBuilder
$ufb)
606 if ($ufb->blank($this->envfield
)) {
611 $this->val
= $ufb->v($this->envfield
);
612 if (! in_array($this->val
, $this->allowedvalues
)) {
614 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
624 // {{{ class UFBF_Bool
625 abstract class UFBF_Bool
extends UFB_Field
627 protected function check(UserFilterBuilder
$ufb)
629 if ($ufb->blank($this->envfield
)) {
634 $this->val
= $ufb->b($this->envfield
);
640 // {{{ class UFBF_Mixed
641 /** A class for building UFBFs when the user can input either a text or an ID
643 abstract class UFBF_Mixed
extends UFB_Field
645 /** Name of the DirEnum on which class is based
649 protected $envfieldindex;
651 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
653 parent
::__construct($envfieldtext, $formtext);
654 $this->envfieldindex
= $envfieldindex;
657 protected function check(UserFilterBuilder
$ufb)
659 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
664 if (!$ufb->blank($this->envfieldindex
)) {
665 $index = $ufb->v($this->envfieldindex
);
666 if (is_int($index)) {
667 $index = intval($index);
669 $index = strtoupper($index);
671 $this->val
= array($index);
673 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
674 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
675 if (count($indexes) == 0) {
678 $this->val
= $indexes;
683 public function getEnvFieldNames()
685 return array($this->envfieldindex
, $this->envfield
);
690 // {{{ class UFBF_Quick
691 class UFBF_Quick
extends UFB_Field
693 protected function check(UserFilterBuilder
$ufb)
695 if ($ufb->blank($this->envfield
)) {
700 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
705 protected function buildUFC(UserFilterBuilder
$ufb)
708 $r = $s = $this->val
;
712 if (S
::admin() && strpos($s, '@') !== false
) {
713 return new UFC_Email($s);
714 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
715 return new UFC_Ip($s);
718 $conds = new PFC_And();
722 $s = preg_replace('!\d+!', ' ', $s);
723 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY
);
724 foreach ($strings as $key => $string) {
725 if (strlen($string) < 2) {
726 unset($strings[$key]);
729 if (count($strings) > 5) {
730 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
731 $strings = array_slice($strings, 0, 5);
734 if (count($strings)) {
735 if (S
::user() != null
&& S
::user()->checkPerms('directory_private')) {
738 $flags = array('public');
740 $exact =$ufb->b('exact');
741 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
743 $ufb->addOrder(new UFO_Score());
748 $s = preg_replace('! *- *!', '-', $r);
749 $s = preg_replace('!([<>]) *!', ' \1', $s);
750 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
751 $s = preg_replace('![<>\-] !', '', $s);
752 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY
);
753 $grades = array('' => UserFilter
::GRADE_ING
, 'x' => UserFilter
::GRADE_ING
, 'm' => UserFilter
::GRADE_MST
, 'd' => UserFilter
::GRADE_PHD
);
754 foreach ($ranges as $r) {
755 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
756 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
757 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
758 $p1 = min(intval($matches[2]), intval($matches[3]));
759 $p2 = max(intval($matches[2]), intval($matches[3]));
760 $conds->addChild(new PFC_And(
761 new UFC_Promo('>=', $grades[$matches[1]], $p1),
762 new UFC_Promo('<=', $grades[$matches[1]], $p2)
764 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
765 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
766 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
767 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
773 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
774 $t = preg_replace('![<>\- ]!', '', $t);
775 if (strlen($t) > 4) {
776 $conds->addChild(new UFC_Phone($t));
784 // {{{ class UFBF_SchoolIds
785 class UFBF_SchoolIds
extends UFB_Field
787 // One of UFC_SchoolId types
789 protected $reversed_envfield;
790 protected $reversed = false
;
792 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
794 parent
::__construct($envfield, $formtext);
796 if ($reversed_envfield == '') {
797 $reversed_envfield = $envfield . '_reversed';
799 $this->reversed_envfield
= $reversed_envfield;
802 protected function check(UserFilterBuilder
$ufb)
804 if ($ufb->blank($this->envfield
)) {
809 $value = $ufb->t($this->envfield
);
810 $values = explode("\r\n", $value);
812 foreach ($values as $val) {
813 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
817 if (count($ids) == 0) {
818 return $this->raise("Le champ %s ne contient aucune valeur valide.");
821 $this->reversed
= $ufb->b($this->reversed_envfield
);
826 protected function buildUFC(UserFilterBuilder
$ufb)
828 $ufc = new UFC_SchoolId($this->type
, $this->val
);
829 if ($this->reversed
) {
830 return new PFC_Not($ufc);
838 // {{{ class UFBF_Name
839 class UFBF_Name
extends UFBF_Text
841 private $envfieldtype;
844 public function __construct($envfield, $formtext = '', $envfieldtype)
846 parent
::__construct($envfield, $formtext);
847 $this->envfieldtype
= $envfieldtype;
850 protected function check(UserFilterBuilder
$ufb)
852 if (!parent
::check($ufb)) {
856 require_once 'name.func.inc.php';
858 $this->val
= split_name_for_search($this->val
);
859 if (count($this->val
) == 0) {
862 $this->type
= $ufb->v($this->envfieldtype
);
863 if (!in_array($this->type
, array('', 'lastname', 'firstname', 'nickname'))) {
864 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
869 protected function buildUFC(UserFilterBuilder
$ufb)
871 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type
);
874 public function getEnvFieldNames()
876 return array($this->envfield
, $this->envfieldtype
);
881 // {{{ class UFBF_Promo
882 class UFBF_Promo
extends UFB_Field
884 private static $validcomps = array('<', '<=', '=', '>=', '>');
885 private static $validtypes = array(UserFilter
::GRADE_ING
, UserFilter
::GRADE_PHD
, UserFilter
::GRADE_MST
);
888 private $envfieldcomp;
889 private $envfieldtype;
891 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
893 parent
::__construct($envfield, $formtext);
894 $this->envfieldcomp
= $envfieldcomp;
895 $this->envfieldtype
= $envfieldtype;
898 protected function check(UserFilterBuilder
$ufb)
900 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
) ||
$ufb->blank($this->envfieldtype
)) {
905 $this->val
= $ufb->i($this->envfield
);
906 $this->comp
= $ufb->v($this->envfieldcomp
);
907 $this->type
= $ufb->v($this->envfieldtype
);
909 if (!in_array($this->type
, self
::$validtypes)) {
910 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
913 if (!in_array($this->comp
, self
::$validcomps)) {
914 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
917 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
920 if ($this->val
< 1900 ||
$this->val
> 9999) {
921 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
926 protected function buildUFC(UserFilterBuilder
$ufb) {
927 return new UFC_Promo($this->comp
, $this->type
, $this->val
);
930 public function getEnvFieldNames()
932 return array($this->envfield
, $this->envfieldcomp
, $this->envfieldtype
);
937 // {{{ class UFBF_Sex
938 class UFBF_Sex
extends UFBF_Enum
940 public function __construct($envfield, $formtext = '')
942 parent
::__construct($envfield, $formtext, array(1, 2));
945 private static function getVal($id)
949 return User
::GENDER_MALE
;
952 return User
::GENDER_FEMALE
;
957 protected function buildUFC(UserFilterBuilder
$ufb)
959 return new UFC_Sex(self
::getVal($this->val
));
964 // {{{ class UFBF_NotRegistered
965 // Simple field for selecting only alive, not registered users (for quick search)
966 class UFBF_NotRegistered
extends UFBF_Bool
968 protected function buildUFC(UserFilterBuilder
$ufb)
972 new PFC_Not(new UFC_Dead()),
973 new PFC_Not(new UFC_Registered())
980 // {{{ class UFBF_Registered
981 class UFBF_Registered
extends UFBF_Enum
983 public function __construct($envfield, $formtext = '')
985 parent
::__construct($envfield, $formtext, array(1, 2));
988 protected function buildUFC(UserFilterBuilder
$ufb)
990 if ($this->val
== 1) {
991 return new UFC_Registered();
992 } else if ($this->val
== 2) {
993 return new PFC_Not(new UFC_Registered());
999 // {{{ class UFBF_HasEmailRedirect
1000 class UFBF_HasEmailRedirect
extends UFBF_Enum
1002 public function __construct($envfield, $formtext = '')
1004 parent
::__construct($envfield, $formtext, array(1, 2));
1007 protected function buildUFC(UserFilterBuilder
$ufb)
1009 if ($this->val
== 1) {
1010 return new UFC_HasEmailRedirect();
1011 } else if ($this->val
== 2) {
1012 return new PFC_Not(new UFC_HasEmailRedirect());
1018 // {{{ class UFBF_Dead
1019 class UFBF_Dead
extends UFBF_Enum
1021 public function __construct($envfield, $formtext = '')
1023 parent
::__construct($envfield, $formtext, array(1, 2));
1026 protected function buildUFC(UserFilterBuilder
$ufb)
1028 if ($this->val
== 1) {
1029 return new PFC_Not(new UFC_Dead());
1030 } else if ($this->val
== 2) {
1031 return new UFC_Dead();
1037 // {{{ class UFBF_AddressMixed
1038 class UFBF_AddressMixed
extends UFBF_Mixed
1040 protected $onlycurrentfield;
1042 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
1044 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1045 $this->onlycurrentfield
= $onlycurrentfield;
1046 $this->direnum
= constant('DirEnum::' . $addressfield);
1049 protected function buildUFC(UserFilterBuilder
$ufb)
1051 if ($ufb->isOn($this->onlycurrentfield
)) {
1052 $flags = UFC_Address
::FLAG_CURRENT
;
1054 $flags = UFC_Address
::FLAG_ANY
;
1057 return new UFC_AddressComponent($this->val
, $this->envfieldindex
, UFC_Address
::TYPE_NON_HQ
, $flags);
1060 public function getEnvFieldNames()
1062 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1067 // {{{ class UFBF_AddressIndex
1068 class UFBF_AddressIndex
extends UFBF_Index
1071 protected $onlycurrentfield;
1073 public function __construct($envfield, $formtext = '', $addressfield, $onlycurrentfield = 'only_current')
1075 parent
::__construct($envfield, $formtext);
1076 $this->onlycurrentfield
= $onlycurrentfield;
1077 $this->direnum
= constant('DirEnum::' . $addressfield);
1081 protected function buildUFC(UserFilterBuilder
$ufb)
1083 if ($ufb->isOn($this->onlycurrentfield
)) {
1084 $flags = UFC_Address
::FLAG_CURRENT
;
1086 $flags = UFC_Address
::FLAG_ANY
;
1089 return new UFC_AddressComponent($this->val
, $this->envfield
, UFC_Address
::TYPE_NON_HQ
, $flags);
1092 public function getEnvFieldNames()
1094 return array($this->envfield
, $this->onlycurrentfield
);
1099 // {{{ class UFBF_JobCompany
1100 class UFBF_JobCompany
extends UFBF_Text
1102 private $onlymentorfield;
1104 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1106 parent
::__construct($envfield, $formtext);
1107 $this->onlymentorfield
= $onlymentorfield;
1110 public function check(UserFilterBuilder
$ufb) {
1111 if (parent
::check($ufb)) {
1112 # No company check for mentors
1113 if ($ufb->isOn($this->onlymentorfield
)) {
1114 $this->empty = true
;
1122 protected function buildUFC(UserFilterBuilder
$ufb)
1124 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1127 public function getEnvFieldNames()
1129 return array($this->envfield
, $this->onlymentorfield
);
1134 // {{{ class UFBF_JobTerms
1135 class UFBF_JobTerms
extends UFBF_Index
1137 protected function buildUFC(UserFilterBuilder
$ufb)
1139 return new UFC_Job_Terms($this->val
);
1144 // {{{ class UFBF_JobDescription
1145 class UFBF_JobDescription
extends UFBF_Text
1147 private $onlymentorfield;
1149 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1151 parent
::__construct($envfield, $formtext);
1152 $this->onlymentorfield
= $onlymentorfield;
1155 protected function buildUFC(UserFilterBuilder
$ufb)
1157 if ($ufb->isOn($this->onlymentorfield
)) {
1158 return new UFC_Mentor_Expertise($this->val
);
1160 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1164 public function getEnvFieldNames()
1166 return array($this->envfield
, $this->onlymentorfield
);
1171 // {{{ class UFBF_JobCv
1172 class UFBF_JobCv
extends UFBF_Text
1174 private $onlymentorfield;
1176 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1178 parent
::__construct($envfield, $formtext);
1179 $this->onlymentorfield
= $onlymentorfield;
1182 protected function buildUFC(UserFilterBuilder
$ufb)
1184 if ($ufb->isOn($this->onlymentorfield
)) {
1185 return new UFC_Mentor_Expertise($this->val
);
1187 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1191 public function getEnvFieldNames()
1193 return array($this->envfield
, $this->onlymentorfield
);
1198 // {{{ class UFBF_Nationality
1199 class UFBF_Nationality
extends UFBF_Mixed
1201 protected $direnum = DirEnum
::NATIONALITIES
;
1203 protected function buildUFC(UserFilterBuilder
$ufb)
1205 return new UFC_Nationality($this->val
);
1210 // {{{ class UFBF_Binet
1211 class UFBF_Binet
extends UFBF_Mixed
1213 protected $direnum = DirEnum
::BINETS
;
1215 protected function buildUFC(UserFilterBuilder
$ufb)
1217 return new UFC_Binet($this->val
);
1222 // {{{ class UFBF_Group
1223 class UFBF_Group
extends UFBF_Mixed
1225 protected $direnum = DirEnum
::GROUPESX
;
1227 protected function buildUFC(UserFilterBuilder
$ufb)
1229 if (count($this->val
) == 1) {
1230 return new UFC_Group($this->val
[0]);
1234 foreach ($this->val
as $grp) {
1235 $or->addChild(new UFC_Group($grp));
1242 // {{{ class UFBF_Section
1243 class UFBF_Section
extends UFBF_Mixed
1245 protected $direnum = DirEnum
::SECTIONS
;
1247 protected function buildUFC(UserFilterBuilder
$ufb)
1249 return new UFC_Section($this->val
);
1254 // {{{ class UFBF_EducationSchool
1255 class UFBF_EducationSchool
extends UFBF_Mixed
1257 protected $direnum = DirEnum
::EDUSCHOOLS
;
1259 protected function buildUFC(UserFilterBuilder
$ufb)
1261 return new UFC_EducationSchool($this->val
);
1266 // {{{ class UFBF_EducationDegree
1267 class UFBF_EducationDegree
extends UFBF_Mixed
1269 protected $direnum = DirEnum
::EDUDEGREES
;
1271 protected function buildUFC(UserFilterBuilder
$ufb)
1273 return new UFC_EducationDegree($this->val
);
1278 // {{{ class UFBF_EducationField
1279 class UFBF_EducationField
extends UFBF_Mixed
1281 protected $direnum = DirEnum
::EDUFIELDS
;
1283 protected function buildUFC(UserFilterBuilder
$ufb)
1285 return new UFC_EducationField($this->val
);
1290 // {{{ class UFBF_OriginCorps
1291 class UFBF_OriginCorps
extends UFBF_Index
1293 protected $direnum = DirEnum
::ORIGINCORPS
;
1295 protected function buildUFC(UserFilterBuilder
$ufb)
1297 return new UFC_Corps(null
, $this->val
, UFC_Corps
::ORIGIN
);
1302 // {{{ class UFBF_CurrentCorps
1303 class UFBF_CurrentCorps
extends UFBF_Index
1305 protected $direnum = DirEnum
::CURRENTCORPS
;
1307 protected function buildUFC(UserFilterBuilder
$ufb)
1309 return new UFC_Corps(null
, $this->val
, UFC_Corps
::CURRENT
);
1314 // {{{ class UFBF_CorpsRank
1315 class UFBF_CorpsRank
extends UFBF_Index
1317 protected $direnum = DirEnum
::CORPSRANKS
;
1319 protected function buildUFC(UserFilterBuilder
$ufb)
1321 return new UFC_Corps_Rank(null
, $this->val
);
1326 // {{{ class UFBF_Comment
1327 class UFBF_Comment
extends UFBF_Text
1329 protected function buildUFC(UserFilterBuilder
$ufb)
1331 return new UFC_Comment($this->val
);
1336 // {{{ class UFBF_Phone
1337 class UFBF_Phone
extends UFBF_Text
1339 protected function buildUFC(UserFilterBuilder
$ufb)
1341 return new UFC_Phone($this->val
);
1346 // {{{ class UFBF_Networking
1347 class UFBF_Networking
extends UFBF_Text
1349 private $networktypefield;
1352 public function __construct($envfield, $networktypefield, $formtext = '')
1354 parent
::__construct($envfield, $formtext);
1355 $this->networktypefield
= $networktypefield;
1358 public function check(UserFilterBuilder
$ufb)
1360 if (parent
::check($ufb)) {
1361 $this->nwtype
= $ufb->i($this->networktypefield
);
1368 public function isEmpty()
1370 return parent
::isEmpty() ||
$this->nwtype
== 0;
1373 public function buildUFC(UserFilterBuilder
$ufb)
1375 return new UFC_Networking($this->nwtype
, $this->val
);
1378 public function getEnvFieldNames()
1380 return array($this->envfield
, $this->networktypefield
);
1385 // {{{ class UFBF_Mentor
1386 class UFBF_Mentor
extends UFBF_Bool
1388 protected function buildUFC(UserFilterBuilder
$ufb)
1390 return new UFC_Mentor();
1395 // {{{ class UFBF_MentorCountry
1396 class UFBF_MentorCountry
extends UFBF_Text
1398 protected function buildUFC(UserFilterBuilder
$ufb)
1400 return new UFC_Mentor_Country($this->val
);
1405 // {{{ class UFBF_Mentorterm
1406 class UFBF_MentorTerm
extends UFBF_Index
1408 protected function buildUFC(UserFilterBuilder
$ufb)
1410 return new UFC_Mentor_Terms($this->val
);
1415 // {{{ class UFBF_MentorExpertise
1416 class UFBF_MentorExpertise
extends UFBF_Text
1418 protected function buildUFC(UserFilterBuilder
$ufb)
1420 return new UFC_Mentor_Expertise($this->val
);
1425 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: