This commit is contained in:
2023-11-09 19:24:47 +02:00
parent 1645f58a63
commit fc17eada24
19 changed files with 1255 additions and 953 deletions
@@ -0,0 +1,18 @@
<?php
namespace Model\Constant;
use Core\Db;
class Constant
{
protected static string $tableName = '';
protected array $rows = [];
public function __construct()
{
$this->rows = Db::getRows('select * from ' . self::$tableName);
}
}
@@ -0,0 +1,47 @@
<?php
namespace Model\Constant;
class ShopOtdel extends Constant
{
public function __construct()
{
self::$tableName = 'const_shop_otdels';
parent::__construct();
}
public function getName(int $id): string
{
foreach ($this->rows as $row) {
if ($row['id'] === $id) {
return $row['name'];
}
}
return '';
}
/**
* Âîçâðàùàåò ñïèñîê ãðóïï òîâàðîâ, ãäå id áåð¸òñÿ èç ïåðâîãî òîâàðà â ãðóïïå.
* Ëîãèêà ñòðàííàÿ èç çà legacy-ðåøåíèÿ.
* @return array
*/
public function getGroups(): array
{
$groups = [];
foreach ($this->getGrouped() as $name => $arr) {
$groups[$name] = array_keys($arr)[0];
}
return array_flip($groups);
}
public function getGrouped(): array
{
$result = [];
foreach ($this->rows as $row) {
//$result[$row['id']] = [$row['name'], $row['group_name']];
$result[$row['group_name']][$row['id']] = $row['name'];
}
return $result;
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace Model\Constant;
use Enum\StatFilterCellName;
class Stat extends Constant
{
public function __construct()
{
self::$tableName = 'const_stats';
parent::__construct();
}
public function getBonusNames(): array
{
return $this->filterByCell(StatFilterCellName::Bonus);
}
private function filterByCell(StatFilterCellName $cellName): array
{
$result = [];
foreach ($this->rows as $row) {
if (!$row[$cellName->value]) {
continue;
}
if ($row['sys_name'] === 'level') {
$row['sys_name'] = 'lvl';
}
$result[$row['sys_name']] = $row['name'];
}
return $result;
}
public function getRequirementNames(): array
{
return $this->filterByCell(StatFilterCellName::Requirement);
}
}