Alright. I try my best to avoid modifying module code that is not mine (in fact, I've only done it twice, including this one). I'm working on a project where the users should be able to vote (fivestar) every 24 hours. I realized that this is already possible with anonymous users (though not for the same reasons; the vote rollover for anon is to allow multiple users from the same IP to place votes). So, borrowing this functionality, I added a few lines of code to make the same behavior happen for logged-in users.
Please see the code below. I don't expect this to be included in future updates to the module. I'm simply providing it for others' reference. I've tested every scenario I can think of and it all seems to be working well. Let me know if there is something severely wrong with this, other than the fact that I'm modifying the module instead of using hooks in my own module. Thanks!
CHANGES:
diff --git a/sites/all/modules/votingapi/votingapi.admin.inc b/sites/all/modules/votingapi/votingapi.admin.inc
index 35fc211..5c62bd8 100644
--- a/sites/all/modules/votingapi/votingapi.admin.inc
+++ b/sites/all/modules/votingapi/votingapi.admin.inc
@@ -20,6 +20,14 @@ function votingapi_settings_form($form_state) {
'#options' => $period
);
+ $form['votingapi_authenticated_window'] = array(
+ '#type' => 'select',
+ '#title' => t('Authenticated vote rollover'),
+ '#description' => t('The amount of time that must pass before additional votes from a single user are accepted. Setting this to \'never\' will disallow more than one vote from a user (on the same piece of content). Note that this will affect your ability to get a user\'s vote for a node. The default "get the user\'s current vote" functions will only return the vote that the user submitted within the period of time specified here. For example, if 1 day is the rollover time for authenticated users, using the default functions you will only get the vote the user left within the last 24 hours. If the user voted 3 days ago and has not voted since, asking for the user\'s vote will return nothing (by default).'),
+ '#default_value' => variable_get('votingapi_authenticated_window', 86400),
+ '#options' => $period
+ );
+
$form['votingapi_calculation_schedule'] = array(
'#type' => 'radios',
'#title' => t('Vote tallying'),
diff --git a/sites/all/modules/votingapi/votingapi.module b/sites/all/modules/votingapi/votingapi.module
index c28fa85..e131b16 100644
--- a/sites/all/modules/votingapi/votingapi.module
+++ b/sites/all/modules/votingapi/votingapi.module
@@ -311,6 +311,12 @@ function votingapi_select_votes($criteria = array(), $limit = 0) {
if (!empty($criteria['vote_source']) && $anon_window > 0) {
$criteria['timestamp'] = time() - $anon_window;
}
+
+ $auth_window = variable_get('votingapi_authenticated_window', 0);
+ if ($criteria['uid'] > 0 && $auth_window > 0) {
+ $criteria['timestamp'] = time() - $auth_window;
+ }
+
$votes = array();
$result = _votingapi_select('vote', $criteria, $limit);
while ($vote = db_fetch_array($result)) {
Comments
Comment #1
legolasboDrupal 6 is no longer supported. Closing old issues to clean up the issue queue.
Please reopen and update this issue if this is still an issue in the D7 or D8 version.