From a9ef52c96594b408aae8b084f13d872a211ea086 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 3 Aug 2010 23:42:38 +0200 Subject: [PATCH] Allow sorting by name for accounts as well MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/profile.php | 20 ++++++++++++++++++++ classes/userfilter.php | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/classes/profile.php b/classes/profile.php index 8c791fa..b4e5463 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -1000,6 +1000,26 @@ class Profile || $name == self::DN_SHORT || $name == self::DN_SORT; } + /** Returns the closest "accounts only" name type for $name + */ + public static function getAccountEquivalentName($name) + { + switch ($name) + { + case self::DN_DIRECTORY: + case self::DN_SORT: + return 'directory_name'; + case self::DN_FULL: + case self::DN_PUBLIC: + return 'full_name'; + case self::DN_PRIVATE: + case self::DN_SHORT: + case self::DN_YOURSELF: + default: + return 'display_name'; + } + } + public static function getNameTypeId($type, $for_sql = false) { if (!S::has('name_types')) { diff --git a/classes/userfilter.php b/classes/userfilter.php index e988793..98ef33c 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -1401,7 +1401,13 @@ class UFO_Name extends UserFilterOrder { if (Profile::isDisplayName($this->type)) { $sub = $uf->addDisplayFilter(); - return 'pd' . $sub . '.' . $this->type; + $token = 'pd' . $sub . '.' . $this->type; + if ($uf->accountsRequired()) { + $account_token = Profile::getAccountEquivalentName($this->type); + return 'IFNULL(' . $token . ', a.' . $account_token . ')'; + } else { + return $token; + } } else { $sub = $uf->addNameFilter($this->type, $this->variant); if ($this->particle) { @@ -1980,11 +1986,21 @@ class UserFilter extends PlFilter $this->with_accounts = true; } + public function accountsRequired() + { + return $this->with_accounts; + } + public function requireProfiles() { $this->with_profiles = true; } + public function profilesRequired() + { + return $this->with_profiles; + } + protected function accountJoins() { $joins = array(); -- 2.1.4