/**
 * Notification to modules that a goal is completed.
 *
 * @param int $goal_id
 *   Goal being completed.
 * @param int $uid
 *   UserID of user completing the goal.
 */
function hook_goals_completed_goal($goal_id, $uid)
{
    if (field_info_instance('goal', 'goal_userpoints', 'goal_bundle') && function_exists('userpoints_userpointsapi')) {
        $goals = entity_load('goal', array($goal_id));
        $goal = $goals[$goal_id];
        $point_array = field_get_items('goal', $goal, 'goal_userpoints');
        $points = $point_array[0]['value'];
        if ($points) {
            $params = array('uid' => $uid, 'points' => $points, 'description' => t('Goal @goal completed.', array('@goal' => $goal->title)));
            userpoints_userpointsapi($params);
        }
    }
}
/**
 * hook_mongodb_statistics_firstvisits
 *
 * Hook used in the cron synchonisation of user counters
 * 
 * We are giving you the list of nodes visited by some users since last synchonisations.
 * 
 * @param $visits is an array indexed by uid, containing for each uid the list (array) of newly visited nodes (nid)
 * @return unknown_type
 */
function hook_mongodb_statistics_firstvisits($visits) {
  
  foreach($visits as $uid => $nid_array) {
    foreach($nid_array as $k => $nid) {
      $node = node_load($nid);
      // Award the points.
      userpoints_userpointsapi(array(
        'uid' => $uid,
        'points' => variable_get("labs_vis_default", 0),
        'moderate' => FALSE,
        'time_stamp' => REQUEST_TIME,
        'operation' => 'userpoints_1st_visit',
        'entity_id' => $nid,
        'entity_type' => 'node',
        'description' => t('visited : @title', array('@title' => $node->title)),
        //'tid' => variable_get('my_point_category'),
        'display' => FALSE,
      ));
    }
  }
  
}