datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
<?php
|
|
|
|
|
|
namespace App\Tables;
|
|
|
|
|
|
class JsonExporter extends BaseExporter
|
|
{
|
|
private $fullJsDoc = false;
|
|
|
|
public function withJsWrapper()
|
|
{
|
|
$this->fullJsDoc = true;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string - mime type for the downloaded file
|
|
*/
|
|
protected function getMimeType()
|
|
{
|
|
return $this->fullJsDoc ? 'application/javascript' : 'application/json';
|
|
}
|
|
|
|
/**
|
|
* @return string - file extension for the downloaded file
|
|
*/
|
|
protected function getFileExtension()
|
|
{
|
|
return 'json';
|
|
}
|
|
|
|
/**
|
|
* Write the document to stdout ('php://output')
|
|
*/
|
|
protected function writeDocument()
|
|
{
|
|
if ($this->fullJsDoc) {
|
|
echo "/*\n" . $this->getHeaderComment(' ') . "*/\n\n";
|
|
|
|
echo 'module.exports = ';
|
|
}
|
|
|
|
echo "[\n";
|
|
|
|
$first = true;
|
|
foreach ($this->iterateRows() as $row) {
|
|
if ($first) {
|
|
$first = false;
|
|
} else {
|
|
echo ",\n";
|
|
}
|
|
echo ' '.json_encode($row, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
|
}
|
|
|
|
echo "\n]\n";
|
|
}
|
|
}
|
|
|