Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productrowactionsprovider.php
1<?php
2
4
12
13Loader::requireModule('iblock');
14
20{
21 public function __construct(ProductSettings $settings, ProductRightsChecker $rights)
22 {
23 parent::__construct($settings, $rights);
24 }
25
26 public function prepareActions(): array
27 {
28 $elementActions = parent::prepareActions();
29
30 if ($this->getIblockRightsChecker()->canEditElements())
31 {
32 $elementActions[] = new ConvertToServiceItem($this->getIblockId(), $this->getIblockRightsChecker());
33 $elementActions[] = new ConvertToProductItem($this->getIblockId(), $this->getIblockRightsChecker());
34 }
35
36 return $elementActions;
37 }
38
39 public function prepareControls(array $rawFields): array
40 {
41 $controls = parent::prepareControls($rawFields);
42
43 $isSection = isset($rawFields['ROW_TYPE']) && $rawFields['ROW_TYPE'] === 'S';
44 if (!$isSection)
45 {
46 $id = (int)($rawFields['ID'] ?? 0);
47 if ($id > 0)
48 {
49 $additionalItems = [];
50
51 $productType = (int)($rawFields['TYPE'] ?? $this->getProductType($id) ?? 0);
52 if ($productType === ProductTable::TYPE_SERVICE)
53 {
54 $additionalItems[] = $this->getActionById(ConvertToProductItem::getId());
55 }
56 else
57 {
58 $additionalItems[] = $this->getActionById(ConvertToServiceItem::getId());
59 }
60
61 foreach ($additionalItems as $item)
62 {
66 $control = isset($item) ? $item->getControl($rawFields) : null;
67 if (isset($control))
68 {
69 $controls[] = $control;
70 }
71 }
72 }
73 }
74
75 return $controls;
76 }
77
78 private function getProductType(int $productId): ?int
79 {
81 'select' => [
82 'TYPE'
83 ],
84 'filter' => [
85 '=ID' => $productId,
86 ],
87 ]);
88 if ($row)
89 {
90 return (int)$row['TYPE'];
91 }
92
93 return null;
94 }
95}
__construct(ProductSettings $settings, ProductRightsChecker $rights)
static getRow(array $parameters)