You are here

public function JSONExporter::compile in Loft Data Grids 7.2

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

Build the string content of $this->output and return $this for chaining.

Parameters

mixed $page_id: (Optional) Defaults to NULL. Set this to only compile a single page.

Return value

$this

Overrides ExporterInterface::compile

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/JSONExporter.php, line 35

Class

JSONExporter
Class JSONExporter

Namespace

AKlump\LoftDataGrids

Code

public function compile($page_id = null) {
  $data = $this
    ->getDataAsTransformedArray($page_id, null);

  // Prune?
  if ($this
    ->getSettings()->prune) {

    // Prune pages.
    if (count($data) === 1) {
      $data = reset($data);
    }

    // Prune rows
    if (count($data) === 1) {
      $data = reset($data);
    }
  }
  $this->output = json_encode($data);
  return $this;
}