* Logs an event to an item's history log. Any other details about the
* event are passed in $attributes.
*
- * @param Horde_HistoryObject $history The history item to add to.
- * @param array $attributes The hash of name => value
- * entries that describe this
- * event.
- * @param boolean $replaceAction If $attributes['action'] is
- * already present in the item's
- * history log, update that entry
- * instead of creating a new one.
+ * @param Horde_History_Log $history The history item to add to.
+ * @param array $attributes The hash of name => value
+ * entries that describe this
+ * event.
+ * @param boolean $replaceAction If $attributes['action'] is
+ * already present in the item's
+ * history log, update that entry
+ * instead of creating a new one.
*
* @throws Horde_History_Exception
*/
- abstract protected function _log(Horde_HistoryObject $history,
+ abstract protected function _log(Horde_History_Log $history,
array $attributes, $replaceAction = false);
/**
- * Returns a Horde_HistoryObject corresponding to the named history
- * entry, with the data retrieved appropriately.
+ * Returns a Horde_History_Log corresponding to the named history entry,
+ * with the data retrieved appropriately.
*
* @param string $guid The name of the history entry to retrieve.
*
- * @return Horde_HistoryObject A Horde_HistoryObject
+ * @return Horde_History_Log A Horde_History_Log object.
*
* @throws Horde_History_Exception
* @throws InvalidArgumentException
}
/**
- * Returns a Horde_HistoryObject corresponding to the named history
- * entry, with the data retrieved appropriately.
+ * Returns a Horde_History_Log corresponding to the named history entry,
+ * with the data retrieved appropriately.
*
- * @param string $guid The name of the history entry to retrieve.
- *
- * @return Horde_HistoryObject A Horde_HistoryObject
+ * @param string $guid The name of the history entry to retrieve.
*
- * @throws Horde_History_Exception
+ * @return Horde_History_Log A Horde_History_Log object.
*/
abstract public function _getHistory($guid);
$last = 0;
- if (is_array($history->data)) {
- foreach ($history->data as $entry) {
- if (($entry['action'] == $action) && ($entry['ts'] > $last)) {
- $last = $entry['ts'];
- }
+ foreach ($history as $entry) {
+ if (($entry['action'] == $action) && ($entry['ts'] > $last)) {
+ $last = $entry['ts'];
}
}
--- /dev/null
+<?php
+/**
+ * Class for presenting Horde_History information.
+ *
+ * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Jan Schneider <jan@horde.org>
+ * @package History
+ */
+class Horde_History_Log implements Iterator, ArrayAccess, Countable
+{
+ /**
+ * TODO
+ */
+ public $uid;
+
+ /**
+ * TODO
+ */
+ protected $_data = array();
+
+ /**
+ * Constructor.
+ *
+ * TODO
+ */
+ public function __construct($uid, $data = array())
+ {
+ $this->uid = $uid;
+
+ if (!$data) {
+ return;
+ }
+
+ reset($data);
+ while (list(,$row) = each($data)) {
+ $history = array(
+ 'action' => $row['history_action'],
+ 'desc' => $row['history_desc'],
+ 'who' => $row['history_who'],
+ 'id' => $row['history_id'],
+ 'ts' => $row['history_ts']
+ );
+
+ if ($row['history_extra']) {
+ $extra = @unserialize($row['history_extra']);
+ if ($extra) {
+ $history = array_merge($history, $extra);
+ }
+ }
+ $this->_data[] = $history;
+ }
+ }
+
+ public function current()
+ {
+ return current($this->_data);
+ }
+
+ public function key()
+ {
+ return key($this->_data);
+ }
+
+ public function next()
+ {
+ next($this->_data);
+ }
+
+ public function rewind()
+ {
+ reset($this->_data);
+ }
+
+ public function valid()
+ {
+ return current($this->_data) !== false;
+ }
+
+ public function offsetExists($offset)
+ {
+ return isset($this->_data[$offset]);
+ }
+
+ public function offsetGet($offset)
+ {
+ return $this->_data[$offset];
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ $this->_data[$offset] = $value;
+ }
+
+ public function offsetUnset($offset)
+ {
+ unset($this->_data[$offset]);
+ }
+
+ public function count()
+ {
+ return count($this->_data);
+ }
+}
* Logs an event to an item's history log. Any other details about the
* event are passed in $attributes.
*
- * @param Horde_HistoryObject $history The history item to add to.
- * @param array $attributes The hash of name => value
- * entries that describe this
- * event.
- * @param boolean $replaceAction If $attributes['action'] is
- * already present in the item's
- * history log, update that entry
- * instead of creating a new one.
+ * @param Horde_History_Log $history The history item to add to.
+ * @param array $attributes The hash of name => value
+ * entries that describe this
+ * event.
+ * @param boolean $replaceAction If $attributes['action'] is
+ * already present in the item's
+ * history log, update that entry
+ * instead of creating a new one.
*
* @throws Horde_History_Exception
*/
- protected function _log(Horde_HistoryObject $history,
- array $attributes,
+ protected function _log(Horde_History_Log $history, array $attributes,
$replaceAction = false)
{
$values = array(
* or not to add the entry later. */
$done = false;
if ($replaceAction && !empty($values['history_action'])) {
- for ($i = 0, $count = count($history->data); $i < $count; ++$i) {
- if (!empty($history->data[$i]['action']) &&
- $history->data[$i]['action'] == $values['history_action']) {
- $this->_data[$history->data[$i]['id']] = $values;
+ foreach ($history as $entry) {
+ if (!empty($entry['action']) &&
+ $entry['action'] == $values['history_action']) {
+ $this->_data[$entry['id']] = $values;
$done = true;
break;
}
}
/**
- * Returns a Horde_HistoryObject corresponding to the named history entry,
+ * Returns a Horde_History_Log corresponding to the named history entry,
* with the data retrieved appropriately.
*
* @param string $guid The name of the history entry to retrieve.
*
- * @return Horde_HistoryObject A Horde_HistoryObject
+ * @return Horde_History_Log A Horde_History_Log object.
*/
public function _getHistory($guid)
{
$result[] = $element;
}
}
- return new Horde_HistoryObject($guid, $result);
+ return new Horde_History_Log($guid, $result);
}
/**
* Logs an event to an item's history log. Any other details about the
* event are passed in $attributes.
*
- * @param Horde_HistoryObject $history The history item to add to.
- * @param array $attributes The hash of name => value
- * entries that describe this
- * event.
- * @param boolean $replaceAction If $attributes['action'] is
- * already present in the item's
- * history log, update that entry
- * instead of creating a new one.
+ * @param Horde_History_Log $history The history item to add to.
+ * @param array $attributes The hash of name => value
+ * entries that describe this
+ * event.
+ * @param boolean $replaceAction If $attributes['action'] is
+ * already present in the item's
+ * history log, update that entry
+ * instead of creating a new one.
*
* @throws Horde_History_Exception
*/
- protected function _log(Horde_HistoryObject $history,
- array $attributes,
+ protected function _log(Horde_History_Log $history, array $attributes,
$replaceAction = false)
{
/* If we want to replace an entry with the same action, try and find
* or not to add the entry later. */
$done = false;
if ($replaceAction && !empty($attributes['action'])) {
- for ($i = 0, $count = count($history->data); $i < $count; ++$i) {
- if (!empty($history->data[$i]['action']) &&
- $history->data[$i]['action'] == $attributes['action']) {
+ foreach ($history as $entry) {
+ if (!empty($entry['action']) &&
+ $entry['action'] == $attributes['action']) {
$values = array(
$attributes['ts'],
$attributes['who'],
$values[] = $attributes
? serialize($attributes)
: null;
- $values[] = $history->data[$i]['id'];
+ $values[] = $entry['id'];
$r = $this->_write_db->query(
'UPDATE horde_histories SET history_ts = ?,' .
}
/**
- * Returns a Horde_HistoryObject corresponding to the named history entry,
+ * Returns a Horde_History_Log corresponding to the named history entry,
* with the data retrieved appropriately.
*
* @param string $guid The name of the history entry to retrieve.
*
- * @return Horde_HistoryObject A Horde_HistoryObject
+ * @return Horde_History_Log A Horde_History_Log object.
*
* @throws Horde_History_Exception
*/
{
$rows = $this->_db->getAll('SELECT * FROM horde_histories WHERE object_uid = ?', array($guid), DB_FETCHMODE_ASSOC);
$this->handleError($rows);
- return new Horde_HistoryObject($guid, $rows);
+ return new Horde_History_Log($guid, $rows);
}
/**
+++ /dev/null
-<?php
-/**
- * Class for presenting Horde_History information.
- *
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package History
- */
-class Horde_HistoryObject
-{
- /**
- * TODO
- */
- public $uid;
-
- /**
- * TODO
- */
- public $data = array();
-
- /**
- * Constructor.
- *
- * TODO
- */
- public function __construct($uid, $data = array())
- {
- $this->uid = $uid;
-
- if (!$data) {
- return;
- }
-
- reset($data);
- while (list(,$row) = each($data)) {
- $history = array(
- 'action' => $row['history_action'],
- 'desc' => $row['history_desc'],
- 'who' => $row['history_who'],
- 'id' => $row['history_id'],
- 'ts' => $row['history_ts']
- );
-
- if ($row['history_extra']) {
- $extra = @unserialize($row['history_extra']);
- if ($extra) {
- $history = array_merge($history, $extra);
- }
- }
- $this->data[] = $history;
- }
- }
-
- public function getData()
- {
- return $this->data;
- }
-
-}
$history = $this->getHistory($environment);
$history->log('test', array('action' => 'test'));
$this->assertTrue($history->getActionTimestamp('test', 'test') > 0);
- $data = $history->getHistory('test')->getData();
+ $data = $history->getHistory('test');
$this->assertTrue(isset($data[0]['who']));
}
}
$history->log('test', array('who' => 'me', 'ts' => 1000, 'action' => 'test'), false);
$history->log('test', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'));
$history->log('test', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'), true);
- $data = $history->getHistory('test')->getData();
+ $data = $history->getHistory('test');
$expect = array(
- array(
- 'action' => 'test',
- 'desc' => '',
- 'who' => 'me',
- 'id' => 1,
- 'ts' => 1000,
- ),
- array(
- 'action' => 'test',
- 'desc' => '',
- 'who' => 'me',
- 'id' => 2,
- 'ts' => 1000,
- ),
- array(
- 'action' => 'yours',
- 'desc' => '',
- 'who' => 'you',
- 'id' => 3,
- 'ts' => 2000,
- ),
+ 'action' => 'test',
+ 'desc' => '',
+ 'who' => 'me',
+ 'id' => 1,
+ 'ts' => 1000,
);
- $this->assertEquals($expect, $data);
+ $this->assertEquals($expect, $data[0]);
+ $expect = array(
+ 'action' => 'test',
+ 'desc' => '',
+ 'who' => 'me',
+ 'id' => 2,
+ 'ts' => 1000,
+ );
+ $this->assertEquals($expect, $data[1]);
+ $expect = array(
+ 'action' => 'yours',
+ 'desc' => '',
+ 'who' => 'you',
+ 'id' => 3,
+ 'ts' => 2000,
+ );
+ $this->assertEquals($expect, $data[2]);
}
}
}
}
- public function testMethodGethistoryHasResultHordehistoryobjectRepresentingTheHistoryLogMatchingTheGivenGuid()
+ public function testMethodGethistoryHasResultHordehistorylogRepresentingTheHistoryLogMatchingTheGivenGuid()
{
foreach ($this->getEnvironments() as $environment) {
$history = $this->getHistory($environment);
$history->log('test', array('who' => 'me', 'ts' => 1000, 'action' => 'test'));
$history->log('test', array('who' => 'you', 'ts' => 2000, 'action' => 'yours', 'extra' => array('a' => 'a')));
- $data = $history->getHistory('test')->getData();
+ $data = $history->getHistory('test');
+ $expect = array(
+ 'action' => 'test',
+ 'desc' => '',
+ 'who' => 'me',
+ 'id' => 1,
+ 'ts' => 1000,
+ );
+ $this->assertEquals($expect, $data[0]);
$expect = array(
- array(
- 'action' => 'test',
- 'desc' => '',
- 'who' => 'me',
- 'id' => 1,
- 'ts' => 1000,
- ),
- array(
- 'action' => 'yours',
- 'desc' => '',
- 'who' => 'you',
- 'id' => 2,
- 'ts' => 2000,
- 'extra' => array('a' => 'a'),
- ),
+ 'action' => 'yours',
+ 'desc' => '',
+ 'who' => 'you',
+ 'id' => 2,
+ 'ts' => 2000,
+ 'extra' => array('a' => 'a'),
);
- $this->assertEquals($expect, $data);
+ $this->assertEquals($expect, $data[1]);
}
}
$history->log('yours', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'));
$history->log('yours', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'), true);
$history->removeByNames(array('test'));
- $data = $history->getHistory('test')->getData();
- $this->assertEquals(array(), $data);
- $data = $history->getHistory('yours')->getData();
+ $data = $history->getHistory('test');
+ $this->assertEquals(0, count($data));
+ $data = $history->getHistory('yours');
$expect = array(
- array(
- 'action' => 'yours',
- 'desc' => '',
- 'who' => 'you',
- 'id' => 3,
- 'ts' => 2000,
- ),
+ 'action' => 'yours',
+ 'desc' => '',
+ 'who' => 'you',
+ 'id' => 3,
+ 'ts' => 2000,
);
- $this->assertEquals($expect, $data);
+ $this->assertEquals($expect, $data[0]);
$history->removeByNames(array('yours'));
- $data = $history->getHistory('yours')->getData();
- $this->assertEquals(array(), $data);
+ $data = $history->getHistory('yours');
+ $this->assertEquals(0, count($data));
}
}
$history->log('yours', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'));
$history->log('yours', array('who' => 'you', 'ts' => 2000, 'action' => 'yours'), true);
$history->removeByNames(array('test', 'yours'));
- $data = $history->getHistory('test')->getData();
- $this->assertEquals(array(), $data);
- $data = $history->getHistory('yours')->getData();
- $this->assertEquals(array(), $data);
+ $data = $history->getHistory('test');
+ $this->assertEquals(0, count($data));
+ $data = $history->getHistory('yours');
+ $this->assertEquals(0, count($data));
}
}