Projet

Général

Profil

Paste
Télécharger (3,23 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / votingapi / votingapi.admin.inc @ 384fc62a

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Configuration forms and helper functions for VotingAPI module.
6
 */
7
8
/**
9
 * Administrative settings for VotingAPI.
10
 */
11
function votingapi_settings_form($form_state) {
12
  $period = array(0 => t('Immediately')) + drupal_map_assoc(array(300, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 345600, 604800), 'format_interval') + array(-1 => t('Never'));
13
14
  $form['votingapi_anonymous_window'] = array(
15
    '#type' => 'select',
16
    '#title' => t('Anonymous vote rollover'),
17
    '#description' => t('The amount of time that must pass before two anonymous votes from the same computer are considered unique. Setting this to \'never\' will eliminate most double-voting, but will make it impossible for multiple anonymous on the same computer (like internet cafe customers) from casting votes.'),
18
    '#default_value' => variable_get('votingapi_anonymous_window', 86400),
19
    '#options' => $period
20
  );
21
22
  $form['votingapi_user_window'] = array(
23
    '#type' => 'select',
24
    '#title' => t('Registered user vote rollover'),
25
    '#description' => t('The amount of time that must pass before two registered user votes from the same user ID are considered unique. Setting this to \'never\' will eliminate most double-voting for registered users.'),
26
    '#default_value' => variable_get('votingapi_user_window', -1),
27
    '#options' => $period
28
  );
29
30
  $form['votingapi_calculation_schedule'] = array(
31
    '#type' => 'radios',
32
    '#title' => t('Vote tallying'),
33
    '#description' => t('On high-traffic sites, administrators can use this setting to postpone the calculation of vote results.'),
34
    '#default_value' => variable_get('votingapi_calculation_schedule', 'immediate'),
35
    '#options' => array(
36
      'immediate' => t('Tally results whenever a vote is cast'),
37
      'cron' => t('Tally results at cron-time'),
38
      'manual' => t('Do not tally results automatically: I am using a module that manages its own vote results.')
39
    ),
40
  );
41
42
  return system_settings_form($form);
43
}
44
45
/**
46
 * Developer tool to generate dummy votes.
47
 */
48
function votingapi_generate_votes_form() {
49
  $form['node_types'] = array(
50
    '#type' => 'checkboxes',
51
    '#title' => t('Which node types should receive votes?'),
52
    '#options' => node_type_get_names(),
53
    '#default_value' => array_keys(node_type_get_names()),
54
  );
55
56
  $form['vote_type'] = array(
57
    '#type' => 'select',
58
    '#title' => t('What type of votes should be generated?'),
59
    '#options' => array(
60
      'percent' => t('Percentage (Fivestar style)'),
61
      'points' => t('Point-based (Digg style)'),
62
    ),
63
    '#default_value' => 'percent',
64
  );
65
66
  $form['kill_votes'] = array(
67
    '#type' => 'checkbox',
68
    '#title' => t('Delete existing votes before generating new ones.'),
69
    '#default_value' => FALSE,
70
  );
71
  $form['submit'] = array(
72
    '#type' => 'submit',
73
    '#value' => t('Do it!'),
74
  );
75
  return $form;
76
}
77
78
/**
79
 * Submit handler for votingapi_generate_votes_form.
80
 */
81
function votingapi_generate_votes_form_submit($form, &$form_state) {
82
  $options = array(
83
    'types' => $form_state['values']['node_types'],
84
    'kill' => $form_state['values']['kill_votes'],
85
  );
86 7942932f Assos Assos
  require_once(drupal_get_path('module', 'votingapi') . '/votingapi.devel.inc');
87 85ad3d82 Assos Assos
  votingapi_generate_votes('node', $form_state['values']['vote_type'], $options);
88
}