class ArrayExporter in Loft Data Grids 7.2
Class ArrayExporter
// Use the prune setting for leaner arrays when possible. This is best when you know you are only working with one page or one page and one row, and that is consistent in your implementation.
$obj = new ArrayExporter($data);
$obj
->addSetting('prune', true);
$array = $obj
->export();
Hierarchy
- class \AKlump\LoftDataGrids\Exporter implements ExporterInterface
- class \AKlump\LoftDataGrids\ArrayExporter implements ExporterInterface
Expanded class hierarchy of ArrayExporter
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ ArrayExporter.php, line 19
Namespace
AKlump\LoftDataGridsView source
class ArrayExporter extends Exporter implements ExporterInterface {
protected $extension = '.php';
public function getInfo() {
$info = parent::getInfo();
$info = array(
'name' => 'Php Array Format',
'shortname' => 'Array',
'description' => 'Export data in PHP array format.',
) + $info;
return $info;
}
public function compile($page_id = null) {
$data = $this
->getDataAsTransformedArray();
if (!is_null($page_id) && array_key_exists($page_id, $data)) {
$data = array(
$data[$page_id],
);
}
// 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 = $data;
return $this;
}
public function saveFile($directory, $filename = null, $page_id = null) {
// Go through the setter to ensure the file_extension.
$filename = $filename ? $this
->setFilename($filename) : $this
->getFilename();
if (!is_writable($directory)) {
throw new \RuntimeException("{$directory} is not writable; cannot save {$filename}.");
}
$path = $directory . '/' . $filename;
$contents = $this
->compile($page_id)
->export();
$contents = "<?php" . PHP_EOL . var_export($contents, true) . ';' . PHP_EOL;
file_put_contents($path, $contents);
return $path;
}
protected function setSettingsDefault() {
parent::setSettingsDefault();
// When true...
// ... if there is only one page do not include a page key.
// ... if there is only one row do not include a row key.
$this->settings->prune = false;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArrayExporter:: |
protected | property | ||
ArrayExporter:: |
public | function |
Build the string content of $this->output and return $this for chaining. Overrides ExporterInterface:: |
|
ArrayExporter:: |
public | function |
Return info about this class Overrides Exporter:: |
|
ArrayExporter:: |
public | function |
Compile and and save to a filepath. Overrides Exporter:: |
|
ArrayExporter:: |
protected | function |
Setup default values on object data. Overrides Exporter:: |
|
Exporter:: |
protected | property | ||
Exporter:: |
protected | property | ||
Exporter:: |
protected | property | ||
Exporter:: |
public | function |
Adds/Updates a single setting by name. Overrides ExporterInterface:: |
|
Exporter:: |
protected | function | ||
Exporter:: |
protected | function | Iterate over all cells and transform data as appropriate. | |
Exporter:: |
public | function |
Export data as a string Overrides ExporterInterface:: |
1 |
Exporter:: |
protected | function | Return a string as a safe filename | |
Exporter:: |
public | function |
Format a single column with format by string Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Return the ExportDataInterface object Overrides ExporterInterface:: |
|
Exporter:: |
protected | function | Convert ExportData to an array transforming every cell. | |
Exporter:: |
public | function |
Get the filename Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return an array each of the keys present in the data on a page. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return the settings object. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return the showPageIds. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set the exporter to hide page ids. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Stream as a file to the server with headers. Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Set the export data object Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Getter/Setter for the filename Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set the settings object. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set a title for the exported document Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Set the exporter to display page ids. Overrides ExporterInterface:: |
|
Exporter:: |
public | function | Constructor | 5 |