basics for actions

This commit is contained in:
Daniel Seifert 2021-05-05 23:20:42 +02:00
parent 98fd499599
commit edd7d33587
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
7 changed files with 409 additions and 3 deletions

View File

@ -0,0 +1,91 @@
<?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\Controller\Admin;
use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
class d3ActionWizard extends AdminDetailsController
{
protected $_sThisTemplate = 'd3ActionWizard.tpl';
/** @var Configuration */
protected $configuration;
public function __construct()
{
parent::__construct();
$this->configuration = oxNew(Configuration::class);
}
public function getGroups()
{
return $this->configuration->getGroups();
}
public function getGroupActions($group)
{
return $this->configuration->getActionsByGroup($group);
}
/**
* @throws DatabaseConnectionException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
public function doAction()
{
try {
$id = Registry::getRequest()->getRequestEscapedParameter('actionid');
$action = $this->configuration->getActionById($id);
[ $queryString, $parameters ] = $action->getQuery();
if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew(
DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
);
}
$action->run();
} catch (DataWizardException|DBALException|DatabaseErrorException $e) {
Registry::getUtilsView()->addErrorToDisplay($e);
}
}
public function getUserMessages()
{
return null;
}
public function getHelpURL()
{
return null;
}
}

View File

@ -0,0 +1,142 @@
<?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;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\ModCfg\Application\Model\d3filesystem;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
abstract class ActionBase implements QueryBase
{
/**
* @return string
*/
public function getDescription() : string
{
return '';
}
/**
* @param string $format
*
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException
* @throws Exceptions\TaskException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
public function run()
{
$rowCount = $this->getExportData( $this->getQuery() );
}
/**
* @return string
*/
public function getButtonText() : string
{
return "D3_DATAWIZARD_EXPORT_SUBMIT";
}
/**
* @param $format
*
* @return ExportRenderer\RendererInterface
* @throws Exceptions\NoSuitableRendererException
*/
public function getRenderer($format): ExportRenderer\RendererInterface
{
return oxNew(RendererBridge::class)->getRenderer($format);
}
/**
* @param $format
*
* @return string
* @throws Exceptions\NoSuitableRendererException
*/
public function getFileExtension($format): string
{
return $this->getRenderer($format)->getFileExtension();
}
/**
* @param $rows
* @param $fieldnames
* @param $format
*
* @return string
* @throws Exceptions\NoSuitableRendererException
*/
public function renderContent($rows, $fieldnames, $format): string
{
$renderer = $this->getRenderer($format);
return $renderer->getContent($rows, $fieldnames);
}
/**
* @return string
*/
public function getExportFilenameBase() : string
{
return $this->getTitle();
}
/**
* @param $format
*
* @return string
* @throws Exceptions\NoSuitableRendererException
*/
public function getExportFileName($format) : string
{
return $this->getExportFilenameBase().'_'.date('Y-m-d_H-i-s').'.'.$this->getFileExtension($format);
}
/**
* @param array $query
*
* @return int
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public function getExportData( array $query ): array
{
[ $queryString, $parameters ] = $query;
$queryString = trim($queryString);
if ( strtolower( substr( $queryString, 0, 6 ) ) === 'select' ) {
throw oxNew(
Exceptions\TaskException::class,
$this,
Registry::getLang()->translateString( 'D3_DATAWIZARD_ERR_ACTIONSELECT' )
);
}
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->execute( $queryString, $parameters );
}
}

View File

@ -28,6 +28,7 @@ class Configuration
const GROUP_ORDERS = 'D3_DATAWIZARD_GROUP_ORDERS';
const GROUP_REMARKS = 'D3_DATAWIZARD_GROUP_REMARKS';
protected $actions = [];
protected $exports = [];
public function __construct()
@ -43,6 +44,15 @@ class Configuration
}
}
/**
* @param $group
* @param ActionBase $action
*/
public function registerAction($group, ActionBase $action)
{
$this->actions[$group][md5(serialize($action))] = $action;
}
/**
* @param $group
* @param ExportBase $export
@ -52,6 +62,14 @@ class Configuration
$this->exports[$group][md5(serialize($export))] = $export;
}
/**
* @return array
*/
public function getGroupedActions(): array
{
return $this->actions;
}
/**
* @return array
*/
@ -68,11 +86,30 @@ class Configuration
return array_keys($this->exports);
}
public function getActionsByGroup($group)
{
return $this->actions[$group];
}
public function getExportsByGroup($group)
{
return $this->exports[$group];
}
/**
* @return array
*/
public function getAllActions() : array
{
$all = [];
foreach ($this->getGroups() as $group) {
$all = array_merge($all, $this->getActionsByGroup($group));
}
return $all;
}
/**
* @return array
*/
@ -87,6 +124,16 @@ class Configuration
return $all;
}
/**
* @param $id
*
* @return ActionBase
*/
public function getActionById($id) : ActionBase
{
return $this->getAllExports()[$id];
}
/**
* @param $id
*
@ -96,4 +143,4 @@ class Configuration
{
return $this->getAllExports()[$id];
}
}
}

View File

@ -23,6 +23,7 @@ $aLang = array(
'charset' => 'UTF-8',
'd3mxDataWizard' => '<i class="fas fa-fw fa-hat-wizard"></i> Data Wizard',
'd3mxDataWizard_Export' => 'Exporte',
'd3mxDataWizard_Action' => 'Aktionen',
'SHOP_MODULE_GROUP_d3datawizard_general' => 'Grundeinstellungen',
'SHOP_MODULE_d3datawizard_debug' => 'zeigt Abfragen anstatt diese auszuführen',

View File

@ -0,0 +1,122 @@
[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]
[{oxstyle include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"}]
[{oxscript include="https://code.jquery.com/jquery-3.2.1.slim.min.js"}]
[{oxscript include="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"}]
[{oxscript include="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"}]
[{oxstyle include="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/solid.min.css"}]
<style>
button {
margin: 1em 1em 1em 5em;
}
html {
font-size: 0.8em;
}
body {
background-image: linear-gradient(339deg, rgba(47, 47, 47,0.02) 0%, rgba(47, 47, 47,0.02) 42%,transparent 42%, transparent 99%,rgba(17, 17, 17,0.02) 99%, rgba(17, 17, 17,0.02) 100%),linear-gradient(257deg, rgba(65, 65, 65,0.02) 0%, rgba(65, 65, 65,0.02) 11%,transparent 11%, transparent 92%,rgba(53, 53, 53,0.02) 92%, rgba(53, 53, 53,0.02) 100%),linear-gradient(191deg, rgba(5, 5, 5,0.02) 0%, rgba(5, 5, 5,0.02) 1%,transparent 1%, transparent 45%,rgba(19, 19, 19,0.02) 45%, rgba(19, 19, 19,0.02) 100%),linear-gradient(29deg, rgba(28, 28, 28,0.02) 0%, rgba(28, 28, 28,0.02) 33%,transparent 33%, transparent 40%,rgba(220, 220, 220,0.02) 40%, rgba(220, 220, 220,0.02) 100%),linear-gradient(90deg, rgb(255,255,255),rgb(255,255,255));
}
h4 .btn {
font-size: 1.3rem;
}
h5.card-header {
font-size: 1.1rem;
}
</style>
[{capture name="d3script"}][{strip}]
function startExport(id, format) {
let elements = document.getElementsByClassName('errorbox');
for (var i = 0; i < elements.length; i++){
elements[i].style.display = 'none';
}
setTimeout(function(){
document.getElementById('mask').className='';
document.getElementById('popup2').className='d3loader-2';
}, 3000);
document.getElementById('mask').className='on';
document.getElementById('popup2').className='d3loader-2 on';
document.getElementById('exportid').value = id;
document.getElementById('exportformat').value = format;
document.getElementById('myedit').submit();
}
[{/strip}][{/capture}]
[{oxscript add=$smarty.capture.d3script}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" style="padding: 0;margin: 0;height:0;">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="[{$oViewConf->getActiveClassName()}]">
<input type="hidden" name="fnc" value="doExport">
<input type="hidden" name="exportid" id="exportid" value="">
<input type="hidden" name="exportformat" id="exportformat" value="CSV">
[{assign var="groups" value=$oView->getGroups()}]
[{if $groups|@count}]
<div id="accordion">
[{foreach from=$oView->getGroups() item="group"}]
<div class="card mb-2">
<div class="card-header p-1" id="heading[{$group}]">
<h4 class="mb-0">
<span class="btn p-1" data-toggle="collapse" data-target="#collapse[{$group}]" aria-expanded="false" aria-controls="collapse[{$group}]">
[{oxmultilang ident=$group}]
</span>
</h4>
</div>
<div id="collapse[{$group}]" class="collapse" aria-labelledby="heading[{$group}]" data-parent="#accordion">
<div class="card-body pb-0">
<div class="row">
[{foreach from=$oView->getGroupActions($group) key="id" item="export"}]
<div class="col-sm-6 col-md-4 col-lg-3 pb-4">
<div class="card">
<h5 class="card-header">
[{$export->getTitle()}]
</h5>
<div class="card-body">
<p class="card-text">
[{$export->getDescription()}]
</p>
<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="startAction('[{$id}]')">
<i class="fas fa-magic"></i>
[{oxmultilang ident=$export->getButtonText()}]
</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">
<i class="fas fa-magic"></i>
[{oxmultilang ident=$export->getButtonText()}]
</span>
</button>
</div>
</div>
</div>
</div>
[{/foreach}]
</div>
<div class="clear"></div>
</div>
</div>
</div>
[{/foreach}]
</div>
[{else}]
<div class="alert alert-primary" role="alert">
[{oxmultilang ident="D3_DATAWIZARD_ERR_NOACTION_INSTALLED"}]
</div>
[{/if}]
</form>
<div id="mask" class=""></div>
<div id="popup2" class="d3loader-2">
<div class="d3loader-spinner">
<div class="d3loader-circle-1"></div>
<div class="d3loader-circle-2"></div>
<div class="d3loader-circle-3"></div>
</div>
</div>
[{include file="d3_cfg_mod_inc.tpl"}]

View File

@ -3,6 +3,7 @@
<OXMENU id="d3mxd3modules">
<MAINMENU id="d3mxDataWizard">
<SUBMENU id="d3mxDataWizard_Export" cl="d3ExportWizard" disableForDemoShop="1" />
<SUBMENU id="d3mxDataWizard_Action" cl="d3ActionWizard" disableForDemoShop="1" />
</MAINMENU>
</OXMENU>
</OX>
</OX>

View File

@ -37,12 +37,14 @@ $aModule = [
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
'controllers' => [
'd3ExportWizard' => D3\DataWizard\Application\Controller\Admin\d3ExportWizard::class
'd3ExportWizard' => D3\DataWizard\Application\Controller\Admin\d3ExportWizard::class,
'd3ActionWizard' => D3\DataWizard\Application\Controller\Admin\d3ActionWizard::class
],
'extend' => [],
'events' => [],
'templates' => [
'd3ExportWizard.tpl' => 'd3/datawizard/Application/views/admin/tpl/d3ExportWizard.tpl',
'd3ActionWizard.tpl' => 'd3/datawizard/Application/views/admin/tpl/d3ActionWizard.tpl',
],
'settings' => [
[