| 1 |
|
<?php |
| 2 |
|
|
| 3 |
|
/** |
| 4 |
|
* Implementation of hook_views_data(). |
| 5 |
|
*/ |
| 6 |
|
function cre_views_data() { |
| 7 |
|
$data['cre_recommendations']['table']['group'] = t('Recommendations'); |
| 8 |
|
$data['cre_recommendations']['table']['join'] = array( |
| 9 |
|
'node' => array( |
| 10 |
|
'field' => 'nid', |
| 11 |
|
'left_field' => 'nid', |
| 12 |
|
'extra' => array( |
| 13 |
|
array( |
| 14 |
|
'field' => 'uid', |
| 15 |
|
'value' => '***CURRENT_USER***', |
| 16 |
|
'operator' => '=', |
| 17 |
|
), |
| 18 |
|
), |
| 19 |
|
'type' => 'INNER', |
| 20 |
|
), |
| 21 |
|
); |
| 22 |
|
|
| 23 |
|
$data['cre_recommendations']['score'] = array( |
| 24 |
|
'title' => t('Predicted rating'), |
| 25 |
|
'help' => t('The predicted rating for the current user on this node'), |
| 26 |
|
'field' => array( |
| 27 |
|
'handler' => 'views_handler_field_numeric', |
| 28 |
|
'click sortable' => TRUE, |
| 29 |
|
), |
| 30 |
|
'sort' => array( |
| 31 |
|
'handler' => 'views_handler_sort', |
| 32 |
|
), |
| 33 |
|
); |
| 34 |
|
|
| 35 |
|
$data['cre_node_recommendations']['table']['group'] = t('Recommendations'); |
| 36 |
|
$data['cre_node_recommendations']['table']['join'] = array( |
| 37 |
|
'node' => array( |
| 38 |
|
'table' => 'node', |
| 39 |
|
'left_table' => 'cre_recommendations', |
| 40 |
|
'left_field' => 'nid', |
| 41 |
|
'field' => 'nid', |
| 42 |
|
'type' => 'INNER', |
| 43 |
|
), |
| 44 |
|
); |
| 45 |
|
|
| 46 |
|
// Add in title and help for the fields to be added via hook_views_data_alter() |
| 47 |
|
$data['cre_node_recommendations']['title']['title'] = t('Recommended Node\'s title'); |
| 48 |
|
$data['cre_node_recommendations']['title']['help'] = t('Recommended nodes title'); |
| 49 |
|
|
| 50 |
|
$data['cre_node_recommendations']['nid']['title'] = t('Recommended Node\'s nid'); |
| 51 |
|
$data['cre_node_recommendations']['nid']['help'] = t('The node id for the recommendated node'); |
| 52 |
|
|
| 53 |
|
return $data; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
/** |
| 57 |
|
* Implementation of hook_views_data_alter(). |
| 58 |
|
*/ |
| 59 |
|
function cre_views_data_alter(&$data) { |
| 60 |
|
// Make use of views core |
| 61 |
|
$data['cre_node_recommendations']['title']['field'] = $data['node']['title']['field']; |
| 62 |
|
$data['cre_node_recommendations']['nid']['field'] = $data['node']['nid']['field']; |
| 63 |
|
|
| 64 |
|
// remove the grouping so that it will use the recommendations group |
| 65 |
|
unset($data['cre_node_recommendations']['title']['field']['group']); |
| 66 |
|
unset($data['cre_node_recommendations']['nid']['field']['group']); |
| 67 |
|
} |