game/_incl_data/class/Item/DataModel.php
2023-11-09 19:24:47 +02:00

51 lines
1.0 KiB
PHP

<?php
namespace Item;
use Core\Db;
use Helper\Conversion;
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;
}
$this->data = Conversion::dataStringToArray($datastring);
}
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) {
if (str_starts_with($k, $prefix)) {
$result[str_replace($prefix, '', $k)] = $v;
}
}
return $result;
}
public function getBonuses(): array
{
return $this->getPrefixed('add_');
}
public function getProperties(): array
{
return $this->getPrefixed('sv_');
}
}