You are here

function recommender_views_data in Recommender API 7.6

Same name and namespace in other branches
  1. 6.3 views/recommender.views.inc \recommender_views_data()
  2. 6.2 recommender.views.inc \recommender_views_data()
  3. 7.3 recommender.views.inc \recommender_views_data()
  4. 7.4 recommender.views.inc \recommender_views_data()
  5. 7.5 recommender.views.inc \recommender_views_data()

Implements hook_views_data().

File

./recommender.views.inc, line 6

Code

function recommender_views_data() {
  $views_data = array();
  $recommender_data = recommender_fetch_data();
  $tables = array();

  // NOTE: if different recommender applications use the same tables in hook_recommender_data(),
  // then these will cause the later tables to override the first few.
  // We'll just rely on hook_recommender_data() define recommender applications correctly.
  foreach ($recommender_data as $name => $def) {
    $raw_structure = $def['data structure'];
    $default_structure = recommender_prepare_data_structure($raw_structure);
    $item_entity_info = entity_get_info(@$default_structure['item entity type']);
    $user_entity_info = entity_get_info(@$default_structure['user entity type']);

    // handle preference table.
    if (isset($raw_structure['preference']) && $default_structure['preference']['type'] == 'table' && !@$raw_structure['preference']['no views']) {
      $table_structure = $default_structure['preference'];
      $tables[$table_structure['name']][] = $def['title'];
      $views_data[$table_structure['name']] = _recommender_views_template_table($table_structure, 'preference', implode(', ', $tables[$table_structure['name']]), $user_entity_info, $item_entity_info);
    }

    // handle user similarity table
    if (isset($raw_structure['user similarity']) && $default_structure['user similarity']['type'] == 'table' && !@$raw_structure['user similarity']['no views']) {
      $table_structure = $default_structure['user similarity'];
      $tables[$table_structure['name']][] = $def['title'];
      $views_data[$table_structure['name']] = _recommender_views_template_table($table_structure, 'user similarity', implode(', ', $tables[$table_structure['name']]), $user_entity_info, $item_entity_info);
    }

    // handle item similarity table
    if (isset($raw_structure['item similarity']) && $default_structure['item similarity']['type'] == 'table' && !@$raw_structure['item similarity']['no views']) {
      $table_structure = $default_structure['item similarity'];
      $tables[$table_structure['name']][] = $def['title'];
      $views_data[$table_structure['name']] = _recommender_views_template_table($table_structure, 'item similarity', implode(', ', $tables[$table_structure['name']]), $user_entity_info, $item_entity_info);
    }

    // handler prediction table
    if (isset($raw_structure['prediction']) && $default_structure['prediction']['type'] == 'table' && !@$raw_structure['prediction']['no views']) {
      $table_structure = $default_structure['prediction'];
      $tables[$table_structure['name']][] = $def['title'];
      $views_data[$table_structure['name']] = _recommender_views_template_table($table_structure, 'prediction', implode(', ', $tables[$table_structure['name']]), $user_entity_info, $item_entity_info);
    }
  }

  // end of foreach
  return $views_data;
}