Move history retrieval to Turba_Object.
authorJan Schneider <jan@horde.org>
Fri, 2 Jul 2010 16:11:00 +0000 (18:11 +0200)
committerJan Schneider <jan@horde.org>
Mon, 5 Jul 2010 10:34:45 +0000 (12:34 +0200)
turba/lib/Object.php
turba/lib/View/Contact.php

index 2dfb378..58590a1 100644 (file)
@@ -188,6 +188,59 @@ class Turba_Object {
     }
 
     /**
+     * Returns history information about this contact.
+     *
+     * @return array  A hash with the optional entries 'created' and 'modified'
+     *                and human readable history information as the values.
+     */
+    function getHistory()
+    {
+        if (!$this->getValue('__uid')) {
+            return array();
+        }
+
+        $history = array();
+        try {
+            $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory($this->getGuid());
+            foreach ($log as $entry) {
+                switch ($entry['action']) {
+                case 'add':
+                    if ($GLOBALS['registry']->getAuth() != $entry['who']) {
+                        $createdby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
+                    } else {
+                        $createdby = _("by me");
+                    }
+                    $history['created']
+                        = strftime($GLOBALS['prefs']->getValue('date_format'), $entry['ts'])
+                        . ' '
+                        . date($GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts'])
+                        . ' '
+                        . @htmlspecialchars($createdby, ENT_COMPAT, Horde_Nls::getCharset());
+                    break;
+
+                case 'modify':
+                    if ($GLOBALS['registry']->getAuth() != $entry['who']) {
+                        $modifiedby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
+                    } else {
+                        $modifiedby = _("by me");
+                    }
+                    $history['modified']
+                        = strftime($GLOBALS['prefs']->getValue('date_format'), $entry['ts'])
+                        . ' '
+                        . date($GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts'])
+                        . ' '
+                        . @htmlspecialchars($modifiedby, ENT_COMPAT, Horde_Nls::getCharset());
+                    break;
+                }
+            }
+        } catch (Exception $e) {
+            return array();
+        }
+
+        return $history;
+    }
+
+    /**
      * Returns true if this object is a group of multiple contacts.
      *
      * @return boolean  True if this object is a group of multiple contacts.
index b3ec222..3e5dc4a 100644 (file)
@@ -39,38 +39,15 @@ class Turba_View_Contact {
 
         $vars = new Horde_Variables();
         $form = new Turba_Form_Contact($vars, $this->contact);
-        $userId = $GLOBALS['registry']->getAuth();
 
         /* Get the contact's history. */
-        if ($this->contact->getValue('__uid')) {
-            try {
-                $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory($this->contact->getGuid());
-                foreach ($log as $entry) {
-                    switch ($entry['action']) {
-                    case 'add':
-                        if ($userId != $entry['who']) {
-                            $createdby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
-                        } else {
-                            $createdby = _("by me");
-                        }
-                        $v = &$form->addVariable(_("Created"), 'object[__created]', 'text', false, false);
-                        $v->disable();
-                        $vars->set('object[__created]', strftime($prefs->getValue('date_format'), $entry['ts']) . ' ' . date($prefs->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . @htmlspecialchars($createdby, ENT_COMPAT, Horde_Nls::getCharset()));
-                        break;
-
-                    case 'modify':
-                        if ($userId != $entry['who']) {
-                            $modifiedby = sprintf(_("by %s"), Turba::getUserName($entry['who']));
-                        } else {
-                            $modifiedby = _("by me");
-                        }
-                        $v = &$form->addVariable(_("Last Modified"), 'object[__modified]', 'text', false, false);
-                        $v->disable();
-                        $vars->set('object[__modified]', strftime($prefs->getValue('date_format'), $entry['ts']) . ' ' . date($prefs->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . @htmlspecialchars($modifiedby, ENT_COMPAT, Horde_Nls::getCharset()));
-                        break;
-                    }
-                }
-            } catch (Exception $e) {}
+        $history = $this->contact->getHistory();
+        foreach ($history as $what => $when) {
+            $v = &$form->addVariable(
+                $what == 'created' ? _("Created") : _("Last Modified"),
+                'object[__' . $what . ']', 'text', false, false);
+            $v->disable();
+            $vars->set('object[__' . $what . ']', $when);
         }
 
         echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>';