getMetric() public static method

Helper method that will access a metric in a {@link Piwik\DataTable\Row} or array either by its name or by its special numerical index value.
public static getMetric ( Row | array $row, string $columnName, int[] | null $mappingNameToId = null ) : mixed
$row Piwik\DataTable\Row | array
$columnName string
$mappingNameToId int[] | null A custom mapping of metric names to special index values. By default {@link Metrics::getMappingFromNameToId()} is used.
return mixed The metric value or false if none exists.
コード例 #1
0
 private function deleteRowsWithNoVisit(DataTable $table)
 {
     foreach ($table->getRows() as $key => $row) {
         $nbVisits = Metric::getMetric($row, 'nb_visits');
         $nbActions = Metric::getMetric($row, 'nb_actions');
         if ($nbVisits == 0 && $nbActions == 0) {
             // case of keyword/website/campaign with a conversion for this day, but no visit, we don't show it
             $table->deleteRow($key);
         }
     }
 }
コード例 #2
0
 private function getGoalsInTable(DataTable $table)
 {
     $result = array();
     foreach ($table->getRows() as $row) {
         $goals = Metric::getMetric($row, 'goals');
         if (!$goals) {
             continue;
         }
         foreach ($goals as $goalId => $goalMetrics) {
             $goalId = str_replace("idgoal=", "", $goalId);
             $result[] = $goalId;
         }
     }
     return array_unique($result);
 }