You are here

function user_views_tables in Views (for Drupal 7) 5

This include file implements views functionality on behalf of user.module

File

modules/views_user.inc, line 7

Code

function user_views_tables() {
  $tables['users'] = array(
    'name' => 'users',
    'provider' => 'internal',
    // won't show up in external list.
    'join' => array(
      'type' => 'inner',
      'left' => array(
        'table' => 'node',
        'field' => 'uid',
      ),
      'right' => array(
        'field' => 'uid',
      ),
    ),
    'fields' => array(
      'name' => array(
        'name' => t('Node: Author Name'),
        'handler' => 'views_handler_field_username',
        'sortable' => true,
        'uid' => 'uid',
        'addlfields' => array(
          'uid',
        ),
        'help' => t('This will display the author of the node.'),
      ),
      'uid' => array(
        'name' => t('User: Author Picture'),
        'handler' => 'views_handler_field_userpic',
        'sortable' => false,
        'help' => t('Display the user picture of the author.'),
      ),
      'mail' => array(
        'name' => t('User: E-mail'),
        'sortable' => TRUE,
        'help' => t("Display the user's email address. Beware that this should only be shown to administrators in a normal Drupal installation. Further, no attempt is made to obfuscate the email address."),
      ),
    ),
    'sorts' => array(
      'name' => array(
        'name' => t('Node: Author Name'),
        'help' => t('This allows you to sort alphabetically by author.'),
      ),
    ),
    'filters' => array(
      'uid' => array(
        'name' => t('Node: Author Name'),
        'operator' => 'views_handler_operator_or',
        'list' => 'views_handler_filter_username',
        'value-type' => 'array',
        'help' => t('This allows you to filter by a particular user. You might not find this useful if you have a lot of users.'),
      ),
    ),
  );

  // Get the list of non-default user roles indexed by rid.
  $user_roles = user_roles(TRUE);
  unset($user_roles[DRUPAL_AUTHENTICATED_RID]);
  foreach ($user_roles as $rid => $name) {
    $tables["users_role_{$rid}"] = array(
      'name' => 'users',
      'provider' => 'internal',
      // won't show up in external list.
      'join' => array(
        'left' => array(
          'table' => 'node',
          'field' => 'uid',
        ),
        'right' => array(
          'field' => 'uid',
        ),
      ),
      'filters' => array(
        'uid' => array(
          'name' => t('Node: Authors in role %role-name', array(
            '%role-name' => $name,
          )),
          'list' => 'views_handler_filter_username',
          'value-type' => 'array',
          'operator' => 'views_handler_operator_or',
          'rid' => $rid,
          'help' => t("Only users in role %role-name will appear in the select box for this filter.", array(
            '%role-name' => theme('placeholder', $name),
          )),
        ),
      ),
    );
  }
  $tables['users_roles'] = array(
    'name' => 'users_roles',
    'provider' => 'internal',
    // won't show up in external list.
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'uid',
      ),
      'right' => array(
        'field' => 'uid',
      ),
    ),
    'filters' => array(
      'rid' => array(
        'name' => t('Role: Author Role'),
        'operator' => 'views_handler_operator_andor',
        'list' => 'views_handler_filter_role',
        'handler' => 'views_handler_filter_role_custom',
        'value-type' => 'array',
        'help' => t('Include the node only if the author is a member of the selected role.'),
      ),
    ),
  );
  return $tables;
}