ocPortal Developer's Guide: Points
» Return to Contents
sources/points.php
Global_functions_points.php
void init__points()
Standard code module initialisation function.
Parameters…
(No return value)
function init__points()
{
global $TOTAL_POINTS_CACHE;
$TOTAL_POINTS_CACHE=array();
global $POINTS_USED_CACHE;
$POINTS_USED_CACHE=array();
global $POINT_INFO_CACHE;
$POINT_INFO_CACHE=array();
}
integer get_price(ID_TEXT item)
Get the price of the specified item for sale in the point-store (only for tableless items).
Parameters…
| Name |
item |
| Description |
The name of the item |
| Type |
ID_TEXT |
Returns…
| Description |
The price of the item |
| Type |
integer |
function get_price($item)
{
return $GLOBALS['SITE_DB']->query_value('prices','price',array('name'=>$item));
}
integer total_points(MEMBER member)
Get the total points in the specified member's account; some of these will probably have been spent already
Parameters…
| Name |
member |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The number of points the member has |
| Type |
integer |
function total_points($member)
{
if (!has_specific_permission($member,'use_points')) return 0;
global $TOTAL_POINTS_CACHE;
if (array_key_exists($member,$TOTAL_POINTS_CACHE)) return $TOTAL_POINTS_CACHE[$member];
$points_gained_posting=$GLOBALS['FORUM_DRIVER']->get_post_count($member);
$_points_gained=point_info($member);
$points_gained_given=array_key_exists('points_gained_given',$_points_gained)?$_points_gained['points_gained_given']:0;
$points_gained_rating=array_key_exists('points_gained_rating',$_points_gained)?$_points_gained['points_gained_rating']:0;
$points_gained_voting=array_key_exists('points_gained_voting',$_points_gained)?$_points_gained['points_gained_voting']:0;
$points_gained_cedi=array_key_exists('points_gained_seedy',$_points_gained)?$_points_gained['points_gained_seedy']:0;
$points_gained_chat=array_key_exists('points_gained_chat',$_points_gained)?$_points_gained['points_gained_chat']:0;
$points_posting=intval(get_option('points_posting'));
$points_rating=intval(get_option('points_rating'));
$points_voting=intval(get_option('points_voting'));
$points_joining=intval(get_option('points_joining'));
$points_per_day=intval(get_option('points_per_day',true));
$points_chat=intval(get_option('points_chat',true));
$points_cedi=intval(get_option('points_cedi',true));
$points_gained_auto=$points_per_day*intval(floor(floatval(time()-$GLOBALS['FORUM_DRIVER']->get_member_join_timestamp($member))/floatval(60*60*24)));
$points=$points_joining+$points_gained_chat*$points_chat+$points_gained_cedi*$points_cedi+$points_gained_posting*$points_posting+$points_gained_given+$points_gained_rating*$points_rating+$points_gained_voting*$points_voting+$points_gained_auto;
$TOTAL_POINTS_CACHE[$member]=$points;
return $points;
}
integer points_used(MEMBER member)
Get the total points the specified member has used (spent).
Parameters…
| Name |
member |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The number of points the member has spent |
| Type |
integer |
function points_used($member)
{
global $POINTS_USED_CACHE;
if (array_key_exists($member,$POINTS_USED_CACHE)) return $POINTS_USED_CACHE[$member];
$_points=point_info($member);
$points=array_key_exists('points_used',$_points)?$_points['points_used']:0;
$POINTS_USED_CACHE[$member]=$points;
return $points;
}
integer available_points(MEMBER member)
Get the total points the specified member has
Parameters…
| Name |
member |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The number of points the member has |
| Type |
integer |
function available_points($member)
{
if (!has_specific_permission($member,'use_points')) return 0;
return total_points($member)-points_used($member);
}
array point_info(MEMBER member)
Get all sorts of information about a specified member's point account.
Parameters…
| Name |
member |
| Description |
The member the point info is of |
| Type |
MEMBER |
Returns…
| Description |
The map containing the members point info (fields as enumerated in description) |
| Type |
array |
function point_info($member)
{
require_code('lang');
require_lang('points');
global $POINT_INFO_CACHE;
if (array_key_exists($member,$POINT_INFO_CACHE)) return $POINT_INFO_CACHE[$member];
$values=$GLOBALS['FORUM_DRIVER']->get_custom_fields($member);
if (is_null($values))
{
$values=array();
}
$POINT_INFO_CACHE[$member]=array();
foreach ($values as $key=>$val)
{
if (!is_object($val))
$POINT_INFO_CACHE[$member][$key]=intval($val);
}
return $POINT_INFO_CACHE[$member];
}
integer get_gift_points_used(MEMBER member)
Get the number of gift points used by the given member.
Parameters…
| Name |
member |
| Description |
The member we want it for |
| Type |
MEMBER |
Returns…
| Description |
The number of gift points used by the member |
| Type |
integer |
function get_gift_points_used($member)
{
$actual_used=intval($GLOBALS['SITE_DB']->query_value_null_ok('gifts','SUM(amount)',array('gift_from'=>$member)));
$_used=point_info($member);
$claimed_used=$_used['gift_points_used'];
return ($claimed_used<0)?$claimed_used:$actual_used; // Allows $claimed_used to be fiddled to give members extra gift points
}
integer get_gift_points_to_give(MEMBER member)
Get the number of gifts points to give that the given member has.
Parameters…
| Name |
member |
| Description |
The member we want it for |
| Type |
MEMBER |
Returns…
| Description |
The number of gifts points to give that the given member has |
| Type |
integer |
function get_gift_points_to_give($member)
{
$used=get_gift_points_used($member);
if (get_forum_type()=='ocf')
{
require_lang('ocf');
require_code('ocf_groups');
$base=ocf_get_member_best_group_property($member,'gift_points_base');
$per_day=ocf_get_member_best_group_property($member,'gift_points_per_day');
} else
{
$base=25;
$per_day=1;
}
$available=$base+$per_day*intval(floor((time()-$GLOBALS['FORUM_DRIVER']->get_member_join_timestamp($member))/(60*60*24)))-$used;
return $available;
}
0 reviews: Unrated (average)
There have been no comments yet