Великое объединение магазинов. #54.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Item;
|
||||
|
||||
use Core\ConversionHelper;
|
||||
use Core\Db;
|
||||
|
||||
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 = ConversionHelper::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 ($this->searchByPrefix($prefix, $k)) {
|
||||
$result[str_replace($prefix, '', $k)] = $v;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function searchByPrefix(string $prefix, string $string): bool
|
||||
{
|
||||
return substr($string, 0, strlen($prefix)) === $prefix;
|
||||
}
|
||||
|
||||
public function getBonuses(): array
|
||||
{
|
||||
return $this->getPrefixed('add_');
|
||||
}
|
||||
|
||||
public function getProperties(): array
|
||||
{
|
||||
return $this->getPrefixed('sv_');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user