Hi,

I'm setting up a small site for an amateur sporting organisation and want to create a contact list for coaches and managers. Views 2 does this nicely, except, when a user has another role (eg club president), both roles are included in the listing. Filtering the user listing by role is easy, but the listing still shows the other role that I don't want include. Is there some way that I can exclude the output of those roles that I have filtered out? I've tried messing around with arguments, but this is not my strength. I've included the exported code below, if that's any help. Thanks.

Finally, a deep-felt personal thanks to merlinofchaos for Views and everything he does for the Drupal community. There are a number of reasons why I use Drupal, but without doubt, Views and CCK are the top two.

$view = new view;
$view->name = 'coaches_managers';
$view->description = 'List of coaches and managers for Contact Us page';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'rid' => array(
    'label' => 'Coaches and managers',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'type' => 'separator',
    'separator' => ', ',
    'empty' => '',
    'exclude' => 0,
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_user' => 0,
    'overwrite_anonymous' => 0,
    'anonymous_text' => '',
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'contact' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'text' => 'Contact',
    'link_display' => 'link',
    'exclude' => 0,
    'id' => 'contact',
    'table' => 'users',
    'field' => 'contact',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'rid' => array(
    'operator' => 'or',
    'value' => array(
      '4' => '4',
      '5' => '5',
      '6' => '6',
      '7' => '7',
      '8' => '8',
      '9' => '9',
      '10' => '10',
      '11' => '11',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'rid',
    'table' => 'users_roles',
    'field' => 'rid',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Coaches and Managers');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 0,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'rid' => 'rid',
    'name' => 'name',
    'contact' => 'contact',
  ),
  'info' => array(
    'rid' => array(
      'separator' => '',
    ),
    'name' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'contact' => array(
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'coaches-managers');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));

Comments

dawehner’s picture

thats currently not really easy to do:

You have to implement hook_views_data_alter and change the handler of user roles.
Then you would have to extend "views_handler_field_user_roles" to remove unneeded roles.

Perhaps as alternative there could be also a patch which lets the user select which roles should be displayed.

glennr’s picture

Category: support » feature

Thanks for the tip, dereine. I'll give it a go, but it's probably out of my league. So I'm also changing this to a feature request. I'll understand if it doesn't get a high priority, but it'd be great to have the option to let the user select which roles should be displayed.

dawehner’s picture

This does not work yet

  function option_definition() {
    $options = parent::option_definition();

    $options['excluded_roles'] = array('default' => array());
    return $options;
  }
  
  function options_form(&$form, &$form_state) {
    $form = parent::options_form($form, $form_state);
    $form['excluded_roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Exluded roles'),
      '#description' => t('Select roles which should be hidden from display.'),
      '#default_value' => $this->options['excluded_roles'] ? $this->options['excluded_roles'] : array(),
      '#options' => user_roles(),
    );
  }
iamjon’s picture

I spoke to merlinofchaos about this on irc he said

it should be togglable. i.e "Include only the checked roles" or "Exclude the checked roles"

I'm marking this as an unassigned task. If anyone would like to role up their sleeves and take it upon themselves to write a patch it would be awesome

esmerel’s picture

Category: feature » task
les lim’s picture

Version: 6.x-2.6 » 7.x-3.x-dev
les lim’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev

Whoops, didn't mean to change the major version.

chris matthews’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

The Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue