b3233e1c7c7880cc8abbe4e5cb53d783410f8e93
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()
188 return new PFC_False();
192 /** Returns adequate orders
194 public function getOrders()
197 return $this->orders
;
200 public function getEnvFieldNames()
203 foreach ($this->fields
as $ufbf) {
204 $fields = array_merge($fields, $ufbf->getEnvFieldNames());
206 return array_unique($fields);
209 public function getEnv()
212 foreach ($this->getEnvFieldNames() as $field) {
213 if ($this->has($field)) {
214 $values[$field] = $this->v($field);
220 public function setEnv($values)
222 foreach ($this->getEnvFieldNames() as $field) {
223 if (array_key_exists($field, $values)) {
224 Env
::set($this->envprefix
. $field, $values[$field]);
229 /** Wrappers around Env::i/s/..., to add envprefix
231 public function s($key, $def = '')
233 if ($this->fake_env
) {
234 return $this->fake_env
->s($key, $def);
236 return Env
::s($this->envprefix
. $key, $def);
240 public function t($key, $def = '')
242 if ($this->fake_env
) {
243 return $this->fake_env
->t($key, $def);
245 return Env
::t($this->envprefix
. $key, $def);
249 public function i($key, $def = 0)
251 if ($this->fake_env
) {
252 return $this->fake_env
->i($key, $def);
254 return Env
::i($this->envprefix
. $key, $def);
258 public function v($key, $def = null
)
260 if ($this->fake_env
) {
261 return $this->fake_env
->v($key, $def);
263 return Env
::v($this->envprefix
. $key, $def);
267 public function b($key, $def = false
)
269 if ($this->fake_env
) {
270 return $this->fake_env
->b($key, $def);
272 return Env
::b($this->envprefix
. $key, $def);
276 public function has($key)
278 if ($this->fake_env
) {
279 return $this->fake_env
->has($key);
281 return Env
::has($this->envprefix
. $key);
285 public function blank($key, $strict = false
)
287 if ($this->fake_env
) {
288 return $this->fake_env
->blank($key, $strict);
290 return Env
::blank($key, $strict);
294 public function hasAlnum($key)
296 $str = $this->s($key);
297 return preg_match('/[a-z0-9]/i', $str);
300 public function hasAlpha($key)
302 $str = $this->s($key);
303 return preg_match('/[a-z]/i', $str);
306 public function isOn($key)
308 return $this->has($key) && $this->t($key) == 'on';
313 // {{{ class UFB_QuickSearch
314 class UFB_QuickSearch
extends UserFilterBuilder
316 public function __construct($envprefix = '')
319 new UFBF_Quick('quick', 'Recherche rapide'),
320 new UFBF_NotRegistered('nonins', 'Non inscrits'),
322 parent
::__construct($fields, $envprefix);
327 // {{{ class UFB_AdvancedSearch
328 class UFB_AdvancedSearch
extends UserFilterBuilder
330 /** Create a UFB_AdvancedSearch.
331 * @param $include_admin Whether to include 'admin-only' fields
332 * @param $include_ax Whether to include 'ax-only' fields
333 * @param $envprefix Optional prefix for form field names.
335 public function __construct($include_admin = false
, $include_ax = false
, $envprefix = '')
338 new UFBF_Name('name', 'Nom'),
339 new UFBF_Promo('promo1', 'Promotion', 'egal1'),
340 new UFBF_Promo('promo2', 'Promotion', 'egal2'),
341 new UFBF_Sex('woman', 'Sexe'),
342 new UFBF_Registered('subscriber', 'Inscrit'),
343 new UFBF_Dead('alive', 'En vie'),
345 new UFBF_Town('city', 'Ville / Code Postal'),
346 new UFBF_Country('countryTxt', 'country', 'Pays'),
347 new UFBF_AdminArea('administrativearea', 'Région'),
348 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
350 new UFBF_JobCompany('entreprise', 'Entreprise'),
351 new UFBF_JobDescription('jobdescription', 'Fonction'),
352 new UFBF_JobCv('cv', 'CV'),
353 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
355 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
356 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
357 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
358 new UFBF_Section('sectionTxt', 'section', 'Section'),
360 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
361 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
362 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
364 new UFBF_Comment('free', 'Commentaire'),
365 new UFBF_Phone('phone_number', 'Téléphone'),
366 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
368 new UFBF_Mentor('only_referent', 'Référent'),
371 if ($include_admin ||
$include_ax) {
372 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId
::AX
);
375 parent
::__construct($fields, $envprefix);
380 // {{{ class UFB_MentorSearch
381 class UFB_MentorSearch
extends UserFilterBuilder
383 public function __construct($envprefix = '')
386 new UFBF_MentorCountry('country'),
387 new UFBF_MentorTerm('jobterm', 'jobtermText'),
388 new UFBF_MentorExpertise('expertise'),
390 parent
::__construct($fields, $envprefix);
395 // {{{ class UFB_NewsLetter
396 class UFB_NewsLetter
extends UserFilterBuilder
398 const FIELDS_PROMO
= 'promo';
399 const FIELDS_AXID
= 'axid';
400 const FIELDS_GEO
= 'geo';
402 public function __construct($flags, $envprefix = '')
405 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
406 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
407 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
409 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
410 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
412 parent
::__construct($fields, $envprefix);
417 // {{{ class UFB_Field
418 abstract class UFB_Field
423 protected $empty = false
;
424 protected $val = null
;
427 * @param $envfield Name of the field in the environment
428 * @param $formtext User-friendly name of that field
430 public function __construct($envfield, $formtext = '')
432 $this->envfield
= $envfield;
433 if ($formtext != '') {
434 $this->formtext
= $formtext;
436 $formtext = ucfirst($envfield);
440 /** Prints the given error message to the user, and returns false
441 * in order to be used as return $this->raise('ERROR');
443 * All %s in the $msg will be replaced with the formtext.
445 protected function raise($msg)
447 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
451 public function apply(UserFilterBuilder
&$ufb) {
452 if (!$this->check($ufb)) {
456 if (!$this->isEmpty()) {
457 $ufc = $this->buildUFC($ufb);
465 public function isEmpty()
470 /** Create the UFC associated to the field; won't be called
471 * if the field is "empty"
472 * @param &$ufb UFB to which fields must be added
475 abstract protected function buildUFC(UserFilterBuilder
&$ufb);
477 /** This function is intended to run consistency checks on the value
478 * @return boolean Whether the input is valid
480 abstract protected function check(UserFilterBuilder
&$ufb);
482 // Simple form interface
484 /** Retrieve a list of env field names used by that field
485 * their values will be recorded when saving the 'search' and used to prefill the form
488 public function getEnvFieldNames()
490 return array($this->envfield
);
495 // {{{ class UFBF_Text
496 abstract class UFBF_Text
extends UFB_Field
501 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
503 parent
::__construct($envfield, $formtext);
504 $this->minlength
= $minlength;
505 $this->maxlength
= $maxlength;
508 protected function check(UserFilterBuilder
&$ufb)
510 if ($ufb->blank($this->envfield
)) {
515 $this->val
= $ufb->t($this->envfield
);
516 if (strlen($this->val
) < $this->minlength
) {
517 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
518 } else if (strlen($this->val
) > $this->maxlength
) {
519 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
520 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
521 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
529 // {{{ class UFBF_Range
530 /** Subclass to use for fields which only allow integers within a range
532 abstract class UFBF_Range
extends UFB_Field
538 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
540 parent
::__construct($envfield, $formtext);
545 protected function check(UserFilterBuilder
&$ufb)
547 if ($ufb->blank($this->envfield
)) {
552 $this->val
= $ufb->i($this->envfield
);
553 if ($this->val
< $this->min
) {
554 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
555 } else if ($this->val
> $this->max
) {
556 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
563 // {{{ class UFBF_Index
564 /** Subclass to use for indexed fields
566 abstract class UFBF_Index
extends UFB_Field
568 protected function check(UserFilterBuilder
&$ufb)
570 if ($ufb->blank($this->envfield
)) {
573 $this->val
= $ufb->i($this->envfield
);
579 // {{{ class UFBF_Enum
580 /** Subclass to use for fields whose value must belong to a specific set of values
582 abstract class UFBF_Enum
extends UFB_Field
584 protected $allowedvalues;
586 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
588 parent
::__construct($envfield, $formtext);
589 $this->allowedvalues
= $allowedvalues;
590 $this->strict
= $strict;
593 protected function check(UserFilterBuilder
&$ufb)
595 if ($ufb->blank($this->envfield
)) {
600 $this->val
= $ufb->v($this->envfield
);
601 if (! in_array($this->val
, $this->allowedvalues
)) {
603 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
613 // {{{ class UFBF_Bool
614 abstract class UFBF_Bool
extends UFB_Field
616 protected function check(UserFilterBuilder
&$ufb)
618 if ($ufb->blank($this->envfield
)) {
623 $this->val
= $ufb->b($this->envfield
);
629 // {{{ class UFBF_Mixed
630 /** A class for building UFBFs when the user can input either a text or an ID
632 abstract class UFBF_Mixed
extends UFB_Field
634 /** Name of the DirEnum on which class is based
638 protected $envfieldindex;
640 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
642 parent
::__construct($envfieldtext, $formtext);
643 $this->envfieldindex
= $envfieldindex;
646 protected function check(UserFilterBuilder
&$ufb)
648 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
653 if (!$ufb->blank($this->envfieldindex
)) {
654 $index = $ufb->v($this->envfieldindex
);
655 if (is_int($index)) {
656 $index = intval($index);
658 $index = strtoupper($index);
660 $this->val
= array($index);
662 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
663 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
664 if (count($indexes) == 0) {
667 $this->val
= $indexes;
672 public function getEnvFieldNames()
674 return array($this->envfieldindex
, $this->envfield
);
679 // {{{ class UFBF_Quick
680 class UFBF_Quick
extends UFB_Field
682 protected function check(UserFilterBuilder
&$ufb)
684 if ($ufb->blank($this->envfield
)) {
689 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
694 protected function buildUFC(UserFilterBuilder
&$ufb)
697 $r = $s = $this->val
;
701 if (S
::admin() && strpos($s, '@') !== false
) {
702 return new UFC_Email($s);
703 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
704 return new UFC_Ip($s);
707 $conds = new PFC_And();
711 $s = preg_replace('!\d+!', ' ', $s);
712 $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY
);
713 if (count($strings) > 5) {
714 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
715 $strings = array_slice($strings, 0, 5);
718 if (count($strings)) {
722 $flags = array('public');
724 $exact =$ufb->b('exact');
725 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
727 $ufb->addOrder(new UFO_Score());
732 $s = preg_replace('! *- *!', '-', $r);
733 $s = preg_replace('!([<>]) *!', ' \1', $s);
734 $s = preg_replace('![^0-9\-><]!', ' ', $s);
735 $s = preg_replace('![<>\-] !', '', $s);
736 $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY
);
737 foreach ($ranges as $r) {
738 if (preg_match('!^\d{4}$!', $r)) {
739 $conds->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, 'X' . $r));
740 } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
741 $p1=min(intval($matches[1]), intval($matches[2]));
742 $p2=max(intval($matches[1]), intval($matches[2]));
743 $conds->addChild(new PFC_And(
744 new UFC_Promo('>=', UserFilter
::DISPLAY
, 'X' . $p1),
745 new UFC_Promo('<=', UserFilter
::DISPLAY
, 'X' . $p2)
747 } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
748 $conds->addChild(new UFC_Promo('<=', UserFilter
::DISPLAY
, 'X' . $matches[1]));
749 } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
750 $conds->addChild(new UFC_Promo('>=', UserFilter
::DISPLAY
, 'X' . $matches[1]));
756 $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
757 $t = preg_replace('![<>\- ]!', '', $t);
758 if (strlen($t) > 4) {
759 $conds->addChild(new UFC_Phone($t));
767 // {{{ class UFBF_SchoolIds
768 class UFBF_SchoolIds
extends UFB_Field
770 // One of UFC_SchoolId types
772 protected $reversed_envfield;
773 protected $reversed = false
;
775 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
777 parent
::__construct($envfield, $formtext);
779 if ($reversed_envfield == '') {
780 $reversed_envfield = $envfield . '_reversed';
782 $this->reversed_envfield
= $reversed_envfield;
785 protected function check(UserFilterBuilder
&$ufb)
787 if ($ufb->blank($this->envfield
)) {
792 $value = $ufb->t($this->envfield
);
793 $values = explode("\n", $value);
795 foreach ($values as $val) {
796 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
800 if (count($ids) == 0) {
801 return $this->raise("Le champ %s ne contient aucune valeur valide.");
804 $this->reversed
= $ufb->b($this->reversed_envfield
);
809 protected function buildUFC(UserFilterBuilder
&$ufb)
811 $ufc = new UFC_SchoolId($this->type
, $this->val
);
812 if ($this->reversed
) {
813 return new PFC_Not($ufc);
821 // {{{ class UFBF_Name
822 class UFBF_Name
extends UFBF_Text
824 protected function check(UserFilterBuilder
&$ufb)
826 if (!parent
::check($ufb)) {
830 $this->val
= preg_split('/[[:space:]]/', $this->val
);
831 if (count($this->val
) == 0) {
837 protected function buildUFC(UserFilterBuilder
&$ufb)
839 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'));
844 // {{{ class UFBF_Promo
845 class UFBF_Promo
extends UFB_Field
847 private static $validcomps = array('<', '<=', '=', '>=', '>');
849 private $envfieldcomp;
851 public function __construct($envfield, $formtext = '', $envfieldcomp)
853 parent
::__construct($envfield, $formtext);
854 $this->envfieldcomp
= $envfieldcomp;
857 protected function check(UserFilterBuilder
&$ufb)
859 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
)) {
864 $this->val
= $ufb->i($this->envfield
);
865 $this->comp
= $ufb->v($this->envfieldcomp
);
867 if (!in_array($this->comp
, self
::$validcomps)) {
868 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
871 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
874 if ($this->val
< 1900 ||
$this->val
> 9999) {
875 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
880 protected function buildUFC(UserFilterBuilder
&$ufb) {
881 return new UFC_Promo($this->comp
, UserFilter
::GRADE_ING
, $this->val
);
884 public function getEnvFieldNames()
886 return array($this->envfield
, $this->envfieldcomp
);
891 // {{{ class UFBF_Sex
892 class UFBF_Sex
extends UFBF_Enum
894 public function __construct($envfield, $formtext = '')
896 parent
::__construct($envfield, $formtext, array(1, 2));
899 private static function getVal($id)
903 return User
::GENDER_MALE
;
906 return User
::GENDER_FEMALE
;
911 protected function buildUFC(UserFilterBuilder
&$ufb)
913 return new UFC_Sex(self
::getVal($this->val
));
918 // {{{ class UFBF_NotRegistered
919 // Simple field for selecting only alive, not registered users (for quick search)
920 class UFBF_NotRegistered
extends UFBF_Bool
922 protected function buildUFC(UserFilterBuilder
&$ufb)
926 new PFC_Not(new UFC_Dead()),
927 new PFC_Not(new UFC_Registered())
934 // {{{ class UFBF_Registered
935 class UFBF_Registered
extends UFBF_Enum
937 public function __construct($envfield, $formtext = '')
939 parent
::__construct($envfield, $formtext, array(1, 2));
942 protected function buildUFC(UserFilterBuilder
&$ufb)
944 if ($this->val
== 1) {
945 return new UFC_Registered();
946 } else if ($this->val
== 2) {
947 return new PFC_Not(new UFC_Registered());
953 // {{{ class UFBF_Dead
954 class UFBF_Dead
extends UFBF_Enum
956 public function __construct($envfield, $formtext = '')
958 parent
::__construct($envfield, $formtext, array(1, 2));
961 protected function buildUFC(UserFilterBuilder
&$ufb)
963 if ($this->val
== 1) {
964 return new PFC_Not(new UFC_Dead());
965 } else if ($this->val
== 2) {
966 return new UFC_Dead();
972 // {{{ class UFBF_Town
973 /** Retrieves a town, either from a postal code or a town name
975 class UFBF_Town
extends UFBF_Text
982 private $onlycurrentfield;
984 public function __construct($envfield, $formtext = '', $type = self
::TYPE_ANY
, $onlycurrentfield = 'only_current')
987 $this->onlycurrentfield
= $onlycurrentfield;
988 parent
::__construct($envfield, $formtext, 2, 30);
991 protected function buildUFC(UserFilterBuilder
&$ufb)
993 if ($ufb->isOn($this->onlycurrentfield
)) {
994 $flags = UFC_Address
::FLAG_CURRENT
;
996 $flags = UFC_Address
::FLAG_ANY
;
999 if (preg_match('/[0-9]/', $this->val
)) {
1000 if ($this->type
& self
::TYPE_ZIP
) {
1001 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1003 return new PFC_False();
1006 $byname = new UFC_AddressText(null
, XDB
::WILDCARD_CONTAINS
, UFC_Address
::TYPE_ANY
, $flags, null
, $this->val
);
1007 $byzip = new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1008 if ($this->type
& self
::TYPE_ANY
) {
1009 return new PFC_Or($byname, $byzip);
1010 } else if ($this->type
& self
::TYPE_TEXT
) {
1018 public function getEnvFieldNames()
1020 return array($this->envfield
, $this->onlycurrentfield
);
1025 // {{{ class UFBF_Country
1026 class UFBF_Country
extends UFBF_Mixed
1028 protected $direnum = DirEnum
::COUNTRIES
;
1029 protected $onlycurrentfield;
1031 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
1033 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1034 $this->onlycurrentfield
= $onlycurrentfield;
1037 protected function buildUFC(UserFilterBuilder
&$ufb)
1039 if ($ufb->isOn($this->onlycurrentfield
)) {
1040 $flags = UFC_Address
::FLAG_CURRENT
;
1042 $flags = UFC_Address
::FLAG_ANY
;
1045 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_COUNTRY
, UFC_Address
::TYPE_ANY
, $flags);
1048 public function getEnvFieldNames()
1050 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1055 // {{{ class UFBF_AdminArea
1056 class UFBF_AdminArea
extends UFBF_Index
1058 protected $direnum = DirEnum
::ADMINAREAS
;
1059 protected $onlycurrentfield;
1061 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1063 parent
::__construct($envfield, $formtext);
1064 $this->onlycurrentfield
= $onlycurrentfield;
1068 protected function buildUFC(UserFilterBuilder
&$ufb)
1070 if ($ufb->isOn($this->onlycurrentfield
)) {
1071 $flags = UFC_Address
::FLAG_CURRENT
;
1073 $flags = UFC_Address
::FLAG_ANY
;
1076 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1079 public function getEnvFieldNames()
1081 return array($this->envfield
, $this->onlycurrentfield
);
1086 // {{{ class UFBF_SubAdminArea
1087 class UFBF_SubAdminArea
extends UFBF_Index
1089 protected $direnum = DirEnum
::SUBADMINAREAS
;
1090 protected $onlycurrentfield;
1092 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1094 parent
::__construct($envfield, $formtext);
1095 $this->onlycurrentfield
= $onlycurrentfield;
1099 protected function buildUFC(UserFilterBuilder
&$ufb)
1101 if ($ufb->isOn($this->onlycurrentfield
)) {
1102 $flags = UFC_Address
::FLAG_CURRENT
;
1104 $flags = UFC_Address
::FLAG_ANY
;
1107 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_SUBADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1110 public function getEnvFieldNames()
1112 return array($this->envfield
, $this->onlycurrentfield
);
1117 // {{{ class UFBF_SubAdminArea
1118 class UFBF_SubAdminArea
extends UFBF_Index
1120 protected $direnum = DirEnum
::SUBADMINAREAS
;
1121 protected $onlycurrentfield;
1123 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1125 parent
::__construct($envfield, $formtext);
1126 $this->onlycurrentfield
= $onlycurrentfield;
1130 protected function buildUFC(UserFilterBuilder
&$ufb)
1132 if ($ufb->isOn($this->onlycurrentfield
)) {
1133 $flags = UFC_Address
::FLAG_CURRENT
;
1135 $flags = UFC_Address
::FLAG_ANY
;
1138 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_SUBADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1143 // {{{ class UFBF_JobCompany
1144 class UFBF_JobCompany
extends UFBF_Text
1146 private $onlymentorfield;
1148 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1150 parent
::__construct($envfield, $formtext);
1151 $this->onlymentorfield
= $onlymentorfield;
1154 public function check(UserFilterBuilder
&$ufb) {
1155 if (parent
::check($ufb)) {
1156 # No company check for mentors
1157 if ($ufb->isOn($this->onlymentorfield
)) {
1158 $this->empty = true
;
1166 protected function buildUFC(UserFilterBuilder
&$ufb)
1168 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1171 public function getEnvFieldNames()
1173 return array($this->envfield
, $this->onlymentorfield
);
1178 // {{{ class UFBF_JobTerms
1179 class UFBF_JobTerms
extends UFBF_Index
1181 protected function buildUFC(UserFilterBuilder
&$ufb)
1183 return new UFC_Job_Terms($this->val
);
1188 // {{{ class UFBF_JobDescription
1189 class UFBF_JobDescription
extends UFBF_Text
1191 private $onlymentorfield;
1193 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1195 parent
::__construct($envfield, $formtext);
1196 $this->onlymentorfield
= $onlymentorfield;
1199 protected function buildUFC(UserFilterBuilder
&$ufb)
1201 if ($ufb->isOn($this->onlymentorfield
)) {
1202 return new UFC_Mentor_Expertise($this->val
);
1204 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1208 public function getEnvFieldNames()
1210 return array($this->envfield
, $this->onlymentorfield
);
1215 // {{{ class UFBF_JobCv
1216 class UFBF_JobCv
extends UFBF_Text
1218 private $onlymentorfield;
1220 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1222 parent
::__construct($envfield, $formtext);
1223 $this->onlymentorfield
= $onlymentorfield;
1226 protected function buildUFC(UserFilterBuilder
&$ufb)
1228 if ($ufb->isOn($this->onlymentorfield
)) {
1229 return new UFC_Mentor_Expertise($this->val
);
1231 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1235 public function getEnvFieldNames()
1237 return array($this->envfield
, $this->onlymentorfield
);
1242 // {{{ class UFBF_Nationality
1243 class UFBF_Nationality
extends UFBF_Mixed
1245 protected $direnum = DirEnum
::NATIONALITIES
;
1247 protected function buildUFC(UserFilterBuilder
&$ufb)
1249 return new UFC_Nationality($this->val
);
1254 // {{{ class UFBF_Binet
1255 class UFBF_Binet
extends UFBF_Mixed
1257 protected $direnum = DirEnum
::BINETS
;
1259 protected function buildUFC(UserFilterBuilder
&$ufb)
1261 return new UFC_Binet($this->val
);
1266 // {{{ class UFBF_Group
1267 class UFBF_Group
extends UFBF_Mixed
1269 protected $direnum = DirEnum
::GROUPESX
;
1271 protected function buildUFC(UserFilterBuilder
&$ufb)
1273 if (count($this->val
) == 1) {
1274 return new UFC_Group($this->val
[0]);
1278 foreach ($this->val
as $grp) {
1279 $or->addChild(new UFC_Group($grp));
1286 // {{{ class UFBF_Section
1287 class UFBF_Section
extends UFBF_Mixed
1289 protected $direnum = DirEnum
::SECTIONS
;
1291 protected function buildUFC(UserFilterBuilder
&$ufb)
1293 return new UFC_Section($this->val
);
1298 // {{{ class UFBF_EducationSchool
1299 class UFBF_EducationSchool
extends UFBF_Mixed
1301 protected $direnum = DirEnum
::EDUSCHOOLS
;
1303 protected function buildUFC(UserFilterBuilder
&$ufb)
1305 return new UFC_EducationSchool($this->val
);
1310 // {{{ class UFBF_EducationDegree
1311 class UFBF_EducationDegree
extends UFBF_Mixed
1313 protected $direnum = DirEnum
::EDUDEGREES
;
1315 protected function buildUFC(UserFilterBuilder
&$ufb)
1317 return new UFC_EducationDegree($this->val
);
1322 // {{{ class UFBF_EducationField
1323 class UFBF_EducationField
extends UFBF_Mixed
1325 protected $direnum = DirEnum
::EDUFIELDS
;
1327 protected function buildUFC(UserFilterBuilder
&$ufb)
1329 return new UFC_EducationField($this->val
);
1334 // {{{ class UFBF_Comment
1335 class UFBF_Comment
extends UFBF_Text
1337 protected function buildUFC(UserFilterBuilder
&$ufb)
1339 return new UFC_Comment($this->val
);
1344 // {{{ class UFBF_Phone
1345 class UFBF_Phone
extends UFBF_Text
1347 protected function buildUFC(UserFilterBuilder
&$ufb)
1349 return new UFC_Phone($this->val
);
1354 // {{{ class UFBF_Networking
1355 class UFBF_Networking
extends UFBF_Text
1357 private $networktypefield;
1360 public function __construct($envfield, $networktypefield, $formtext = '')
1362 parent
::__construct($envfield, $formtext);
1363 $this->networktypefield
= $networktypefield;
1366 public function check(UserFilterBuilder
&$ufb)
1368 if (parent
::check($ufb)) {
1369 $this->nwtype
= $ufb->i($this->networktypefield
);
1376 public function isEmpty()
1378 return parent
::isEmpty() ||
$this->nwtype
== 0;
1381 public function buildUFC(UserFilterBuilder
&$ufb)
1383 return new UFC_Networking($this->nwtype
, $this->val
);
1386 public function getEnvFieldNames()
1388 return array($this->envfield
, $this->networktypefield
);
1393 // {{{ class UFBF_Mentor
1394 class UFBF_Mentor
extends UFBF_Bool
1396 protected function buildUFC(UserFilterBuilder
&$ufb)
1398 return new UFC_Mentor();
1403 // {{{ class UFBF_MentorCountry
1404 class UFBF_MentorCountry
extends UFBF_Text
1406 protected function buildUFC(UserFilterBuilder
&$ufb)
1408 return new UFC_Mentor_Country($this->val
);
1413 // {{{ class UFBF_Mentorterm
1414 class UFBF_MentorTerm
extends UFBF_Index
1416 protected function buildUFC(UserFilterBuilder
&$ufb)
1418 return new UFC_Mentor_Terms($this->val
);
1423 // {{{ class UFBF_MentorExpertise
1424 class UFBF_MentorExpertise
extends UFBF_Text
1426 protected function buildUFC(UserFilterBuilder
&$ufb)
1428 return new UFC_Mentor_Expertise($this->val
);
1433 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: