You are here

protected function MatomoBase::buildDateRows in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php \Drupal\dashboards_matomo\Plugin\Dashboard\MatomoBase::buildDateRows()

Helper function for build rows from matomo.

Parameters

mixed $response: Data from matomo.

string $label: Label for display.

array $column: Columns to show.

File

modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php, line 126

Class

MatomoBase
Base class for matomo plugins.

Namespace

Drupal\dashboards_matomo\Plugin\Dashboard

Code

protected function buildDateRows($response, $label, array $column) {
  $labels = [
    $label,
  ];
  foreach ($response as $date => &$row) {
    foreach ($row as $key => $r) {
      $labels[$r['label']] = $r['label'];
      unset($row[$key]);
      $row[$r['label']] = $r;
      uksort($row, function ($a, $b) {
        return strcmp($a, $b);
      });
    }
  }
  $items = [];
  foreach ($response as $date => &$row) {
    $item = [
      $date,
    ];
    if (empty($row)) {
      if (is_array($column)) {
        foreach ($column as $c) {
          $item[] = 0;
        }
        continue;
      }
      $item[] = 0;
    }
    foreach ($row as $r) {
      if (is_array($column)) {
        foreach ($column as $c) {
          $item[] = $r[$c];
        }
        continue;
      }
      $item[] = $r[$column];
    }
    $items[] = $item;
  }
  $this
    ->setRows($items);
  $this
    ->setLabels($labels);
}