public static function givePoints($UserID, $Points, $Source = 'Other', $Timestamp = false)
{
if (!$Timestamp === false) {
$Timestamp = time();
}
if (is_array($Source)) {
$CategoryID = val('CategoryID', $Source, 0);
$Source = $Source[0];
} else {
$CategoryID = 0;
}
if ($CategoryID > 0) {
$CategoryIDs = [$CategoryID, 0];
} else {
$CategoryIDs = [$CategoryID];
}
foreach ($CategoryIDs as $ID) {
// Increment source points for the user.
self::givePointsInternal($UserID, $Points, 'a', $Source, $ID);
// Increment total points for the user.
self::givePointsInternal($UserID, $Points, 'w', 'Total', $ID, $Timestamp);
self::givePointsInternal($UserID, $Points, 'm', 'Total', $ID, $Timestamp);
self::givePointsInternal($UserID, $Points, 'a', 'Total', $ID, $Timestamp);
// Increment global daily points.
self::givePointsInternal(0, $Points, 'd', 'Total', $ID, $Timestamp);
}
// Grab the user's total points.
$totalPoints = Gdn::sql()->getWhere('UserPoints', ['UserID' => $UserID, 'SlotType' => 'a', 'Source' => 'Total', 'CategoryID' => 0])->value('Points');
Gdn::userModel()->setField($UserID, 'Points', $totalPoints);
// Fire a give points event.
Gdn::userModel()->EventArguments['UserID'] = $UserID;
Gdn::userModel()->EventArguments['CategoryID'] = $CategoryID;
Gdn::userModel()->EventArguments['TotalPoints'] = $totalPoints;
Gdn::userModel()->EventArguments['GivenPoints'] = $Points;
Gdn::userModel()->EventArguments['Source'] = $Source;
Gdn::userModel()->EventArguments['Timestamp'] = $Timestamp;
Gdn::userModel()->EventArguments['Points'] = $totalPoints;
// Deprecated in favor of TotalPoints
Gdn::userModel()->fireEvent('GivePoints');
}