game/_incl_data/class/UserStats.php

36 lines
1.2 KiB
PHP

<?php
use Insallah\Db;
class UserStats
{
/**
* Ñîáèðàåò ñóììû âñåõ áîíóñîâ ñ îäåòûõ ïðåäìåòîâ è àêòèâíûõ ýôåêòîâ.
* @param $userId
* @param bool $showAll
* @return array
*/
public static function getAllBonuses($userId, $showAll = false)
{
require_once '_incl_data/class/Insallah/Core/Db.php';
$db = new Db();
$q = 'select data from items_users where uid = ? and inOdet > 0 and `delete` = 0
union all select data from eff_users where uid = ? and `delete` = 0';
$iData = $db::getColumn($q, [$userId, $userId]);
$params = [];
$params2 = json_decode(str_replace(['=', '|'], ['":', ',"'], '{"' . $iData . '}'), true);
foreach ($iData as $datum) {
foreach (explode('|', $datum) as $inner) {
list($a, $b) = explode('=', $inner);
if (strpos($a, 'add') !== false || strpos($a, 'sv') !== false || $showAll) {
if (isset($params[$a])) {
$params[$a] += $b;
} else {
$params[$a] = $b;
}
}
}
}
return $params;
}
}