function _fivestar_field_helper in Fivestar 7.2
3 calls to _fivestar_field_helper()
- fivestar_field_delete in includes/
fivestar.field.inc - Implements hook_field_delete().
- fivestar_field_insert in includes/
fivestar.field.inc - Implements hook_field_insert().
- fivestar_field_update in includes/
fivestar.field.inc - Implements hook_field_update().
File
- includes/
fivestar.field.inc, line 149 - Provides CCK integration for fivestar module.
Code
function _fivestar_field_helper($entity_type, $entity, $field, $instance, $langcode, &$items, $op = '') {
foreach ($items as $delta => $item) {
if (isset($entity->status) && !$entity->status || $op == 'delete') {
$rating = 0;
}
else {
$rating = isset($items[$delta]['rating']) ? $items[$delta]['rating'] : 0;
}
$target = _fivestar_field_target($entity, $field, $instance, $item, $langcode);
if (!empty($target)) {
if ($entity_type == 'comment' && $op == 'delete') {
$target['vote_source'] = $entity->hostname;
}
else {
$target['vote_source'] = NULL;
}
_fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE, $target['vote_source']);
votingapi_recalculate_results($target['entity_type'], $target['entity_id']);
}
// The original callback is only called for a single updated field, but the
// Field API then updates all fields of the entity. For an update, the Field
// API first deletes the equivalent row in the database and then adds a new
// row based on the information in $items here. If there are multiple
// Fivestar fields on an entity, the one being updated is handled OK
// ('rating' having already been set to the new value), but other Fivestar
// fields are set to NULL as 'rating' isn't set - not what an update would
// be expected to do. So set 'rating' for all of the Fivestar fields from
// the existing user data in $items. This preserves the user vote thru Field
// API's delete/re-insert process.
if (!isset($items[$delta]['rating'])) {
$items[$delta]['rating'] = $items[$delta]['user'];
}
}
}