View source
<?php
function recommender_views_data() {
$data = array(
'recommender_app' => array(
'table' => array(
'group' => t('Recommender Application'),
'join' => array(
'recommender_similarity' => array(
'left_field' => 'app_id',
'field' => 'id',
'type' => 'inner',
),
'recommender_prediction' => array(
'left_field' => 'app_id',
'field' => 'id',
'type' => 'inner',
),
),
),
'name' => array(
'title' => t('Application name'),
'help' => t('Recommender application used to provide similarity/prediction data. Filtering is a little slower than using application id.'),
'filter' => array(
'handler' => 'views_handler_filter_recommender_app_name',
),
),
),
'recommender_similarity' => array(
'table' => array(
'group' => t('Recommender Similarity'),
'help' => t('Recommender similarity data between node-node and user-user'),
'base' => array(
'field' => 'id',
'title' => t('Recommender Similarity'),
'help' => t('Recommender similarity data between node-node and user-user'),
),
),
'app_id' => array(
'title' => t('Application ID'),
'help' => t('Recommender application used to provide similarity data'),
'filter' => array(
'handler' => 'views_handler_filter_recommender_app_id',
),
),
'source_eid' => array(
'title' => t('Entity ID (Source)'),
'help' => t('The entity ID (node, user, etc) upon which this similarity is for.'),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
),
'target_eid' => array(
'title' => t('Entity ID (Target)'),
'help' => t('The entity ID (node, user, etc) similar to the source entity.'),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship_recommender_entity_type',
'label' => t('Recommended entity (by similarity)'),
),
),
'score' => array(
'title' => t('Similarity score'),
'help' => t('Score of how similar the source entity and the target entity are.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
'updated' => array(
'title' => t('Updated'),
'help' => t('Last updated timestamp of this similarity score.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
),
),
'recommender_prediction' => array(
'table' => array(
'group' => t('Recommender Prediction'),
'help' => t('Recommender prediction data between user-node.'),
'base' => array(
'field' => 'id',
'title' => t('Recommender Prediction'),
'help' => t('Recommender prediction data for node-user pairs.'),
),
),
'app_id' => array(
'title' => t('Application ID'),
'help' => t('Recommender application used to provide prediction data'),
'filter' => array(
'handler' => 'views_handler_filter_recommender_app_id',
),
),
'source_eid' => array(
'title' => t('Entity ID (Source)'),
'help' => t('The entity ID (node, user, etc) upon which this prediction is for.'),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
),
'target_eid' => array(
'title' => t('Entity ID (Target)'),
'help' => t('The entity ID (node, user, etc) recommended to the source entity.'),
'relationship' => array(
'base' => 'node',
'base field' => 'nid',
'handler' => 'views_handler_relationship_recommender_entity_type',
'label' => t('Recommended entity (by prediction)'),
),
),
'score' => array(
'title' => t('Prediction score'),
'help' => t('Score of how confident to recommend the target entity to the source entity'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
'updated' => array(
'title' => t('Updated'),
'help' => t('Last updated timestamp of this prediction score.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
),
),
);
return $data;
}
class views_handler_filter_recommender_app_id extends views_handler_filter_in_operator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$apps = db_query('SELECT id, title FROM {recommender_app}');
foreach ($apps as $app) {
$this->value_options[$app->id] = check_plain($app->title);
}
}
}
class views_handler_filter_recommender_app_name extends views_handler_filter_in_operator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$apps = db_query('SELECT name, title FROM {recommender_app}');
foreach ($apps as $app) {
$this->value_options[$app->name] = check_plain($app->title);
}
}
}
class views_handler_relationship_recommender_entity_type extends views_handler_relationship {
function init(&$view, &$options) {
parent::init($view, $options);
$base_type = isset($options['base_entity_type']) ? $options['base_entity_type'] : 'node';
$base_table = views_fetch_data($base_type);
$this->definition['base'] = $base_type;
$this->definition['base field'] = $base_table['table']['base']['field'];
}
function option_definition() {
$options = parent::option_definition();
$options['base_entity_type'] = array(
'default' => 'node',
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$base_tables = views_fetch_base_tables();
$entity_options = array();
foreach ($base_tables as $name => $table) {
$entity_options[$name] = $table['title'];
}
$form['base_entity_type'] = array(
'#type' => 'select',
'#title' => t('Entity type (base table)'),
'#default_value' => isset($this->options['base_entity_type']) ? $this->options['base_entity_type'] : 'node',
'#options' => $entity_options,
'#description' => t('Select the entity type (node, user, etc) of the recommended items.'),
);
}
}