Index: userpoints_views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints_views.module,v
retrieving revision 1.1.4.1
diff -u -F^f -r1.1.4.1 userpoints_views.module
--- userpoints_views.module	31 Jan 2008 03:53:12 -0000	1.1.4.1
+++ userpoints_views.module	12 Mar 2008 16:21:40 -0000
@@ -224,6 +224,15 @@ function userpoints_views_views_tables()
         'sortable' => TRUE,
         'help' => t('Displays the operation which caused the transaction.'),
       ),
+      'points_month_sum' => array(
+        'name' => t('Userpoints: Points This Month'), 
+        'help' => t('Displays the accumulated points for a given user this month'),
+        'notafield' => TRUE,
+        'sortable' => FALSE,
+        'option' => 'string',
+        'handler' => 'userpoints_views_views_points_handler_thismonth',
+        'query_handler' => 'userpoints_views_views_points_query_handler_thismonth'
+      ),
     ),
     'sorts' => array(
       'points' => array(
@@ -238,6 +247,37 @@ function userpoints_views_views_tables()
       ),
     ),
     'filters' => array(
+      'month' => array(
+        'field' => 'time_stamp',
+        'name' => t('Userpoints: Month'),
+        'operator' => 'views_handler_operator_gtlt',
+        'list' => array(
+          '',
+          'January',
+          'February',
+          'March',
+          'April',
+          'May',
+          'June',
+          'July',
+          'August',
+          'September',
+          'October',
+          'November',
+          'December'
+        ),
+        'list-type' => 'select',
+        'handler' => 'userpoints_views_handler_filter_month',
+        'type' => 'MONTHNAME',
+        'help' => t('Filter by month. Use the option to select the date field to filter on.'),
+      ),
+      'userpoints_thismonth' => array(
+        'field' => 'time_stamp',
+        'name' => t('Userpoints: This Month'),
+        'operator' => 'views_handler_operator_gtlt',
+        'handler' => 'userpoints_views_handler_filter_month',
+        'help' => t('Display user points acquired this month')
+      )
     ),
   );
   
@@ -451,3 +491,70 @@ function views_handler_field_userpoints_
   }
   return $stati[$value];
 }
+
+/**
+ * userpoints_views_views_points_handler_thismonth
+ *
+ * Handler function to handle the calculation of the userpoints data for the current month
+ *
+ * @since v1.0.0
+ * @access  public
+ *  @param  mixed $fieldinfo The array from the $tables data for this particular field. It will contain the information from this very list.
+ * @param mixed $fielddata The information on the field from the database.
+ * @param string/int $value The actual value retrieved from the database.
+ * @param obj $data The entire record from the database.
+ * @return  string The string to display.
+ */
+function userpoints_views_views_points_handler_thismonth($fieldinfo, $fielddata, $value, $data) {
+  $intPointsThisMonth = db_result(db_query("SELECT SUM(t.points)
+    FROM {userpoints_txn} t INNER JOIN {userpoints} p ON p.uid = t.uid
+    WHERE p.uid = %d
+    AND   t.uid = %d
+    AND   MONTH(FROM_UNIXTIME(t.time_stamp)) = MONTH(NOW())
+    AND   YEAR(FROM_UNIXTIME(t.time_stamp)) = YEAR(NOW())",
+    $data->usernode_users_uid,
+    $data->usernode_users_uid));
+
+  return (int)$intPointsThisMonth;
+  
+}
+
+function userpoints_views_views_points_query_handler_thismonth($fielddata, $fieldinfo, &$query) {
+  return $query->add_where[0];
+}
+
+/**
+ * Custom views filter for year, month, day queries
+ *
+ * @param $filter[operator] is =, >=, >, <=, <
+ * @param $filter[value] is the month number
+ */
+function userpoints_views_handler_filter_month($op, $filter, $filterinfo, &$query) {
+  switch($op) {
+    case 'handler':
+      switch(trim($filter['value'])) {
+        // No filter value was entered, filter by current month
+        case '':
+          $query->add_table("userpoints_txn", false, 1, array('left' => array('table' => 'userpoints_txn', 'field' => 'uid'), 'right' => array('field' => 'uid')));
+          $query->add_field('userpoints_txn.time_stamp', null, 'userpoints_txn_time_stamp');
+          $query->add_where('MONTH(FROM_UNIXTIME(userpoints_txn.time_stamp)) = MONTH(NOW())');
+          $query->add_where('YEAR(FROM_UNIXTIME(userpoints_txn.time_stamp)) = YEAR(NOW())');
+          break;
+        
+        case 'now':
+          $query->add_table("userpoints_txn", false, 1, array('left' => array('table' => 'userpoints_txn', 'field' => 'uid'), 'right' => array('field' => 'uid')));
+          $query->add_field('userpoints_txn.time_stamp', null, 'userpoints_txn_time_stamp');
+          $query->add_where('MONTH(FROM_UNIXTIME(userpoints_txn.time_stamp)) = MONTH(NOW())');
+          $query->add_where('YEAR(FROM_UNIXTIME(userpoints_txn.time_stamp)) = YEAR(NOW())');
+          
+          break;
+          
+        default:
+          $query->add_table("userpoints_txn", false, 1, array('left' => array('table' => 'userpoints_txn', 'field' => 'uid'), 'right' => array('field' => 'uid')));
+          $query->add_field('userpoints_txn.time_stamp', null, 'userpoints_txn_time_stamp');
+          $query->add_where("MONTH(FROM_UNIXTIME(userpoints_txn.time_stamp)) %s %d", $filter['operator'], $filter['value']);
+          $query->add_where('YEAR(FROM_UNIXTIME(userpoints_txn.time_stamp)) = YEAR(NOW())');
+          break;
+      }
+  }
+}
