From 2823d84224434bad25cb14b8bd3fadcde117208f Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 2 Jul 2010 18:11:00 +0200 Subject: [PATCH] Move history retrieval to Turba_Object. --- turba/lib/Object.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ turba/lib/View/Contact.php | 37 ++++++-------------------------- 2 files changed, 60 insertions(+), 30 deletions(-) diff --git a/turba/lib/Object.php b/turba/lib/Object.php index 2dfb378da..58590a133 100644 --- a/turba/lib/Object.php +++ b/turba/lib/Object.php @@ -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. diff --git a/turba/lib/View/Contact.php b/turba/lib/View/Contact.php index b3ec22251..3e5dc4a1b 100644 --- a/turba/lib/View/Contact.php +++ b/turba/lib/View/Contact.php @@ -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 '