Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storeprofitgraph.php
1<?php
2
4
12
14{
15 public const ENABLE_SORTING = false;
16 public const VIEW_KEY = 'store_profit_graph';
17 public const MAX_RENDER_REPORT_COUNT = 1;
18 public const USE_IN_VISUAL_CONSTRUCTOR = false;
19
20 public function __construct()
21 {
22 parent::__construct();
23
24 $this->setLabel(Loc::getMessage('STORE_PROFIT_CHART_LABEL'));
25 $this->setDraggable(false);
26 Extension::load(["catalog.store-chart"]);
27 }
28
32 public function handlerFinallyBeforePassToView($dataFromReport)
33 {
34 $result = parent::handlerFinallyBeforePassToView($dataFromReport);
35
36 if (is_array($dataFromReport) && isset($result['valueAxes']))
37 {
38 foreach ($dataFromReport as $data)
39 {
40 if (empty($data['items']))
41 {
42 continue;
43 }
44
45 foreach ($data['items'] as $item)
46 {
47 if ($item['value'] < 0 && $result['valueAxes'][0]['minimum'] > $item['value'])
48 {
49 $result['valueAxes'][0]['minimum'] = $item['value'];
50 }
51 }
52 }
53 }
54
55 if (is_array($result['dataProvider']))
56 {
57 $result['categoryAxis']['autoGridCount'] = true;
58 $result['categoryAxis']['minHorizontalGap'] = 0;
59 $result['categoryAxis']['labelFrequency'] = ceil(count($result['dataProvider']) / 10);
60
61 foreach ($result['dataProvider'] as $k => $item)
62 {
63 if (!isset($result['dataProvider'][$k]['value_1']))
64 {
65 $result['dataProvider'][$k]['value_1'] = 0;
66 }
67 if (!isset($result['dataProvider'][$k]['value_2']))
68 {
69 $result['dataProvider'][$k]['value_2'] = 0;
70 }
71 }
72 }
73
74 if (is_array($result['graphs']))
75 {
76 $baseCurrency = CurrencyManager::getBaseCurrency();
77 foreach ($result['graphs'] as $k => $graph)
78 {
79 $result['graphs'][$k]["balloonFunction"] = "BX.Catalog.LinearGraphBalloon.renderBalloon";
80 $result['graphs'][$k]["balloon"]["borderThickness"] = 0;
81 $title = $result['graphs'][$k]['title'];
82 $amount = $dataFromReport[$k]['config']['amount'] ?? \CCurrencyLang::CurrencyFormat(0, $baseCurrency);
83 $result['graphs'][$k]["title"] = "$title ($amount)";
84 }
85 }
86
87 $result['legend']['valueText'] = '';
88 $result['legend']['align'] = 'center';
89
90 return $result;
91 }
92
96 public function getViewHandler(): BaseHandler
97 {
98 return new GraphHandler();
99 }
100}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static load($extNames)
Definition extension.php:17