In hook_views_tables, I used the 'extra' field to make sure that when my table was used in a view,it ony used records which matched the current group. i.e.:

  $tables['og_users_roles'] = array(
    'name' => 'og_users_roles',
    'provider' => 'internal', // won't show up in external list.
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'uid'
      ),
      'right' => array(
        'field' => 'uid'
      ),
      'extra' => array(
        'gid' => '***CURRENT_GID***'
      ),
    ),

How do I implement this using hook_views_data()?:

  $data['og_users_roles']['table']['group']  = t('OGUR Groups');
  $data['og_users_roles']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'gid',
    ),
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
    'role' => array(
      'left_field' => 'rid',
      'field' => 'rid',
    ),
  );

I've been searching for an example, but so far no luck. Thanks for any info anyone can provide.

Comments

somebodysysop’s picture

Any suggestions?

somebodysysop’s picture

Status: Active » Fixed

Well, just for the purposes of documentation, I resolved the issue in another way. I created a filter:

class ogur_handler_filter_og_users_roles_picg extends views_handler_filter {
  function query() {
    $table = $this->ensure_my_table();
    $this->query->add_where($this->options['group'], "$table.gid  = ***CURRENT_GID***");
  }

actually, lifted it from the OG module.

When I add this filter to my view, it makes sure that the table is only showing records related to the current view.

Would still like to know the answer to my original question, if anyone ever gets around to it.

cdale’s picture

The views Advanced Help documentation has good details on how to achieve this. But you probably want something like the following:

  $data['og_users_roles']['table']['group']  = t('OGUR Groups');
  $data['og_users_roles']['table']['join'] = array(
    'node' => array(
      'left_field' => 'nid',
      'field' => 'gid',
      'extra' => array(
        'field' => 'gid',
        'value' => '***CURRENT_GID***',
        'table' => 'og_users_roles',
      ),
    ),
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
      'extra' => array(
        'field' => 'gid',
        'value' => '***CURRENT_GID***',
        'table' => 'og_users_roles',
      ),
    ),
    'role' => array(
      'left_field' => 'rid',
      'field' => 'rid',
      'extra' => array(
        'field' => 'gid',
        'value' => '***CURRENT_GID***',
        'table' => 'og_users_roles',
      ),
    ),
  );

One thing I would love to know myself is how to use the table alias for the left table, instead of the actual table name, but from looking at the code, I can't see anyway that this might be possible.

somebodysysop’s picture

Yes, thank you. This is exactly what I was looking for.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.