views_handler_filter_views_published_or_roles_current_user_has_roles.inc 1.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php

/**
 * @file
 * Definition of views_handler_filter_views_published_or_roles_current_user_has_roles.
 */

/**
 * Filter by published status and by role.
 *
 * @ingroup views_filter_handlers
 */
class views_handler_filter_views_published_or_roles_current_user_has_roles extends views_handler_filter {

  function can_expose() { return FALSE; }

  function get_value_options() {
    $options = user_roles(TRUE);
    unset($options[DRUPAL_AUTHENTICATED_RID]);

    return $options;
  }

  function value_form(&$form, &$form_state) {
    $form['value'] = array(
      '#type' => 'select',
      '#title' => 'Select Role(s)',
      '#options' => $this->get_value_options(),
      '#default_value' => $this->value,
      '#multiple' => TRUE,
    );
  }

  function query() {
    $table = $this->ensure_my_table();
    $table = 'node';
    $roles = array_keys($this->value);
    $this->query->add_where_expression(
      $this->options['group'],
40
      '***CURRENT_USER*** IN (SELECT ur.uid FROM {users_roles} ur WHERE ur.rid IN (:roles))', array(':roles' => $roles));
41 42
  }
}