From 389b41d559898ac62fa341280ab6456a6cec9b27 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 26 Oct 2009 18:41:20 +0100 Subject: [PATCH] Add preference for the name format to use for sorting (Request #6721). --- turba/config/prefs.php.dist | 16 ++++++++++++++-- turba/docs/CHANGES | 1 + turba/lib/ListView.php | 7 +++++-- turba/lib/Turba.php | 20 ++++++++++++-------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/turba/config/prefs.php.dist b/turba/config/prefs.php.dist index d06cb59ad..07a1c90aa 100644 --- a/turba/config/prefs.php.dist +++ b/turba/config/prefs.php.dist @@ -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 display 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 sort names:"), 'enum' => array('last_first' => _("\"Lastname, Firstname\" (ie. Doe, John)"), 'first_last' => _("\"Firstname Lastname\" (ie. John Doe)"), 'none' => _("no formatting")), diff --git a/turba/docs/CHANGES b/turba/docs/CHANGES index 304db11c2..5a2ee06b3 100644 --- a/turba/docs/CHANGES +++ b/turba/docs/CHANGES @@ -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 , diff --git a/turba/lib/ListView.php b/turba/lib/ListView.php index 157db8d14..fd4e11c5a 100644 --- a/turba/lib/ListView.php +++ b/turba/lib/ListView.php @@ -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; diff --git a/turba/lib/Turba.php b/turba/lib/Turba.php index ad8d3d0f8..c0254b0ed 100644 --- a/turba/lib/Turba.php +++ b/turba/lib/Turba.php @@ -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 */ -- 2.11.0