You are here

function biblio_views_data in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 views/biblio.views.inc \biblio_views_data()
  2. 7 views/biblio.views.inc \biblio_views_data()

Implementation of hook_views_data().

Exposes all fields to the views system.

File

./biblio.views.inc, line 105

Code

function biblio_views_data() {
  $viewsdata = array();

  /**************** biblio table **************/
  $data = array();

  // everything belongs to the Biblio group
  $data['table']['group'] = t('Biblio');
  $data['citation'] = array(
    'title' => t('Biblio Citation'),
    'help' => t("Display the complete citation for a given node"),
    'field' => array(
      'handler' => 'biblio_handler_citation',
    ),
  );
  $result = db_query('SELECT f.name,f.type,ftd.title,ft.ftdid FROM {biblio_fields} f
                      INNER JOIN {biblio_field_type} AS ft ON ft.fid = f.fid
                      INNER JOIN {biblio_field_type_data} ftd ON ft.ftdid = ftd.ftdid
                      WHERE ft.tid=0');
  while ($field = db_fetch_array($result)) {
    $data[$field['name']] = array(
      'title' => $field['title'],
      'help' => "Display the " . $field['title'],
      'field' => array(
        'handler' => 'biblio_handler_field',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ),
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
    );

    // for contrib_widgets we use a special handler:
    if ($field['type'] == 'contrib_widget') {
      $data[$field['name']]['field'] = array(
        'handler' => 'biblio_handler_field_contributor',
        'auth_category' => $field['ftdid'],
      );
      unset($data[$field['name']]['sort']);
      unset($data[$field['name']]['filter']);
      unset($data[$field['name']]['argument']);
    }
  }
  $data['biblio_year']['argument'] = array(
    'handler' => 'views_handler_argument_numeric',
  );

  // biblio_year is an int
  $data['biblio_year']['filter'] = array(
    'handler' => 'views_handler_filter_numeric',
  );

  // biblio_year is an int
  unset($data['biblio_keywords']);

  // keywords are in a separate table which has it's own handlers
  $data['table']['join'] = array(
    'node' => array(
      // links directly to node via vid
      'left_field' => 'vid',
      'field' => 'vid',
      'type' => 'inner',
    ),
    'node_revisions' => array(
      'left_field' => 'vid',
      'field' => 'vid',
      'type' => 'inner',
    ),
  );
  $viewsdata['biblio'] = $data;

  /**************** biblio_types table *********************/
  $data = array();
  $data['table']['group'] = t('Biblio');
  $data['table']['join'] = array(
    'node' => array(
      'left_table' => 'biblio',
      'left_field' => 'biblio_type',
      'field' => 'tid',
    ),
    'node_revision' => array(
      'left_table' => 'biblio',
      'left_field' => 'biblio_type',
      'field' => 'tid',
    ),
  );
  $data['name'] = array(
    'field' => array(
      'handler' => 'views_handler_field',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'title' => t('Type of Publication'),
    'help' => t('The type of publication: Journal, Book, Conference Paper, etc.'),
  );
  $data['tid'] = array(
    'argument' => array(
      'handler' => 'biblio_handler_argument_many_to_one',
      'name table' => 'biblio_types',
      'name field' => 'name',
      'empty name field' => t('No Type'),
      'numeric' => TRUE,
    ),
    'filter' => array(
      'handler' => 'biblio_handler_filter_biblio_type',
    ),
    'title' => t('Type ID of Publication'),
    'help' => t('The type of publication: Journal, Book, Conference Paper, etc.'),
  );
  $viewsdata['biblio_types'] = $data;

  /**************** biblio contributors table **************/
  $data = array();
  $data['table']['group'] = t('Biblio');
  $data['table']['join'] = array(
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
      'type' => 'inner',
    ),
    'node_revision' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
    // This is provided for many_to_one argument
    'biblio' => array(
      'field' => 'vid',
      'left_field' => 'vid',
      'type' => 'inner',
    ),
    'users' => array(
      'left_table' => 'biblio_contributor_data',
      'field' => 'cid',
      'left_field' => 'cid',
    ),
  );
  $data['cid'] = array(
    'title' => t('Author ID'),
    'help' => t('Filter by author id.'),
    'argument' => array(
      'handler' => 'biblio_handler_argument_many_to_one',
      'name table' => 'biblio_contributor_data',
      'name field' => 'lastname',
      'empty name field' => t('No Author'),
      'numeric' => TRUE,
    ),
    'filter' => array(
      'handler' => 'biblio_handler_filter_contributor',
    ),
  );
  $data['rank'] = array(
    'title' => t('Author Rank'),
    'help' => t('Rank defines the author order "0" being the first author, "1" the second and so on.'),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
  );
  $data['auth_type'] = array(
    'title' => t('Author Type'),
    'help' => t('Rank defines the type of author Author, Editor, Translator and so on.'),
    'filter' => array(
      'handler' => 'biblio_handler_filter_biblio_contributor_auth_type',
    ),
  );
  $viewsdata['biblio_contributor'] = $data;

  /**************** biblio_contributor_data table ***********/
  $data = array();
  $data['table']['group'] = t('Biblio');
  $data['table']['join'] = array(
    'biblio_contributor' => array(
      'left_field' => 'cid',
      'field' => 'cid',
    ),
    'node' => array(
      'left_table' => 'biblio_contributor',
      'left_field' => 'cid',
      'field' => 'cid',
    ),
    'users' => array(
      'left_field' => 'uid',
      'field' => 'drupal_uid',
    ),
  );
  $data['drupal_uid'] = array(
    'field' => array(
      'handler' => 'views_handler_field',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'base' => 'users',
      'base field' => 'uid',
      'label' => t('user'),
    ),
    'title' => t('Drupal UserID'),
    'help' => t('This is the Drupal user associated with the Biblio Author.'),
  );
  $data['lastname'] = array(
    'sort' => array(
      'handler' => 'biblio_handler_sort_contributor_lastname',
    ),
    'filter' => array(
      'handler' => 'biblio_handler_filter_contributor_lastname',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'title' => t('Author Lastname'),
    'help' => t('Author Lastname'),
  );
  $viewsdata['biblio_contributor_data'] = $data;

  /***************** Describe the keyword table *************/
  $data = array();
  $data['table']['group'] = t('Biblio');
  $data['table']['join'] = array(
    'node' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
    'node_revision' => array(
      'left_field' => 'vid',
      'field' => 'vid',
    ),
    // This is provided for many_to_one argument
    'biblio' => array(
      'field' => 'vid',
      'left_field' => 'vid',
    ),
  );
  $data['kid'] = array(
    'title' => t('Keyword ID'),
    'help' => t('The Biblio keyword ID'),
    'field' => array(
      'title' => t('All keywords'),
      'help' => t('Display all keywords associated with a node.'),
      'handler' => 'biblio_handler_field_biblio_keyword_kid',
    ),
    'argument' => array(
      'handler' => 'biblio_handler_argument_many_to_one',
      'name table' => 'biblio_keyword_data',
      'name field' => 'word',
      'empty name field' => t('No Keyword'),
      'numeric' => TRUE,
    ),
    'filter' => array(
      'title' => t('Keyword'),
      'handler' => 'biblio_handler_filter_biblio_keyword_kid',
      'numeric' => TRUE,
    ),
  );
  $viewsdata['biblio_keyword'] = $data;

  /***************** Describe the keyword_data table ***********/
  $data = array();
  $data['table']['group'] = t('Biblio');
  $data['table']['base'] = array(
    'field' => 'kid',
    'title' => t('Biblio Keywords'),
  );
  $data['table']['join'] = array(
    'biblio_keyword' => array(
      'left_field' => 'kid',
      'field' => 'kid',
    ),
    'node' => array(
      'left_table' => 'biblio_keyword',
      'left_field' => 'kid',
      'field' => 'kid',
    ),
    'biblio' => array(
      'left_table' => 'biblio_keyword',
      'left_field' => 'kid',
      'field' => 'kid',
    ),
  );
  $data['word'] = array(
    'field' => array(
      'handler' => 'biblio_handler_field_biblio_keyword_data_word',
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'title' => t('Keyword'),
    'skip base' => array(
      'node',
      'node_revision',
    ),
  );
  $data['kid'] = array(
    'field' => array(
      'handler' => 'views_handler_field_numeric',
    ),
    //   'filter'    => array('handler' => 'views_handler_filter'),
    //   'argument'  => array('handler' => 'views_handler_argument'),
    'title' => t('Keyword ID'),
    'skip base' => array(
      'node',
      'node_revision',
    ),
  );
  $viewsdata['biblio_keyword_data'] = $data;
  return $viewsdata;
}