Ordermanager/src/Application/Controller/Admin/d3_ordermanager_jobs.php

399 regels
12 KiB
PHP

2017-12-20 13:43:20 +01:00
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Ordermanager\Application\Controller\Admin;
2019-07-09 10:27:20 +02:00
use D3\ModCfg\Application\Model\d3filesystem;
use D3\ModCfg\Application\Model\d3str;
2018-01-11 11:45:22 +01:00
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
2019-05-15 11:31:18 +02:00
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
2018-01-11 11:45:22 +01:00
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
2017-12-20 13:43:20 +01:00
use D3\Ordermanager\Application\Model\d3ordermanager;
use D3\Ordermanager\Application\Model\d3ordermanagerlist;
use D3\Ordermanager\Application\Model\d3ordermanager_execute;
use D3\Ordermanager\Application\Model\d3ordermanager_toorderassignment;
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
2018-01-11 11:45:22 +01:00
use Doctrine\DBAL\DBALException;
2019-05-15 11:31:18 +02:00
use Exception;
2017-12-20 13:43:20 +01:00
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
2018-01-11 11:45:22 +01:00
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
2019-12-10 11:40:17 +01:00
use OxidEsales\Eshop\Core\Field;
2019-05-15 11:31:18 +02:00
use OxidEsales\Eshop\Core\Language;
2019-12-10 11:40:17 +01:00
use OxidEsales\Eshop\Core\Model\BaseModel;
2017-12-20 13:43:20 +01:00
use OxidEsales\Eshop\Core\Request;
2019-05-15 11:31:18 +02:00
use OxidEsales\Eshop\Core\Session;
2017-12-20 13:43:20 +01:00
class d3_ordermanager_jobs extends AdminDetailsController
{
2019-05-15 11:31:18 +02:00
private $_sModId = 'd3_ordermanager';
2017-12-20 13:43:20 +01:00
/** @var d3ordermanagerlist */
protected $_aJobList;
protected $_sHelpLinkMLAdd;
2019-05-15 11:31:18 +02:00
/**
* d3_ordermanager_jobs constructor.
*/
public function __construct()
{
2020-08-20 09:35:38 +02:00
// prevent the use of the global currency setting instead of the order setting
unset($_GET['cur']);
2019-05-15 11:31:18 +02:00
d3GetModCfgDIC()->setParameter('d3.ordermanager.modcfgid', $this->_sModId);
parent::__construct();
}
/**
* @return Order
* @throws Exception
*/
public function getItemObject()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Order::class);
}
2017-12-20 13:43:20 +01:00
/**
* @return string
2018-01-11 11:45:22 +01:00
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function render()
{
parent::render();
$soxId = $this->getEditObjectId();
$this->addTplParam("oxid", $soxId);
if ($soxId != "-1" && isset($soxId)) {
2019-05-15 11:31:18 +02:00
$oItem = $this->getItemObject();
2017-12-20 13:43:20 +01:00
$oItem->load($soxId);
$this->addTplParam("edit", $oItem);
}
2019-05-15 11:31:18 +02:00
/** @var Session $session */
$session = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Session::class);
$sJobFolder = $session->getVariable('d3OrderManagerFolderSelect');
2017-12-20 13:43:20 +01:00
$this->addTplParam("jobfolder", $sJobFolder);
$this->_aJobList = $this->_d3GetManuallyManagerJobs($sJobFolder);
return "d3_ordermanager_jobs.tpl";
}
2019-05-15 11:31:18 +02:00
/**
* @return Session
* @throws Exception
*/
public function d3GetSession()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Session::class);
}
/**
* @throws Exception
*/
2017-12-20 13:43:20 +01:00
public function changeFolder()
{
2019-05-15 11:31:18 +02:00
/** @var Request $request */
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
$this->d3GetSession()->setVariable(
2017-12-20 13:43:20 +01:00
'd3OrderManagerFolderSelect',
2019-05-15 11:31:18 +02:00
$request->getRequestEscapedParameter('jobfolder')
2017-12-20 13:43:20 +01:00
);
}
/**
* @return d3ordermanagerlist
2019-05-15 11:31:18 +02:00
* @throws Exception
*/
public function getManagerList()
{
return d3GetModCfgDIC()->get(d3ordermanagerlist::class);
}
/**
* @return d3ordermanagerlist
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3GetManagerJobs()
{
2019-05-15 11:31:18 +02:00
$oManagerList = $this->getManagerList();
2017-12-20 13:43:20 +01:00
$oManagerList->getList();
return $oManagerList;
}
/**
* @param $sFolderId
2019-05-15 11:31:18 +02:00
*
2017-12-20 13:43:20 +01:00
* @return d3ordermanagerlist
2018-01-11 11:45:22 +01:00
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
protected function _d3GetManuallyManagerJobs($sFolderId)
{
2019-05-15 11:31:18 +02:00
$oManagerList = $this->getManagerList();
2019-07-09 10:27:20 +02:00
$oList = $oManagerList->d3GetManuallyManagerJobsByFolder($sFolderId);
/** @var d3ordermanager $oManager */
foreach ($oList as $sId => $oManager) {
$oManagerExecute = $this->getManagerExecute($oManager);
if ($oManager->getValue('sManuallyExecMeetCondition') &&
false == $oManagerExecute->orderMeetsConditions($this->getEditObjectId())
) {
$oList->offsetUnset($sId);
}
}
return $oList;
2017-12-20 13:43:20 +01:00
}
/**
* @return array
*/
public function d3GetJobList()
{
return $this->_aJobList->getArray();
}
2019-05-15 11:31:18 +02:00
/**
* @return d3ordermanager
* @throws Exception
*/
public function getManager()
{
return d3GetModCfgDIC()->get(d3ordermanager::class);
}
/**
* @param d3ordermanager $oManager
* @return d3ordermanager_execute
* @throws Exception
*/
public function getManagerExecute(d3ordermanager $oManager)
{
d3GetModCfgDIC()->set(
d3ordermanager_execute::class.'.args.ordermanager',
$oManager
);
return d3GetModCfgDIC()->get(d3ordermanager_execute::class);
}
2018-01-11 11:45:22 +01:00
/**
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
2019-05-15 11:31:18 +02:00
* @throws Exception
2018-01-11 11:45:22 +01:00
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
2017-12-20 13:43:20 +01:00
public function d3execordermanager()
{
2019-05-15 11:31:18 +02:00
/** @var Request $request */
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
$oManager = $this->getManager();
$oManager->load($request->getRequestEscapedParameter('ordermanagerid'));
$oManagerExec = $this->getManagerExecute($oManager);
2019-07-09 10:27:20 +02:00
if (false == $oManager->getValue('sManuallyExecMeetCondition') ||
$oManagerExec->orderMeetsConditions($this->getEditObjectId())
) {
$oManagerExec->exec4order($this->getEditObjectId());
$oManagerExec->finishJobExecution();
}
2017-12-20 13:43:20 +01:00
}
2018-01-11 11:45:22 +01:00
/**
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws StandardException
2019-05-15 11:31:18 +02:00
* @throws Exception
2018-01-11 11:45:22 +01:00
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/
2017-12-20 13:43:20 +01:00
public function d3ExecChangedOrderManager()
{
2019-05-15 11:31:18 +02:00
/** @var Request $request */
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
$oManager = $this->getManager();
$oManager->load($request->getRequestEscapedParameter('ordermanagerid'));
$oManager->setEditedValues($request->getRequestEscapedParameter('aContent'));
$oManagerExec = $this->getManagerExecute($oManager);
2019-07-09 10:27:20 +02:00
if (false == $oManager->getValue('sManuallyExecMeetCondition') ||
$oManagerExec->orderMeetsConditions($this->getEditObjectId())
) {
$oManagerExec->exec4order($this->getEditObjectId());
$oManagerExec->finishJobExecution();
}
2017-12-20 13:43:20 +01:00
}
2018-01-11 11:45:22 +01:00
/**
2019-05-15 11:31:18 +02:00
* @param d3ordermanager $oManager
* @return d3ordermanager_toorderassignment
* @throws Exception
*/
public function getOrderManagerAssignment(d3ordermanager $oManager)
{
d3GetModCfgDIC()->set(
d3ordermanager_toorderassignment::class.'.args.ordermanager',
$oManager
);
return d3GetModCfgDIC()->get(d3ordermanager_toorderassignment::class);
}
/**
2018-01-11 11:45:22 +01:00
* @throws DatabaseErrorException
2019-05-15 11:31:18 +02:00
* @throws d3ParameterNotFoundException
* @throws Exception
2018-01-11 11:45:22 +01:00
*/
2017-12-20 13:43:20 +01:00
public function d3resetOrderManagerAssignment()
{
2019-05-15 11:31:18 +02:00
/** @var Request $request */
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
$oManager = $this->getManager();
$oAssignment = $this->getOrderManagerAssignment($oManager);
2017-12-20 13:43:20 +01:00
$oAssignment->resetAssignment(
2019-05-15 11:31:18 +02:00
$request->getRequestEscapedParameter('ordermanagerid'),
2019-07-09 10:27:20 +02:00
$this->getEditObjectId()
2017-12-20 13:43:20 +01:00
);
}
/**
* @return mixed
2018-01-11 11:45:22 +01:00
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function getFolderList()
{
2019-05-15 11:31:18 +02:00
$oManager = $this->getManager();
2017-12-20 13:43:20 +01:00
return $oManager->d3getSelectableFolderList();
}
2018-01-11 11:45:22 +01:00
/**
2019-05-15 11:31:18 +02:00
* @throws DBALException
2018-01-11 11:45:22 +01:00
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
2019-05-15 11:31:18 +02:00
* @throws StandardException
2018-01-11 11:45:22 +01:00
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
2019-05-15 11:31:18 +02:00
* @throws Exception
2018-01-11 11:45:22 +01:00
*/
2017-12-20 13:43:20 +01:00
public function execChangedContents()
{
2019-05-15 11:31:18 +02:00
/** @var Request $request */
$request = d3GetModCfgDIC()->get('d3ox.ordermanager.'.Request::class);
2019-07-09 10:27:20 +02:00
$sItemId = $this->getEditObjectId();
2019-05-15 11:31:18 +02:00
$oManager = $this->getManager();
$oManager->load($request->getRequestEscapedParameter('ordermanagerid'));
2017-12-20 13:43:20 +01:00
$this->addTplParam('aMailContent', $oManager->getEditableContent($sItemId));
2019-12-10 11:40:17 +01:00
$contents = $oManager->getEditableContent($sItemId);
$field = oxNew(Field::class);
$field->setValue($contents['html']);
$object = oxNew(BaseModel::class);
$object->__set(
'aContent[mail][html]',
$field
);
$this->addTplParam("htmleditor", $this->generateTextEditor("95%", 180, $object, "aContent[mail][html]", "list.tpl.css"));
2017-12-20 13:43:20 +01:00
$this->addTplParam('sAction', __FUNCTION__);
$this->addTplParam('oOrderManager', $oManager);
}
/**
* @return array
*/
public function getUserMessages()
{
return array();
}
2019-05-15 11:31:18 +02:00
/**
* @return Language
* @throws Exception
*/
public function getLang()
{
return d3GetModCfgDIC()->get('d3ox.ordermanager.'.Language::class);
}
2017-12-20 13:43:20 +01:00
/**
* @return string
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function getHelpURL()
{
$sUrl = $this->d3GetSet()->getHelpURL();
2019-07-09 10:27:20 +02:00
/** @var d3str $oD3Str */
$oD3Str = d3GetModCfgDIC()->get(d3str::class);
2017-12-20 13:43:20 +01:00
if ($this->_sHelpLinkMLAdd) {
2019-07-09 10:27:20 +02:00
$sUrl .= $oD3Str->unprefixedslashit($this->getLang()->translateString($this->_sHelpLinkMLAdd));
2017-12-20 13:43:20 +01:00
}
2019-07-09 10:27:20 +02:00
/** @var d3filesystem $oFS */
$oFS = d3GetModCfgDIC()->get(d3filesystem::class);
2017-12-20 13:43:20 +01:00
$aFileName = $oFS->splitFilename($sUrl);
// has no extension
if (false == $aFileName['ext']) {
2019-07-09 10:27:20 +02:00
$sUrl = $oD3Str->trailingslashit($sUrl);
2017-12-20 13:43:20 +01:00
}
return $sUrl;
}
/**
* @return d3_cfg_mod
2019-05-15 11:31:18 +02:00
* @throws Exception
2017-12-20 13:43:20 +01:00
*/
public function d3GetSet()
{
2019-05-15 11:31:18 +02:00
return d3GetModCfgDIC()->get('d3.ordermanager.modcfg');
2017-12-20 13:43:20 +01:00
}
public function getLink()
{
return '';
}
}