diff -upN ../recommender_old/recommender.module ./recommender.module --- ../recommender_old/recommender.module 2009-07-04 03:32:05.000000000 +0100 +++ ./recommender.module 2010-04-22 14:47:32.000000000 +0100 @@ -194,6 +194,15 @@ function recommender_menu() { return $items; } +/** + * Implementation of hook_views_api(). + */ +function recommender_views_api() { + return array( + 'api' => 2, + ); +} + function recommender_settings_form() { $form = array(); diff -upN ../recommender_old/recommender.views.inc ./recommender.views.inc --- ../recommender_old/recommender.views.inc 1970-01-01 01:00:00.000000000 +0100 +++ ./recommender.views.inc 2010-04-22 14:47:32.000000000 +0100 @@ -0,0 +1,322 @@ + array( + 'path' => drupal_get_path('module', 'recommender'), + ), + 'handlers' => array(), + ); +} + +function recommender_views_data() { + $views_data = array(); + $views_data['recommender_similarity'] = array( + 'table' => array( + 'group' => t('Recommender'), + 'base' => array( + 'field' => 'pair_id', + 'title' => t('Recommender similarity'), + 'help' => t('Content recommendation.'), + 'weight' => 10, + ), + ), + 'pair_id' => array( + 'title' => t( 'ID' ), + 'help' => t( 'Unique ID for each recommendation pair.' ), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'app_id' => array( + 'title' => t('Application ID'), + 'help' => t('Application used provide data'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'mouse1_id' => array( + 'title' => t('Node ID'), + 'help' => t('Node ID'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Node'), + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'mouse2_id' => array( + 'title' => t('Similar Node ID'), + 'help' => t('Node ID for recommended content'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Node'), + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'similarity' => array( + 'title' => t('Similarity'), + 'help' => t('Score of how similar Node ID and Similar Node ID are.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'created' => array( + 'title' => t('Created'), + 'help' => t('Date when the similarity was calculated.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_date', + ), + ), + ); + + $views_data['recommender_prediction'] = array( + 'table' => array( + 'group' => t('Recommender'), + 'base' => array( + 'field' => 'link_id', + 'title' => t('Recommender predictions'), + 'help' => t('Predictions of content users may like from similar users.'), + 'weight' => 11, + ), + ), + 'link_id' => array( + 'title' => t( 'ID' ), + 'help' => t( 'Unique ID for each prediction.' ), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'app_id' => array( + 'title' => t('Application ID'), + 'help' => t('Application used provide data'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'mouse_id' => array( + 'title' => t('User ID'), + 'help' => t('User ID'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'users', + 'base field' => 'uid', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_user_uid', + 'name field' => 'name', // display this field in the summary + ), + ), + 'cheese_id' => array( + 'title' => t('Predicted Node ID'), + 'help' => t('Node ID for predicted content'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Node'), + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'prediction' => array( + 'title' => t('Predicition confidence'), + 'help' => t('Score of how confidence the user will like the Node ID.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ), + 'created' => array( + 'title' => t('Created'), + 'help' => t('Date when the prediction was calculated.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_date', + ), + ), + ); + + return $views_data; +} + +/** + * Implementation of hook_views_plugins_alter(). + * Allow recommender tables to use the node view row style + * @see recommender_views_query_alter() + */ +function recommender_views_plugins_alter(&$plugins) { + // Add recommender modules to the base of the node row plugin. + $plugins['row']['node']['base'][] = 'recommender_similarity'; + $plugins['row']['node']['base'][] = 'recommender_prediction'; +} + + +/** + * 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 + */ +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; + } + } +} \ No newline at end of file