34 lines
1021 B
PHP
34 lines
1021 B
PHP
<?php
|
|
|
|
use Core\Db;
|
|
|
|
class UserStats
|
|
{
|
|
/**
|
|
* Ñîáèðàåò ñóììû âñåõ áîíóñîâ ñ îäåòûõ ïðåäìåòîâ è àêòèâíûõ ýôåêòîâ.
|
|
* @param int $userId
|
|
* @param bool $showAll
|
|
* @return array
|
|
*/
|
|
public static function getAllBonuses(int $userId, bool $showAll = false): array
|
|
{
|
|
|
|
$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 = [];
|
|
foreach ($iData as $datum) {
|
|
foreach (explode('|', $datum) as $inner) {
|
|
[$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;
|
|
}
|
|
} |