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_DeltaTenSearch
405 class UFB_DeltaTenSearch
extends UserFilterBuilder
407 public function __construct($envprefix = '')
410 new UFBF_DeltaTenMessage('deltaten_message'),
412 new UFBF_Town('city', 'Ville / Code Postal'),
413 new UFBF_Country('countryTxt', 'country', 'Pays'),
414 new UFBF_AdminArea('administrativearea', 'Région'),
415 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
418 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
419 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
420 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
422 new UFBF_JobCompany('entreprise', 'Entreprise'),
423 new UFBF_JobDescription('jobdescription', 'Fonction'),
424 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
426 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
427 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
428 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
429 new UFBF_Section('sectionTxt', 'section', 'Section'),
430 new UFBF_Sex('woman', 'Sexe'),
432 parent
::__construct($fields, $envprefix);
437 // {{{ class UFB_NewsLetter
438 class UFB_NewsLetter
extends UserFilterBuilder
440 const FIELDS_PROMO
= 'promo';
441 const FIELDS_AXID
= 'axid';
442 const FIELDS_GEO
= 'geo';
444 public function __construct($flags, $envprefix = '')
447 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
448 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1', 'edu_type');
449 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2', 'edu_type');
451 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
452 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
454 parent
::__construct($fields, $envprefix);
459 // {{{ class UFB_Field
460 abstract class UFB_Field
465 protected $empty = false
;
466 protected $val = null
;
469 * @param $envfield Name of the field in the environment
470 * @param $formtext User-friendly name of that field
472 public function __construct($envfield, $formtext = '')
474 $this->envfield
= $envfield;
475 if ($formtext != '') {
476 $this->formtext
= $formtext;
478 $formtext = ucfirst($envfield);
482 /** Prints the given error message to the user, and returns false
483 * in order to be used as return $this->raise('ERROR');
485 * All %s in the $msg will be replaced with the formtext.
487 protected function raise($msg)
489 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
493 public function apply(UserFilterBuilder
$ufb) {
494 if (!$this->check($ufb)) {
498 if (!$this->isEmpty()) {
499 $ufc = $this->buildUFC($ufb);
507 public function isEmpty()
512 /** Create the UFC associated to the field; won't be called
513 * if the field is "empty"
514 * @param $ufb UFB to which fields must be added
517 abstract protected function buildUFC(UserFilterBuilder
$ufb);
519 /** This function is intended to run consistency checks on the value
520 * @return boolean Whether the input is valid
522 abstract protected function check(UserFilterBuilder
$ufb);
524 // Simple form interface
526 /** Retrieve a list of env field names used by that field
527 * their values will be recorded when saving the 'search' and used to prefill the form
530 public function getEnvFieldNames()
532 return array($this->envfield
);
537 // {{{ class UFBF_Text
538 abstract class UFBF_Text
extends UFB_Field
543 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
545 parent
::__construct($envfield, $formtext);
546 $this->minlength
= $minlength;
547 $this->maxlength
= $maxlength;
550 protected function check(UserFilterBuilder
$ufb)
552 if ($ufb->blank($this->envfield
)) {
557 $this->val
= $ufb->t($this->envfield
);
558 if (strlen($this->val
) < $this->minlength
) {
559 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
560 } else if (strlen($this->val
) > $this->maxlength
) {
561 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
562 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
563 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
571 // {{{ class UFBF_Range
572 /** Subclass to use for fields which only allow integers within a range
574 abstract class UFBF_Range
extends UFB_Field
580 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
582 parent
::__construct($envfield, $formtext);
587 protected function check(UserFilterBuilder
$ufb)
589 if ($ufb->blank($this->envfield
)) {
594 $this->val
= $ufb->i($this->envfield
);
595 if ($this->val
< $this->min
) {
596 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
597 } else if ($this->val
> $this->max
) {
598 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
605 // {{{ class UFBF_Index
606 /** Subclass to use for indexed fields
608 abstract class UFBF_Index
extends UFB_Field
610 protected function check(UserFilterBuilder
$ufb)
612 if ($ufb->blank($this->envfield
)) {
615 $this->val
= $ufb->i($this->envfield
);
621 // {{{ class UFBF_Enum
622 /** Subclass to use for fields whose value must belong to a specific set of values
624 abstract class UFBF_Enum
extends UFB_Field
626 protected $allowedvalues;
628 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
630 parent
::__construct($envfield, $formtext);
631 $this->allowedvalues
= $allowedvalues;
632 $this->strict
= $strict;
635 protected function check(UserFilterBuilder
$ufb)
637 if ($ufb->blank($this->envfield
)) {
642 $this->val
= $ufb->v($this->envfield
);
643 if (! in_array($this->val
, $this->allowedvalues
)) {
645 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
655 // {{{ class UFBF_Bool
656 abstract class UFBF_Bool
extends UFB_Field
658 protected function check(UserFilterBuilder
$ufb)
660 if ($ufb->blank($this->envfield
)) {
665 $this->val
= $ufb->b($this->envfield
);
671 // {{{ class UFBF_Mixed
672 /** A class for building UFBFs when the user can input either a text or an ID
674 abstract class UFBF_Mixed
extends UFB_Field
676 /** Name of the DirEnum on which class is based
680 protected $envfieldindex;
682 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
684 parent
::__construct($envfieldtext, $formtext);
685 $this->envfieldindex
= $envfieldindex;
688 protected function check(UserFilterBuilder
$ufb)
690 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
695 if (!$ufb->blank($this->envfieldindex
)) {
696 $index = $ufb->v($this->envfieldindex
);
697 if (is_int($index)) {
698 $index = intval($index);
700 $index = strtoupper($index);
702 $this->val
= array($index);
704 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
705 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
706 if (count($indexes) == 0) {
709 $this->val
= $indexes;
714 public function getEnvFieldNames()
716 return array($this->envfieldindex
, $this->envfield
);
721 // {{{ class UFBF_Quick
722 class UFBF_Quick
extends UFB_Field
724 protected function check(UserFilterBuilder
$ufb)
726 if ($ufb->blank($this->envfield
)) {
731 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
736 protected function buildUFC(UserFilterBuilder
$ufb)
739 $r = $s = $this->val
;
743 if (S
::admin() && strpos($s, '@') !== false
) {
744 return new UFC_Email($s);
745 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
746 return new UFC_Ip($s);
749 $conds = new PFC_And();
753 $s = preg_replace('!\d+!', ' ', $s);
754 $strings = preg_split("![^a-z%]+!i", $s, -1, PREG_SPLIT_NO_EMPTY
);
755 foreach ($strings as $key => $string) {
756 if (strlen($string) < 2) {
757 unset($strings[$key]);
760 if (count($strings) > 5) {
761 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
762 $strings = array_slice($strings, 0, 5);
765 if (count($strings)) {
766 if (S
::user() != null
&& S
::user()->checkPerms('directory_private')) {
769 $flags = array('public');
771 $exact =$ufb->b('exact');
772 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
774 $ufb->addOrder(new UFO_Score());
779 $s = preg_replace('! *- *!', '-', $r);
780 $s = preg_replace('!([<>]) *!', ' \1', $s);
781 $s = preg_replace('![^0-9xmd\-><]!i', ' ', $s);
782 $s = preg_replace('![<>\-] !', '', $s);
783 $ranges = preg_split('! +!', strtolower($s), -1, PREG_SPLIT_NO_EMPTY
);
784 $grades = array('' => UserFilter
::GRADE_ING
, 'x' => UserFilter
::GRADE_ING
, 'm' => UserFilter
::GRADE_MST
, 'd' => UserFilter
::GRADE_PHD
);
785 foreach ($ranges as $r) {
786 if (preg_match('!^([xmd]?)(\d{4})$!', $r, $matches)) {
787 $conds->addChild(new UFC_Promo('=', $grades[$matches[1]], $matches[2]));
788 } elseif (preg_match('!^([xmd]?)(\d{4})-\1(\d{4})$!', $r, $matches)) {
789 $p1 = min(intval($matches[2]), intval($matches[3]));
790 $p2 = max(intval($matches[2]), intval($matches[3]));
791 $conds->addChild(new PFC_And(
792 new UFC_Promo('>=', $grades[$matches[1]], $p1),
793 new UFC_Promo('<=', $grades[$matches[1]], $p2)
795 } elseif (preg_match('!^<([xmd]?)(\d{4})!', $r, $matches)) {
796 $conds->addChild(new UFC_Promo('<=', $grades[$matches[1]], $matches[2]));
797 } elseif (preg_match('!^>([xmd]?)(\d{4})!', $r, $matches)) {
798 $conds->addChild(new UFC_Promo('>=', $grades[$matches[1]], $matches[2]));
804 $t = preg_replace('!([xmd]?\d{4}-|>|<|)[xmd]?\d{4}!i', '', $s);
805 $t = preg_replace('![<>\- ]!', '', $t);
806 if (strlen($t) > 4) {
807 $conds->addChild(new UFC_Phone($t));
815 // {{{ class UFBF_SchoolIds
816 class UFBF_SchoolIds
extends UFB_Field
818 // One of UFC_SchoolId types
820 protected $reversed_envfield;
821 protected $reversed = false
;
823 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
825 parent
::__construct($envfield, $formtext);
827 if ($reversed_envfield == '') {
828 $reversed_envfield = $envfield . '_reversed';
830 $this->reversed_envfield
= $reversed_envfield;
833 protected function check(UserFilterBuilder
$ufb)
835 if ($ufb->blank($this->envfield
)) {
840 $value = $ufb->t($this->envfield
);
841 $values = explode("\r\n", $value);
843 foreach ($values as $val) {
844 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
848 if (count($ids) == 0) {
849 return $this->raise("Le champ %s ne contient aucune valeur valide.");
852 $this->reversed
= $ufb->b($this->reversed_envfield
);
857 protected function buildUFC(UserFilterBuilder
$ufb)
859 $ufc = new UFC_SchoolId($this->type
, $this->val
);
860 if ($this->reversed
) {
861 return new PFC_Not($ufc);
869 // {{{ class UFBF_Name
870 class UFBF_Name
extends UFBF_Text
872 private $envfieldtype;
875 public function __construct($envfield, $formtext = '', $envfieldtype)
877 parent
::__construct($envfield, $formtext);
878 $this->envfieldtype
= $envfieldtype;
881 protected function check(UserFilterBuilder
$ufb)
883 if (!parent
::check($ufb)) {
887 require_once 'name.func.inc.php';
889 $this->val
= split_name_for_search($this->val
);
890 if (count($this->val
) == 0) {
893 $this->type
= $ufb->v($this->envfieldtype
);
894 if (!in_array($this->type
, array('', 'lastname', 'firstname', 'nickname'))) {
895 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
900 protected function buildUFC(UserFilterBuilder
$ufb)
902 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'), $this->type
);
905 public function getEnvFieldNames()
907 return array($this->envfield
, $this->envfieldtype
);
912 // {{{ class UFBF_Promo
913 class UFBF_Promo
extends UFB_Field
915 private static $validcomps = array('<', '<=', '=', '>=', '>');
916 private static $validtypes = array(UserFilter
::GRADE_ING
, UserFilter
::GRADE_PHD
, UserFilter
::GRADE_MST
);
919 private $envfieldcomp;
920 private $envfieldtype;
922 public function __construct($envfield, $formtext = '', $envfieldcomp, $envfieldtype)
924 parent
::__construct($envfield, $formtext);
925 $this->envfieldcomp
= $envfieldcomp;
926 $this->envfieldtype
= $envfieldtype;
929 protected function check(UserFilterBuilder
$ufb)
931 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
) ||
$ufb->blank($this->envfieldtype
)) {
936 $this->val
= $ufb->i($this->envfield
);
937 $this->comp
= $ufb->v($this->envfieldcomp
);
938 $this->type
= $ufb->v($this->envfieldtype
);
940 if (!in_array($this->type
, self
::$validtypes)) {
941 return $this->raise("Le critère {$this->type} n'est pas valide pour le champ %s");
944 if (!in_array($this->comp
, self
::$validcomps)) {
945 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
948 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
951 if ($this->val
< 1900 ||
$this->val
> 9999) {
952 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
957 protected function buildUFC(UserFilterBuilder
$ufb) {
958 return new UFC_Promo($this->comp
, $this->type
, $this->val
);
961 public function getEnvFieldNames()
963 return array($this->envfield
, $this->envfieldcomp
, $this->envfieldtype
);
968 // {{{ class UFBF_Sex
969 class UFBF_Sex
extends UFBF_Enum
971 public function __construct($envfield, $formtext = '')
973 parent
::__construct($envfield, $formtext, array(1, 2));
976 private static function getVal($id)
980 return User
::GENDER_MALE
;
983 return User
::GENDER_FEMALE
;
988 protected function buildUFC(UserFilterBuilder
$ufb)
990 return new UFC_Sex(self
::getVal($this->val
));
995 // {{{ class UFBF_NotRegistered
996 // Simple field for selecting only alive, not registered users (for quick search)
997 class UFBF_NotRegistered
extends UFBF_Bool
999 protected function buildUFC(UserFilterBuilder
$ufb)
1003 new PFC_Not(new UFC_Dead()),
1004 new PFC_Not(new UFC_Registered())
1011 // {{{ class UFBF_Registered
1012 class UFBF_Registered
extends UFBF_Enum
1014 public function __construct($envfield, $formtext = '')
1016 parent
::__construct($envfield, $formtext, array(1, 2));
1019 protected function buildUFC(UserFilterBuilder
$ufb)
1021 if ($this->val
== 1) {
1022 return new UFC_Registered();
1023 } else if ($this->val
== 2) {
1024 return new PFC_Not(new UFC_Registered());
1030 // {{{ class UFBF_HasEmailRedirect
1031 class UFBF_HasEmailRedirect
extends UFBF_Enum
1033 public function __construct($envfield, $formtext = '')
1035 parent
::__construct($envfield, $formtext, array(1, 2));
1038 protected function buildUFC(UserFilterBuilder
$ufb)
1040 if ($this->val
== 1) {
1041 return new UFC_HasEmailRedirect();
1042 } else if ($this->val
== 2) {
1043 return new PFC_Not(new UFC_HasEmailRedirect());
1049 // {{{ class UFBF_Dead
1050 class UFBF_Dead
extends UFBF_Enum
1052 public function __construct($envfield, $formtext = '')
1054 parent
::__construct($envfield, $formtext, array(1, 2));
1057 protected function buildUFC(UserFilterBuilder
$ufb)
1059 if ($this->val
== 1) {
1060 return new PFC_Not(new UFC_Dead());
1061 } else if ($this->val
== 2) {
1062 return new UFC_Dead();
1068 // {{{ class UFBF_Town
1069 /** Retrieves a town, either from a postal code or a town name
1071 class UFBF_Town
extends UFBF_Text
1073 const TYPE_TEXT
= 1;
1078 private $onlycurrentfield;
1080 public function __construct($envfield, $formtext = '', $type = self
::TYPE_ANY
, $onlycurrentfield = 'only_current')
1082 $this->type
= $type;
1083 $this->onlycurrentfield
= $onlycurrentfield;
1084 parent
::__construct($envfield, $formtext, 2, 30);
1087 protected function buildUFC(UserFilterBuilder
$ufb)
1089 if ($ufb->isOn($this->onlycurrentfield
)) {
1090 $flags = UFC_Address
::FLAG_CURRENT
;
1092 $flags = UFC_Address
::FLAG_ANY
;
1095 if (preg_match('/[0-9]/', $this->val
)) {
1096 if ($this->type
& self
::TYPE_ZIP
) {
1097 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1099 return new PFC_False();
1102 $byname = new UFC_AddressText(null
, XDB
::WILDCARD_CONTAINS
, UFC_Address
::TYPE_ANY
, $flags, null
, $this->val
);
1103 $byzip = new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1104 if ($this->type
& self
::TYPE_ANY
) {
1105 return new PFC_Or($byname, $byzip);
1106 } else if ($this->type
& self
::TYPE_TEXT
) {
1114 public function getEnvFieldNames()
1116 return array($this->envfield
, $this->onlycurrentfield
);
1121 // {{{ class UFBF_Country
1122 class UFBF_Country
extends UFBF_Mixed
1124 protected $direnum = DirEnum
::COUNTRIES
;
1125 protected $onlycurrentfield;
1127 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
1129 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1130 $this->onlycurrentfield
= $onlycurrentfield;
1133 protected function buildUFC(UserFilterBuilder
$ufb)
1135 if ($ufb->isOn($this->onlycurrentfield
)) {
1136 $flags = UFC_Address
::FLAG_CURRENT
;
1138 $flags = UFC_Address
::FLAG_ANY
;
1141 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_COUNTRY
, UFC_Address
::TYPE_ANY
, $flags);
1144 public function getEnvFieldNames()
1146 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1151 // {{{ class UFBF_AdminArea
1152 class UFBF_AdminArea
extends UFBF_Index
1154 protected $direnum = DirEnum
::ADMINAREAS
;
1155 protected $onlycurrentfield;
1157 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1159 parent
::__construct($envfield, $formtext);
1160 $this->onlycurrentfield
= $onlycurrentfield;
1164 protected function buildUFC(UserFilterBuilder
$ufb)
1166 if ($ufb->isOn($this->onlycurrentfield
)) {
1167 $flags = UFC_Address
::FLAG_CURRENT
;
1169 $flags = UFC_Address
::FLAG_ANY
;
1172 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1175 public function getEnvFieldNames()
1177 return array($this->envfield
, $this->onlycurrentfield
);
1182 // {{{ class UFBF_SubAdminArea
1183 class UFBF_SubAdminArea
extends UFBF_Index
1185 protected $direnum = DirEnum
::SUBADMINAREAS
;
1186 protected $onlycurrentfield;
1188 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1190 parent
::__construct($envfield, $formtext);
1191 $this->onlycurrentfield
= $onlycurrentfield;
1195 protected function buildUFC(UserFilterBuilder
$ufb)
1197 if ($ufb->isOn($this->onlycurrentfield
)) {
1198 $flags = UFC_Address
::FLAG_CURRENT
;
1200 $flags = UFC_Address
::FLAG_ANY
;
1203 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_SUBADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1206 public function getEnvFieldNames()
1208 return array($this->envfield
, $this->onlycurrentfield
);
1213 // {{{ class UFBF_JobCompany
1214 class UFBF_JobCompany
extends UFBF_Text
1216 private $onlymentorfield;
1218 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1220 parent
::__construct($envfield, $formtext);
1221 $this->onlymentorfield
= $onlymentorfield;
1224 public function check(UserFilterBuilder
$ufb) {
1225 if (parent
::check($ufb)) {
1226 # No company check for mentors
1227 if ($ufb->isOn($this->onlymentorfield
)) {
1228 $this->empty = true
;
1236 protected function buildUFC(UserFilterBuilder
$ufb)
1238 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1241 public function getEnvFieldNames()
1243 return array($this->envfield
, $this->onlymentorfield
);
1248 // {{{ class UFBF_JobTerms
1249 class UFBF_JobTerms
extends UFBF_Index
1251 protected function buildUFC(UserFilterBuilder
$ufb)
1253 return new UFC_Job_Terms($this->val
);
1258 // {{{ class UFBF_JobDescription
1259 class UFBF_JobDescription
extends UFBF_Text
1261 private $onlymentorfield;
1263 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1265 parent
::__construct($envfield, $formtext);
1266 $this->onlymentorfield
= $onlymentorfield;
1269 protected function buildUFC(UserFilterBuilder
$ufb)
1271 if ($ufb->isOn($this->onlymentorfield
)) {
1272 return new UFC_Mentor_Expertise($this->val
);
1274 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1278 public function getEnvFieldNames()
1280 return array($this->envfield
, $this->onlymentorfield
);
1285 // {{{ class UFBF_JobCv
1286 class UFBF_JobCv
extends UFBF_Text
1288 private $onlymentorfield;
1290 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1292 parent
::__construct($envfield, $formtext);
1293 $this->onlymentorfield
= $onlymentorfield;
1296 protected function buildUFC(UserFilterBuilder
$ufb)
1298 if ($ufb->isOn($this->onlymentorfield
)) {
1299 return new UFC_Mentor_Expertise($this->val
);
1301 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1305 public function getEnvFieldNames()
1307 return array($this->envfield
, $this->onlymentorfield
);
1312 // {{{ class UFBF_Nationality
1313 class UFBF_Nationality
extends UFBF_Mixed
1315 protected $direnum = DirEnum
::NATIONALITIES
;
1317 protected function buildUFC(UserFilterBuilder
$ufb)
1319 return new UFC_Nationality($this->val
);
1324 // {{{ class UFBF_Binet
1325 class UFBF_Binet
extends UFBF_Mixed
1327 protected $direnum = DirEnum
::BINETS
;
1329 protected function buildUFC(UserFilterBuilder
$ufb)
1331 return new UFC_Binet($this->val
);
1336 // {{{ class UFBF_Group
1337 class UFBF_Group
extends UFBF_Mixed
1339 protected $direnum = DirEnum
::GROUPESX
;
1341 protected function buildUFC(UserFilterBuilder
$ufb)
1343 if (count($this->val
) == 1) {
1344 return new UFC_Group($this->val
[0]);
1348 foreach ($this->val
as $grp) {
1349 $or->addChild(new UFC_Group($grp));
1356 // {{{ class UFBF_Section
1357 class UFBF_Section
extends UFBF_Mixed
1359 protected $direnum = DirEnum
::SECTIONS
;
1361 protected function buildUFC(UserFilterBuilder
$ufb)
1363 return new UFC_Section($this->val
);
1368 // {{{ class UFBF_EducationSchool
1369 class UFBF_EducationSchool
extends UFBF_Mixed
1371 protected $direnum = DirEnum
::EDUSCHOOLS
;
1373 protected function buildUFC(UserFilterBuilder
$ufb)
1375 return new UFC_EducationSchool($this->val
);
1380 // {{{ class UFBF_EducationDegree
1381 class UFBF_EducationDegree
extends UFBF_Mixed
1383 protected $direnum = DirEnum
::EDUDEGREES
;
1385 protected function buildUFC(UserFilterBuilder
$ufb)
1387 return new UFC_EducationDegree($this->val
);
1392 // {{{ class UFBF_EducationField
1393 class UFBF_EducationField
extends UFBF_Mixed
1395 protected $direnum = DirEnum
::EDUFIELDS
;
1397 protected function buildUFC(UserFilterBuilder
$ufb)
1399 return new UFC_EducationField($this->val
);
1404 // {{{ class UFBF_OriginCorps
1405 class UFBF_OriginCorps
extends UFBF_Index
1407 protected $direnum = DirEnum
::ORIGINCORPS
;
1409 protected function buildUFC(UserFilterBuilder
$ufb)
1411 return new UFC_Corps(null
, $this->val
, UFC_Corps
::ORIGIN
);
1416 // {{{ class UFBF_CurrentCorps
1417 class UFBF_CurrentCorps
extends UFBF_Index
1419 protected $direnum = DirEnum
::CURRENTCORPS
;
1421 protected function buildUFC(UserFilterBuilder
$ufb)
1423 return new UFC_Corps(null
, $this->val
, UFC_Corps
::CURRENT
);
1428 // {{{ class UFBF_CorpsRank
1429 class UFBF_CorpsRank
extends UFBF_Index
1431 protected $direnum = DirEnum
::CORPSRANKS
;
1433 protected function buildUFC(UserFilterBuilder
$ufb)
1435 return new UFC_Corps_Rank(null
, $this->val
);
1440 // {{{ class UFBF_Comment
1441 class UFBF_Comment
extends UFBF_Text
1443 protected function buildUFC(UserFilterBuilder
$ufb)
1445 return new UFC_Comment($this->val
);
1450 // {{{ class UFBF_Phone
1451 class UFBF_Phone
extends UFBF_Text
1453 protected function buildUFC(UserFilterBuilder
$ufb)
1455 return new UFC_Phone($this->val
);
1460 // {{{ class UFBF_Networking
1461 class UFBF_Networking
extends UFBF_Text
1463 private $networktypefield;
1466 public function __construct($envfield, $networktypefield, $formtext = '')
1468 parent
::__construct($envfield, $formtext);
1469 $this->networktypefield
= $networktypefield;
1472 public function check(UserFilterBuilder
$ufb)
1474 if (parent
::check($ufb)) {
1475 $this->nwtype
= $ufb->i($this->networktypefield
);
1482 public function isEmpty()
1484 return parent
::isEmpty() ||
$this->nwtype
== 0;
1487 public function buildUFC(UserFilterBuilder
$ufb)
1489 return new UFC_Networking($this->nwtype
, $this->val
);
1492 public function getEnvFieldNames()
1494 return array($this->envfield
, $this->networktypefield
);
1499 // {{{ class UFBF_Mentor
1500 class UFBF_Mentor
extends UFBF_Bool
1502 protected function buildUFC(UserFilterBuilder
$ufb)
1504 return new UFC_Mentor();
1509 // {{{ class UFBF_MentorCountry
1510 class UFBF_MentorCountry
extends UFBF_Text
1512 protected function buildUFC(UserFilterBuilder
$ufb)
1514 return new UFC_Mentor_Country($this->val
);
1519 // {{{ class UFBF_Mentorterm
1520 class UFBF_MentorTerm
extends UFBF_Index
1522 protected function buildUFC(UserFilterBuilder
$ufb)
1524 return new UFC_Mentor_Terms($this->val
);
1529 // {{{ class UFBF_MentorExpertise
1530 class UFBF_MentorExpertise
extends UFBF_Text
1532 protected function buildUFC(UserFilterBuilder
$ufb)
1534 return new UFC_Mentor_Expertise($this->val
);
1539 // {{{ class UFBF_DeltaTenMessage
1540 class UFBF_DeltaTenMessage
extends UFBF_Text
1542 protected function buildUFC(UserFilterBuilder
$ufb)
1544 return new UFC_DeltaTen_Message($this->val
);
1549 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: