public function assignUserPoints($userId, $type)
{
$db = XenForo_Application::get('db');
$options = XenForo_Application::get('options');
switch ($type)
{
case 'post':
{
$numPoints = $options->xfpoints_currency_posts;
break;
}
case 'thread':
{
$numPoints = $options->xfpoints_currency_thread;
break;
}
case 'poll':
{
$numPoints = $options->xfpoints_currency_poll;
break;
}
case 'attachment':
{
$numPoints = $options->xfpoints_currency_upload;
break;
}
case 'register':
{
$numPoints = $options->xfpoints_currency_register;
break;
}
case 'donation':
{
$numPoints = $options->xfpoints_currency_donation;
break;
}
case 'refer':
{
$numPoints = $options->xfpoints_currency_refer;
break;
}
case 'upgrade':
{
$numPoints = $options->xfpoints_currency_upgrade;
break;
}
case 'birthday':
{
$numPoints = $options->xfpoints_currency_birthday;
break;
}
case 'activity':
{
$numPoints = $options->xfpoints_currency_activity;
break;
}
case 'size':
{
$numPoints = $options->xfpoints_currency_size;
break;
}
case 'avatar':
{
$numPoints = $options->xfpoints_currency_avatar;
break;
}
case 'friend':
{
$numPoints = $options->xfpoints_currency_friend;
break;
}
case 'download':
{
$numPoints = $options->xfpoints_currency_download;
break;
}
case 'like':
{
$numPoints = $options->xfpoints_like;
break;
}
case 'unlike':
{
$numPoints = $options->xfpoints_unlike;
break;
}
case 'attachment_downloaded':
if (!empty($extraData)) {
$extension = strtolower($extraData);
$list = explode("\n", $options->xfpoints_attachment_download);
foreach ($list as $line) {
$parts = explode("=", $line);
if (count($parts) == 2) {
$extensions = explode(',', str_replace(' ', '', strtolower($parts[0])));
$point = intval($parts[1]);
if (count($extensions) == 1 AND $extensions[0] == '*') {
// match all rule
return $point;
} else if (in_array($extension, $extensions)) {
return $point;
}
}
}
}
return 0;
break;
default: // unknown type
{
return false;
}
}
// for a new insert
$pointsEarned = $numPoints;
$userPoints = $this->getUserPoints($userId);
if (!empty($userPoints)) // update
{
if ($type == 'register')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
}
if ($type == 'attachment')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'download')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'attachment_downloaded')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'donation')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'like')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'unlike')
{
$pointsEarned = $userPoints['xfpoints_currency'] - $numPoints;
}
if ($type == 'upgrade')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'downgrade')
{
$pointsEarned = $userPoints['xfpoints_currency'] - $options->xfpoints_currency_upgrade;
}
if ($type == 'friend')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'unfriend')
{
$pointsEarned = $userPoints['xfpoints_currency'] - $options->xfpoints_currency_friend;
}
if ($type == 'post')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $options->xfpoints_currency_posts;
}
if ($type == 'thread')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $options->xfpoints_currency_thread;
}
if ($type == 'upgrade')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'avatar')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'poll')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'birthday')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
if ($type == 'activity')
{
$pointsEarned = $userPoints['xfpoints_currency'] + $numPoints;
}
return $pointsEarned ? $pointsEarned : false;
}
public static function updateUserPoints($userId, $pointsEarned)
{
$db = XenForo_Application::get('db');
return $db->query("
UPDATE xf_user
SET xfpoints_currency = ?
WHERE user_id = ?
", array($pointsEarned, $userId));
}