Allow sorting by name for accounts as well
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Tue, 3 Aug 2010 21:42:38 +0000 (23:42 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Tue, 3 Aug 2010 21:42:38 +0000 (23:42 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
classes/userfilter.php

index 8c791fa..b4e5463 100644 (file)
@@ -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')) {
index e988793..98ef33c 100644 (file)
@@ -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();