34 lines
988 B
PHP
34 lines
988 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca\Catalog;
|
|
|
|
use Jinove\Vinoteca\Config;
|
|
use Jinove\Vinoteca\Cached;
|
|
|
|
class Countries
|
|
{
|
|
private const CACHE_TTL = 86400;
|
|
private const CACHE_DIR = "/jinove.vinoteca/countries";
|
|
|
|
private static ?array $names = null;
|
|
|
|
public static function names(): array
|
|
{
|
|
if (self::$names !== null) {
|
|
return self::$names;
|
|
}
|
|
$catalogId = Config::iblockId("catalog");
|
|
return self::$names = (array)Cached::remember(self::CACHE_DIR, "names-" . $catalogId, self::CACHE_TTL, ["iblock_id_" . $catalogId], static function () use ($catalogId): array {
|
|
$names = [];
|
|
$rows = \CIBlockPropertyEnum::GetList(["SORT" => "ASC", "VALUE" => "ASC"], ["IBLOCK_ID" => $catalogId, "CODE" => "COUNTRY"]);
|
|
while ($row = $rows->Fetch()) {
|
|
$names[(string)$row["XML_ID"]] = (string)$row["VALUE"];
|
|
}
|
|
|
|
return $names;
|
|
});
|
|
}
|
|
}
|