<?php
/**
 * @file
 * Main module to add fivestar as a webform component
 *
 */


/**
 * Implements hook_webform_component_info().
 */
function webform_fivestar_webform_component_info() {
  return array(
    'fivestar' => array(
      'label' => t('Fivestar'),
      'description' => t('Add fivestar functionality.'),
      'features' => array(
      // Add content to CSV downloads. Defaults to TRUE.
      'csv' => TRUE,
      // Show this field in e-mailed submissions. Defaults to TRUE.
      'email' => TRUE,
      // Allow this field to be used as an e-mail FROM or TO address. Defaults
      // to FALSE.
      'email_address' => FALSE,
      // Allow this field to be used as an e-mail SUBJECT or FROM name. Defaults
      // to FALSE.
      'email_name' => FALSE,
      // This field may be toggled as required or not. Defaults to TRUE.
      'required' => TRUE,
      // If this field can be used as a conditional SOURCE. All fields may
      // always be displayed conditionally, regardless of this setting.
      // Defaults to TRUE.
      'conditonal' => TRUE,
      ),
      'file' => 'fivestar.inc',
    ),
  );
}

/**
 * Implements hook_theme().
 */
function webform_fivestar_theme() {
  return array(
    'webform_fivestar_formatter_percentage' => array(
      'variables' => array('rating' => NULL),
    ),
  );
}


/**
 * Theme function to display static percentages.
 */
function theme_webform_fivestar_formatter_percentage($variables) {

  $rating = $variables['rating'];

  if (empty($rating)) {
    $rating = 0;
  }

  return round($rating, 1) . '%';
}
