You are here

function votingapi_views_data_alter in Voting API 6.2

Same name and namespace in other branches
  1. 8.3 votingapi.views.inc \votingapi_views_data_alter()
  2. 7.3 views/votingapi.views.inc \votingapi_views_data_alter()
  3. 7.2 views/votingapi.views.inc \votingapi_views_data_alter()

Related topics

File

views/votingapi.views.inc, line 272
Provide views data for votingapi.module.

Code

function votingapi_views_data_alter(&$views_data) {

  // Add relationship handlers for both tables, for any base tables currently
  // available to Views.
  $default_relationships = module_invoke_all('votingapi_relationships');
  $default_relationships[] = array(
    'description' => t('nodes'),
    'content_type' => 'node',
    'base_table' => 'node',
    'content_id_column' => 'nid',
    'pseudo_vote' => 'votingapi_vote',
    // for legacy compatability w/RC1.
    'pseudo_cache' => 'votingapi_cache',
  );
  $default_relationships[] = array(
    'description' => t('comments'),
    'content_type' => 'comment',
    'base_table' => 'comments',
    'content_id_column' => 'cid',
    'pseudo_vote' => 'votingapi_vote',
    // for legacy compatability w/RC1.
    'pseudo_cache' => 'votingapi_cache',
  );
  $default_relationships[] = array(
    'description' => t('users'),
    'content_type' => 'user',
    'base_table' => 'users',
    'content_id_column' => 'uid',
    'pseudo_vote' => 'votingapi_vote',
    // for legacy compatability w/RC1.
    'pseudo_cache' => 'votingapi_cache',
  );
  foreach ($default_relationships as $data) {
    $pseudo = str_replace(array(
      ' ',
      '-',
      '.',
    ), '_', $data['content_type'] . '_' . $data['content_id_column']);
    $pseudo_vote = empty($data['pseudo_vote']) ? 'vapi_' . $pseudo : $data['pseudo_vote'];
    $pseudo_cache = empty($data['pseudo_cache']) ? 'vapic_' . $pseudo : $data['pseudo_cache'];
    $views_data[$data['base_table']][$pseudo_vote]['relationship'] = array(
      'title' => 'Votes',
      'help' => 'Votes cast by users on ' . $data['description'] . '.',
      'base' => 'votingapi_vote',
      'field' => 'content_id',
      'relationship field' => $data['content_id_column'],
      'handler' => 'votingapi_views_handler_relationship',
      'extra' => array(
        array(
          'field' => 'content_type',
          'value' => $data['content_type'],
          'numeric' => FALSE,
        ),
      ),
    );
    $views_data[$data['base_table']][$pseudo_cache]['relationship'] = array(
      'title' => 'Vote results',
      'help' => 'Aggregate results of votes cast on ' . $data['description'] . '.',
      'base' => 'votingapi_cache',
      'field' => 'content_id',
      'relationship field' => $data['content_id_column'],
      'handler' => 'votingapi_views_handler_relationship',
      'extra' => array(
        array(
          'field' => 'content_type',
          'value' => $data['content_type'],
          'numeric' => FALSE,
        ),
      ),
    );
  }
}