2023-07-28 21:18:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Item;
|
|
|
|
|
|
|
|
use Core\Db;
|
2023-08-14 15:15:05 +00:00
|
|
|
use Helper\Conversion;
|
2023-07-28 21:18:04 +00:00
|
|
|
|
|
|
|
class DataModel
|
|
|
|
{
|
|
|
|
private array $data = [];
|
|
|
|
|
|
|
|
public function __construct(int $itemId)
|
|
|
|
{
|
|
|
|
$datastring = Db::getValue('select data from items_main_data where items_id = ?', [$itemId]);
|
|
|
|
if (empty($datastring)) {
|
|
|
|
return;
|
|
|
|
}
|
2023-08-14 15:15:05 +00:00
|
|
|
$this->data = Conversion::dataStringToArray($datastring);
|
2023-07-28 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getAll(): array
|
|
|
|
{
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequirements(): array
|
|
|
|
{
|
|
|
|
return $this->getPrefixed('tr_');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPrefixed(string $prefix): array
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
foreach ($this->data as $k => $v) {
|
2023-11-09 17:24:47 +00:00
|
|
|
if (str_starts_with($k, $prefix)) {
|
2023-07-28 21:18:04 +00:00
|
|
|
$result[str_replace($prefix, '', $k)] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBonuses(): array
|
|
|
|
{
|
|
|
|
return $this->getPrefixed('add_');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProperties(): array
|
|
|
|
{
|
|
|
|
return $this->getPrefixed('sv_');
|
|
|
|
}
|
|
|
|
}
|