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)
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();
}
}
// }}}
-// {{{ 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;
}
}
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':
// }}}
// {{{ 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;
}
}
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;
}
}
&& $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);