You are here

function rate_views_widget in Rate 6.2

Same name and namespace in other branches
  1. 7 rate.module \rate_views_widget()
3 calls to rate_views_widget()
rate_views_widget_compact in ./rate.module
rate_views_widget_compact_disabled in ./rate.module
rate_views_widget_disabled in ./rate.module

File

./rate.module, line 807
Rate module

Code

function rate_views_widget($value, $field, $columns, $mode = RATE_FULL) {
  if ($field->view->base_table != 'node' && $field->view->base_table != 'comments') {
    return '';
  }

  // Find the VotingAPI tag and value_type for this field.
  foreach ($field->query->table_queue[$field->relationship]['join']->extra as $votingapi_setting) {
    if ($votingapi_setting['field'] == 'tag') {
      $tag = $votingapi_setting['value'];
    }
    elseif ($votingapi_setting['field'] == 'value_type') {
      $value_type = $votingapi_setting['value'];
    }
  }
  switch ($field->view->base_table) {
    case 'node':
      $content_type = 'node';
      $content_id = $columns->nid;
      if (isset($columns->node_type)) {
        $node_type = $columns->node_type;
      }
      else {
        $node_type = db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $columns->nid));
      }
      break;
    case 'comments':
      $content_type = 'comment';
      $content_id = $columns->cid;
      if (isset($columns->node_type)) {
        $node_type = $columns->node_type;
      }
      else {
        $node_type = db_result(db_query('SELECT n.type FROM {comments} c JOIN {node} n ON n.nid = c.nid WHERE c.cid = %d', $columns->cid));
      }
      break;
  }
  if ($field->query->table_queue[$field->relationship]['table'] == 'votingapi_cache') {
    $displayed_rating = RATE_AVERAGE;
  }
  else {
    $displayed_rating = RATE_USER;
  }

  // Loop through all the widgets and search for a suitable widget to display.
  $widgets = variable_get(RATE_VAR_WIDGETS, array());
  foreach ($widgets as $widget_id => $widget) {
    if ($tag == $widget->tag && $value_type == $widget->value_type && in_array($node_type, $widget->node_types)) {
      return rate_generate_widget($widget_id, $content_type, $content_id, $mode, TRUE, FALSE, $displayed_rating);
    }
  }

  // No suitable widget was found.
  return '';
}