From: Michael J. Rubinsky Date: Tue, 27 Apr 2010 13:38:21 +0000 (-0400) Subject: Allow listBy API calls to take an optional end timestamp as well. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bb701dabc2661d2481fe50ad9f0955f1e736b82d;p=horde.git Allow listBy API calls to take an optional end timestamp as well. --- diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index 441a4e562..f95015ffe 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -478,6 +478,7 @@ class Kronolith_Api extends Horde_Registry_Api * @param string $action The action to check for - add, modify, or delete. * @param integer $timestamp The time to start the search. * @param string $calendar The calendar to search in. + * @param integer $end The optional ending timestamp * * @return array An array of UIDs matching the action and time criteria. * @@ -485,7 +486,7 @@ class Kronolith_Api extends Horde_Registry_Api * @throws Horde_History_Exception * @throws InvalidArgumentException */ - public function listBy($action, $timestamp, $calendar = null) + public function listBy($action, $timestamp, $calendar = null, $end = null) { if (empty($calendar)) { $calendar = Kronolith::getDefaultCalendar(); @@ -496,7 +497,11 @@ class Kronolith_Api extends Horde_Registry_Api throw new Horde_Exception_PermissionDenied(); } - $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'kronolith:' . $calendar); + $filter = array(array('op' => '=', 'field' => 'action', 'value' => $action)); + if (!empty($end)) { + $filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end); + } + $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, $filter, 'kronolith:' . $calendar); // Strip leading kronolith:username:. return preg_replace('/^([^:]*:){2}/', '', array_keys($histories)); diff --git a/mnemo/lib/Api.php b/mnemo/lib/Api.php index e206c9a75..9b9eaccbc 100644 --- a/mnemo/lib/Api.php +++ b/mnemo/lib/Api.php @@ -235,10 +235,11 @@ function _mnemo_list($notepad = null) * @param string $action The action to check for - add, modify, or delete. * @param integer $timestamp The time to start the search. * @param string $notepad The notepad to search in. + * @param integer $end The optional ending timestamp. * * @return array An array of UIDs matching the action and time criteria. */ -function _mnemo_listBy($action, $timestamp, $notepad = null) +function _mnemo_listBy($action, $timestamp, $notepad = null, $end = null) { require_once dirname(__FILE__) . '/base.php'; @@ -252,8 +253,12 @@ function _mnemo_listBy($action, $timestamp, $notepad = null) return PEAR::raiseError(_("Permission Denied")); } + $filter = array(array('op' => '=', 'field' => 'action', 'value' => $action)); + if (!empty($end)) { + $filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end); + } $history = $GLOBALS['injector']->getInstance('Horde_History'); - $histories = $history->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'mnemo:' . $notepad); + $histories = $history->getByTimestamp('>', $timestamp, $filter, 'mnemo:' . $notepad); if (is_a($histories, 'PEAR_Error')) { return $histories; } diff --git a/nag/lib/Api.php b/nag/lib/Api.php index 134da4c7f..fc6fbf67a 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -677,13 +677,14 @@ class Nag_Api extends Horde_Registry_Api * @param integer $timestamp The time to start the search. * @param string $tasklist The tasklist to be used. If 'null', the * user's default tasklist will be used. + * @param integer $end The optional ending timestamp. * * @return array An array of UIDs matching the action and time criteria. * * @throws Horde_History_Exception * @throws InvalidArgumentException */ - public function listBy($action, $timestamp, $tasklist = null) + public function listBy($action, $timestamp, $tasklist = null, $end = null) { if ($tasklist === null) { $tasklist = Nag::getDefaultTasklist(Horde_Perms::READ); @@ -692,9 +693,13 @@ class Nag_Api extends Horde_Registry_Api if (!array_key_exists($tasklist, Nag::listTasklists(false, Horde_Perms::READ))) { return PEAR::raiseError(_("Permission Denied")); - } + } - $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, array(array('op' => '=', 'field' => 'action', 'value' => $action)), 'nag:' . $tasklist); + $filter = array(array('op' => '=', 'field' => 'action', 'value' => $action)); + if (!empty($end)) { + $filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end); + } + $histories = $GLOBALS['injector']->getInstance('Horde_History')->getByTimestamp('>', $timestamp, $filter, 'nag:' . $tasklist); // Strip leading nag:username:. return preg_replace('/^([^:]*:){2}/', '', array_keys($histories)); diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 11c27c34e..1ce8825b4 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -485,13 +485,14 @@ class Turba_Api extends Horde_Registry_Api * @param integer $timestamp The time to start the search. * @param string|array $sources The source(s) for which to retrieve the * history. + * @param integer $end The optinal ending timestamp. * * @return array An array of UIDs matching the action and time criteria. * * @throws Horde_Exception * @throws InvalidArgumentException */ - public function listBy($action, $timestamp, $sources = null) + public function listBy($action, $timestamp, $sources = null, $end = null) { global $prefs, $cfgSources; @@ -510,6 +511,10 @@ class Turba_Api extends Horde_Registry_Api $uids = array(); $history = $GLOBALS['injector']->getInstance('Horde_History'); + $filter = array(array('op' => '=', 'field' => 'action', 'value' => $action)); + if (!empty($end)) { + $filter[] = array('op' => '<', 'field' => 'ts', 'value' => $end); + } foreach ($sources as $source) { if (empty($source) || !isset($cfgSources[$source])) { throw new Horde_Exception(sprintf(_("Invalid address book: %s"), $source)); @@ -521,10 +526,7 @@ class Turba_Api extends Horde_Registry_Api } $histories = $history->getByTimestamp( - '>', $timestamp, - array(array('op' => '=', - 'field' => 'action', - 'value' => $action)), + '>', $timestamp, $filter, 'turba:' . $driver->getName()); // Strip leading turba:addressbook:.