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