| 1 |
<?php |
<?php |
| 2 |
// $Id: fivestar.module,v 1.24 2009/07/01 02:43:58 quicksketch Exp $ |
// $Id: fivestar.module,v 1.25 2009/07/01 03:06:11 quicksketch Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 1215 |
} |
} |
| 1216 |
} |
} |
| 1217 |
|
|
| 1218 |
|
/** |
| 1219 |
|
* Implementation of hook_votingapi_views_formatters(). |
| 1220 |
|
*/ |
| 1221 |
function fivestar_votingapi_views_formatters($details = array()) { |
function fivestar_votingapi_views_formatters($details = array()) { |
| 1222 |
if ($details->field == 'value') { |
if ($details->field == 'value') { |
| 1223 |
return array( |
return array( |
| 1224 |
'fivestar_views_value_display_handler' => t('Fivestar Stars (display only)'), |
'fivestar_views_value_display_handler' => t('Fivestar Stars (display only)'), |
| 1225 |
|
'fivestar_views_value_text_handler' => t('Fivestar Stars (text star count)'), |
| 1226 |
'fivestar_views_widget_compact_handler' => t('Fivestar Stars (clickable, no text)'), |
'fivestar_views_widget_compact_handler' => t('Fivestar Stars (clickable, no text)'), |
| 1227 |
'fivestar_views_widget_normal_handler' => t('Fivestar Stars (clickable, with text)'), |
'fivestar_views_widget_normal_handler' => t('Fivestar Stars (clickable, with text)'), |
| 1228 |
); |
); |
| 1229 |
} |
} |
| 1230 |
} |
} |
| 1231 |
|
|
| 1232 |
|
/** |
| 1233 |
|
* VotingAPI Views formatter for displaying static stars. |
| 1234 |
|
*/ |
| 1235 |
function fivestar_views_value_display_handler($value, $field, $columns) { |
function fivestar_views_value_display_handler($value, $field, $columns) { |
| 1236 |
// Determine number of stars to display |
// Determine number of stars to display |
| 1237 |
// TODO need to get the tag here to support >1 tag |
// TODO need to get the tag here to support >1 tag |
| 1259 |
return theme('fivestar_static', $value, $stars, $tag); |
return theme('fivestar_static', $value, $stars, $tag); |
| 1260 |
} |
} |
| 1261 |
|
|
| 1262 |
|
/** |
| 1263 |
|
* VotingAPI Views formatter for displaying number of stars as text. |
| 1264 |
|
*/ |
| 1265 |
|
function fivestar_views_value_text_handler($value, $field, $columns) { |
| 1266 |
|
// Get the number of stars for this node type. |
| 1267 |
|
$node_type = isset($columns->node_type) ? $columns->node_type : db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $columns->nid)); |
| 1268 |
|
$stars = variable_get('fivestar_stars_'. $node_type, 5); |
| 1269 |
|
|
| 1270 |
|
// If displaying a user's vote, always display a whole value. |
| 1271 |
|
if ($field->table == 'votingapi_vote') { |
| 1272 |
|
return ceil(($value / 100) * $stars); |
| 1273 |
|
} |
| 1274 |
|
else { |
| 1275 |
|
return round(($value / 100) * $stars, 1); |
| 1276 |
|
} |
| 1277 |
|
} |
| 1278 |
|
|
| 1279 |
|
/** |
| 1280 |
|
* VotingAPI Views formatter for displaying rating widget without text. |
| 1281 |
|
*/ |
| 1282 |
function fivestar_views_widget_compact_handler($value, $field, $columns) { |
function fivestar_views_widget_compact_handler($value, $field, $columns) { |
| 1283 |
return fivestar_views_widget_handler($value, $field, $columns, FALSE); |
return fivestar_views_widget_handler($value, $field, $columns, FALSE); |
| 1284 |
} |
} |
| 1285 |
|
|
| 1286 |
|
/** |
| 1287 |
|
* VotingAPI Views formatter for displaying rating widget with text. |
| 1288 |
|
*/ |
| 1289 |
function fivestar_views_widget_normal_handler($value, $field, $columns) { |
function fivestar_views_widget_normal_handler($value, $field, $columns) { |
| 1290 |
return fivestar_views_widget_handler($value, $field, $columns, TRUE); |
return fivestar_views_widget_handler($value, $field, $columns, TRUE); |
| 1291 |
} |
} |
| 1292 |
|
|
| 1293 |
|
/** |
| 1294 |
|
* Generic VotingAPI Views formatter for displaying rating widget. |
| 1295 |
|
*/ |
| 1296 |
function fivestar_views_widget_handler($value, $field, $columns, $summary) { |
function fivestar_views_widget_handler($value, $field, $columns, $summary) { |
| 1297 |
|
|
| 1298 |
// If the user can't rate, use the display handler. |
// If the user can't rate, use the display handler. |