You are here

public function HtmlListExporter::compile in Loft Data Grids 6.2

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

Build $this->output in prep for export/save

This is the main method to be extended for the different exporters

Overrides Exporter::compile

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/HtmlListExporter.php, line 28

Class

HtmlListExporter
Class HtmlListExporter

Namespace

AKlump\LoftDataGrids

Code

public function compile($page_id = NULL) {
  $pages = $this
    ->getData()
    ->get();
  $this->output = array();

  // Apply spacing and build output
  foreach ($pages as $page_id => $page) {
    if ($this
      ->getShowPageIds()) {
      $tag = $this
        ->getSettings()->pageTag;
      $this->output[] = "<{$tag}>{$page_id}</{$tag}>";
    }
    foreach ($page as $record) {
      $this->output[] = "<hr />";
      $class = $this
        ->cssSafe($page_id);
      $data = str_replacE('"', '\\"', $page_id);
      $this->output[] = "<table class=\"page {$class}\" data-page=\"{$data}\">";
      $this->output[] = "<tbody>";
      $odd = TRUE;
      foreach ($record as $key => $value) {
        $zebra = $odd ? 'odd' : 'even';
        $odd = !$odd;
        $this->output[] = "<tr class=\"{$zebra}\"><td class=\"key\">{$key}</td><td class=\"value\">{$value}</td></tr>";
      }
      $this->output[] = "</tbody>";
      $this->output[] = "</table>";
    }
  }
  $this->output = implode(PHP_EOL, $this->output);
}