can export save in file
This commit is contained in:
parent
9e9bab88f0
commit
34b2b0b061
31
Application/Model/Exceptions/ExportFileException.php
Normal file
31
Application/Model/Exceptions/ExportFileException.php
Normal file
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\DataWizard\Application\Model;
|
namespace D3\DataWizard\Application\Model;
|
||||||
|
|
||||||
|
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
|
||||||
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
|
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
|
||||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||||
use D3\ModCfg\Application\Model\d3filesystem;
|
use D3\ModCfg\Application\Model\d3filesystem;
|
||||||
@ -44,6 +45,7 @@ abstract class ExportBase implements QueryBase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $format
|
* @param string $format
|
||||||
|
* @param $path
|
||||||
*
|
*
|
||||||
* @throws DBALException
|
* @throws DBALException
|
||||||
* @throws DatabaseConnectionException
|
* @throws DatabaseConnectionException
|
||||||
@ -53,8 +55,9 @@ abstract class ExportBase implements QueryBase
|
|||||||
* @throws StandardException
|
* @throws StandardException
|
||||||
* @throws d3ShopCompatibilityAdapterException
|
* @throws d3ShopCompatibilityAdapterException
|
||||||
* @throws d3_cfg_mod_exception
|
* @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()) {
|
if ($this->hasFormElements()) {
|
||||||
/** @var Input $element */
|
/** @var Input $element */
|
||||||
@ -70,11 +73,18 @@ abstract class ExportBase implements QueryBase
|
|||||||
$content = $this->renderContent($rows, $fieldNames, $format);
|
$content = $this->renderContent($rows, $fieldNames, $format);
|
||||||
|
|
||||||
/** @var $oFS d3filesystem */
|
/** @var $oFS d3filesystem */
|
||||||
$oFS = oxNew(d3filesystem::class);
|
$oFS = oxNew( d3filesystem::class );
|
||||||
$oFS->startDirectDownload(
|
if (is_null($path)) {
|
||||||
$oFS->filterFilename($this->getExportFileName($format)),
|
$oFS->startDirectDownload( $oFS->filterFilename( $this->getExportFileName( $format ) ), $content );
|
||||||
$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 '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +48,7 @@ $aLang = array(
|
|||||||
'D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED' => 'Es sind keine Exporte installiert oder aktiviert.',
|
'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_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_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' => 'deaktivierte Kategorien, mit aktiven Artikel',
|
||||||
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum',
|
'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum',
|
||||||
|
Loading…
Reference in New Issue
Block a user