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'),
343 new UFBF_Promo('promo1', 'Promotion', 'egal1'),
344 new UFBF_Promo('promo2', 'Promotion', 'egal2'),
345 new UFBF_Sex('woman', 'Sexe'),
346 new UFBF_Registered('subscriber', 'Inscrit'),
347 new UFBF_Dead('alive', 'En vie'),
349 new UFBF_Town('city', 'Ville / Code Postal'),
350 new UFBF_Country('countryTxt', 'country', 'Pays'),
351 new UFBF_AdminArea('administrativearea', 'Région'),
352 new UFBF_SubAdminArea('subadministrativearea', 'Département'),
354 new UFBF_JobCompany('entreprise', 'Entreprise'),
355 new UFBF_JobDescription('jobdescription', 'Fonction'),
356 new UFBF_JobCv('cv', 'CV'),
357 new UFBF_JobTerms('jobterm', 'Mots-clefs'),
359 new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'),
360 new UFBF_Binet('binetTxt', 'binet', 'Binet'),
361 new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'),
362 new UFBF_Section('sectionTxt', 'section', 'Section'),
364 new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"),
365 new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'),
366 new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"),
368 new UFBF_Comment('free', 'Commentaire'),
369 new UFBF_Phone('phone_number', 'Téléphone'),
370 new UFBF_Networking('networking_address', 'networking_type', 'Networking et sites webs'),
372 new UFBF_Mentor('only_referent', 'Référent'),
375 if ($include_admin ||
$include_ax) {
376 $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId
::AX
);
379 parent
::__construct($fields, $envprefix);
384 // {{{ class UFB_MentorSearch
385 class UFB_MentorSearch
extends UserFilterBuilder
387 public function __construct($envprefix = '')
390 new UFBF_MentorCountry('country'),
391 new UFBF_MentorTerm('jobterm', 'jobtermText'),
392 new UFBF_MentorExpertise('expertise'),
394 parent
::__construct($fields, $envprefix);
399 // {{{ class UFB_NewsLetter
400 class UFB_NewsLetter
extends UserFilterBuilder
402 const FIELDS_PROMO
= 'promo';
403 const FIELDS_AXID
= 'axid';
404 const FIELDS_GEO
= 'geo';
406 public function __construct($flags, $envprefix = '')
409 if ($flags->hasFlag(self
::FIELDS_PROMO
)) {
410 $fields[] = new UFBF_Promo('promo1', 'Promotion', 'egal1');
411 $fields[] = new UFBF_Promo('promo2', 'Promotion', 'egal2');
413 if ($flags->hasFlag(self
::FIELDS_AXID
)) {
414 $fields[] = new UFBF_SchoolIds('axid', 'Matricule AX', UFC_SchoolId
::AX
);
416 parent
::__construct($fields, $envprefix);
421 // {{{ class UFB_Field
422 abstract class UFB_Field
427 protected $empty = false
;
428 protected $val = null
;
431 * @param $envfield Name of the field in the environment
432 * @param $formtext User-friendly name of that field
434 public function __construct($envfield, $formtext = '')
436 $this->envfield
= $envfield;
437 if ($formtext != '') {
438 $this->formtext
= $formtext;
440 $formtext = ucfirst($envfield);
444 /** Prints the given error message to the user, and returns false
445 * in order to be used as return $this->raise('ERROR');
447 * All %s in the $msg will be replaced with the formtext.
449 protected function raise($msg)
451 Platal
::page()->trigError(str_replace('%s', $this->formtext
, $msg));
455 public function apply(UserFilterBuilder
$ufb) {
456 if (!$this->check($ufb)) {
460 if (!$this->isEmpty()) {
461 $ufc = $this->buildUFC($ufb);
469 public function isEmpty()
474 /** Create the UFC associated to the field; won't be called
475 * if the field is "empty"
476 * @param $ufb UFB to which fields must be added
479 abstract protected function buildUFC(UserFilterBuilder
$ufb);
481 /** This function is intended to run consistency checks on the value
482 * @return boolean Whether the input is valid
484 abstract protected function check(UserFilterBuilder
$ufb);
486 // Simple form interface
488 /** Retrieve a list of env field names used by that field
489 * their values will be recorded when saving the 'search' and used to prefill the form
492 public function getEnvFieldNames()
494 return array($this->envfield
);
499 // {{{ class UFBF_Text
500 abstract class UFBF_Text
extends UFB_Field
505 public function __construct($envfield, $formtext = '', $minlength = 2, $maxlength = 255)
507 parent
::__construct($envfield, $formtext);
508 $this->minlength
= $minlength;
509 $this->maxlength
= $maxlength;
512 protected function check(UserFilterBuilder
$ufb)
514 if ($ufb->blank($this->envfield
)) {
519 $this->val
= $ufb->t($this->envfield
);
520 if (strlen($this->val
) < $this->minlength
) {
521 return $this->raise("Le champ %s est trop court (minimum {$this->minlength}).");
522 } else if (strlen($this->val
) > $this->maxlength
) {
523 return $this->raise("Le champ %s est trop long (maximum {$this->maxlength}).");
524 } else if (preg_match(":[\]\[<>{}~§_`|%$^=]|\*\*:u", $this->val
)) {
525 return $this->raise('Le champ %s contient un caractère interdit rendant la recherche impossible.');
533 // {{{ class UFBF_Range
534 /** Subclass to use for fields which only allow integers within a range
536 abstract class UFBF_Range
extends UFB_Field
542 public function __construct($envfield, $formtext = '', $min = 0, $max = 65535)
544 parent
::__construct($envfield, $formtext);
549 protected function check(UserFilterBuilder
$ufb)
551 if ($ufb->blank($this->envfield
)) {
556 $this->val
= $ufb->i($this->envfield
);
557 if ($this->val
< $this->min
) {
558 return $this->raise("Le champs %s est inférieur au minimum ({$this->min}).");
559 } else if ($this->val
> $this->max
) {
560 return $this->raise("Le champ %s est supérieur au maximum ({$this->max}).");
567 // {{{ class UFBF_Index
568 /** Subclass to use for indexed fields
570 abstract class UFBF_Index
extends UFB_Field
572 protected function check(UserFilterBuilder
$ufb)
574 if ($ufb->blank($this->envfield
)) {
577 $this->val
= $ufb->i($this->envfield
);
583 // {{{ class UFBF_Enum
584 /** Subclass to use for fields whose value must belong to a specific set of values
586 abstract class UFBF_Enum
extends UFB_Field
588 protected $allowedvalues;
590 public function __construct($envfield, $formtext = '', $allowedvalues = array(), $strict = false
)
592 parent
::__construct($envfield, $formtext);
593 $this->allowedvalues
= $allowedvalues;
594 $this->strict
= $strict;
597 protected function check(UserFilterBuilder
$ufb)
599 if ($ufb->blank($this->envfield
)) {
604 $this->val
= $ufb->v($this->envfield
);
605 if (! in_array($this->val
, $this->allowedvalues
)) {
607 return $this->raise("La valeur {$this->val} n'est pas valide pour le champ %s.");
617 // {{{ class UFBF_Bool
618 abstract class UFBF_Bool
extends UFB_Field
620 protected function check(UserFilterBuilder
$ufb)
622 if ($ufb->blank($this->envfield
)) {
627 $this->val
= $ufb->b($this->envfield
);
633 // {{{ class UFBF_Mixed
634 /** A class for building UFBFs when the user can input either a text or an ID
636 abstract class UFBF_Mixed
extends UFB_Field
638 /** Name of the DirEnum on which class is based
642 protected $envfieldindex;
644 public function __construct($envfieldtext, $envfieldindex, $formtext = '')
646 parent
::__construct($envfieldtext, $formtext);
647 $this->envfieldindex
= $envfieldindex;
650 protected function check(UserFilterBuilder
$ufb)
652 if ($ufb->blank($this->envfieldindex
) && !$ufb->hasAlnum($this->envfield
)) {
657 if (!$ufb->blank($this->envfieldindex
)) {
658 $index = $ufb->v($this->envfieldindex
);
659 if (is_int($index)) {
660 $index = intval($index);
662 $index = strtoupper($index);
664 $this->val
= array($index);
666 $indexes = DirEnum
::getIDs($this->direnum
, $ufb->t($this->envfield
),
667 $ufb->b('exact') ? XDB
::WILDCARD_EXACT
: XDB
::WILDCARD_CONTAINS
);
668 if (count($indexes) == 0) {
671 $this->val
= $indexes;
676 public function getEnvFieldNames()
678 return array($this->envfieldindex
, $this->envfield
);
683 // {{{ class UFBF_Quick
684 class UFBF_Quick
extends UFB_Field
686 protected function check(UserFilterBuilder
$ufb)
688 if ($ufb->blank($this->envfield
)) {
693 $this->val
= str_replace('*', '%', replace_accent($ufb->t($this->envfield
)));
698 protected function buildUFC(UserFilterBuilder
$ufb)
701 $r = $s = $this->val
;
705 if (S
::admin() && strpos($s, '@') !== false
) {
706 return new UFC_Email($s);
707 } else if (S
::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
708 return new UFC_Ip($s);
711 $conds = new PFC_And();
715 $s = preg_replace('!\d+!', ' ', $s);
716 $strings = preg_split("![^a-zA-Z%]+!",$s, -1, PREG_SPLIT_NO_EMPTY
);
717 if (count($strings) > 5) {
718 Platal
::page()->trigWarning("Tu as indiqué trop d'éléments dans ta recherche, seuls les 5 premiers seront pris en compte");
719 $strings = array_slice($strings, 0, 5);
722 if (count($strings)) {
723 if (S
::user()->checkPerms('directory_private')) {
726 $flags = array('public');
728 $exact =$ufb->b('exact');
729 $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact));
731 $ufb->addOrder(new UFO_Score());
736 $s = preg_replace('! *- *!', '-', $r);
737 $s = preg_replace('!([<>]) *!', ' \1', $s);
738 $s = preg_replace('![^0-9\-><]!', ' ', $s);
739 $s = preg_replace('![<>\-] !', '', $s);
740 $ranges = preg_split('! +!', $s, -1, PREG_SPLIT_NO_EMPTY
);
741 foreach ($ranges as $r) {
742 if (preg_match('!^\d{4}$!', $r)) {
743 $conds->addChild(new UFC_Promo('=', UserFilter
::DISPLAY
, 'X' . $r));
744 } elseif (preg_match('!^(\d{4})-(\d{4})$!', $r, $matches)) {
745 $p1=min(intval($matches[1]), intval($matches[2]));
746 $p2=max(intval($matches[1]), intval($matches[2]));
747 $conds->addChild(new PFC_And(
748 new UFC_Promo('>=', UserFilter
::DISPLAY
, 'X' . $p1),
749 new UFC_Promo('<=', UserFilter
::DISPLAY
, 'X' . $p2)
751 } elseif (preg_match('!^<(\d{4})!', $r, $matches)) {
752 $conds->addChild(new UFC_Promo('<=', UserFilter
::DISPLAY
, 'X' . $matches[1]));
753 } elseif (preg_match('!^>(\d{4})!', $r, $matches)) {
754 $conds->addChild(new UFC_Promo('>=', UserFilter
::DISPLAY
, 'X' . $matches[1]));
760 $t = preg_replace('!(\d{4}-\d{4}|>\d{4}|<\d{4})!', '', $s);
761 $t = preg_replace('![<>\- ]!', '', $t);
762 if (strlen($t) > 4) {
763 $conds->addChild(new UFC_Phone($t));
771 // {{{ class UFBF_SchoolIds
772 class UFBF_SchoolIds
extends UFB_Field
774 // One of UFC_SchoolId types
776 protected $reversed_envfield;
777 protected $reversed = false
;
779 public function __construct($envfield, $formtext, $type = UFC_SchoolId
::AX
, $reversed_envfield = '')
781 parent
::__construct($envfield, $formtext);
783 if ($reversed_envfield == '') {
784 $reversed_envfield = $envfield . '_reversed';
786 $this->reversed_envfield
= $reversed_envfield;
789 protected function check(UserFilterBuilder
$ufb)
791 if ($ufb->blank($this->envfield
)) {
796 $value = $ufb->t($this->envfield
);
797 $values = explode("\r\n", $value);
799 foreach ($values as $val) {
800 if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) {
804 if (count($ids) == 0) {
805 return $this->raise("Le champ %s ne contient aucune valeur valide.");
808 $this->reversed
= $ufb->b($this->reversed_envfield
);
813 protected function buildUFC(UserFilterBuilder
$ufb)
815 $ufc = new UFC_SchoolId($this->type
, $this->val
);
816 if ($this->reversed
) {
817 return new PFC_Not($ufc);
825 // {{{ class UFBF_Name
826 class UFBF_Name
extends UFBF_Text
828 protected function check(UserFilterBuilder
$ufb)
830 if (!parent
::check($ufb)) {
834 $this->val
= preg_split('/[[:space:]]/', $this->val
);
835 if (count($this->val
) == 0) {
841 protected function buildUFC(UserFilterBuilder
$ufb)
843 return new UFC_NameTokens($this->val
, array(), $ufb->b('with_soundex'), $ufb->b('exact'));
848 // {{{ class UFBF_Promo
849 class UFBF_Promo
extends UFB_Field
851 private static $validcomps = array('<', '<=', '=', '>=', '>');
853 private $envfieldcomp;
855 public function __construct($envfield, $formtext = '', $envfieldcomp)
857 parent
::__construct($envfield, $formtext);
858 $this->envfieldcomp
= $envfieldcomp;
861 protected function check(UserFilterBuilder
$ufb)
863 if ($ufb->blank($this->envfield
) ||
$ufb->blank($this->envfieldcomp
)) {
868 $this->val
= $ufb->i($this->envfield
);
869 $this->comp
= $ufb->v($this->envfieldcomp
);
871 if (!in_array($this->comp
, self
::$validcomps)) {
872 return $this->raise("Le critère {$this->comp} n'est pas valide pour le champ %s");
875 if (preg_match('/^[0-9]{2}$/', $this->val
)) {
878 if ($this->val
< 1900 ||
$this->val
> 9999) {
879 return $this->raise("Le champ %s doit être une année à 4 chiffres.");
884 protected function buildUFC(UserFilterBuilder
$ufb) {
885 return new UFC_Promo($this->comp
, UserFilter
::GRADE_ING
, $this->val
);
888 public function getEnvFieldNames()
890 return array($this->envfield
, $this->envfieldcomp
);
895 // {{{ class UFBF_Sex
896 class UFBF_Sex
extends UFBF_Enum
898 public function __construct($envfield, $formtext = '')
900 parent
::__construct($envfield, $formtext, array(1, 2));
903 private static function getVal($id)
907 return User
::GENDER_MALE
;
910 return User
::GENDER_FEMALE
;
915 protected function buildUFC(UserFilterBuilder
$ufb)
917 return new UFC_Sex(self
::getVal($this->val
));
922 // {{{ class UFBF_NotRegistered
923 // Simple field for selecting only alive, not registered users (for quick search)
924 class UFBF_NotRegistered
extends UFBF_Bool
926 protected function buildUFC(UserFilterBuilder
$ufb)
930 new PFC_Not(new UFC_Dead()),
931 new PFC_Not(new UFC_Registered())
938 // {{{ class UFBF_Registered
939 class UFBF_Registered
extends UFBF_Enum
941 public function __construct($envfield, $formtext = '')
943 parent
::__construct($envfield, $formtext, array(1, 2));
946 protected function buildUFC(UserFilterBuilder
$ufb)
948 if ($this->val
== 1) {
949 return new UFC_Registered();
950 } else if ($this->val
== 2) {
951 return new PFC_Not(new UFC_Registered());
957 // {{{ class UFBF_Dead
958 class UFBF_Dead
extends UFBF_Enum
960 public function __construct($envfield, $formtext = '')
962 parent
::__construct($envfield, $formtext, array(1, 2));
965 protected function buildUFC(UserFilterBuilder
$ufb)
967 if ($this->val
== 1) {
968 return new PFC_Not(new UFC_Dead());
969 } else if ($this->val
== 2) {
970 return new UFC_Dead();
976 // {{{ class UFBF_Town
977 /** Retrieves a town, either from a postal code or a town name
979 class UFBF_Town
extends UFBF_Text
986 private $onlycurrentfield;
988 public function __construct($envfield, $formtext = '', $type = self
::TYPE_ANY
, $onlycurrentfield = 'only_current')
991 $this->onlycurrentfield
= $onlycurrentfield;
992 parent
::__construct($envfield, $formtext, 2, 30);
995 protected function buildUFC(UserFilterBuilder
$ufb)
997 if ($ufb->isOn($this->onlycurrentfield
)) {
998 $flags = UFC_Address
::FLAG_CURRENT
;
1000 $flags = UFC_Address
::FLAG_ANY
;
1003 if (preg_match('/[0-9]/', $this->val
)) {
1004 if ($this->type
& self
::TYPE_ZIP
) {
1005 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1007 return new PFC_False();
1010 $byname = new UFC_AddressText(null
, XDB
::WILDCARD_CONTAINS
, UFC_Address
::TYPE_ANY
, $flags, null
, $this->val
);
1011 $byzip = new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ZIPCODE
, UFC_Address
::TYPE_ANY
, $flags);
1012 if ($this->type
& self
::TYPE_ANY
) {
1013 return new PFC_Or($byname, $byzip);
1014 } else if ($this->type
& self
::TYPE_TEXT
) {
1022 public function getEnvFieldNames()
1024 return array($this->envfield
, $this->onlycurrentfield
);
1029 // {{{ class UFBF_Country
1030 class UFBF_Country
extends UFBF_Mixed
1032 protected $direnum = DirEnum
::COUNTRIES
;
1033 protected $onlycurrentfield;
1035 public function __construct($envfieldtext, $envfieldindex, $formtext = '', $onlycurrentfield = 'only_current')
1037 parent
::__construct($envfieldtext, $envfieldindex, $formtext);
1038 $this->onlycurrentfield
= $onlycurrentfield;
1041 protected function buildUFC(UserFilterBuilder
$ufb)
1043 if ($ufb->isOn($this->onlycurrentfield
)) {
1044 $flags = UFC_Address
::FLAG_CURRENT
;
1046 $flags = UFC_Address
::FLAG_ANY
;
1049 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_COUNTRY
, UFC_Address
::TYPE_ANY
, $flags);
1052 public function getEnvFieldNames()
1054 return array($this->envfield
, $this->envfieldindex
, $this->onlycurrentfield
);
1059 // {{{ class UFBF_AdminArea
1060 class UFBF_AdminArea
extends UFBF_Index
1062 protected $direnum = DirEnum
::ADMINAREAS
;
1063 protected $onlycurrentfield;
1065 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1067 parent
::__construct($envfield, $formtext);
1068 $this->onlycurrentfield
= $onlycurrentfield;
1072 protected function buildUFC(UserFilterBuilder
$ufb)
1074 if ($ufb->isOn($this->onlycurrentfield
)) {
1075 $flags = UFC_Address
::FLAG_CURRENT
;
1077 $flags = UFC_Address
::FLAG_ANY
;
1080 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_ADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1083 public function getEnvFieldNames()
1085 return array($this->envfield
, $this->onlycurrentfield
);
1090 // {{{ class UFBF_SubAdminArea
1091 class UFBF_SubAdminArea
extends UFBF_Index
1093 protected $direnum = DirEnum
::SUBADMINAREAS
;
1094 protected $onlycurrentfield;
1096 public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current')
1098 parent
::__construct($envfield, $formtext);
1099 $this->onlycurrentfield
= $onlycurrentfield;
1103 protected function buildUFC(UserFilterBuilder
$ufb)
1105 if ($ufb->isOn($this->onlycurrentfield
)) {
1106 $flags = UFC_Address
::FLAG_CURRENT
;
1108 $flags = UFC_Address
::FLAG_ANY
;
1111 return new UFC_AddressField($this->val
, UFC_AddressField
::FIELD_SUBADMAREA
, UFC_Address
::TYPE_ANY
, $flags);
1114 public function getEnvFieldNames()
1116 return array($this->envfield
, $this->onlycurrentfield
);
1121 // {{{ class UFBF_JobCompany
1122 class UFBF_JobCompany
extends UFBF_Text
1124 private $onlymentorfield;
1126 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1128 parent
::__construct($envfield, $formtext);
1129 $this->onlymentorfield
= $onlymentorfield;
1132 public function check(UserFilterBuilder
$ufb) {
1133 if (parent
::check($ufb)) {
1134 # No company check for mentors
1135 if ($ufb->isOn($this->onlymentorfield
)) {
1136 $this->empty = true
;
1144 protected function buildUFC(UserFilterBuilder
$ufb)
1146 return new UFC_Job_Company(UFC_Job_Company
::JOBNAME
, $this->val
);
1149 public function getEnvFieldNames()
1151 return array($this->envfield
, $this->onlymentorfield
);
1156 // {{{ class UFBF_JobTerms
1157 class UFBF_JobTerms
extends UFBF_Index
1159 protected function buildUFC(UserFilterBuilder
$ufb)
1161 return new UFC_Job_Terms($this->val
);
1166 // {{{ class UFBF_JobDescription
1167 class UFBF_JobDescription
extends UFBF_Text
1169 private $onlymentorfield;
1171 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1173 parent
::__construct($envfield, $formtext);
1174 $this->onlymentorfield
= $onlymentorfield;
1177 protected function buildUFC(UserFilterBuilder
$ufb)
1179 if ($ufb->isOn($this->onlymentorfield
)) {
1180 return new UFC_Mentor_Expertise($this->val
);
1182 return new UFC_Job_Description($this->val
, UserFilter
::JOB_USERDEFINED
);
1186 public function getEnvFieldNames()
1188 return array($this->envfield
, $this->onlymentorfield
);
1193 // {{{ class UFBF_JobCv
1194 class UFBF_JobCv
extends UFBF_Text
1196 private $onlymentorfield;
1198 public function __construct($envfield, $formtext = '', $onlymentorfield = 'only_referent')
1200 parent
::__construct($envfield, $formtext);
1201 $this->onlymentorfield
= $onlymentorfield;
1204 protected function buildUFC(UserFilterBuilder
$ufb)
1206 if ($ufb->isOn($this->onlymentorfield
)) {
1207 return new UFC_Mentor_Expertise($this->val
);
1209 return new UFC_Job_Description($this->val
, UserFilter
::JOB_CV
);
1213 public function getEnvFieldNames()
1215 return array($this->envfield
, $this->onlymentorfield
);
1220 // {{{ class UFBF_Nationality
1221 class UFBF_Nationality
extends UFBF_Mixed
1223 protected $direnum = DirEnum
::NATIONALITIES
;
1225 protected function buildUFC(UserFilterBuilder
$ufb)
1227 return new UFC_Nationality($this->val
);
1232 // {{{ class UFBF_Binet
1233 class UFBF_Binet
extends UFBF_Mixed
1235 protected $direnum = DirEnum
::BINETS
;
1237 protected function buildUFC(UserFilterBuilder
$ufb)
1239 return new UFC_Binet($this->val
);
1244 // {{{ class UFBF_Group
1245 class UFBF_Group
extends UFBF_Mixed
1247 protected $direnum = DirEnum
::GROUPESX
;
1249 protected function buildUFC(UserFilterBuilder
$ufb)
1251 if (count($this->val
) == 1) {
1252 return new UFC_Group($this->val
[0]);
1256 foreach ($this->val
as $grp) {
1257 $or->addChild(new UFC_Group($grp));
1264 // {{{ class UFBF_Section
1265 class UFBF_Section
extends UFBF_Mixed
1267 protected $direnum = DirEnum
::SECTIONS
;
1269 protected function buildUFC(UserFilterBuilder
$ufb)
1271 return new UFC_Section($this->val
);
1276 // {{{ class UFBF_EducationSchool
1277 class UFBF_EducationSchool
extends UFBF_Mixed
1279 protected $direnum = DirEnum
::EDUSCHOOLS
;
1281 protected function buildUFC(UserFilterBuilder
$ufb)
1283 return new UFC_EducationSchool($this->val
);
1288 // {{{ class UFBF_EducationDegree
1289 class UFBF_EducationDegree
extends UFBF_Mixed
1291 protected $direnum = DirEnum
::EDUDEGREES
;
1293 protected function buildUFC(UserFilterBuilder
$ufb)
1295 return new UFC_EducationDegree($this->val
);
1300 // {{{ class UFBF_EducationField
1301 class UFBF_EducationField
extends UFBF_Mixed
1303 protected $direnum = DirEnum
::EDUFIELDS
;
1305 protected function buildUFC(UserFilterBuilder
$ufb)
1307 return new UFC_EducationField($this->val
);
1312 // {{{ class UFBF_Comment
1313 class UFBF_Comment
extends UFBF_Text
1315 protected function buildUFC(UserFilterBuilder
$ufb)
1317 return new UFC_Comment($this->val
);
1322 // {{{ class UFBF_Phone
1323 class UFBF_Phone
extends UFBF_Text
1325 protected function buildUFC(UserFilterBuilder
$ufb)
1327 return new UFC_Phone($this->val
);
1332 // {{{ class UFBF_Networking
1333 class UFBF_Networking
extends UFBF_Text
1335 private $networktypefield;
1338 public function __construct($envfield, $networktypefield, $formtext = '')
1340 parent
::__construct($envfield, $formtext);
1341 $this->networktypefield
= $networktypefield;
1344 public function check(UserFilterBuilder
$ufb)
1346 if (parent
::check($ufb)) {
1347 $this->nwtype
= $ufb->i($this->networktypefield
);
1354 public function isEmpty()
1356 return parent
::isEmpty() ||
$this->nwtype
== 0;
1359 public function buildUFC(UserFilterBuilder
$ufb)
1361 return new UFC_Networking($this->nwtype
, $this->val
);
1364 public function getEnvFieldNames()
1366 return array($this->envfield
, $this->networktypefield
);
1371 // {{{ class UFBF_Mentor
1372 class UFBF_Mentor
extends UFBF_Bool
1374 protected function buildUFC(UserFilterBuilder
$ufb)
1376 return new UFC_Mentor();
1381 // {{{ class UFBF_MentorCountry
1382 class UFBF_MentorCountry
extends UFBF_Text
1384 protected function buildUFC(UserFilterBuilder
$ufb)
1386 return new UFC_Mentor_Country($this->val
);
1391 // {{{ class UFBF_Mentorterm
1392 class UFBF_MentorTerm
extends UFBF_Index
1394 protected function buildUFC(UserFilterBuilder
$ufb)
1396 return new UFC_Mentor_Terms($this->val
);
1401 // {{{ class UFBF_MentorExpertise
1402 class UFBF_MentorExpertise
extends UFBF_Text
1404 protected function buildUFC(UserFilterBuilder
$ufb)
1406 return new UFC_Mentor_Expertise($this->val
);
1411 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: