34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
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;
|
||
}
|
||
} |