Common subdirectories: userpoints/po and userpoints.new/po Common subdirectories: userpoints/tests and userpoints.new/tests Common subdirectories: userpoints/translations and userpoints.new/translations diff -up userpoints/userpoints.install userpoints.new/userpoints.install --- userpoints/userpoints.install 2009-06-25 16:49:35.000000000 -0700 +++ userpoints.new/userpoints.install 2009-06-25 16:50:23.000000000 -0700 @@ -243,3 +243,11 @@ function userpoints_update_6010() { $ret[] = update_sql("UPDATE {permission} SET perm = REPLACE(perm, 'admin userpoints', 'administer userpoints') WHERE perm LIKE '%admin userpoints%'"); return $ret; } + +function userpoints_update_6011() { + $ret = array(); + db_change_field($ret, 'userpoints_txn', 'points', 'points', array('type' => 'float', 'not null' => true, 'default' => 0)); + db_change_field($ret, 'userpoints', 'points', 'points', array('type' => 'float', 'not null' => true, 'default' => 0)); + db_change_field($ret, 'userpoints', 'max_points', 'max_points', array('type' => 'float', 'not null' => true, 'default' => 0)); + return $ret; +} Only in userpoints.new/: userpoints.install.orig diff -up userpoints/userpoints.module userpoints.new/userpoints.module --- userpoints/userpoints.module 2009-01-09 02:02:01.000000000 -0800 +++ userpoints.new/userpoints.module 2009-06-25 16:50:23.000000000 -0700 @@ -33,6 +33,8 @@ define('USERPOINTS_REPORT_USERCOUNT', 'u define('USERPOINTS_REPORT_LIMIT', 'userpoints_report_limit'); define('USERPOINTS_REPORT_DISPLAYZERO', 'userpoints_report_displayzero'); +define('USERPOINTS_PRECISION_NUM', 'userpoints_precision_num'); + define('USERPOINTS_CATEGORY_NAME', 'Userpoints'); define('USERPOINTS_CATEGORY_DEFAULT_VID', 'userpoints_category_default_vid'); define('USERPOINTS_CATEGORY_DEFAULT_TID', 'userpoints_category_default_tid'); @@ -401,6 +403,23 @@ function userpoints_admin_settings() { ); } + $group = "precision"; + $form[$group] = array( + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#title' => t('Precision'), + '#description' => t(''), + ); + + $form[$group][USERPOINTS_PRECISION_NUM] = array( + '#type' => 'textfield', + '#title' => t('Number of decimals to use when displaying and calculating !points', userpoints_translation()), + '#default_value' => variable_get(USERPOINTS_PRECISION_NUM, 2), + '#size' => 2, + '#maxlength' => 2, + ); + $form['setting'] = module_invoke_all('userpoints', 'setting'); return system_settings_form($form); } @@ -419,9 +438,9 @@ function userpoints_get_current_points($ $tid = userpoints_get_default_tid(); } elseif ($tid == 'all') { - return (int)db_result(db_query('SELECT SUM(points) FROM {userpoints} WHERE uid = %d', $uid)); + return (float)db_result(db_query('SELECT SUM(points) FROM {userpoints} WHERE uid = %d', $uid)); } - return (int)db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid)); + return (float)db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid)); } /** @@ -438,9 +457,9 @@ function userpoints_get_max_points($uid $tid = userpoints_get_default_tid(); } elseif ($tid == 'all') { - return (int)db_result(db_query('SELECT SUM(max_points) FROM {userpoints} WHERE uid = %d', $uid)); + return (float)db_result(db_query('SELECT SUM(max_points) FROM {userpoints} WHERE uid = %d', $uid)); } - return (int)db_result(db_query('SELECT max_points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid)); + return (float)db_result(db_query('SELECT max_points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid)); } /** @@ -688,7 +707,7 @@ function _userpoints_transaction(&$param $ret = db_query("INSERT INTO {userpoints_txn} (uid, points, time_stamp, status, operation, description, reference, expirydate, expired, parent_txn_id, tid, entity_id, entity_type) - VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s')", + VALUES (%d, %f, %d, %d, '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s')", $params['uid'], $params['points'], time(), @@ -723,19 +742,19 @@ function _userpoints_update_cache(&$para } // Calculate the current points based upon the tid - $current_points = (int)$params['points'] + userpoints_get_current_points($params['uid'], $params['tid']); + $current_points = (float)$params['points'] + userpoints_get_current_points($params['uid'], $params['tid']); //Grab the user's maximum points to preserve it $max_points = db_result(db_query('SELECT max_points FROM {userpoints} WHERE uid = %d AND tid = %d', $params['uid'], $params['tid'])); if ($params['points'] > 0) { //points are greater than zero, update their max_points - $max_points = (int)$params['points'] + (int)$max_points; + $max_points = (float)$params['points'] + (float)$max_points; } // insert or update the userpoints caching table with the user's current points if (_userpoints_user_exists($params['uid'], $params['tid'])) { db_query("UPDATE {userpoints} - SET points = %d, max_points = %d, last_update = %d + SET points = %f, max_points = %f, last_update = %d WHERE uid = %d AND tid = %d", $current_points, $max_points, @@ -747,7 +766,7 @@ function _userpoints_update_cache(&$para else { $result = db_query("INSERT INTO {userpoints} (uid, points, max_points, last_update, tid) - VALUES (%d, %d, %d, %d, %d )", + VALUES (%d, %f, %f, %d, %d )", $params['uid'], $current_points, $max_points, @@ -1453,7 +1472,7 @@ function userpoints_block($op = 'list', if ($delta == -1) { $title = t('@user\'s !points', array_merge(array('@user' => $user->name), userpoints_translation()));; if ($user->uid) { - $points = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)); + $points = number_format((float)db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d', $user->uid)), variable_get(USERPOINTS_PRECISION_NUM, 2)); $show_points = format_plural($points, '!point', '!points', userpoints_translation()); $content = t('You have %p %c', array('%p' => $points, '%c' => $show_points)); } @@ -1660,11 +1641,9 @@ function userpoints_list_my_userpoints() $args['unapproved_total'] = db_result($result, 0, 0); } else { - $args['unapproved_total'] = 0; + $args['unapproved_total'] =0; } - $args['overall_total'] = number_format($args['approved_total'] + $args['unapproved_total'], variable_get(USERPOINTS_PRECISION_NUM, 2)); - $args['approved_total'] = number_format($args['approved_total'], variable_get(USERPOINTS_PRECISION_NUM, 2)); - $args['unapproved_total'] = number_format($args['unapproved_total'], variable_get(USERPOINTS_PRECISION_NUM, 2)); + $args['overall_total'] = ($args['approved_total'] + $args['unapproved_total']); $header = array( array('data' => t('!Points', userpoints_translation()), 'field' => 'points'), @@ -1726,7 +1705,7 @@ function userpoints_list_my_userpoints() } } $rows[] = array( - array('data' => $row->points, 'align' => 'center'), + array('data' => number_format($row->points, variable_get(USERPOINTS_PRECISION_NUM, 2)), 'align' => 'center'), array('data' => $status, 'align' => 'center'), array('data' => format_date($row->time_stamp, 'small'), 'align' => 'center'), array('data' => $operation), Only in userpoints.new/: userpoints.module.orig