public function TextListExporter::compile in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/aklump/loft_data_grids/src/AKlump/LoftDataGrids/TextListExporter.php \AKlump\LoftDataGrids\TextListExporter::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/ TextListExporter.php, line 26
Class
- TextListExporter
- Class TextListExporter
Namespace
AKlump\LoftDataGridsCode
public function compile($page_id = null) {
$pages = $this
->getData()
->get();
$this->output = '';
$output = '';
$longest_key = $longest_value = 0;
// Determine spacing
foreach ($pages as $page_id => $page) {
foreach ($page as $record) {
foreach ($record as $key => $value) {
$longest_key = max($longest_key, strlen($key));
$longest_value = max($longest_value, strlen($value));
}
}
}
// Apply spacing and build output
foreach ($pages as $page_id => $page) {
if ($this
->getShowPageIds()) {
$output .= $page_id . PHP_EOL;
}
foreach ($page as $record) {
$output .= "<hr />\n";
foreach ($record as $key => $value) {
$output .= str_pad($key, $longest_key, $this->pad_char) . $this->separator . $value . PHP_EOL;
}
$output .= "\n";
}
$output .= "\n";
}
$line_break = str_repeat($this->line_break, $longest_key + strlen($this->separator) + $longest_value + 2);
$output = str_replace('<hr />', $line_break, $output);
$this->output = $output;
return $this;
}