add JSON export renderer
This commit is contained in:
parent
ea77239510
commit
74edceafc8
51
Application/Model/ExportRenderer/Json.php
Normal file
51
Application/Model/ExportRenderer/Json.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\DataWizard\Application\Model\ExportRenderer;
|
||||||
|
|
||||||
|
use D3\DataWizard\Application\Model\Exceptions\RenderException;
|
||||||
|
|
||||||
|
class Json implements RendererInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $rows
|
||||||
|
* @param $fieldNames
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws RenderException
|
||||||
|
*/
|
||||||
|
public function getContent($rows, $fieldNames): string
|
||||||
|
{
|
||||||
|
$flags = JSON_PRETTY_PRINT;
|
||||||
|
$json = json_encode( $rows, $flags );
|
||||||
|
if ( $json === false ) {
|
||||||
|
throw oxNew( RenderException::class, json_last_error_msg(), json_last_error());
|
||||||
|
}
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFileExtension(): string
|
||||||
|
{
|
||||||
|
return 'json';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTitleTranslationId(): string
|
||||||
|
{
|
||||||
|
return "D3_DATAWIZARD_EXPORT_FORMAT_JSON";
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ class RendererBridge
|
|||||||
{
|
{
|
||||||
const FORMAT_CSV = 'CSV';
|
const FORMAT_CSV = 'CSV';
|
||||||
const FORMAT_PRETTY = 'Pretty';
|
const FORMAT_PRETTY = 'Pretty';
|
||||||
|
const FORMAT_JSON = 'JSON';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
@ -29,7 +30,8 @@ class RendererBridge
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
self::FORMAT_CSV => oxNew(Csv::class),
|
self::FORMAT_CSV => oxNew(Csv::class),
|
||||||
self::FORMAT_PRETTY => oxNew(Pretty::class)
|
self::FORMAT_PRETTY => oxNew(Pretty::class),
|
||||||
|
self::FORMAT_JSON => oxNew(Json::class)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ $aLang = array(
|
|||||||
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'Export starten',
|
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'Export starten',
|
||||||
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV-Format',
|
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV-Format',
|
||||||
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty-Format',
|
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty-Format',
|
||||||
|
'D3_DATAWIZARD_EXPORT_FORMAT_JSON' => 'JSON-Format',
|
||||||
|
|
||||||
'D3_DATAWIZARD_ACTION_SUBMIT' => 'Aktion starten',
|
'D3_DATAWIZARD_ACTION_SUBMIT' => 'Aktion starten',
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ $aLang = array(
|
|||||||
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'generate export',
|
'D3_DATAWIZARD_EXPORT_SUBMIT' => 'generate export',
|
||||||
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV format',
|
'D3_DATAWIZARD_EXPORT_FORMAT_CSV' => 'CSV format',
|
||||||
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty format',
|
'D3_DATAWIZARD_EXPORT_FORMAT_PRETTY' => 'Pretty format',
|
||||||
|
'D3_DATAWIZARD_EXPORT_FORMAT_JSON' => 'JSON format',
|
||||||
|
|
||||||
'D3_DATAWIZARD_ACTION_SUBMIT' => 'run action',
|
'D3_DATAWIZARD_ACTION_SUBMIT' => 'run action',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user