Skip to content

Instantly share code, notes, and snippets.

@fangel
Created March 19, 2012 12:31
Show Gist options
  • Save fangel/2110262 to your computer and use it in GitHub Desktop.
Save fangel/2110262 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_views_plugins().
*/
function whitepaper_views_plugins() {
return array(
'module' => 'whitepaper',
'access' => array(
'whitepaper' => array(
'title' => t('Whitepaper Customer Access'),
'help' => t('Only allow access to valid whitepapers for customers.'),
'handler' => 'whitepaper_plugin_access_whitepaper',
'help topic' => 'access-whitepaper',
'uses options' => TRUE,
),
),
);
}
/**
* Implements hook_views_data()
*/
function whitepaper_views_data() {
// Basic table information.
// ----------------------------------------------------------------
// whitepaper_leads table
$data['whitepaper_leads']['table']['group'] = t('Whitepaper Leads');
$data['whitepaper_leads']['table']['base'] = array(
'field' => 'lid',
'title' => t('Whitepaper Leads'),
'help' => t("Whitepaper Leads are people who've agreed to download a whitepaper in exchange for their information being given to the author."),
);
$data['whitepaper_leads']['table']['join'] = array(
// ...to the node table
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
// ...to the user table
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
// uid
$data['whitepaper_leads']['uid'] = array(
'title' => t('Uid'),
'help' => t('The user ID'),
'field' => array(
'handler' => 'views_handler_field_user',
'click sortable' => TRUE,
),
'relationship' => array(
'title' => t('User'),
'help' => t('The user that this user is for.'),
'base' => 'users',
'base field' => 'uid',
'handler' => 'views_handler_relationship',
'label' => t('User'),
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'title' => t('Name'),
'handler' => 'views_handler_filter_user_name',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// nid
$data['whitepaper_leads']['nid'] = array(
'title' => t('Nid'),
'help' => t('The node ID.'),
'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),
'relationship' => array(
'title' => t('Content'),
'help' => t('The whitepaper that generated this lead.'),
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship',
'label' => t('Content'),
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// answers
$data['whitepaper_leads']['answers'] = array(
'title' => t('Answers'),
'help' => t('The list of answers the user gave when downloading the whitepaper.'),
'field' => array(
'handler' => 'whitepaper_handler_field_answers',
'click sortable' => TRUE,
),
);
// created
$data['whitepaper_leads']['date'] = array(
'title' => t('Date'),
'help' => t('The time when this lead was generated.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/**
* Implements hook_views_data()
**/
function whitepaper_views_data_alter(&$data) {
$data['node']['whitepaper_leads'] = array(
'title' => t('Whitepaper Leads'),
'help' => t('Number of leads this whitepaper has collected.'),
'field' => array(
'handler' => 'whitepaper_handler_field_leads',
// 'click sortable' => TRUE,
),
// 'sort' => array(
// 'handler' => 'similarterms_handler_sort_similar',
// ),
);
}
function whitepaper_views_pre_execute(&$view) {
if ($view->name == 'whitepaper_lead_list') {
if (!empty($view->args[0])) {
$node = node_load($view->args[0]);
$desired_leads = reset(field_get_items('node', $node, 'whitepaper_desired_leads'));
if (!empty($desired_leads['value'])) {
$view->query->limit = $desired_leads['value'];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment