* @link https://www.oxidmodule.com */ declare(strict_types=1); namespace D3\Usermanager\Application\Controller\Admin; use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use D3\Usermanager\Application\Model\Actions\d3usermanager_action_interface as ActionModelInterface; use D3\Usermanager\Application\Model\Actions\d3usermanager_actiongrouplist as ActionGroupList; use D3\Usermanager\Application\Model\Actions\d3usermanager_actionlist as ActionList; use D3\Usermanager\Application\Model\Constants; use D3\Usermanager\Application\Model\d3usermanager as Manager; use D3\Usermanager\Application\Model\d3usermanager_vars as VariablesTrait; use D3\Usermanager\Application\Model\Exceptions\d3usermanager_actionException; use DateTime; use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Query\QueryBuilder; use OxidEsales\Eshop\Application\Model\ContentList; use OxidEsales\Eshop\Application\Model\User as Item; use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Language; use OxidEsales\Eshop\Core\Model\ListModel; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Request; use D3\Usermanager\Application\Controller\Admin\d3_cfg_usermanageritem_settings as ItemSettingsController; use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; class d3_cfg_usermanageritem_action extends ItemSettingsController { use VariablesTrait; protected $_sThisTemplate = '@'. Constants::OXID_MODULE_ID .'/admin/d3_cfg_usermanageritem_action'; protected $_sMenuSubItemTitle = 'd3mxusermanager_items'; protected $_sSavedId; protected $_sExportFieldDescMLIdent = 'D3_USERMANAGER_FIELDDESC'; protected $_sExportFieldTitleBaseMLIdent = 'D3_USERMANAGER_FIELDTITLE_'; protected $_sExportFieldLangMLIdent = 'D3_USERMANAGER_FIELDADD_LANG'; /** * @throws d3ShopCompatibilityAdapterException * @throws d3_cfg_mod_exception * @throws DatabaseConnectionException * @throws DatabaseErrorException * @throws StandardException */ public function save(): void { // @codeCoverageIgnoreStart if (!defined('OXID_PHP_UNIT')) { parent::save(); } // @codeCoverageIgnoreEnd $aMissingRequiredValues = []; /** @var ActionModelInterface $oAction */ foreach ($this->getActionList() as $sId => $oAction) { if ($this->getProfile()->getValue($oAction->getActiveSwitchParameter())) { try { $oAction->throwUnvalidConfigurationException(); } catch (d3usermanager_actionException $e) { unset($e); $aMissingRequiredValues[] = $sId; } } } if ($aMissingRequiredValues !== []) { $this->addTplParam('missingRequValuesActions', $aMissingRequiredValues); } } public function getContentList(): ListModel { /** @var $oContentList ContentList */ $oContentList = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.ContentList::class); return $this->_getObjectList($oContentList); } public function d3GetConfig(): Config { /** @var Config $config */ $config = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Config::class); return $config; } public function getItemFieldNames(): array { /** @var Item $item */ $item = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Item::class); return $item->getFieldNames(); } public function getProfile(): Manager { /** @var Manager $oProfile */ $oProfile = d3GetOxidDIC()->get(Manager::class); $soxId = $this->getEditObjectId(); if ($soxId != "-1") { // load object $oProfile->loadInLang($this->_iEditLang, $soxId); // load object in other languages $oOtherLang = $oProfile->getAvailableInLangs(); if (!isset($oOtherLang[$this->_iEditLang])) { $oProfile->loadInLang(key($oOtherLang), $soxId); } } return $oProfile; } public function getExportExamplePath(): string { $oProfile = $this->getProfile(); /** @var Request $request */ $request = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Request::class); $soxId = $request->getRequestEscapedParameter("oxid"); if (isset($soxId) && $soxId && $soxId != "-1") { // load object $oProfile->loadInLang($this->_iEditLang, $soxId); $oProfile = $this->_d3LoadInOtherLang($oProfile, $soxId); } $aSearch = [(new DateTime())->setTimestamp($oProfile->getStartTime())->format('Y-m-d_H-i-s')]; /** @var Language $oLang */ $oLang = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Language::class); $aReplace = [$oLang->translateString('D3_USERMANAGER_ACTION_DATEPLACEHOLDER')]; return str_replace($aSearch, $aReplace, $oProfile->getListExportFilePath()); } /** * @param $sFieldName */ public function getFieldNameDescription($sFieldName): string { if (($sFieldNameTitle = $this->getFieldNameTitle($sFieldName))) { return sprintf( $this->getLang()->translateString($this->_sExportFieldDescMLIdent), $sFieldNameTitle, $sFieldName ); } return $sFieldName; } public function getLang(): Language { /** @var Language $language */ $language = d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Language::class); return $language; } /** * @param $sFieldName */ public function getFieldNameTitle($sFieldName): ?string { $sLangAdd = ''; $sPattern = "@(.*)([_]([0-9]{1,3}))$@"; if (preg_match($sPattern, $sFieldName, $aMatches)) { $sFieldMLIdent = $this->_sExportFieldTitleBaseMLIdent.strtoupper($aMatches[1]); $aLangNames = $this->getLang()->getLanguageNames(); $sLangAdd = sprintf( $this->getLang()->translateString($this->_sExportFieldLangMLIdent), $aLangNames[$aMatches[3]] ); } else { $sFieldMLIdent = $this->_sExportFieldTitleBaseMLIdent.strtoupper($sFieldName); } $sFieldName = $this->getLang()->translateString($sFieldMLIdent); if ($sFieldName != $sFieldMLIdent) { return $sFieldName.$sLangAdd; } return null; } public function getActionGroupList(): ActionGroupList { d3GetOxidDIC()->set( ActionGroupList::class.'.args.usermanager', $this->getProfile() ); d3GetOxidDIC()->set( ActionGroupList::class.'.args.user', d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Item::class) ); /** @var ActionGroupList $actiongroup */ $actiongroup = d3GetOxidDIC()->get(ActionGroupList::class); return $actiongroup; } public function getActionListObject(): ActionList { d3GetOxidDIC()->set( ActionList::class.'.args.usermanager', $this->getProfile() ); d3GetOxidDIC()->set( ActionList::class.'.args.user', d3GetOxidDIC()->get($this->_DIC_OxInstance_Id.Item::class) ); /** @var ActionList $actionlist */ $actionlist = d3GetOxidDIC()->get(ActionList::class); return $actionlist; } public function getGroupedActionList(): array { $oManager = $this->getProfile(); $oActionList = $this->getActionGroupList(); $oActionList->setGroups($oManager->getConfiguration()->getGroupedActionIdList()); return $oActionList->getGroupList(); } public function getActionList(): array { $oManager = $this->getProfile(); $oActionList = $this->getActionListObject(); $oActionList->setActions($oManager->getConfiguration()->getActionIdList()); return $oActionList->getActionList(); } /** * @param $soxId * */ protected function _d3LoadInOtherLang(Manager $oProfile, $soxId): Manager { // load object in other languages $oOtherLang = $oProfile->getAvailableInLangs(); if (!isset($oOtherLang[$this->_iEditLang])) { $oProfile->loadInLang(key($oOtherLang), $soxId); } return $oProfile; } /** * @throws DatabaseConnectionException * @throws DatabaseErrorException * @throws StandardException * @throws d3ParameterNotFoundException * @throws DoctrineException * @throws d3ShopCompatibilityAdapterException * @throws d3_cfg_mod_exception */ public function markAsFinished(): void { $oProfile = $this->getProfile(); /** @var QueryBuilder $queryBuilder */ $queryBuilder = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilder->select('count(*)') ->from(d3GetOxidDIC()->get('d3ox.usermanager.'.Item::class)->getViewName()); $iAllCount = $queryBuilder->execute()->fetchOne(); $iCount = $oProfile->markConcernedItemsAsFinished(true); $oEx = oxNew( StandardException::class, sprintf( Registry::getLang()->translateString('D3_USERMANAGER_ACTION_MARKASFINISHED_MESSAGE'), $iCount, $iAllCount ) ); Registry::get(UtilsView::class)->addErrorToDisplay($oEx); } }