PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.1.4
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.1.4
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / DataArray.php
matomo / app / core Last commit date
API 2 years ago Access 2 years ago Application 2 years ago Archive 2 years ago ArchiveProcessor 2 years ago Archiver 2 years ago AssetManager 2 years ago Auth 2 years ago Category 2 years ago Changes 2 years ago CliMulti 2 years ago Columns 2 years ago Concurrency 2 years ago Config 2 years ago Container 2 years ago CronArchive 2 years ago DataAccess 2 years ago DataFiles 2 years ago DataTable 2 years ago Db 1 year ago DeviceDetector 2 years ago Email 2 years ago Exception 2 years ago Http 2 years ago Intl 2 years ago Log 2 years ago Mail 2 years ago Measurable 2 years ago Menu 2 years ago Metrics 2 years ago Notification 2 years ago Period 1 year ago Plugin 2 years ago ProfessionalServices 2 years ago Report 2 years ago ReportRenderer 2 years ago Scheduler 2 years ago Segment 2 years ago Session 2 years ago Settings 2 years ago Tracker 1 year ago Translation 2 years ago Twig 2 years ago UpdateCheck 2 years ago Updater 1 year ago Updates 1 year ago Validators 2 years ago View 2 years ago ViewDataTable 2 years ago Visualization 2 years ago Widget 2 years ago .htaccess 2 years ago Access.php 2 years ago Archive.php 2 years ago ArchiveProcessor.php 2 years ago AssetManager.php 2 years ago Auth.php 2 years ago AuthResult.php 2 years ago BaseFactory.php 2 years ago Cache.php 2 years ago CacheId.php 2 years ago CliMulti.php 2 years ago Common.php 2 years ago Config.php 2 years ago Console.php 2 years ago Context.php 2 years ago Cookie.php 2 years ago CronArchive.php 2 years ago DI.php 2 years ago DataArray.php 2 years ago DataTable.php 2 years ago Date.php 2 years ago Db.php 1 year ago DbHelper.php 1 year ago Development.php 2 years ago ErrorHandler.php 2 years ago EventDispatcher.php 2 years ago ExceptionHandler.php 2 years ago FileIntegrity.php 2 years ago Filechecks.php 2 years ago Filesystem.php 2 years ago FrontController.php 2 years ago Http.php 2 years ago IP.php 2 years ago Log.php 2 years ago LogDeleter.php 2 years ago Mail.php 2 years ago Metrics.php 2 years ago NoAccessException.php 2 years ago Nonce.php 2 years ago Notification.php 2 years ago NumberFormatter.php 2 years ago Option.php 2 years ago Period.php 2 years ago Piwik.php 2 years ago Plugin.php 2 years ago Profiler.php 2 years ago ProxyHeaders.php 2 years ago ProxyHttp.php 2 years ago QuickForm2.php 2 years ago RankingQuery.php 2 years ago ReportRenderer.php 2 years ago Request.php 2 years ago Segment.php 2 years ago Sequence.php 2 years ago Session.php 2 years ago SettingsPiwik.php 2 years ago SettingsServer.php 2 years ago Singleton.php 2 years ago Site.php 2 years ago SiteContentDetector.php 2 years ago SupportedBrowser.php 2 years ago TCPDF.php 2 years ago Theme.php 2 years ago Timer.php 2 years ago Tracker.php 2 years ago Twig.php 2 years ago Unzip.php 2 years ago UpdateCheck.php 2 years ago Updater.php 2 years ago UpdaterErrorException.php 2 years ago Updates.php 2 years ago Url.php 2 years ago UrlHelper.php 1 year ago Version.php 1 year ago View.php 2 years ago bootstrap.php 2 years ago dispatch.php 2 years ago testMinimumPhpVersion.php 2 years ago
DataArray.php
335 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik;
10
11 use Exception;
12 use Piwik\DataTable\Filter\EnrichRecordWithGoalMetricSums;
13 use Piwik\Tracker\GoalManager;
14 /**
15 * The DataArray is a data structure used to aggregate datasets,
16 * ie. sum arrays made of rows made of columns,
17 * data from the logs is stored in a DataArray before being converted in a DataTable
18 *
19 */
20 class DataArray
21 {
22 protected $data = array();
23 protected $dataTwoLevels = array();
24 public function __construct($data = array(), $dataArrayByLabel = array())
25 {
26 $this->data = $data;
27 $this->dataTwoLevels = $dataArrayByLabel;
28 }
29 /**
30 * This returns the actual raw data array
31 *
32 * @return array
33 */
34 public function &getDataArray()
35 {
36 return $this->data;
37 }
38 public function getDataArrayWithTwoLevels()
39 {
40 return $this->dataTwoLevels;
41 }
42 public function sumMetricsVisits($label, $row)
43 {
44 if (!isset($this->data[$label])) {
45 $this->data[$label] = static::makeEmptyRow();
46 }
47 $this->doSumVisitsMetrics($row, $this->data[$label]);
48 }
49 /**
50 * Returns an empty row containing default metrics
51 *
52 * @return array
53 */
54 public static function makeEmptyRow()
55 {
56 return array(\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS => 0, \Piwik\Metrics::INDEX_NB_VISITS => 0, \Piwik\Metrics::INDEX_NB_ACTIONS => 0, \Piwik\Metrics::INDEX_NB_USERS => 0, \Piwik\Metrics::INDEX_MAX_ACTIONS => 0, \Piwik\Metrics::INDEX_SUM_VISIT_LENGTH => 0, \Piwik\Metrics::INDEX_BOUNCE_COUNT => 0, \Piwik\Metrics::INDEX_NB_VISITS_CONVERTED => 0);
57 }
58 /**
59 * Adds the given row $newRowToAdd to the existing $oldRowToUpdate passed by reference
60 * The rows are php arrays Name => value
61 *
62 * @param array $newRowToAdd
63 * @param array $oldRowToUpdate
64 * @param bool $onlyMetricsAvailableInActionsTable
65 *
66 * @return void
67 */
68 protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate)
69 {
70 // Pre 1.2 format: string indexed rows are returned from the DB
71 // Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string
72 if (!isset($newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS])) {
73 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits'];
74 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions'];
75 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors'];
76 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_USERS] += $newRowToAdd['nb_users'];
77 $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS] = (float) max($newRowToAdd['max_actions'], $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS]);
78 $oldRowToUpdate[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH] += $newRowToAdd['sum_visit_length'];
79 $oldRowToUpdate[\Piwik\Metrics::INDEX_BOUNCE_COUNT] += $newRowToAdd['bounce_count'];
80 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED] += $newRowToAdd['nb_visits_converted'];
81 return;
82 }
83 // Edge case fail safe
84 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS])) {
85 return;
86 }
87 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
88 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_ACTIONS];
89 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
90 // In case the existing Row had no action metrics (eg. Custom Variable XYZ with "visit" scope)
91 // but the new Row has action metrics (eg. same Custom Variable XYZ this time with a "page" scope)
92 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS])) {
93 $toZero = array(\Piwik\Metrics::INDEX_NB_USERS, \Piwik\Metrics::INDEX_MAX_ACTIONS, \Piwik\Metrics::INDEX_SUM_VISIT_LENGTH, \Piwik\Metrics::INDEX_BOUNCE_COUNT, \Piwik\Metrics::INDEX_NB_VISITS_CONVERTED);
94 foreach ($toZero as $metric) {
95 $oldRowToUpdate[$metric] = 0;
96 }
97 }
98 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_USERS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_USERS];
99 $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS] = (float) max($newRowToAdd[\Piwik\Metrics::INDEX_MAX_ACTIONS], $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS]);
100 $oldRowToUpdate[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH] += $newRowToAdd[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH];
101 $oldRowToUpdate[\Piwik\Metrics::INDEX_BOUNCE_COUNT] += $newRowToAdd[\Piwik\Metrics::INDEX_BOUNCE_COUNT];
102 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED];
103 }
104 /**
105 * Adds the given row $newRowToAdd to the existing $oldRowToUpdate passed by reference
106 * The rows are php arrays Name => value
107 *
108 * @param array $newRowToAdd
109 * @param array $oldRowToUpdate
110 * @param bool $onlyMetricsAvailableInActionsTable
111 *
112 * @return void
113 */
114 protected function doSumActionsMetrics($newRowToAdd, &$oldRowToUpdate)
115 {
116 // Pre 1.2 format: string indexed rows are returned from the DB
117 // Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string
118 if (!isset($newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS])) {
119 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits'];
120 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions'];
121 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors'];
122 return;
123 }
124 // Edge case fail safe
125 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS])) {
126 return;
127 }
128 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
129 if (array_key_exists(\Piwik\Metrics::INDEX_NB_ACTIONS, $newRowToAdd)) {
130 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_ACTIONS];
131 }
132 if (array_key_exists(\Piwik\Metrics::INDEX_PAGE_NB_HITS, $newRowToAdd)) {
133 if (!array_key_exists(\Piwik\Metrics::INDEX_PAGE_NB_HITS, $oldRowToUpdate)) {
134 $oldRowToUpdate[\Piwik\Metrics::INDEX_PAGE_NB_HITS] = 0;
135 }
136 $oldRowToUpdate[\Piwik\Metrics::INDEX_PAGE_NB_HITS] += $newRowToAdd[\Piwik\Metrics::INDEX_PAGE_NB_HITS];
137 }
138 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
139 }
140 public function sumMetricsGoals($label, $row)
141 {
142 $idGoal = $row['idgoal'];
143 if (!isset($this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal])) {
144 $this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal);
145 }
146 $this->doSumGoalsMetrics($row, $this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal]);
147 }
148 /**
149 * @param $idGoal
150 * @return array
151 */
152 protected static function makeEmptyGoalRow($idGoal)
153 {
154 if ($idGoal > GoalManager::IDGOAL_ORDER) {
155 return array(\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS => 0, \Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 0, \Piwik\Metrics::INDEX_GOAL_REVENUE => 0);
156 }
157 if ($idGoal == GoalManager::IDGOAL_ORDER) {
158 return array(\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS => 0, \Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 0, \Piwik\Metrics::INDEX_GOAL_REVENUE => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS => 0);
159 }
160 // idGoal == GoalManager::IDGOAL_CART
161 return array(\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS => 0, \Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 0, \Piwik\Metrics::INDEX_GOAL_REVENUE => 0, \Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS => 0);
162 }
163 /**
164 *
165 * @param $newRowToAdd
166 * @param $oldRowToUpdate
167 */
168 protected function doSumGoalsMetrics($newRowToAdd, &$oldRowToUpdate)
169 {
170 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS];
171 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED];
172 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_REVENUE] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_REVENUE];
173 // Cart & Order
174 if (isset($oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS])) {
175 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS];
176 // Order only
177 if (isset($oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL])) {
178 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL];
179 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX];
180 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING];
181 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT];
182 }
183 }
184 }
185 public function sumMetricsActions($label, $row)
186 {
187 if (!isset($this->data[$label])) {
188 $this->data[$label] = static::makeEmptyActionRow();
189 }
190 $this->doSumActionsMetrics($row, $this->data[$label]);
191 }
192 protected static function makeEmptyActionRow()
193 {
194 return array(\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS => 0, \Piwik\Metrics::INDEX_NB_VISITS => 0, \Piwik\Metrics::INDEX_NB_ACTIONS => 0);
195 }
196 public function sumMetricsEvents($label, $row)
197 {
198 if (!isset($this->data[$label])) {
199 $this->data[$label] = static::makeEmptyEventRow();
200 }
201 $this->doSumEventsMetrics($row, $this->data[$label], $onlyMetricsAvailableInActionsTable = true);
202 }
203 protected static function makeEmptyEventRow()
204 {
205 return array(\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS => 0, \Piwik\Metrics::INDEX_NB_VISITS => 0, \Piwik\Metrics::INDEX_EVENT_NB_HITS => 0, \Piwik\Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE => 0, \Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE => 0, \Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE => false, \Piwik\Metrics::INDEX_EVENT_MAX_EVENT_VALUE => 0);
206 }
207 public const EVENT_VALUE_PRECISION = 2;
208 /**
209 * @param array $newRowToAdd
210 * @param array $oldRowToUpdate
211 * @return void
212 */
213 protected function doSumEventsMetrics($newRowToAdd, &$oldRowToUpdate)
214 {
215 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
216 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
217 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_NB_HITS] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_NB_HITS];
218 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE];
219 $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE] = round($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE], static::EVENT_VALUE_PRECISION);
220 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE];
221 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MAX_EVENT_VALUE] = round(max(0, $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MAX_EVENT_VALUE], $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MAX_EVENT_VALUE]), static::EVENT_VALUE_PRECISION);
222 // Update minimum only if it is set
223 if ($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false && $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== null) {
224 if ($oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] === false) {
225 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE], static::EVENT_VALUE_PRECISION);
226 } else {
227 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round(min($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE], $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE]), static::EVENT_VALUE_PRECISION);
228 }
229 }
230 }
231 /**
232 * Generic function that will sum all columns of the given row, at the specified label's row.
233 *
234 * @param $label
235 * @param $row
236 * @throws Exception if the the data row contains non numeric values
237 */
238 public function sumMetrics($label, $row)
239 {
240 foreach ($row as $columnName => $columnValue) {
241 if (empty($columnValue)) {
242 continue;
243 }
244 if (empty($this->data[$label][$columnName])) {
245 $this->data[$label][$columnName] = 0;
246 }
247 if (!is_numeric($columnValue)) {
248 throw new Exception("DataArray->sumMetricsPivot expects rows of numeric values, non numeric found: " . var_export($columnValue, true) . " for column {$columnName}");
249 }
250 $this->data[$label][$columnName] += $columnValue;
251 }
252 }
253 public function sumMetricsVisitsPivot($parentLabel, $label, $row)
254 {
255 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
256 $this->dataTwoLevels[$parentLabel][$label] = static::makeEmptyRow();
257 }
258 $this->doSumVisitsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
259 }
260 public function sumMetricsGoalsPivot($parentLabel, $label, $row)
261 {
262 $idGoal = $row['idgoal'];
263 if (!isset($this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal])) {
264 $this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal);
265 }
266 $this->doSumGoalsMetrics($row, $this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal]);
267 }
268 public function sumMetricsActionsPivot($parentLabel, $label, $row)
269 {
270 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
271 $this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyActionRow();
272 }
273 $this->doSumActionsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
274 }
275 public function sumMetricsEventsPivot($parentLabel, $label, $row)
276 {
277 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
278 $this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyEventRow();
279 }
280 $this->doSumEventsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
281 }
282 public function setRowColumnPivot($parentLabel, $label, $column, $value)
283 {
284 $this->dataTwoLevels[$parentLabel][$label][$column] = $value;
285 }
286 public function enrichMetricsWithConversions()
287 {
288 $this->enrichWithConversions($this->data);
289 foreach ($this->dataTwoLevels as &$metricsBySubLabel) {
290 $this->enrichWithConversions($metricsBySubLabel);
291 }
292 }
293 /**
294 * Given an array of stats, it will process the sum of goal conversions
295 * and sum of revenue and add it in the stats array in two new fields.
296 *
297 * @param array $data Passed by reference, two new columns
298 * will be added: total conversions, and total revenue, for all goals for this label/row
299 */
300 protected function enrichWithConversions(&$data)
301 {
302 foreach ($data as &$values) {
303 EnrichRecordWithGoalMetricSums::enrichWithConversions($values);
304 }
305 }
306 /**
307 * Returns true if the row looks like an Action metrics row
308 *
309 * @param $row
310 * @return bool
311 */
312 public static function isRowActions($row)
313 {
314 return count($row) == count(static::makeEmptyActionRow()) && isset($row[\Piwik\Metrics::INDEX_NB_ACTIONS]);
315 }
316 /**
317 * Converts array to a datatable
318 *
319 * @return \Piwik\DataTable
320 */
321 public function asDataTable()
322 {
323 $dataArray = $this->getDataArray();
324 $dataArrayTwoLevels = $this->getDataArrayWithTwoLevels();
325 $subtableByLabel = null;
326 if (!empty($dataArrayTwoLevels)) {
327 $subtableByLabel = array();
328 foreach ($dataArrayTwoLevels as $label => $subTable) {
329 $subtableByLabel[$label] = \Piwik\DataTable::makeFromIndexedArray($subTable);
330 }
331 }
332 return \Piwik\DataTable::makeFromIndexedArray($dataArray, $subtableByLabel);
333 }
334 }
335