You are here

public function ExportData::setKeys in Loft Data Grids 7.2

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

Set the data key order for the current page

Parameters

array|mixed $key:

  • If this is an array, it will be taken as the key order
  • Or, you can list individual keys in correct order as function

arguments

Return value

$this

Overrides ExportDataInterface::setKeys

2 calls to ExportData::setKeys()
ExportData::getKeys in vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ExportData.php
Return an array of all keys for current of specified page
ScheduleData::addStatsPage in vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/ScheduleData.php

File

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

Class

ExportData

Namespace

AKlump\LoftDataGrids

Code

public function setKeys($key) {
  if (is_array($key)) {
    $this->keys[$this->current_page] = $key;
  }
  else {
    $this->keys[$this->current_page] = func_get_args();
  }

  // If we have data then we need to go through and modify the order
  if (!empty($this->data[$this->current_page])) {
    foreach ($this->data[$this->current_page] as $row => $data) {
      $new_row = array();
      foreach ($this->keys[$this->current_page] as $key) {
        if (array_key_exists($key, $data)) {
          $new_row[$key] = $data[$key];
        }
      }
      $new_row += $data;
      $this->data[$this->current_page][$row] = $new_row;
    }
  }
  return $this;
}