You are here

public function MarkdownExporter::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/MarkdownExporter.php \AKlump\LoftDataGrids\MarkdownExporter::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/MarkdownExporter.php, line 21

Class

MarkdownExporter
Class MarkdownExporter

Namespace

AKlump\LoftDataGrids

Code

public function compile($page_id = NULL) {
  $pages = $this
    ->getData()
    ->get();
  $this->output = '';
  $multi = count($pages) > 1 ? '#' : '';
  $output = '';
  foreach ($pages as $page_id => $page) {
    if ($multi) {
      $output .= "{$multi}# Page " . ($page_id + 1) . "\n";
    }
    foreach ($page as $record_id => $record) {
      $index = 1;
      $output .= "{$multi}## Record " . ($record_id + 1) . "\n";
      foreach ($record as $key => $value) {
        $output .= $index++ . ". __{$key}__: {$value}\n";
      }
      $output .= "\n";
    }
    $output .= "\n";
  }
  $this->output = $output;
}