Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/catalog/lib/Access/Model/ |
Upload File : |
<?php namespace Bitrix\Catalog\Access\Model; use Bitrix\Catalog\StoreDocumentElementTable; use Bitrix\Main\Access\AccessibleItem; class StoreDocumentElement implements AccessibleItem { private int $id; /** * @var int[] */ private array $storeIds; /** * @param int $id * @param array $storeIds */ public function __construct(int $id, array $storeIds = []) { $this->id = $id; $this->storeIds = array_unique( array_map('intval', $storeIds) ); } private static function getStoresById(int $id): array { $storeIds = []; if ($id > 0) { $row = StoreDocumentElementTable::getRow([ 'select' => [ 'STORE_TO', 'STORE_FROM', ], 'filter' => [ '=ID' => $id, ], ]); if ($row) { if (isset($row['STORE_TO'])) { $storeIds[] = $row['STORE_TO']; } if (isset($row['STORE_FROM'])) { $storeIds[] = $row['STORE_FROM']; } } } return $storeIds; } /** * @inheritDoc * * @param int $itemId * @param array|null $storeIds * * @return StoreDocumentElement */ public static function createFromId(int $itemId, ?array $storeIds = null): StoreDocumentElement { return new static( $itemId, $storeIds ?? self::getStoresById($itemId) ); } /** * Create from fields array. * * @param array $fields * * @return StoreDocumentElement */ public static function createFromArray(array $fields): StoreDocumentElement { $id = (int)($fields['ID'] ?? 0); $storeIds = []; if (isset($fields['STORE_TO'])) { $storeIds[] = $fields['STORE_TO']; } if (isset($fields['STORE_FROM'])) { $storeIds[] = $fields['STORE_FROM']; } array_push($storeIds, ... self::getStoresById($id)); return new static($id, $storeIds); } /** * @inheritDoc */ public function getId(): int { return $this->id; } /** * Store ids used in document element. * * @return int[] */ public function getStoreIds(): array { return $this->storeIds; } }