You are here

function voting_rules_rules_data_info in Voting Rules 7

Implements hook_rules_data_type_info().

1 call to voting_rules_rules_data_info()
voting_rules_token_info in ./voting_rules.tokens.inc
Implements hook_token_info().

File

./voting_rules.rules.inc, line 11
Provides Rules integration for the Voting API module.

Code

function voting_rules_rules_data_info() {

  // Default properties common to vote and vote results.
  $defaults = array(
    'entity_type' => array(
      'label' => t('Entity type'),
      'description' => t('The type of the entity.'),
      // Unrelated with token module! Means machine name.
      'type' => 'token',
    ),
    'entity_id' => array(
      'label' => t('Entity ID'),
      'description' => t('The entity ID.'),
      'type' => 'integer',
    ),
    'entity' => array(
      'label' => t('Entity'),
      'description' => t('The entity being voted on.'),
      'type' => 'entity',
      'getter callback' => 'voting_rules_get_property',
    ),
    'value_type' => array(
      'label' => t('Value type'),
      'description' => t('The value type.'),
      'type' => 'token',
    ),
    'value' => array(
      'label' => t('Value'),
      'description' => t('The value of the vote.'),
      'type' => 'decimal',
    ),
    'timestamp' => array(
      'label' => t('Date'),
      'description' => t('The date of the vote.'),
      'type' => 'date',
    ),
    'tag' => array(
      'label' => t('Tag'),
      'description' => t('The tag.'),
      'type' => 'token',
    ),
  );

  // Data info for vote and vote results.
  $data_info = array(
    'vote' => array(
      'label' => t('Vote'),
      'description' => t('A vote.'),
      'group' => t('Voting API'),
      'wrap' => TRUE,
      'property info' => array(
        'uid' => array(
          'label' => t("User ID"),
          'description' => t('The user ID.'),
          'type' => 'integer',
          'description' => t("The unique ID of the user account."),
        ),
        'user' => array(
          'label' => t("User"),
          'description' => t('The user account.'),
          'type' => 'user',
          'getter callback' => 'voting_rules_get_property',
        ),
        'vote_source' => array(
          'label' => t('Vote source'),
          'description' => t('The source of the vote.'),
          'type' => 'text',
        ),
        'prepped' => array(
          'label' => t('Prepped'),
          'description' => t('Whether the vote was prepopulated or not.'),
          'type' => 'boolean',
        ),
        'vote_id' => array(
          'label' => t('Vote ID'),
          'description' => t('The vote ID.'),
          'type' => 'integer',
        ),
      ) + $defaults,
    ),
    'vote_results' => array(
      'label' => t('Vote Results'),
      'description' => t('The vote results.'),
      'group' => t('Voting API'),
      'property info' => array(),
      'wrap' => TRUE,
    ),
  );

  // Format vote result data info for each defined calculation function (count,
  // sum, average...).
  $votingapi_metadata = votingapi_metadata();
  foreach ($votingapi_metadata['functions'] as $function => $info) {
    $data_info['vote_results']['property info'][$function] = array(
      'label' => $info['name'],
      'description' => $info['description'],
      'type' => 'vote_result',
      'wrap' => TRUE,
      'property info' => array(
        'function' => array(
          'label' => t("Function"),
          'description' => t('Function used to calculate the vote - average, count, etc'),
          'type' => 'text',
        ),
      ) + $defaults,
    );
  }
  return $data_info;
}