add JSON export renderer

This commit is contained in:
Daniel Seifert 2021-10-29 11:39:56 +02:00
parent ea77239510
commit 74edceafc8
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
4 changed files with 56 additions and 1 deletions

View 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";
}
}

View File

@ -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)
]; ];
} }

View File

@ -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',

View File

@ -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',