From 3e6ab77824b03f89d8c3a56229a0dbd1b0e37804 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 29 May 2011 21:00:39 +0200 Subject: [PATCH] Adapts name related UFC to new name design. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/userfilter.php | 42 ++-------------------- classes/userfilter/conditions.inc.php | 59 ++++++------------------------- classes/userfilter/orders.inc.php | 65 +++++------------------------------ include/userset.inc.php | 3 +- 4 files changed, 22 insertions(+), 147 deletions(-) diff --git a/classes/userfilter.php b/classes/userfilter.php index 453d94a..d95e9d8 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -543,12 +543,12 @@ class UserFilter extends PlFilter static public function sortByName() { - return array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); + return array(new UFO_Name()); } static public function sortByPromo() { - return array(new UFO_Promo(), new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); + return array(new UFO_Promo(), new UFO_Name()); } static private function getDBSuffix($string) @@ -676,44 +676,6 @@ class UserFilter extends PlFilter return $joins; } - /** NAMES - */ - - static public function assertName($name) - { - if (!DirEnum::getID(DirEnum::NAMETYPES, $name)) { - Platal::page()->kill('Invalid name type: ' . $name); - } - } - - private $pn = array(); - public function addNameFilter($type, $variant = null) - { - $this->requireProfiles(); - if (!is_null($variant)) { - $ft = $type . '_' . $variant; - } else { - $ft = $type; - } - $sub = '_' . $ft; - self::assertName($ft); - - if (!is_null($variant) && $variant == 'other') { - $sub .= $this->option++; - } - $this->pn[$sub] = DirEnum::getID(DirEnum::NAMETYPES, $ft); - return $sub; - } - - protected function nameJoins() - { - $joins = array(); - foreach ($this->pn as $sub => $type) { - $joins['pn' . $sub] = PlSqlJoin::left('profile_name', '$ME.pid = $PID AND $ME.typeid = {?}', $type); - } - return $joins; - } - /** NAMETOKENS */ private $name_tokens = array(); diff --git a/classes/userfilter/conditions.inc.php b/classes/userfilter/conditions.inc.php index cb99cfb..d15ad97 100644 --- a/classes/userfilter/conditions.inc.php +++ b/classes/userfilter/conditions.inc.php @@ -583,67 +583,28 @@ class UFC_EducationField extends UserFilterCondition } } // }}} -// {{{ class UFC_Name -/** Filters users based on name - * @param $type Type of name field on which filtering is done (firstname, lastname...) - * @param $text Text on which to filter - * @param $mode Flag indicating search type (prefix, suffix, with particule...) +// {{{ class UFC_NameInitial +/** Filters users based on sort_name + * @param $initial Initial on which to filter */ -class UFC_Name extends UserFilterCondition +class UFC_NameInitial extends UserFilterCondition { - const EXACT = XDB::WILDCARD_EXACT; // 0x000 - const PREFIX = XDB::WILDCARD_PREFIX; // 0x001 - const SUFFIX = XDB::WILDCARD_SUFFIX; // 0x002 - const CONTAINS = XDB::WILDCARD_CONTAINS; // 0x003 - const PARTICLE = 0x004; - const VARIANTS = 0x008; + private $initial; - private $type; - private $text; - private $mode; - - public function __construct($type, $text, $mode) - { - $this->type = $type; - $this->text = $text; - $this->mode = $mode; - } - - private function buildNameQuery($type, $variant, $where, UserFilter $uf) + public function __construct($initial) { - $sub = $uf->addNameFilter($type, $variant); - return str_replace('$ME', 'pn' . $sub, $where); + $this->initial = $initial; } public function buildCondition(PlFilter $uf) { - $left = '$ME.name'; - if (($this->mode & self::PARTICLE) == self::PARTICLE) { - $left = 'CONCAT($ME.particle, \' \', $ME.name)'; - } - $right = XDB::formatWildcards($this->mode & self::CONTAINS, $this->text); - - $cond = $left . $right; - $conds = array($this->buildNameQuery($this->type, null, $cond, $uf)); - if (($this->mode & self::VARIANTS) != 0 && isset(Profile::$name_variants[$this->type])) { - foreach (Profile::$name_variants[$this->type] as $var) { - $conds[] = $this->buildNameQuery($this->type, $var, $cond, $uf); - } - } - return implode(' OR ', $conds); + $sub = $uf->addDisplayFilter(); + return 'SUBSTRING(pd.sort_name, 1, 1) ' . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $this->initial); } public function export() { - $export = $this->buildExport($this->type); - if ($this->mode & self::VARIANTS) { - $export['search_in_variants'] = true; - } - if ($this->mode & self::PARTICLE) { - $export['search_in_particle'] = true; - } - $export['comparison'] = self::comparisonFromXDBWildcard($this->mode & 0x3); - $export['text'] = $this->text; + $export = $this->buildExport($this->initial); return $export; } } diff --git a/classes/userfilter/orders.inc.php b/classes/userfilter/orders.inc.php index ad41bb3..b64a8e8 100644 --- a/classes/userfilter/orders.inc.php +++ b/classes/userfilter/orders.inc.php @@ -36,13 +36,8 @@ abstract class UserFilterOrders case 'promo': return new UFO_Promo($export->v('grade'), $desc); - case 'lastname': case 'name': - case 'firstname': - case 'nickname': - case 'pseudonym': - return new UFO_Name($type, $export->v('variant'), - $export->b('particle'), $desc); + return new UFO_Name($desc); case 'score': case 'registration': @@ -106,43 +101,19 @@ class UFO_Promo extends PlFilterGroupableOrder // }}} // {{{ class UFO_Name /** Sorts users by name - * @param $type Type of name on which to sort (firstname...) - * @param $variant Variant of that name to use (marital, ordinary...) - * @param $particle Set to true if particles should be included in the sorting order * @param $desc If sort order should be descending */ class UFO_Name extends PlFilterGroupableOrder { - private $type; - private $variant; - private $particle; - - public function __construct($type, $variant = null, $particle = false, $desc = false) - { - parent::__construct($desc); - $this->type = $type; - $this->variant = $variant; - $this->particle = $particle; - } - protected function getSortTokens(PlFilter $uf) { - if (Profile::isDisplayName($this->type)) { - $sub = $uf->addDisplayFilter(); - $token = 'pd' . $sub . '.' . $this->type; - if ($uf->accountsRequired()) { - $account_token = Profile::getAccountEquivalentName($this->type); - return 'IFNULL(' . $token . ', a.' . $account_token . ')'; - } else { - return $token; - } + $sub = $uf->addDisplayFilter(); + $token = 'pd.sort_name'; + if ($uf->accountsRequired()) { + $account_token = Profile::getAccountEquivalentName('sort_name'); + return 'IFNULL(' . $token . ', a.' . $account_token . ')'; } else { - $sub = $uf->addNameFilter($this->type, $this->variant); - if ($this->particle) { - return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)'; - } else { - return 'pn' . $sub . '.name'; - } + return $token; } } @@ -153,30 +124,12 @@ class UFO_Name extends PlFilterGroupableOrder public function getCondition($initial) { - if (Profile::isDisplayName($this->type)) { - switch ($this->type) { - case Profile::DN_PRIVATE: - case Profile::DN_SHORT: - case Profile::DN_YOURSELF: - $type = Profile::FIRSTNAME; - default: - $type = Profile::LASTNAME; - } - } else { - $type = $this->type; - } - return new UFC_Name($type, $initial, UFC_Name::PREFIX); + return new UFC_NameInitial($initial); } public function export() { - $export = $this->buildExport($this->type); - if (!is_null($this->variant)) { - $export['variant'] = $this->variant; - } - if ($this->particle) { - $export['particle'] = true; - } + $export = $this->buildExport(); return $export; } } diff --git a/include/userset.inc.php b/include/userset.inc.php index c590527..3b26682 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -245,8 +245,7 @@ class MinificheView extends MixedView && $this->params['starts_with'] != null) { $this->set->addCond( - new UFC_Name(Profile::LASTNAME, - $this->params['starts_with'], UFC_Name::PREFIX) + new UFC_NameInitial($this->params['starts_with']) ); } return parent::apply($page); -- 2.1.4