You are here

function votingapi_metadata in Voting API 7.3

Same name and namespace in other branches
  1. 6.2 votingapi.module \votingapi_metadata()
  2. 7.2 votingapi.module \votingapi_metadata()

Returns metadata about tags, value_types, and results defined by vote modules.

If your module needs to determine what existing tags, value_types, etc., are being supplied by other modules, call this function. Querying the votingapi tables for this information directly is discouraged, as values may not appear consistently. (For example, 'average' does not appear in the cache table until votes have actually been cast in the cache table.)

Three major bins of data are stored: tags, value_types, and functions. Each entry in these bins is keyed by the value stored in the actual VotingAPI tables, and contains an array with (minimally) 'name' and 'description' keys. Modules can add extra keys to their entries if desired.

This metadata can be modified or expanded using hook_votingapi_metadata_alter().

Return value

An array of metadata defined by VotingAPI and altered by vote modules.

See also

hook_votingapi_metadata_alter()

1 call to votingapi_metadata()
votingapi_views_handler_relationship::options_form in views/votingapi_views_handler_relationship.inc
Default options form that provides the label widget that all fields should have.

File

./votingapi.module, line 560
A generalized voting API for Drupal.

Code

function votingapi_metadata($reset = FALSE) {
  static $data;
  if ($reset || !isset($data)) {
    $data = array(
      'tags' => array(
        'vote' => array(
          'name' => t('Normal vote'),
          'description' => t('The default tag for votes on content. If multiple votes with different tags are being cast on a piece of content, consider casting a "summary" vote with this tag as well.'),
        ),
      ),
      'value_types' => array(
        'percent' => array(
          'name' => t('Percent'),
          'description' => t('Votes in a specific range. Values are stored in a 1-100 range, but can be represented as any scale when shown to the user.'),
        ),
        'points' => array(
          'name' => t('Points'),
          'description' => t('Votes that contribute points/tokens/karma towards a total. May be positive or negative.'),
        ),
      ),
      'functions' => array(
        'count' => array(
          'name' => t('Number of votes'),
          'description' => t('The number of votes cast for a given piece of content.'),
        ),
        'average' => array(
          'name' => t('Average vote'),
          'description' => t('The average vote cast on a given piece of content.'),
        ),
        'sum' => array(
          'name' => t('Total score'),
          'description' => t('The sum of all votes for a given piece of content.'),
          'value_types' => array(
            'points',
          ),
        ),
      ),
    );
    drupal_alter('votingapi_metadata', $data);
  }
  return $data;
}