PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.8.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.8.2
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 3 months ago Access 3 months ago Application 3 months ago Archive 3 months ago ArchiveProcessor 3 months ago Archiver 2 years ago AssetManager 3 months ago Auth 6 months ago Category 6 months ago Changes 3 months ago CliMulti 1 year ago Columns 3 months ago Concurrency 3 months ago Config 3 months ago Container 3 months ago CronArchive 3 months ago DataAccess 3 months ago DataFiles 2 years ago DataTable 3 months ago Db 3 months ago DeviceDetector 1 year ago Email 2 years ago Exception 4 months ago Http 4 months ago Intl 3 months ago Log 2 years ago Mail 1 year ago Measurable 6 months ago Menu 3 months ago Metrics 3 months ago Notification 6 months ago Period 3 months ago Plugin 3 months ago Policy 3 months ago ProfessionalServices 1 year ago Report 1 year ago ReportRenderer 3 months ago Request 3 months ago Scheduler 3 months ago Segment 3 months ago Session 3 months ago Settings 3 months ago Tracker 3 months ago Translation 3 months ago Twig 1 year ago UpdateCheck 3 months ago Updater 4 months ago Updates 3 months ago Validators 1 year ago View 6 months ago ViewDataTable 3 months ago Visualization 1 year ago Widget 3 months ago .htaccess 2 years ago Access.php 3 months ago Archive.php 3 months ago ArchiveProcessor.php 4 months ago AssetManager.php 3 months ago Auth.php 6 months ago AuthResult.php 6 months ago BaseFactory.php 2 years ago Cache.php 2 years ago CacheId.php 4 months ago CliMulti.php 3 months ago Common.php 3 months ago Config.php 3 months ago Console.php 3 months ago Context.php 2 years ago Cookie.php 1 year ago CronArchive.php 3 months ago DI.php 3 months ago DataArray.php 5 months ago DataTable.php 3 months ago Date.php 3 months ago Db.php 3 months ago DbHelper.php 3 months ago Development.php 1 year ago ErrorHandler.php 6 months ago EventDispatcher.php 1 year ago ExceptionHandler.php 4 months ago FileIntegrity.php 3 months ago Filechecks.php 1 year ago Filesystem.php 3 months ago FrontController.php 4 months ago Http.php 4 months ago IP.php 1 year ago Log.php 3 months ago LogDeleter.php 1 year ago Mail.php 1 year ago Metrics.php 3 months ago NoAccessException.php 2 years ago Nonce.php 6 months ago Notification.php 6 months ago NumberFormatter.php 5 months ago Option.php 5 months ago Period.php 3 months ago Piwik.php 3 months ago Plugin.php 3 months ago Process.php 1 year ago Profiler.php 6 months ago ProxyHeaders.php 4 months ago ProxyHttp.php 5 months ago QuickForm2.php 3 months ago RankingQuery.php 5 months ago ReportRenderer.php 3 months ago Request.php 3 months ago Segment.php 3 months ago Sequence.php 6 months ago Session.php 3 months ago SettingsPiwik.php 3 months ago SettingsServer.php 1 year ago Singleton.php 2 years ago Site.php 4 months ago SiteContentDetector.php 3 months ago SupportedBrowser.php 2 years ago TCPDF.php 1 year ago Theme.php 1 year ago Timer.php 2 years ago Tracker.php 3 months ago Twig.php 3 months ago Unzip.php 1 year ago UpdateCheck.php 3 months ago Updater.php 3 months ago UpdaterErrorException.php 2 years ago Updates.php 3 months ago Url.php 3 months ago UrlHelper.php 3 months ago Version.php 3 months ago View.php 3 months ago bootstrap.php 1 year ago dispatch.php 2 years ago testMinimumPhpVersion.php 6 months ago
DataArray.php
333 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 *
65 * @return void
66 */
67 protected function doSumVisitsMetrics($newRowToAdd, &$oldRowToUpdate)
68 {
69 // Pre 1.2 format: string indexed rows are returned from the DB
70 // Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string
71 if (!isset($newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS])) {
72 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits'];
73 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions'];
74 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors'];
75 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_USERS] += $newRowToAdd['nb_users'];
76 $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS] = (float) max($newRowToAdd['max_actions'], $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS]);
77 $oldRowToUpdate[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH] += $newRowToAdd['sum_visit_length'];
78 $oldRowToUpdate[\Piwik\Metrics::INDEX_BOUNCE_COUNT] += $newRowToAdd['bounce_count'];
79 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED] += $newRowToAdd['nb_visits_converted'];
80 return;
81 }
82 // Edge case fail safe
83 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS])) {
84 return;
85 }
86 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
87 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_ACTIONS];
88 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
89 // In case the existing Row had no action metrics (eg. Custom Variable XYZ with "visit" scope)
90 // but the new Row has action metrics (eg. same Custom Variable XYZ this time with a "page" scope)
91 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS])) {
92 $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);
93 foreach ($toZero as $metric) {
94 $oldRowToUpdate[$metric] = 0;
95 }
96 }
97 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_USERS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_USERS];
98 $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS] = (float) max($newRowToAdd[\Piwik\Metrics::INDEX_MAX_ACTIONS], $oldRowToUpdate[\Piwik\Metrics::INDEX_MAX_ACTIONS]);
99 $oldRowToUpdate[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH] += $newRowToAdd[\Piwik\Metrics::INDEX_SUM_VISIT_LENGTH];
100 $oldRowToUpdate[\Piwik\Metrics::INDEX_BOUNCE_COUNT] += $newRowToAdd[\Piwik\Metrics::INDEX_BOUNCE_COUNT];
101 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS_CONVERTED];
102 }
103 /**
104 * Adds the given row $newRowToAdd to the existing $oldRowToUpdate passed by reference
105 * The rows are php arrays Name => value
106 *
107 * @param array $newRowToAdd
108 * @param array $oldRowToUpdate
109 *
110 * @return void
111 */
112 protected function doSumActionsMetrics($newRowToAdd, &$oldRowToUpdate)
113 {
114 // Pre 1.2 format: string indexed rows are returned from the DB
115 // Left here for Backward compatibility with plugins doing custom SQL queries using these metrics as string
116 if (!isset($newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS])) {
117 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd['nb_visits'];
118 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd['nb_actions'];
119 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd['nb_uniq_visitors'];
120 return;
121 }
122 // Edge case fail safe
123 if (!isset($oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS])) {
124 return;
125 }
126 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
127 if (array_key_exists(\Piwik\Metrics::INDEX_NB_ACTIONS, $newRowToAdd)) {
128 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_ACTIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_ACTIONS];
129 }
130 if (array_key_exists(\Piwik\Metrics::INDEX_PAGE_NB_HITS, $newRowToAdd)) {
131 if (!array_key_exists(\Piwik\Metrics::INDEX_PAGE_NB_HITS, $oldRowToUpdate)) {
132 $oldRowToUpdate[\Piwik\Metrics::INDEX_PAGE_NB_HITS] = 0;
133 }
134 $oldRowToUpdate[\Piwik\Metrics::INDEX_PAGE_NB_HITS] += $newRowToAdd[\Piwik\Metrics::INDEX_PAGE_NB_HITS];
135 }
136 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
137 }
138 public function sumMetricsGoals($label, $row)
139 {
140 $idGoal = $row['idgoal'];
141 if (!isset($this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal])) {
142 $this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal);
143 }
144 $this->doSumGoalsMetrics($row, $this->data[$label][\Piwik\Metrics::INDEX_GOALS][$idGoal]);
145 }
146 /**
147 * @param $idGoal
148 * @return array
149 */
150 protected static function makeEmptyGoalRow($idGoal)
151 {
152 if ($idGoal > GoalManager::IDGOAL_ORDER) {
153 return array(\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS => 0, \Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED => 0, \Piwik\Metrics::INDEX_GOAL_REVENUE => 0);
154 }
155 if ($idGoal == GoalManager::IDGOAL_ORDER) {
156 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);
157 }
158 // idGoal == GoalManager::IDGOAL_CART
159 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);
160 }
161 /**
162 *
163 * @param $newRowToAdd
164 * @param $oldRowToUpdate
165 */
166 protected function doSumGoalsMetrics($newRowToAdd, &$oldRowToUpdate)
167 {
168 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_NB_CONVERSIONS];
169 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_NB_VISITS_CONVERTED];
170 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_REVENUE] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_REVENUE];
171 // Cart & Order
172 if (isset($oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS])) {
173 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_ITEMS];
174 // Order only
175 if (isset($oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL])) {
176 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL];
177 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX];
178 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING];
179 $oldRowToUpdate[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT] += $newRowToAdd[\Piwik\Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT];
180 }
181 }
182 }
183 public function sumMetricsActions($label, $row)
184 {
185 if (!isset($this->data[$label])) {
186 $this->data[$label] = static::makeEmptyActionRow();
187 }
188 $this->doSumActionsMetrics($row, $this->data[$label]);
189 }
190 protected static function makeEmptyActionRow()
191 {
192 return array(\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS => 0, \Piwik\Metrics::INDEX_NB_VISITS => 0, \Piwik\Metrics::INDEX_NB_ACTIONS => 0);
193 }
194 public function sumMetricsEvents($label, $row)
195 {
196 if (!isset($this->data[$label])) {
197 $this->data[$label] = static::makeEmptyEventRow();
198 }
199 $this->doSumEventsMetrics($row, $this->data[$label]);
200 }
201 protected static function makeEmptyEventRow()
202 {
203 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);
204 }
205 public const EVENT_VALUE_PRECISION = 2;
206 /**
207 * @param array $newRowToAdd
208 * @param array $oldRowToUpdate
209 * @return void
210 */
211 protected function doSumEventsMetrics($newRowToAdd, &$oldRowToUpdate)
212 {
213 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_VISITS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_VISITS];
214 $oldRowToUpdate[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[\Piwik\Metrics::INDEX_NB_UNIQ_VISITORS];
215 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_NB_HITS] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_NB_HITS];
216 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_NB_HITS_WITH_VALUE];
217 $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE] = round($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE], static::EVENT_VALUE_PRECISION);
218 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE] += $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_SUM_EVENT_VALUE];
219 $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);
220 // Update minimum only if it is set
221 if ($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== \false && $newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== null) {
222 if ($oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] === \false) {
223 $oldRowToUpdate[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE] = round($newRowToAdd[\Piwik\Metrics::INDEX_EVENT_MIN_EVENT_VALUE], static::EVENT_VALUE_PRECISION);
224 } else {
225 $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);
226 }
227 }
228 }
229 /**
230 * Generic function that will sum all columns of the given row, at the specified label's row.
231 *
232 * @param $label
233 * @param $row
234 * @throws Exception if the the data row contains non numeric values
235 */
236 public function sumMetrics($label, $row)
237 {
238 foreach ($row as $columnName => $columnValue) {
239 if (empty($columnValue)) {
240 continue;
241 }
242 if (empty($this->data[$label][$columnName])) {
243 $this->data[$label][$columnName] = 0;
244 }
245 if (!is_numeric($columnValue)) {
246 throw new Exception("DataArray->sumMetricsPivot expects rows of numeric values, non numeric found: " . var_export($columnValue, \true) . " for column {$columnName}");
247 }
248 $this->data[$label][$columnName] += $columnValue;
249 }
250 }
251 public function sumMetricsVisitsPivot($parentLabel, $label, $row)
252 {
253 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
254 $this->dataTwoLevels[$parentLabel][$label] = static::makeEmptyRow();
255 }
256 $this->doSumVisitsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
257 }
258 public function sumMetricsGoalsPivot($parentLabel, $label, $row)
259 {
260 $idGoal = $row['idgoal'];
261 if (!isset($this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal])) {
262 $this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal] = static::makeEmptyGoalRow($idGoal);
263 }
264 $this->doSumGoalsMetrics($row, $this->dataTwoLevels[$parentLabel][$label][\Piwik\Metrics::INDEX_GOALS][$idGoal]);
265 }
266 public function sumMetricsActionsPivot($parentLabel, $label, $row)
267 {
268 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
269 $this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyActionRow();
270 }
271 $this->doSumActionsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
272 }
273 public function sumMetricsEventsPivot($parentLabel, $label, $row)
274 {
275 if (!isset($this->dataTwoLevels[$parentLabel][$label])) {
276 $this->dataTwoLevels[$parentLabel][$label] = $this->makeEmptyEventRow();
277 }
278 $this->doSumEventsMetrics($row, $this->dataTwoLevels[$parentLabel][$label]);
279 }
280 public function setRowColumnPivot($parentLabel, $label, $column, $value)
281 {
282 $this->dataTwoLevels[$parentLabel][$label][$column] = $value;
283 }
284 public function enrichMetricsWithConversions()
285 {
286 $this->enrichWithConversions($this->data);
287 foreach ($this->dataTwoLevels as &$metricsBySubLabel) {
288 $this->enrichWithConversions($metricsBySubLabel);
289 }
290 }
291 /**
292 * Given an array of stats, it will process the sum of goal conversions
293 * and sum of revenue and add it in the stats array in two new fields.
294 *
295 * @param array $data Passed by reference, two new columns
296 * will be added: total conversions, and total revenue, for all goals for this label/row
297 */
298 protected function enrichWithConversions(&$data)
299 {
300 foreach ($data as &$values) {
301 EnrichRecordWithGoalMetricSums::enrichWithConversions($values);
302 }
303 }
304 /**
305 * Returns true if the row looks like an Action metrics row
306 *
307 * @param $row
308 * @return bool
309 */
310 public static function isRowActions($row)
311 {
312 return count($row) == count(static::makeEmptyActionRow()) && isset($row[\Piwik\Metrics::INDEX_NB_ACTIONS]);
313 }
314 /**
315 * Converts array to a datatable
316 *
317 * @return \Piwik\DataTable
318 */
319 public function asDataTable()
320 {
321 $dataArray = $this->getDataArray();
322 $dataArrayTwoLevels = $this->getDataArrayWithTwoLevels();
323 $subtableByLabel = null;
324 if (!empty($dataArrayTwoLevels)) {
325 $subtableByLabel = array();
326 foreach ($dataArrayTwoLevels as $label => $subTable) {
327 $subtableByLabel[$label] = \Piwik\DataTable::makeFromIndexedArray($subTable);
328 }
329 }
330 return \Piwik\DataTable::makeFromIndexedArray($dataArray, $subtableByLabel);
331 }
332 }
333