allow the attributes filter to take an array of values to filter on.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 17 Jan 2011 21:26:36 +0000 (16:26 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 17 Jan 2011 21:26:36 +0000 (16:26 -0500)
e.g.,
To return shares that have a slug of either $slug1 or $slug2:

$shares->listShares($user, array('attributes' => array('slug' => arary($slug1, $slug2))));

framework/Share/lib/Horde/Share/Sql.php
framework/Share/lib/Horde/Share/Sql/Hierarchical.php

index 837a30d..ab0bee3 100644 (file)
@@ -359,7 +359,6 @@ class Horde_Share_Sql extends Horde_Share_Base
                                     'sort_by' => null,
                                     'direction' => 0),
                               $params);
-
         $key = md5(serialize(array($userid, $params)));
         if (!empty($this->_listcache[$key])) {
             return $this->_listcache[$key];
@@ -606,7 +605,12 @@ class Horde_Share_Sql extends Horde_Share_Base
             // Build attribute/key filter.
             $where = ' (' . $where . ') ';
             foreach ($attributes as $key => $value) {
-                $where .= ' AND ' . $key . ' = ' . $this->_db->quote($value);
+                if (is_array($value)) {
+                    $value = array_map(array($this->_db, 'quote'), $value);
+                    $where .= ' AND ' . $key . ' IN (' . implode(', ', $value) . ')';
+                } else {
+                    $where .= ' AND ' . $key . ' = ' . $this->_db->quote($value);
+                }
             }
         } elseif (!empty($attributes)) {
             // Restrict to shares owned by the user specified in the
index eb39e93..3cbcca9 100644 (file)
@@ -166,12 +166,6 @@ class Horde_Share_Sql_Hierarchical extends Horde_Share_Sql
                                      $attributes = null, $parent = null,
                                      $allLevels = true)
     {
-        if (is_object($parent)) {
-            $parent_id = $parent->getId();
-        } else {
-            $parent_id = $parent;
-        }
-
         $query = $where = '';
         if (!is_null($perm)) {
             list($query, $where) = $this->_getUserAndGroupCriteria($userid, $perm);
@@ -190,11 +184,11 @@ class Horde_Share_Sql_Hierarchical extends Horde_Share_Sql
                 $where = ' (' . $where . ') ';
             }
             foreach ($attributes as $key => $value) {
-                $where .= ' AND ' . $key;
                 if (is_array($value)) {
-                    $where .= ' ' . $value[0]. ' ' . $this->_db->quote($value[1]);
+                    $value = array_map(array($this->_db, 'quote'), $value);
+                    $where .= ' AND ' . $key . ' IN (' . implode(', ', $value) . ')';
                 } else {
-                    $where .= ' = ' . $this->_db->quote($value);
+                    $where .= ' AND ' . $key . ' = ' . $this->_db->quote($value);
                 }
             }
         } elseif (!empty($attributes)) {