can export save in file

Cette révision appartient à :
Daniel Seifert 2021-07-14 12:21:12 +02:00
Parent 9e9bab88f0
révision 34b2b0b061
Signé par: DanielS
ID de la clé GPG: 8A7C4C6ED1915C6F
3 fichiers modifiés avec 48 ajouts et 6 suppressions

Voir le fichier

@ -0,0 +1,31 @@
<?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\Exceptions;
use OxidEsales\Eshop\Core\Registry;
class ExportFileException extends DataWizardException
{
public function __construct($sMessage = "not set", $iCode = 0, Exception $previous = null )
{
$sMessage = sprintf(
Registry::getLang()->translateString('D3_DATAWIZARD_ERR_EXPORTFILEERROR'),
$sMessage
);
parent::__construct($sMessage, $iCode, $previous );
}
}

Voir le fichier

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\ModCfg\Application\Model\d3filesystem;
@ -44,6 +45,7 @@ abstract class ExportBase implements QueryBase
/**
* @param string $format
* @param $path
*
* @throws DBALException
* @throws DatabaseConnectionException
@ -53,8 +55,9 @@ abstract class ExportBase implements QueryBase
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
* @return string
*/
public function run($format = RendererBridge::FORMAT_CSV)
public function run( string $format = RendererBridge::FORMAT_CSV, $path = null): string
{
if ($this->hasFormElements()) {
/** @var Input $element */
@ -70,11 +73,18 @@ abstract class ExportBase implements QueryBase
$content = $this->renderContent($rows, $fieldNames, $format);
/** @var $oFS d3filesystem */
$oFS = oxNew(d3filesystem::class);
$oFS->startDirectDownload(
$oFS->filterFilename($this->getExportFileName($format)),
$content
);
$oFS = oxNew( d3filesystem::class );
if (is_null($path)) {
$oFS->startDirectDownload( $oFS->filterFilename( $this->getExportFileName( $format ) ), $content );
} else {
$filePath = $oFS->trailingslashit($path).$oFS->filterFilename( $this->getExportFileName( $format ) );
if (false === $oFS->createFile($filePath, $content,true)) {
throw oxNew(ExportFileException::class, $filePath);
}
return $filePath;
}
return '';
}
/**

Voir le fichier

@ -48,6 +48,7 @@ $aLang = array(
'D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED' => 'Es sind keine Exporte installiert oder aktiviert.',
'D3_DATAWIZARD_ERR_NOEXPORTCONTENT' => 'Export ist leer, kein Inhalt zum Download verfügbar',
'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'kein Renderer für Format "%1$s" registriert',
'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Exportdatei "%1$s" kann nicht angelegt werden',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES' => 'deaktivierte Kategorien, mit aktiven Artikel',
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum',