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