You are here

function fivestar_field in Fivestar 6

Same name and namespace in other branches
  1. 5 fivestar_field.inc \fivestar_field()
  2. 6.2 includes/fivestar.field.inc \fivestar_field()

Implementation of hook_field().

3 string references to 'fivestar_field'
fivestar_enable in ./fivestar.install
Implementation of hook_enable().
fivestar_init in ./fivestar.module
Implementation of hook_init().
fivestar_update_6105 in ./fivestar.install
Belated update for Drupal 6: Re-enable Fivestar CCK fields.

File

./fivestar_field.inc, line 108
Provides CCK integration for fivestar module

Code

function fivestar_field($op, &$node, $field, &$items, $teaser, $page) {
  $fieldname = $field['field_name'];
  switch ($op) {
    case 'insert':
    case 'update':
    case 'delete':
      foreach ($items as $delta => $item) {
        if ($node->status == 0 || $op == 'delete') {
          $rating = 0;
        }
        else {
          $rating = $items[$delta]['rating'];
        }
        $items[$delta]['target'] = fivestar_field_target($node, $field, $item);
        if (is_numeric($items[$delta]['target'])) {
          _fivestar_cast_vote('node', $items[$delta]['target'], $rating, $field['axis'], $node->uid, FALSE, TRUE);
          votingapi_recalculate_results('node', $items[$delta]['target']);
        }
      }
      break;
    case 'sanitize':
      $items[0]['stars'] = $field['stars'];
      break;
  }
}