function fivestar_static in Fivestar 6        
                          
                  
                        Same name and namespace in other branches
- 5 fivestar.module \fivestar_static()
- 6.2 fivestar.module \fivestar_static()
1 call to fivestar_static()
  - fivestar_nodeapi in ./fivestar.module
- Implementation of hook_nodeapi().
File
 
   - ./fivestar.module, line 1094
- A simple n-star voting widget, usable in other forms.
Code
function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = NULL) {
  global $user;
  $criteria = array(
    'content_type' => $content_type,
    'content_id' => $content_id,
    'value_type' => 'percent',
    'tag' => 'vote',
  );
  $votes = fivestar_get_votes($content_type, $content_id, $tag);
  if ($content_type == 'node') {
    
    if (!isset($node_type)) {
      $node = node_load($content_id);
      $node_type = $node->type;
    }
    $star_display = variable_get('fivestar_style_' . $node_type, 'average');
    $text_display = variable_get('fivestar_text_' . $node_type, 'dual');
    $title_display = variable_get('fivestar_title_' . $node_type, 1);
    $stars = variable_get('fivestar_stars_' . $node_type, 5);
    switch ($star_display) {
      case 'average':
      case 'dual':
        $star_value = $votes['average']['value'];
        $title = $title_display ? t('Average') : NULL;
        break;
      case 'user':
        $star_value = $votes['user']['value'];
        $title = $title_display ? t('Your rating') : NULL;
        break;
      case 'smart':
        $star_value = $votes['user']['value'] ? $votes['user']['value'] : $votes['average']['value'];
        $title = $title_display ? $votes['user']['value'] ? t('Your rating') : t('Average') : NULL;
        break;
    }
    
    $user_value = $votes['user']['value'];
    $average_value = $votes['average']['value'];
    $count_value = $votes['count']['value'];
    switch ($text_display) {
      case 'average':
        $user_value = NULL;
        break;
      case 'user':
        $average_value = NULL;
        break;
      case 'smart':
        if ($votes['user']['value']) {
          $average_value = NULL;
        }
        else {
          $user_value = NULL;
        }
        break;
    }
  }
  else {
    $stars = 5;
    $star_value = $votes['average']['value'];
    $user_value = $votes['user']['value'];
    $average_value = $votes['average']['value'];
    $count_value = $votes['count']['value'];
  }
  $star_display = theme('fivestar_static', $star_value, $stars);
  $text_display = $text_display == 'none' ? NULL : theme('fivestar_summary', $user_value, $average_value, $count_value, $stars, FALSE);
  return theme('fivestar_static_element', $star_display, $title, $text_display);
}