Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ElementToGetDetailInfo.php
1<?php
2
4
7
9{
10 private int $iBlockId;
11 private int $elementId;
12 private int $sectionId;
13
14 private array $additionalSelectFields = [];
15 private bool $isNeedCheckPermissions;
16
17 private function __construct(
18 int $iBlockId,
19 int $elementId,
20 int $sectionId
21 ){
22 $this->iBlockId = $iBlockId;
23 $this->elementId = $elementId;
24 $this->sectionId = $sectionId;
25 }
26
30 public static function createFromRequest(GetElementDetailInfoRequest $request): self
31 {
32 $iBlockId = self::validateId($request->iBlockId);
33 if ($iBlockId === null || $iBlockId === 0)
34 {
35 throw new ArgumentOutOfRangeException('iBlockId', 1, null);
36 }
37
38 $elementId = self::validateId($request->elementId);
39 if ($elementId === null)
40 {
41 throw new ArgumentOutOfRangeException('elementId', 0, null);
42 }
43
44 $sectionId = self::validateId($request->sectionId);
45 if ($sectionId === null)
46 {
47 throw new ArgumentOutOfRangeException('sectionId', 0, null);
48 }
49
50 $self = new self($iBlockId, $elementId, $sectionId);
51
52 if ($request->additionalSelectFields)
53 {
54 $self->setAdditionalSelectFields($request->additionalSelectFields);
55 }
56
57 $self->isNeedCheckPermissions = $request->needCheckPermission;
58
59 return $self;
60 }
61
62 private static function validateId(int $id): ?int
63 {
64 if ($id >= 0)
65 {
66 return $id;
67 }
68
69 return null;
70 }
71
72 private function setAdditionalSelectFields(array $selectFields): void
73 {
74 $allowedFields = ['FIELDS', 'PROPS', 'IBLOCK_ID', 'IBLOCK_SECTION_ID'];
75
76 $fields = [];
77 foreach ($selectFields as $fieldId)
78 {
79 if (in_array($fieldId, $allowedFields, true))
80 {
81 $fields[] = $fieldId;
82 }
83 }
84
85 $this->additionalSelectFields = $fields;
86 }
87
91 public function getIBlockId(): int
92 {
93 return $this->iBlockId;
94 }
95
99 public function getElementId(): int
100 {
101 return $this->elementId;
102 }
103
107 public function getSectionId(): int
108 {
109 return $this->sectionId;
110 }
111
115 public function getAdditionalSelectFields(): array
116 {
117 return $this->additionalSelectFields;
118 }
119
123 public function isNeedCheckPermissions(): bool
124 {
125 return $this->isNeedCheckPermissions;
126 }
127}
static createFromRequest(GetElementDetailInfoRequest $request)