You are here

public function HTMLExporter::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/HTMLExporter.php \AKlump\LoftDataGrids\HTMLExporter::compile()

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

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

Overrides CSVExporter::compile

1 method overrides HTMLExporter::compile()
BootstrapHTMLExporter::compile in vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/BootstrapHTMLExporter.php
Build $this->output in prep for export/save

File

vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/HTMLExporter.php, line 84

Class

HTMLExporter
Class HTMLExporter

Namespace

AKlump\LoftDataGrids

Code

public function compile($page_id = NULL) {
  $pages = $this
    ->getData()
    ->get();
  if ($page_id && array_key_exists($page_id, $pages)) {
    $pages = array(
      $pages[$page_id],
    );
  }
  $tables = array();
  foreach ($pages as $page_id => $data) {
    $this->output = '';
    $this->output .= '<thead>' . $this->format->cr;
    $this->format->left = '<th>';
    $this->format->right = '</th>';
    $this->output .= $this
      ->collapseRow($this
      ->getHeader($page_id));
    $this->output .= '</thead>' . $this->format->cr;

    // Format the rows:
    $this->format->left = '<td>';
    $this->format->right = '</td>';
    $this->output .= '<tbody>' . $this->format->cr;
    foreach ($data as $column => $row) {
      $this->output .= $this
        ->collapseRow($row, $column);
    }
    $this->output .= '</tbody>' . $this->format->cr;
    $page_title = '';
    if (count($pages) > 1 && $this
      ->getShowPageIds()) {
      $page_title = '<caption>' . $page_id . '</caption>';
    }
    $tables[] = '<table>' . $page_title . $this->format->cr . $this->output . '</table>' . $this->format->cr;
  }
  $this->output = implode($this->format->cr, $tables);

  // Now decide if this is a snippet or full document
  if (!$this->format->snippet) {
    $snippet = $this->output;
    $this->output = $this->format->html;
    $this->output = str_replace('<style type="text/css"></style>', '<style type="text/css">' . $this->format->css . '</style>', $this->output);
    $this->output = str_replace('<body></body>', '<body>' . $snippet . '</body>', $this->output);
    $this->output = str_replace('<title></title>', '<title>' . $this->title . '</title>', $this->output);
  }
}