[Kolab-devel] [issue3859] [turba] optimized formatName function and fallback to company attribute

Soenke Schwardt-Krummrich issues at kolab.org
Fri Sep 11 17:25:30 CEST 2009


New submission from Soenke Schwardt-Krummrich <schwardt at univention.de>:

Some groupware clients like kontact or allow the creation of contacts without
name entered (fullname, firstname, middlename and lastname are not set).
This patch tries to assemble a formatted name if not all fields are set.

If the formatted name is empty after all turba displays company name (if entered).

----------
files: t_turba_HK_UV_formatName_companyName.diff
keyword: web client
messages: 21652
nosy: schwardt
status: unread
title: [turba] optimized formatName function and fallback to company attribute

______________________________________
Kolab issue tracker <issues at kolab.org>
<https://issues.kolab.org/issue3859>
______________________________________
-------------- next part --------------
Patch by schwardt at univention.de (Thu Sep 10 16:56:07 2009 +0200):

[turba] optimized formatName function and fallback to company attribute

Some groupware clients like kontact or allow the creation of contacts without
name entered (fullname, firstname, middlename and lastname are not set).
This patch tries to assemble a formatted name if not all fields are set.

If the formatted name is empty after all turba displays company name (if entered).


--- a/horde-webmail/turba/lib/Turba.php
+++ b/horde-webmail/turba/lib/Turba.php
@@ -235,18 +235,34 @@ class Turba {
         if (!isset($name_format)) {
             $name_format = $prefs->getValue('name_format');
         }
+        $firstname = $ob->getValue('firstname');
+        $middlename = $ob->getValue('middlenames');
+        $lastname = $ob->getValue('lastname');
+        $name = $ob->getValue('name');
 
         /* if no formatting, return original name */
         if ($name_format != 'first_last' && $name_format != 'last_first') {
-            return $ob->getValue('name');
+            if (!empty($name))
+                return $name;
+            if (!empty($firstname) || !empty($middlenames) || !empty($lastname))
+                return trim($firstname.' '.$middlenames.' '.$lastname);
+            return '';
         }
 
         /* See if we have the name fields split out explicitly. */
         if ($ob->hasValue('firstname') && $ob->hasValue('lastname')) {
             if ($name_format == 'last_first') {
-                return $ob->getValue('lastname') . ', ' . $ob->getValue('firstname');
+                if (!empty($firstname) || !empty($lastname))
+                    return trim($lastname . ', ' . $firstname);
+                if (!empty($name))
+                    return $name;
+                return '';
             } else {
-                return $ob->getValue('firstname') . ' ' . $ob->getValue('lastname');
+                if (!empty($firstname) || !empty($lastname))
+                    return trim ($firstname . ' ' . $lastname);
+                if (!empty($name))
+                    return $name;
+                return '';
             }
         } else {
             /* One field, we'll have to guess. */
--- a/horde-webmail/turba/templates/browse/row.inc
+++ b/horde-webmail/turba/templates/browse/row.inc
@@ -6,6 +6,8 @@ if ($ob->hasValue('name')) {
           !in_array($ob->driver->alternativeName, $this->columns) &&
           $ob->hasValue($ob->driver->alternativeName)) {
     $link_text = htmlspecialchars($ob->getValue($ob->driver->alternativeName));
+} elseif ($ob->hasValue('company')) {
+    $link_text = htmlspecialchars($ob->getValue('company'));
 } else {
     $link_text = '<em>' . _("Blank name") . '</em>';
 }


More information about the devel mailing list