36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca\Catalog;
|
|
|
|
use Bitrix\Main\Localization\Loc;
|
|
|
|
Loc::loadMessages(__FILE__);
|
|
|
|
class EnumNames
|
|
{
|
|
public static function name(string $propertyCode, string $xmlId, string $fallback = "", ?string $language = null): string
|
|
{
|
|
$key = "VINO_ENUM_" . $propertyCode . "_" . strtoupper(str_replace("-", "_", $xmlId));
|
|
$message = Loc::getMessage($key, null, $language);
|
|
|
|
return $message !== null && $message !== "" ? $message : $fallback;
|
|
}
|
|
|
|
public static function fromProperty(array $property): string
|
|
{
|
|
$xmlIds = (array)($property["VALUE_XML_ID"] ?? []);
|
|
$values = (array)($property["~VALUE"] ?? $property["VALUE"] ?? []);
|
|
$names = [];
|
|
foreach ($xmlIds as $index => $xmlId) {
|
|
if ((string)$xmlId === "") {
|
|
continue;
|
|
}
|
|
$names[] = self::name((string)$property["CODE"], (string)$xmlId, (string)($values[$index] ?? ""));
|
|
}
|
|
|
|
return implode(", ", $names);
|
|
}
|
|
}
|