Commit bf2c9be0 authored by Bjoern Schiessle's avatar Bjoern Schiessle
Browse files

concatenate queries with 'or'

parent 154628da
...@@ -247,16 +247,28 @@ class ActivityManager implements IManager { ...@@ -247,16 +247,28 @@ class ActivityManager implements IManager {
* @return array * @return array
*/ */
function getQueryForFilter($filter) { function getQueryForFilter($filter) {
$conditions = array();
$parameters = array();
foreach($this->extensions as $extension) { foreach($this->extensions as $extension) {
$c = $extension(); $c = $extension();
if ($c instanceof IExtension) { if ($c instanceof IExtension) {
$result = $c->getQueryForFilter($filter); $result = $c->getQueryForFilter($filter);
if (is_array($result)) { if (is_array($result)) {
return $result; list($condition, $parameter) = $result;
if ($condition && is_array($parameter)) {
$conditions[] = $condition;
$parameters = array_merge($parameters, $parameter);
}
} }
} }
} }
if (empty($conditions)) {
return array(null, null); return array(null, null);
} }
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
}
} }
...@@ -87,11 +87,14 @@ class Test_ActivityManager extends \Test\TestCase { ...@@ -87,11 +87,14 @@ class Test_ActivityManager extends \Test\TestCase {
} }
public function testQueryForFilter() { public function testQueryForFilter() {
$this->activityManager->registerExtension(function() {
return new SimpleExtension();
});
$result = $this->activityManager->getQueryForFilter('filter1'); $result = $this->activityManager->getQueryForFilter('filter1');
$this->assertEquals( $this->assertEquals(
array( array(
'`app` = ? and `message` like ?', ' and ((`app` = ? and `message` like ?) or (`app` = ? and `message` like ?))',
array('mail', 'ownCloud%') array('mail', 'ownCloud%', 'mail', 'ownCloud%')
), $result ), $result
); );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment