|
9 | 9 |
|
10 | 10 | namespace Piwik\Plugins\SegmentEditor; |
11 | 11 |
|
12 | | -use Piwik\DataTable\Filter\CalculateEvolutionFilter; |
13 | | -use Piwik\DataTable\Renderer\Json; |
14 | | -use Piwik\Container\StaticContainer; |
15 | | -use Piwik\Log\LoggerInterface; |
16 | | -use Piwik\Period\Range; |
17 | 12 | use Piwik\Piwik; |
18 | 13 | use Piwik\Plugins\SegmentEditor; |
19 | 14 | use Piwik\Plugins\SegmentEditor\API as SegmentEditorAPI; |
20 | | -use Piwik\Plugins\VisitsSummary; |
21 | 15 | use Piwik\Request; |
22 | 16 | use Piwik\Url; |
23 | 17 | use Piwik\View; |
24 | 18 |
|
25 | 19 | class Controller extends \Piwik\Plugin\Controller |
26 | 20 | { |
27 | | - private const POSITIVE = 'positive'; |
28 | | - private const NEGATIVE = 'negative'; |
29 | | - private const STABLE = 'stable'; |
30 | | - |
31 | 21 | /** The requested period */ |
32 | 22 | protected $period; |
33 | 23 |
|
@@ -81,85 +71,11 @@ public function manageSegments(): string |
81 | 71 | return $view->render(); |
82 | 72 | } |
83 | 73 |
|
84 | | - public function getSegmentData(): string |
85 | | - { |
86 | | - $segmentDefinition = Request::fromRequest()->getStringParameter('segmentDefinition', ''); |
87 | | - Json::sendHeaderJSON(); |
88 | | - |
89 | | - try { |
90 | | - $data = VisitsSummary\API::getInstance() |
91 | | - ->get($this->idSite, $this->period, $this->strDate, $segmentDefinition) |
92 | | - ->getFirstRow()->getArrayCopy(); |
93 | | - [$previousDate] = Range::getLastDate($this->strDate, $this->period); |
94 | | - $pastNbVisits = VisitsSummary\API::getInstance() |
95 | | - ->getVisits($this->idSite, $this->period, $previousDate, $segmentDefinition) |
96 | | - ->getFirstRow()->getColumn('nb_visits'); |
97 | | - |
98 | | - $nbVisits = (int)($data['nb_visits'] ?? 0); |
99 | | - $nbActions = (int)($data['nb_actions'] ?? 0); |
100 | | - $pastNbVisits = (int)$pastNbVisits; |
101 | | - $evolutionDirection = $this->getEvolutionDirection($nbVisits, $pastNbVisits); |
102 | | - |
103 | | - return json_encode([ |
104 | | - 'nb_visits' => $nbVisits, |
105 | | - 'nb_actions' => $nbActions, |
106 | | - 'evolution_visits_direction' => $evolutionDirection, |
107 | | - 'evolution_visits_icon' => $this->getEvolutionIcon($evolutionDirection), |
108 | | - 'evolution_visits' => CalculateEvolutionFilter::calculate($nbVisits, $pastNbVisits, 0, true, false), |
109 | | - ]); |
110 | | - } catch (\Throwable $e) { |
111 | | - StaticContainer::get(LoggerInterface::class)->warning( |
112 | | - 'SegmentEditor.getSegmentData failed (idSite: {idSite}, period: {period}, date: {date}, segmentDefinition: {segmentDefinition}): {exception}', |
113 | | - [ |
114 | | - 'idSite' => $this->idSite, |
115 | | - 'period' => $this->period, |
116 | | - 'date' => $this->strDate, |
117 | | - 'segmentDefinition' => $segmentDefinition, |
118 | | - 'exception' => $e, |
119 | | - ] |
120 | | - ); |
121 | | - |
122 | | - return json_encode([ |
123 | | - 'result' => 'error', |
124 | | - 'message' => Piwik::translate('General_ErrorRequest'), |
125 | | - ]); |
126 | | - } |
127 | | - } |
128 | | - |
129 | 74 | private function isRealtimeSegment(array $segment): bool |
130 | 75 | { |
131 | 76 | return !empty($segment['definition']) && empty((int)$segment['auto_archive']); |
132 | 77 | } |
133 | 78 |
|
134 | | - protected function getEvolutionDirection(int $currentValue, int $pastValue): string |
135 | | - { |
136 | | - if ($currentValue > $pastValue) { |
137 | | - return self::POSITIVE; |
138 | | - } |
139 | | - |
140 | | - if ($currentValue < $pastValue) { |
141 | | - return self::NEGATIVE; |
142 | | - } |
143 | | - |
144 | | - return self::STABLE; |
145 | | - } |
146 | | - |
147 | | - /* |
148 | | - * @param self::POSITIVE|self::NEGATIVE|self::STABLE $direction |
149 | | - */ |
150 | | - protected function getEvolutionIcon(string $direction): string |
151 | | - { |
152 | | - if ($direction === self::POSITIVE) { |
153 | | - return 'plugins/MultiSites/images/arrow_up.png'; |
154 | | - } |
155 | | - |
156 | | - if ($direction === self::NEGATIVE) { |
157 | | - return 'plugins/MultiSites/images/arrow_down.png'; |
158 | | - } |
159 | | - |
160 | | - return 'plugins/MultiSites/images/stop.png'; |
161 | | - } |
162 | | - |
163 | 79 | protected function getSegmentSparklineUrl(array $segment): string |
164 | 80 | { |
165 | 81 | $params = $this->getGraphParamsModified([ |
|
0 commit comments