Add preference for the name format to use for sorting (Request #6721).
authorJan Schneider <jan@horde.org>
Mon, 26 Oct 2009 17:41:20 +0000 (18:41 +0100)
committerJan Schneider <jan@horde.org>
Mon, 26 Oct 2009 17:41:20 +0000 (18:41 +0100)
turba/config/prefs.php.dist
turba/docs/CHANGES
turba/lib/ListView.php
turba/lib/Turba.php

index d06cb59..07a1c90 100644 (file)
@@ -30,7 +30,7 @@ $prefGroups['format'] = array(
     'column' => _("Display Options"),
     'label' => _("Name Format"),
     'desc' => _("Select which format to display names."),
-    'members' => array('name_format'),
+    'members' => array('name_format', 'name_sort'),
 );
 
 // Address Book selection widget
@@ -122,7 +122,19 @@ $_prefs['name_format'] = array(
     'locked' => false,
     'shared' => false,
     'type' => 'enum',
-    'desc' => _("Select the format used to display names:"),
+    'desc' => _("Select the format used to <em>display</em> names:"),
+    'enum' => array('last_first' => _("\"Lastname, Firstname\" (ie. Doe, John)"),
+                    'first_last' => _("\"Firstname Lastname\"  (ie. John Doe)"),
+                    'none' => _("no formatting")),
+);
+
+// the format to sort names.  Either 'last_first' or 'first_last'
+$_prefs['name_sort'] = array(
+    'value' => 'none',
+    'locked' => false,
+    'shared' => false,
+    'type' => 'enum',
+    'desc' => _("Select the format used to <em>sort</em> names:"),
     'enum' => array('last_first' => _("\"Lastname, Firstname\" (ie. Doe, John)"),
                     'first_last' => _("\"Firstname Lastname\"  (ie. John Doe)"),
                     'none' => _("no formatting")),
index 304db11..5a2ee06 100644 (file)
@@ -10,6 +10,7 @@ v3.0-git
 v2.3.3-cvs
 ----------
 
+[jan] Add preference for the name format to use for sorting (Request #6721).
 [jan] Condense whitespace in composite fields (Request #8654).
 [jan] Add and fix Oracle-specific SQL scripts.
 [jan] Add Croatian translation (Matej Vela <matej.vela@carnet.hr>,
index 157db8d..fd4e11c 100644 (file)
@@ -454,16 +454,19 @@ class Turba_ListView {
 class Turba_ListView_AlphaFilter {
 
     var $_alpha;
+    var $_format;
 
     function Turba_ListView_AlphaFilter($alpha)
     {
         $this->_alpha = Horde_String::lower($alpha);
+        $this->_format = $GLOBALS['prefs']->getValue('name_sort');
     }
 
     function skip(&$ob)
     {
-        $name = Turba::formatName($ob);
-        if ($this->_alpha != '*' && Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) {
+        $name = Turba::formatName($ob, $this->_format);
+        if ($this->_alpha != '*' &&
+            Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) {
             return true;
         }
         return false;
index ad8d3d0..c0254b0 100644 (file)
@@ -216,19 +216,23 @@ class Turba {
     /**
      * Formats the name according to the user's preference.
      *
-     * @param Turba_Object $ob  The object to get a name from.
+     * @param Turba_Object $ob     The object to get a name from.
+     * @param string $name_format  The formatting. One of 'none', 'last_first'
+     *                             or 'first_last'.
      *
      * @return string  The formatted name, either "Firstname Lastname"
-     *                 or "Lastname, Firstname" depending on the user's
-     *                 preference.
+     *                 or "Lastname, Firstname" depending on $name_format or
+     *                 the user's preference.
      */
-    function formatName($ob)
+    function formatName($ob, $name_format = null)
     {
-        global $prefs;
-        static $name_format;
+        static $default_format;
 
-        if (!isset($name_format)) {
-            $name_format = $prefs->getValue('name_format');
+        if (!$name_format) {
+            if (!isset($default_format)) {
+                $default_format = $GLOBALS['prefs']->getValue('name_format');
+            }
+            $name_format = $default_format;
         }
 
         /* if no formatting, return original name */