You are here

public function ExportData::normalize in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php \AKlump\LoftDataGrids\ExportData::normalize()

Normalize all rows so that they all contain the same number of columns, the column order will be taken from the order of the first column

Parameters

array|mixed $empty_value: If this is an array then you may provide default values by column key, as well as the special key `#default` which is the default value for any column whose key is not present in $empty_value. If this is not an array, then the value will be used for all empty values of all columns, rows, cells, etc.

Return value

$this

Overrides ExportDataInterface::normalize

1 call to ExportData::normalize()
ExportData::merge in vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php
Merge another ExportData object into this one

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php, line 324

Class

ExportData

Namespace

AKlump\LoftDataGrids

Code

public function normalize($empty_value) {
  foreach (array_keys($this->data) as $page_id) {
    $columns = $this
      ->getKeys($page_id);

    // Now go through and add all columns
    $column_order = array();
    foreach ($this->data[$page_id] as $key => $row) {
      if (is_array($empty_value)) {
        if (array_key_exists($key, $empty_value)) {
          $empty = $empty_value[$key];
        }
        elseif (array_key_exists('default', $empty_value)) {
          $empty = $empty_value['default'];
        }
        else {
          $empty = NULL;
        }
      }
      else {
        $empty = $empty_value;
      }
      $this->data[$page_id][$key] += array_fill_keys($columns, $empty);

      // Assure the same column order for all rows
      if (empty($column_order)) {
        $column_order = array_keys($this->data[$page_id][$key]);
      }
      $ordered = array();
      foreach ($column_order as $col_key) {
        $ordered[$col_key] = $this->data[$page_id][$key][$col_key];
      }
      $this->data[$page_id][$key] = $ordered;
    }
  }
  return $this;
}