Skip to content

Commit

Permalink
hack around to deal with 0 or 1 realms
Browse files Browse the repository at this point in the history
  • Loading branch information
SupermanScott committed Dec 31, 2010
1 parent 2b86aee commit 9a7f56d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
23 changes: 16 additions & 7 deletions views/views_handler_arguments.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class activity_views_handler_argument_activity_user extends views_handler_argume
'#type' => 'checkboxes',
'#description' => t('Choose the realms to filter the Activity rows'),
'#options' => $options,

'#required' => TRUE,
'#default_value' => $this->options['realms'],
);
}
Expand Down Expand Up @@ -58,13 +58,22 @@ class activity_views_handler_argument_activity_user extends views_handler_argume
$realm_values = array('activity_none' => 1);
}

$grants = db_or();
foreach ($realm_values as $realm => $ids) {
$grants->condition(db_and()
if (count($realm_values) > 1) {
$grants = db_or();
foreach ($realm_values as $realm => $ids) {
$grants->condition(db_and()
->condition($table . '.realm', $realm)
->condition($table . '.value', $ids, 'IN'));
}
$this->query->add_where('AND', $grants);
}
else {
$keys = array_keys($realm_values);
$realm = $keys[0];
$grants = db_and()
->condition($table . '.realm', $realm)
->condition($table . '.value', $ids, 'IN'));
->condition($table . '.value', $realm_values[$realm]);
$this->query->add_where(0, $grants);
}

$this->query->add_where('AND', $grants);
}
}
27 changes: 20 additions & 7 deletions views/views_handler_filters.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class activity_views_handler_filter_access extends views_handler_filter {
'#type' => 'checkboxes',
'#description' => t('Choose the realms to filter the Activity rows'),
'#options' => $options,

'#default_value' => $this->options['realms'],
'#required' => TRUE,
);
}

Expand All @@ -54,13 +54,26 @@ class activity_views_handler_filter_access extends views_handler_filter {
}
}

$grants = db_or();
foreach ($realm_values as $realm => $ids) {
$grants->condition(db_and()
->condition($table . '.realm', $realm)
->condition($table . '.value', $ids, 'IN'));
if (empty($realm_values)) {
$realm_values = array('activity_none' => array(1));
}

$this->query->add_where('AND', $grants);
if (count($realm_values) > 1) {
$grants = db_or();
foreach ($realm_values as $realm => $ids) {
$grants->condition(db_and()
->condition($table . '.realm', $realm)
->condition($table . '.value', $ids, 'IN'));
}
$this->query->add_where('AND', $grants);
}
else {
$keys = array_keys($realm_values);
$realm = $keys[0];
$grants = db_and()
->condition($table . '.realm', $realm)
->condition($table . '.value', $realm_values[$realm]);
$this->query->add_where(0, $grants);
}
}
}

0 comments on commit 9a7f56d

Please sign in to comment.