function entity_metadata_poll_node_get_properties in Entity API 7
Callback for getting poll properties.
See also
entity_metadata_poll_entity_info_alter()
1 string reference to 'entity_metadata_poll_node_get_properties'
- entity_metadata_poll_entity_property_info_alter in modules/
poll.info.inc - Implements hook_entity_property_info_alter() on top of poll module.
File
- modules/
callbacks.inc, line 168 - Provides various callbacks for the whole core module integration.
Code
function entity_metadata_poll_node_get_properties($node, array $options, $name) {
$total_votes = $highest_votes = 0;
foreach ($node->choice as $choice) {
if ($choice['chvotes'] > $highest_votes) {
$winner = $choice;
$highest_votes = $choice['chvotes'];
}
$total_votes = $total_votes + $choice['chvotes'];
}
if ($name == 'poll_duration') {
return $node->runtime;
}
elseif ($name == 'poll_votes') {
return $total_votes;
}
elseif (!isset($winner)) {
// There is no poll winner yet.
return NULL;
}
switch ($name) {
case 'poll_winner_votes':
return $winner['chvotes'];
case 'poll_winner':
return $winner['chtext'];
case 'poll_winner_percent':
return $winner['chvotes'] / $total_votes * 100;
}
}