Allow listBy API calls to take an optional end timestamp as well.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 27 Apr 2010 13:38:21 +0000 (09:38 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 27 Apr 2010 13:44:52 +0000 (09:44 -0400)
kronolith/lib/Api.php
mnemo/lib/Api.php
nag/lib/Api.php
turba/lib/Api.php

index 441a4e5..f95015f 100644 (file)
@@ -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));
index e206c9a..9b9eacc 100644 (file)
@@ -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;
     }
index 134da4c..fc6fbf6 100644 (file)
@@ -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));
index 11c27c3..1ce8825 100644 (file)
@@ -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:.