Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
gridserviceform.php
1<?php
2
4
12
14{
15 protected function buildDescriptions(): array
16 {
17 $result = parent::buildDescriptions();
18
19 return $this->modifyDescriptions($result);
20 }
21
22 protected function getPropertyDescription(Property $property): array
23 {
24 $description = parent::getPropertyDescription($property);
25 if ($property->getCode() === BaseForm::MORE_PHOTO)
26 {
27 $description['title'] = Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_HEADER_NAME_MORE_PHOTO');
28 }
29 $description['isEnabledOfferTree'] = false;
30
31 return $description;
32 }
33
34 protected function buildIblockPropertiesDescriptions(): array
35 {
37
38 foreach ($this->entity->getPropertyCollection() as $property)
39 {
40 if ($property->isActive() && $property->getCode() === BaseForm::MORE_PHOTO)
41 {
43 }
44 }
45
47 }
48
49 public function loadGridHeaders(): array
50 {
51 $defaultWidth = 130;
52
53 $headers = [];
54
55 $headers = array_merge(
59 [
60 'ACTIVE',
61 'AVAILABLE',
62 'MEASURE',
63 ],
64 $defaultWidth
65 ),
66 $this->getPurchasingPriceHeaders($defaultWidth),
67 $this->getPricesHeaders($defaultWidth),
69 [
70 'VAT_ID', 'VAT_INCLUDED',
71 'SHOW_COUNTER', 'CODE', 'TIMESTAMP_X', 'MODIFIED_BY',
72 'DATE_CREATE', 'XML_ID',
73 ],
74 $defaultWidth
75 )
76 );
77
78 self::$headers = $headers;
79
80 return $headers;
81 }
82
83 protected function getProductFieldHeaders(array $fields, int $defaultWidth): array
84 {
85 $result = parent::getProductFieldHeaders($fields, $defaultWidth);
86
87 return $this->modifyProductFieldHeaders($result);
88 }
89
90 protected function modifyProductFieldHeaders(array $headers): array
91 {
92 $index = $this->getIndexFieldDescription($headers, 'id', static::formatFieldName('AVAILABLE'));
93 if ($index !== null)
94 {
95 $row = $headers[$index];
96 $row['editable'] = $this->isAllowedEditFields()
97 ? [
98 'TYPE' => Types::CHECKBOX,
99 ]
100 : false;
101 $row['default'] = true;
102 $headers[$index] = $row;
103 }
104
105 return array_values($headers);
106 }
107
114 protected function getPurchasingPriceHeaders(?int $defaultWidth): array
115 {
116 $headers = [];
117
118 if ($this->isPurchasingPriceAllowed())
119 {
120 $headerName = static::getHeaderName('PURCHASING_PRICE');
121
122 $headers[] = [
123 'id' => static::formatFieldName('PURCHASING_PRICE_FIELD'),
124 'name' => $headerName['NAME'],
125 'title' => $headerName['TITLE'],
126 'sort' => 'PURCHASING_PRICE',
127 'type' => 'money',
128 'align' => 'right',
129 'editable' =>
130 $this->isAllowedEditFields()
131 ? [
132 'TYPE' => Types::MONEY,
133 'CURRENCY_LIST' => CurrencyManager::getSymbolList(),
134 'HTML_ENTITY' => true,
135 ]
136 : false
137 ,
138 'width' => $defaultWidth,
139 'default' => false,
140 ];
141 }
142
143 return $headers;
144 }
145
146 public function getVariationGridId(): string
147 {
148 $iblockInfo = ServiceContainer::getIblockInfo($this->entity->getIblockId());
149
150 if ($iblockInfo)
151 {
152 return 'catalog-product-service-grid-' . $iblockInfo->getProductIblockId();
153 }
154
155 return 'catalog-product-service-grid';
156 }
157
158 public static function getGridCardSettingsItems(): array
159 {
160 $result = [];
161 $result['VAT_INCLUDED'] = [
162 'ITEMS' => [
163 static::formatFieldName('VAT_ID'),
164 static::formatFieldName('VAT_INCLUDED'),
165 ],
166 'TITLE' => Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_SETTINGS_TITLE_VAT_INCLUDED'),
167 'DESCRIPTION' => Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_SETTINGS_DESC_VAT_INCLUDED'),
168 ];
169 if (AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW))
170 {
171 $result['PURCHASING_PRICE_FIELD'] = [
172 'ITEMS' => [
173 static::formatFieldName('PURCHASING_PRICE_FIELD'),
174 ],
175 'TITLE' => Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_SETTINGS_TITLE_PURCHASING_PRICE'),
176 'DESCRIPTION' => Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_SETTINGS_DESC_PURCHASING_PRICE'),
177 ];
178 }
179
180 return $result;
181 }
182
183 protected static function getHeaderIdsBySettingId(string $settingId): array
184 {
185 $headers = [];
186 switch ($settingId)
187 {
188 case 'PURCHASING_PRICE_FIELD':
189 if (AccessController::getCurrent()->check(ActionDictionary::ACTION_PRODUCT_PURCHASE_INFO_VIEW))
190 {
191 $headers = [
192 'PURCHASING_PRICE_FIELD',
193 ];
194 }
195 break;
196 case 'VAT_INCLUDED':
197 $headers = [
198 'VAT_INCLUDED',
199 'VAT_ID'
200 ];
201 break;
202 }
203
204 foreach ($headers as &$id)
205 {
206 $id = static::formatFieldName($id);
207 }
208 unset($id);
209
210 return $headers;
211 }
212
213 protected static function getHeaderName(string $code): array
214 {
215 $headerName = Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_HEADER_NAME_' . $code);
216 $headerTitle = Loc::getMessage('CATALOG_SERVICE_CARD_VARIATION_GRID_HEADER_TITLE_' . $code);
217
218 return [
219 'NAME' => $headerName,
220 'TITLE' => $headerTitle ?? $headerName,
221 ];
222 }
223
224 private function modifyDescriptions(array $descriptions): array
225 {
226 $descriptions = $this->modifyAvailableDescription($descriptions);
227
228 return array_values($descriptions);
229 }
230
231 private function modifyAvailableDescription(array $descriptions): array
232 {
233 $index = $this->getIndexFieldDescription($descriptions, 'originalName', 'AVAILABLE');
234 if ($index !== null)
235 {
236 $row = $descriptions[$index];
237 $row['editable'] = $this->isAllowedEditFields();
238 $row['defaultValue'] = 'Y';
239 $descriptions[$index] = $row;
240 }
241
242 return $descriptions;
243 }
244
245 private function getIndexFieldDescription(array $description, string $key, string $fieldName): ?int
246 {
247 $result = null;
248
249 foreach (array_keys($description) as $index)
250 {
251 if ($description[$index][$key] === $fieldName)
252 {
253 $result = $index;
254 break;
255 }
256 }
257
258 return $result;
259 }
260}
getProductFieldHeaders(array $fields, int $defaultWidth)
static getHeaderIdsBySettingId(string $settingId)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29