Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storechart.php
1<?php
2
4
14
15abstract class StoreChart extends \CBitrixComponent implements Errorable
16{
18
19 abstract protected function getChartId(): string;
20 abstract protected function getInnerChartData(): array;
21 abstract protected function fetchAndBuildStoreColumnData(array $stores): array;
22 abstract protected function buildLinkToSliderDetails(string $linkContent): string;
23 abstract protected function initializeAdditionalData(): void;
24
25 final public function executeComponent()
26 {
27 $this->errorCollection = new ErrorCollection();
28
29 if (!Loader::includeModule('currency'))
30 {
31 $this->errorCollection->add([new Error(Loc::getMessage('STORE_CHART_REPORT_NO_CURRENCY_ERROR'))]);
32 }
33 if (!self::checkDocumentReadRights())
34 {
35 $this->errorCollection->add([new Error(Loc::getMessage('STORE_CHART_REPORT_NO_READ_RIGHTS_ERROR'))]);
36 }
37
38 if (!$this->hasErrors())
39 {
40 $this->initializeComponent();
41 }
42
43 $this->arResult['ERROR_MESSAGES'] = array_map(static function(Error $error) {
44 return $error->getMessage();
45 }, $this->errorCollection->getValues());
46
47 $this->includeComponentTemplate();
48 }
49
50 protected function initializeComponent(): void
51 {
52 $this->initializeChart();
54 }
55
56 protected function initializeChart(): void
57 {
58 $innerChartData = $this->getInnerChartData();
59
60 $this->arResult['chartData'] = [
61 'chartProps' => [
62 'id' => $this->getChartId(),
63 'detailSliderUrl' => $innerChartData['isCommonChart'] ? $innerChartData['sliderUrl'] : null,
64 'stores' => $this->fetchAndBuildStoreColumnData($innerChartData['data'] ?? []),
65 'isPopupEnabled' => !$innerChartData['isCommonChart'] || ($innerChartData['storesInfo']['storeCount'] ?? 0) > 0,
66 'label' => $this->formChartLabel($innerChartData),
67 'isCommonChart' => $innerChartData['isCommonChart'],
68 'currency' => [
69 'id' => $innerChartData['currency'],
70 'symbol' => $this->getCurrencySymbol($innerChartData['currency']),
71 'format' => \CCurrencyLang::GetFormatDescription($innerChartData['currency']),
72 ],
73 ],
74 ];
75 }
76
77 protected function formChartLabel(array $chartData): string
78 {
79 if (!$chartData['isCommonChart'] || $chartData['storesInfo']['storeCount'] <= 0)
80 {
81 return '';
82 }
83
84 $storesInfo = $chartData['storesInfo'];
85 $storesList = htmlspecialcharsbx($storesInfo['cropStoreNamesList']);
86
87 $totalLinkContent = Loc::getMessage(
88 'STORE_CHART_REPORT_STORES_TOTAL',
89 ['#TOTAL_NUMBER#' => $storesInfo['storeCount']]
90 );
91
92 $totalLink = $totalLinkContent;
93 if (isset($chartData['sliderUrl']))
94 {
95 $totalLink = $this->buildLinkToSliderDetails($totalLinkContent);
96 }
97
98 return Loc::getMessage(
99 'STORE_CHART_REPORT_STORES_LIST_TEMPLATE',
100 [
101 '#STORES_LIST#' => $storesList,
102 '#STORES_TOTAL_LINK#' => $totalLink,
103 ]
104 );
105 }
106
107
108 private function getCurrencySymbol(string $currency): string
109 {
110 if (CurrencyManager::isCurrencyExist($currency))
111 {
112 return CurrencyManager::getSymbolList()[$currency];
113 }
114
115 $this->errorCollection->add([new Error(Loc::getMessage(
116 'STORE_CHART_REPORT_UNDEFINED_CURRENCY_ERROR',
117 ['#CURRENCY#' => htmlspecialcharsbx($currency)]
118 ))]);
119
120 return '';
121 }
122
123 private static function checkDocumentReadRights(): bool
124 {
125 return AccessController::getCurrent()->check(ActionDictionary::ACTION_CATALOG_READ);
126 }
127}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29