Vinoteca: wine shop on 1C-Bitrix (module, template, components, pages)
This commit is contained in:
commit
0590195880
593 files changed
+27942
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user