1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
morephotoassembler.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\Grid\Row\Assembler;
4
5use Bitrix\Catalog\Component\ImageInput;
6use Bitrix\Catalog\Grid\Settings\ProductSettings;
7use Bitrix\Catalog\v2\IoC\ServiceContainer;
8use Bitrix\Catalog\v2\Product\BaseProduct;
9use Bitrix\Catalog\v2\Sku\BaseSku;
10use Bitrix\Iblock\Grid\RowType;
11use Bitrix\Main\Grid\Row\FieldAssembler;
12use Bitrix\Main\Loader;
13use Bitrix\Main\Page\Asset;
14use Bitrix\Main\Web\Uri;
15
16Loader::requireModule('iblock');
17
22{
23 private array $entities;
24
25 public function __construct(array $columnIds, ProductSettings $settings)
26 {
27 parent::__construct($columnIds, $settings);
28
29 $this->preloadResources();
30 }
31
42 private function preloadResources(): void
43 {
44 Asset::getInstance()->addJs('/bitrix/components/bitrix/ui.image.input/templates/.default/script.js');
45 Asset::getInstance()->addCss('/bitrix/components/bitrix/ui.image.input/templates/.default/style.css');
46 }
47
48 private function getIblockId(): int
49 {
50 return $this->getSettings()->getIblockId();
51 }
52
53 private function getOffersIblockId(): ?int
54 {
55 return $this->getSettings()->getOffersIblockId();
56 }
57
58 #region override
59
60 public function prepareRows(array $rowList): array
61 {
62 if (empty($this->getColumnIds()))
63 {
64 return $rowList;
65 }
66
67 $this->loadEntities($rowList);
68
69 foreach ($rowList as &$row)
70 {
71 $id = (int)($row['data']['ID'] ?? 0);
72 $type = $row['data']['ROW_TYPE'] ?? null;
76 $entity = $this->entities[$id] ?? null;
77
78 $row['columns'] ??= [];
79
80 foreach ($this->getColumnIds() as $columnId)
81 {
82 if ($id === 0 || $type !== RowType::ELEMENT || !isset($entity))
83 {
84 $row['data'][$columnId] = null;
85 $row['columns'][$columnId] = null;
86 }
87 elseif ($this->getSettings()->isExcelMode())
88 {
89 $imagesSrc = [];
90 foreach ($entity->getFrontImageCollection() as $image)
91 {
92 $uri = new Uri($image->getSource());
93 $imagesSrc[] = (string)$uri->toAbsolute();
94 }
95
96 $row['data'][$columnId] = join(', ', $imagesSrc);
97 $row['columns'][$columnId] = join(', ', $imagesSrc);
98 }
99 else
100 {
101 $imageInput = new ImageInput($entity);
102 //$imageInput->disableAutoSaving();
103 $html = $imageInput->getFormattedField();
104
105 $row['data']['~' . $columnId] = $html['input'];
106 $row['columns'][$columnId] = $html['preview'];
107 }
108 }
109 }
110
111 return $rowList;
112 }
113
114 protected function prepareColumn($value)
115 {
116 return $value;
117 }
118
119 #endregion override
120
121 private function loadEntities(array $rowList): void
122 {
123 $this->entities = [];
124
125 $productToOfferId = $this->getSettings()->getSelectedProductOfferIds();
126 $offerToProductId = array_flip($productToOfferId);
127
128 $ids = [];
129 foreach ($rowList as $row)
130 {
131 $id = (int)($row['data']['ID'] ?? 0);
132 if ($id === 0)
133 {
134 continue;
135 }
136
137 $type = $row['data']['ROW_TYPE'] ?? null;
138 if ($type !== RowType::ELEMENT)
139 {
140 continue;
141 }
142
143 // replace `product id` to `offer id` to display correct offer image.
144 if (isset($productToOfferId[$id]))
145 {
146 $id = $productToOfferId[$id];
147 }
148
149 $ids[] = $id;
150 }
151
152 if (empty($ids))
153 {
154 return;
155 }
156
157 $repository = ServiceContainer::getProductRepository($this->getIblockId());
158 if (isset($repository))
159 {
160 $items = $repository->getEntitiesBy([
161 'filter' => [
162 'ID' => $ids,
163 ],
164 ]);
165 foreach ($items as $item)
166 {
170
171 $this->entities[$item->getId()] = $item;
172 }
173 }
174
175 $offersIblockId = $this->getOffersIblockId();
176 $repository =
177 isset($offersIblockId)
178 ? ServiceContainer::getSkuRepository($offersIblockId)
179 : null
180 ;
181 if (isset($repository))
182 {
183 $items = $repository->getEntitiesBy([
184 'filter' => [
185 'ID' => $ids,
186 ],
187 ]);
188 foreach ($items as $item)
189 {
193
194 $productId = $offerToProductId[$item->getId()];
195 $this->entities[$productId] = $item;
196 }
197 }
198 }
199}
$type
Определения options.php:106
__construct(array $columnIds, ProductSettings $settings)
Определения morephotoassembler.php:25
prepareRows(array $rowList)
Определения fieldassembler.php:126
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$entity
$rowList
Определения iblock_catalog_list.php:273
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$items
Определения template.php:224