Skip to content

Commit

Permalink
Merge branch 'MDL-51652-master' of https://github.com/sammarshallou/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Oct 15, 2015
2 parents 4f5d562 + 07bb79b commit 6bafde6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
18 changes: 16 additions & 2 deletions availability/classes/tree.php
Expand Up @@ -328,7 +328,14 @@ public function filter_user_list(array $users, $not, info $info,
// Loop through all valid children.
foreach ($this->children as $index => $child) {
if (!$child->is_applied_to_user_lists()) {
continue;
if ($andoperator) {
continue;
} else {
// OR condition with one option that doesn't restrict user
// lists = everyone is allowed.
$anyconditions = false;
break;
}
}
$childresult = $child->filter_user_list($users, $innernot, $info, $checker);
if ($andoperator) {
Expand Down Expand Up @@ -359,7 +366,14 @@ public function get_user_list_sql($not, info $info, $onlyactive) {
$childresults = array();
foreach ($this->children as $index => $child) {
if (!$child->is_applied_to_user_lists()) {
continue;
if ($andoperator) {
continue;
} else {
// OR condition with one option that doesn't restrict user
// lists = everyone is allowed.
$childresults = array();
break;
}
}
$childresult = $child->get_user_list_sql($innernot, $info, $onlyactive);
if ($childresult[0]) {
Expand Down
19 changes: 19 additions & 0 deletions availability/tests/tree_test.php
Expand Up @@ -608,6 +608,15 @@ public function test_filter_users() {
ksort($result);
$this->assertEquals(array(1, 3), array_keys($result));

// Tree with OR condition one of which doesn't filter.
$structure = tree::get_root_json(array(
self::mock(array('filter' => array(3))),
self::mock(array())), tree::OP_OR);
$tree = new tree($structure);
$result = $tree->filter_user_list($users, false, $info, $checker);
ksort($result);
$this->assertEquals(array(1, 2, 3), array_keys($result));

// Tree with two condition that both filter (&).
$structure = tree::get_root_json(array(
self::mock(array('filter' => array(2, 3))),
Expand Down Expand Up @@ -726,6 +735,16 @@ public function test_get_user_list_sql() {
$result = $DB->get_fieldset_sql($sql, $params);
sort($result);
$this->assertEquals(array($userinneither->id), $result);

// Tree with 'OR' of group conditions and a non-filtering condition.
// The non-filtering condition should mean that ALL users are included.
$tree = new tree(tree::get_root_json(array(
\availability_group\condition::get_json($group1->id),
\availability_date\condition::get_json(\availability_date\condition::DIRECTION_UNTIL, 3)
), tree::OP_OR));
list($sql, $params) = $tree->get_user_list_sql(false, $info, false);
$this->assertEquals('', $sql);
$this->assertEquals(array(), $params);
}

/**
Expand Down

0 comments on commit 6bafde6

Please sign in to comment.