function recommender_views_query_alter in Recommender API 6.2
Implementation of hook_views_query_alter(). We'd like to make use of the Node view row style. But currently the base table field is being passed through to be used with node_load(). in the case of the recommender tables we need store the node id as cheese_id
File
- ./
recommender.views.inc, line 293 - recommender.views.inc Views support for recommender tables Initially contributed by JoeMcGuire at Drupal.org. Thanks!
Code
function recommender_views_query_alter(&$view, &$query) {
// We only need to tweak queries which intend to display as node views
if ($view->style_plugin->row_plugin instanceof views_plugin_row_node_view) {
// makes changes for the recommender module tables and for everything else do nothing
switch ($view->base_table) {
case 'recommender_prediction':
// add an additional field to the SELECT
$query->fields['cheese_id'] = array(
'table' => 'recommender_prediction',
'field' => 'cheese_id',
'alias' => 'cheese_id',
);
// set the row plugin field_alias to our node id field. This is used by
// template_preprocess_views_view_row_node().
$view->style_plugin->row_plugin->field_alias = 'cheese_id';
break;
case 'recommender_similarity':
// Same approach as above see comments
$query->fields['mouse2_id'] = array(
'table' => 'recommender_similarity',
'field' => 'mouse2_id',
'alias' => 'mouse2_id',
);
$view->style_plugin->row_plugin->field_alias = 'mouse2_id';
break;
default:
// do nothing
break;
}
}
}