Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
reportstoreprofitlist.php
1<?php
2
4
9
10abstract class ReportStoreProfitList extends \CBitrixComponent
11{
12 abstract protected function getGridColumns(): array;
13
14 abstract protected function getReportProductGridComponentName(): string;
15
16 abstract protected function getTotalFields(): array;
17
18 abstract protected function getGridId(): string;
19
20 public function executeComponent()
21 {
22 if (!$this->checkErrors())
23 {
24 return;
25 }
26
27 $this->fillResult();
28
29 $this->includeComponentTemplate();
30 }
31
32 protected function checkErrors(): bool
33 {
34 if (!Loader::includeModule('catalog') || !self::checkDocumentReadRights())
35 {
36 $this->arResult['ERROR_MESSAGES'][] = Loc::getMessage('CATALOG_REPORT_PROFIT_LIST_NO_READ_RIGHTS_ERROR');
37 $this->includeComponentTemplate();
38
39 return false;
40 }
41
42 return true;
43 }
44
45 protected function fillResult(): void
46 {
47 $this->arResult['GRID'] = $this->getGridData();
48 $this->arResult['GRID_FILTER'] = $this->getGridFilter();
49 $this->arResult['PRODUCT_LIST_SLIDER_URL'] = $this->getProductListComponentUrl();
50 }
51
52 private function getGridData(): array
53 {
54 $result = [
55 'GRID_ID' => $this->getGridId(),
56 'COLUMNS' => $this->getGridColumns(),
57 'ROWS' => [],
58 ];
59
60 if (
61 isset($this->arParams['RESULT']['data']['stub'])
62 && is_array($this->arParams['RESULT']['data']['stub'])
63 )
64 {
65 $result['STUB'] = $this->arParams['RESULT']['data']['stub'];
66
67 return $result;
68 }
69
70 $providerData = $this->arParams['RESULT']['data']['items'];
71 $overallData = $this->arParams['RESULT']['data']['overall'];
72
73 if (!empty($providerData))
74 {
75 foreach($providerData as $storeId => $item)
76 {
77 $result['ROWS'][] = [
78 'id' => $storeId,
79 'data' => $item,
80 'columns' => $this->prepareItemColumn($item),
81 ];
82 }
83
84 $result['ROWS'][] = $this->prepareOverallTotalRow($overallData);
85 $result['ROWS'][] = $this->prepareTotalLinkRow();
86 }
87
88 $result['SHOW_PAGINATION'] = false;
89 $result['SHOW_NAVIGATION_PANEL'] = false;
90 $result['SHOW_PAGESIZE'] = false;
91 $result['SHOW_ROW_CHECKBOXES'] = false;
92 $result['SHOW_CHECK_ALL_CHECKBOXES'] = false;
93 $result['SHOW_ACTION_PANEL'] = false;
94 $result['HANDLE_RESPONSE_ERRORS'] = true;
95 $result['SHOW_GRID_SETTINGS_MENU'] = false;
96 $result['ALLOW_STICKED_COLUMNS'] = true;
97
98 return $result;
99 }
100
101 private function prepareItemColumn(array $item): array
102 {
103 $column = $item;
104
105 $column['TITLE'] = $this->prepareTitleViewForColumn($column);
106 if (isset($column['STORE_ID']))
107 {
108 $column['STORE_ID'] = (int)$column['STORE_ID'];
109 }
110
111 foreach ($this->getTotalFields() as $totalField)
112 {
113 $column[$totalField] = $this->formatValue($totalField, $column['TOTALS'][$totalField]);
114 }
115
116 unset($column['TOTALS']);
117
118 return $column;
119 }
120
121 private function prepareOverallTotalRow(array $overallData): array
122 {
123 $overallColumns = [];
124 $overallColumns['TITLE'] = Loc::getMessage('CATALOG_REPORT_PROFIT_LIST_OVERALL_TOTAL');
125
126 foreach ($this->getTotalFields() as $totalField)
127 {
128 $overallColumns[$totalField] = $this->formatValue($totalField, $overallData[$totalField]);
129 }
130
131 return [
132 'id' => 'overallTotal',
133 'data' => $overallData,
134 'columns' => $overallColumns,
135 ];
136 }
137
138 private function prepareTotalLinkRow(): array
139 {
140 return [
141 'id' => 'totalLink',
142 'columns' => [
143 'TITLE' => Loc::getMessage('CATALOG_REPORT_PROFIT_LIST_OPEN_SLIDER_ALL')
144 ],
145 ];
146 }
147
148 protected function formatValue(string $fieldName, $value): ?string
149 {
150 return (string)$value;
151 }
152
153 private function prepareTitleViewForColumn(array $column): string
154 {
155 if (!isset($column['TITLE'], $column['STORE_ID']))
156 {
157 return '';
158 }
159
160 if ($column['TITLE'])
161 {
162 $title = htmlspecialcharsbx($column['TITLE']);
163 }
164 else
165 {
166 $title = Loc::getMessage('CATALOG_REPORT_PROFIT_LIST_EMPTY_STORE_NAME');
167 }
168
169 return $title;
170 }
171
172 private function getGridFilter(): array
173 {
174 return $this->arParams['RESULT']['data']['filter'];
175 }
176
177 protected function getProductListComponentUrl(): string
178 {
179 $productGridPath = \CComponentEngine::makeComponentPath($this->getReportProductGridComponentName());
180
181 return getLocalPath('components' . $productGridPath . '/slider.php');
182 }
183
184 private static function checkDocumentReadRights(): bool
185 {
186 return AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_READ);
187 }
188}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29