X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fufbuilder.inc.php;h=79b918a99ae017a1f99c39da640fcd23c8e9f433;hb=16d2c88314364b5e79936f4262d453dff03abdad;hp=354ef183aeabbc17b21d80598da3424545374a25;hpb=7188601607762f52cf2688b4e97cedd5e36c8ad7;p=platal.git diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 354ef18..79b918a 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -166,6 +166,7 @@ class UFB_QuickSearch extends UserFilterBuilder { $fields = array( new UFBF_Quick('quick', 'Recherche rapide'), + new UFBF_NotRegistered('nonins', 'Non inscrits'), ); parent::__construct($fields, $envprefix); } @@ -175,7 +176,12 @@ class UFB_QuickSearch extends UserFilterBuilder // {{{ class UFB_AdvancedSearch class UFB_AdvancedSearch extends UserFilterBuilder { - public function __construct($envprefix = '') + /** Create a UFB_AdvancedSearch. + * @param $include_admin Whether to include 'admin-only' fields + * @param $include_ax Whether to include 'ax-only' fields + * @param $envprefix Optional prefix for form field names. + */ + public function __construct($include_admin = false, $include_ax = false, $envprefix = '') { $fields = array( new UFBF_Name('name', 'Nom'), @@ -187,7 +193,8 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_Town('city', 'Ville / Code Postal'), new UFBF_Country('countryTxt', 'country', 'Pays'), - new UFBF_AdminArea('region', 'Région'), + new UFBF_AdminArea('administrativearea', 'Région'), + new UFBF_SubAdminArea('subadministrativearea', 'Département'), new UFBF_JobCompany('entreprise', 'Entreprise'), new UFBF_JobDescription('jobdescription', 'Fonction'), @@ -209,6 +216,11 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_Mentor('only_referent', 'Référent'), ); + + if ($include_admin || $include_ax) { + $fields[] = new UFBF_SchoolIds('schoolid_ax', 'Matricule AX', UFC_SchoolId::AX); + } + parent::__construct($fields, $envprefix); } } @@ -268,7 +280,7 @@ abstract class UFB_Field return false; } - if (!$this->empty) { + if (!$this->isEmpty()) { $ufc = $this->buildUFC($ufb); if ($ufc != null) { $ufb->addCond($ufc); @@ -521,7 +533,7 @@ class UFBF_Quick extends UFB_Field $flags = array('public'); } $exact =$ufb->b('exact'); - $conds->addChild(new UFC_NameTokens($st, $flags, $ufb->b('with_soundex'), $exact)); + $conds->addChild(new UFC_NameTokens($strings, $flags, $ufb->b('with_soundex'), $exact)); $ufb->addOrder(new UFO_Score()); } @@ -563,6 +575,48 @@ class UFBF_Quick extends UFB_Field } // }}} +// {{{ class UFBF_SchoolIds +class UFBF_SchoolIds extends UFB_Field +{ + // One of UFC_SchoolId types + protected $type; + + public function __construct($envfield, $formtext, $type = UFC_SchoolId::AX) + { + parent::__construct($envfield, $formtext); + $this->type = $type; + } + + protected function check(UserFilterBuilder &$ufb) + { + if ($ufb->blank($this->envfield)) { + $this->empty = true; + return true; + } + + $value = $ufb->t($this->envfield); + $values = explode("\n", $value); + $ids = array(); + foreach ($values as $val) { + if (preg_match('/^[0-9A-Z]{0,8}$/', $val)) { + $ids[] = $val; + } + } + if (count($ids) == 0) { + return $this->raise("Le champ %s ne contient aucune valeur valide."); + } + + $this->val = $ids; + return true; + } + + protected function buildUFC(UserFilterBuilder &$ufb) + { + return new UFC_SchoolId($this->type, $this->val); + } +} +// }}} + // {{{ class UFBF_Name class UFBF_Name extends UFBF_Text { @@ -655,6 +709,22 @@ class UFBF_Sex extends UFBF_Enum } // }}} +// {{{ class UFBF_NotRegistered +// Simple field for selecting only alive, not registered users (for quick search) +class UFBF_NotRegistered extends UFBF_Bool +{ + protected function buildUFC(UserFilterBuilder &$ufb) + { + if ($this->val) { + return new PFC_And( + new PFC_Not(new UFC_Dead()), + new PFC_Not(new UFC_Registered()) + ); + } + } +} +// }}} + // {{{ class UFBF_Registered class UFBF_Registered extends UFBF_Enum { @@ -792,6 +862,32 @@ class UFBF_AdminArea extends UFBF_Index } // }}} +// {{{ class UFBF_SubAdminArea +class UFBF_SubAdminArea extends UFBF_Index +{ + protected $direnum = DirEnum::SUBADMINAREAS; + protected $onlycurrentfield; + + public function __construct($envfield, $formtext = '', $onlycurrentfield = 'only_current') + { + parent::__construct($envfield, $formtext); + $this->onlycurrentfield = $onlycurrentfield; + } + + + protected function buildUFC(UserFilterBuilder &$ufb) + { + if ($ufb->isOn($this->onlycurrentfield)) { + $flags = UFC_Address::FLAG_CURRENT; + } else { + $flags = UFC_Address::FLAG_ANY; + } + + return new UFC_AddressField($this->val, UFC_AddressField::FIELD_SUBADMAREA, UFC_Address::TYPE_ANY, $flags); + } +} +// }}} + // {{{ class UFBF_JobCompany class UFBF_JobCompany extends UFBF_Text { @@ -1010,6 +1106,11 @@ class UFBF_Networking extends UFBF_Text } } + public function isEmpty() + { + return parent::isEmpty() || $this->nwtype == 0; + } + public function buildUFC(UserFilterBuilder &$ufb) { return new UFC_Networking($this->nwtype, $this->val);