carring feature request #135511: Querying how many points gained during certain period forward for implementation in 6.x branch

make it so that you can query how many points have been gained by users during a defined period (this date and that date)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benjaminbradley’s picture

Assigned: benjaminbradley » Unassigned
Status: Active » Needs review
FileSize
1.84 KB

This has been implemented via the function:

/*
 * @param $uid User ID of the user to check points for, if omitted the currently logged-in user will be used
 * @param $tid taxonomy id of the category to limit to, if omitted will use the "default" category (which may be "all")
 * @param $period_begin The datetime of the beginning of the period to examine (UNIXTIME integer)
 * @param $period_end The datetime of the end of the period to examine (UNIXTIME integer)
 * @return number of points received in that user's account over the given time period
 */
function userpoints_get_points_gained_in_period($uid, $tid, $period_begin, $period_end) { ... }

NOTE: This function does NOT care if the points have since expired. We are only interested in the total number of points GAINED during the specified time period.

Other questions (which this function does NOT answer) might be:

  • what was the total point change (gain/loss) during this time period
  • of the points gained during this time period, how many are still valid (unexpired)

Status: Needs review » Needs work

The last submitted patch, p1388732.patch, failed testing.

arne.olafson’s picture

This would also be a good feature for the drupal 7 module.

FrancoisL’s picture

Status: Needs work » Needs review

#1: p1388732.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, p1388732.patch, failed testing.

FrancoisL’s picture

Any update on this project ? we are looking for a solution to display user point for a specified given time (6 month for example.

Thanks

chipway’s picture

Status: Needs work » Needs review

#1: p1388732.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, p1388732.patch, failed testing.

chipway’s picture

Status: Needs work » Needs review
FileSize
1.83 KB

Patch revu.

Status: Needs review » Needs work

The last submitted patch, userpoints-gained-during-period-p1388732-9.patch, failed testing.

chipway’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Needs work » Needs review
FileSize
1.88 KB

Rebuilt the patch against last dev version.

chipway’s picture

Status: Needs review » Reviewed & tested by the community

We tested this function on one of our web site, and it works.

scalp’s picture

Had to change a couple of things from the patch to get this to work in the Drupal 7 version. I'm actually just using this in a custom module instead of as a patch, but if you wanted to patch the userpoints module just change the function name:

<?php
function customs_get_userpoints_gained_in_period($uid, $tid, $period_begin, $period_end) {
  if (!$uid) {
    global $user;
    $uid = $user->uid;
  }
  if ($tid === 'all') {
    $tid = 'NULL';
  }
	
  $query_sql = 'SELECT SUM(points) FROM {userpoints_txn} WHERE uid = :uid';
  $query_params = array(':uid' => $uid);
  if ($tid != 'NULL') {
    $query_sql .= ' AND tid = :tid';
    $query_params[':tid'] = $tid;
  }
	
  // looking only at points gained
  $query_sql .= ' AND points > 0';
	
  // points created during the specified time period
  $query_sql .= ' AND time_stamp BETWEEN :min AND :max';
  $query_params[':min'] = $period_begin;
  $query_params[':max'] = $period_end;
		
  // NOTE: the (int) cast takes care of converting NULL to 0
  return (int)db_query($query_sql, $query_params)->fetchField();
}
?>
manuel.adan’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (outdated)

Closing this as outdated, 6.x version is no longer maintained.