--- userpoints_votingapi.module.orig 2009-11-08 14:21:28.000000000 -0800 +++ userpoints_votingapi.module 2009-11-08 14:29:43.000000000 -0800 @@ -36,14 +36,28 @@ function userpoints_votingapi_form_alter '#maxlength' => 5, ); - $form[$group][userpoints_votingapi_daily_threshold] = array( + $form[$group][userpoints_votingapi_threshold] = array( '#type' => 'select', - '#title' => t('Daily threshold'), + '#title' => t('Threshold'), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)), - '#default_value' => variable_get(userpoints_votingapi_daily_threshold, 0), - '#description' => t('The maximum number of votes -- that will earn User Points -- in a 24-hour period.
Select 0 to ignore.'), + '#default_value' => variable_get(userpoints_votingapi_threshold, 0), + '#description' => t('The maximum number of votes -- that will earn User Points -- in the selected period.
Select 0 to ignore.'), ); + $form[$group][userpoints_votingapi_period] = array( + '#type' => 'select', + '#title' => t('Period'), + '#options' => array( + '3600' => t('Hourly'), + '86400' => t('Daily'), + '604800' => t('Weekly'), + '2592000' => t('Monthly (30 days)'), + '31536000' => t('Annually'), + ), + '#default_value' => variable_get(userpoints_votingapi_period, 86400), + '#description' => t('The time period during which the threshold applies.'), + ); + $form[$group]['userpoints_votingapi_tid'] = array( '#type' => 'select', '#title' => t('Category'), @@ -61,7 +75,7 @@ function userpoints_votingapi_form_alter */ function userpoints_votingapi_votingapi_insert($vote) { $vote = $vote[0]; - $threshold = variable_get(userpoints_votingapi_daily_threshold, 0); + $threshold = variable_get(userpoints_votingapi_threshold, 0); if (($threshold == '0') OR (userpoints_votingapi_within_threshold($vote['uid'], $threshold))) { userpoints_userpointsapi(array( 'uid' => $vote['uid'], @@ -84,7 +98,7 @@ function userpoints_votingapi_votingapi_ */ function userpoints_votingapi_votingapi_delete($vote) { $vote = $vote[0]; - $threshold = variable_get(userpoints_votingapi_daily_threshold, 0); + $threshold = variable_get(userpoints_votingapi_threshold, 0); if (($threshold == '0') OR (userpoints_votingapi_within_threshold($vote['uid'], $threshold))) { userpoints_userpointsapi(array( 'uid' => $vote['uid'], @@ -102,6 +116,6 @@ function userpoints_votingapi_votingapi_ } function userpoints_votingapi_within_threshold($uid, $threshold) { - $number = db_result(db_query("SELECT COUNT(*) FROM {votingapi_vote} WHERE uid = %d AND timestamp > %d", $uid, time() - 86400)); - return ($number <= $threshold ? TRUE : FALSE); -} \ No newline at end of file + $number = db_result(db_query("SELECT COUNT(*) FROM {userpoints_txn} WHERE operation = 'vote' AND uid = %d AND timestamp > %d", $uid, time() - variable_get(userpoints_votingapi_period, 86400))); + return ($number < $threshold ? TRUE : FALSE); +}