manufacturer-information/Application/Controller/Admin/ManufacturerInfoLongdesc.php

127 lines
3.5 KiB
PHP
Raw Normal View History

2024-10-23 20:18:20 +02:00
<?php
declare(strict_types=1);
namespace D3\ManufacturerInformation\Application\Controller\Admin;
use D3\ManufacturerInformation\Application\Model\Constants;
use D3\ManufacturerInformation\Modules\Application\Model\D3ManufacturerLongDesc;
2024-10-23 20:18:20 +02:00
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Application\Model\Manufacturer;
use OxidEsales\Eshop\Core\Registry;
2024-10-23 20:18:20 +02:00
class ManufacturerInfoLongdesc extends AdminDetailsController
{
/**
* @return string
*/
2024-10-23 20:18:20 +02:00
public function render()
{
parent::render();
$this->_aViewData['edit'] = $oManufacturer = oxNew(\OxidEsales\Eshop\Application\Model\Manufacturer::class);
$sOXID = $this->_aViewData["oxid"] = $this->getEditObjectId();
if (isset($sOXID) && $sOXID != "-1") {
2024-10-23 20:18:20 +02:00
// load object
2024-11-16 16:02:54 +01:00
$d3manufacturerlang = \OxidEsales\Eshop\Core\Registry::getRequest()->getRequestEscapedParameter("catlang");
2024-10-23 20:18:20 +02:00
if (!isset($d3manufacturerlang)) {
$d3manufacturerlang = $this->_iEditLang;
}
2024-10-28 19:35:22 +01:00
$this->_aViewData["catlang"] = $d3manufacturerlang;
2024-10-23 20:18:20 +02:00
$oManufacturer->loadInLang($d3manufacturerlang, $sOXID);
2024-10-23 20:18:20 +02:00
//Disable editing for derived items
if ($oManufacturer->isDerived()) {
$this->_aViewData['readonly'] = true;
}
foreach (\OxidEsales\Eshop\Core\Registry::getLang()->getLanguageNames() as $id => $language) {
$oLang = new \stdClass();
$oLang->sLangDesc = $language;
$oLang->selected = ($id == $this->_iEditLang);
$this->_aViewData["otherlang"][$id] = clone $oLang;
}
}
2024-11-16 17:27:30 +01:00
$this->_aViewData["editor"] = $this->generateTextEditor("100%", 280, $oManufacturer, "oxmanufacturers__D3DESCRIPTION", "list.css");
2024-10-23 20:18:20 +02:00
2024-11-16 14:33:16 +01:00
return "@d3manufacturerinformation/admin/d3manufacturerlongdesc";
2024-10-23 20:18:20 +02:00
}
/**
* @return void
* @throws \Exception
*/
2024-10-23 20:18:20 +02:00
public function save()
{
parent::save();
2024-11-16 16:02:54 +01:00
$iManufacturerLang = intval(\OxidEsales\Eshop\Core\Registry::getRequest()->getRequestEscapedParameter("catlang"));
$sOXID = $this->getEditObjectId();
$this->setEditObjectId($sOXID);
if ($sOXID == "-1") {
return;
}
/** @var Manufacturer|D3ManufacturerLongDesc $oManufacturer */
$oManufacturer = oxNew(Manufacturer::class);
2024-10-28 19:35:22 +01:00
$oManufacturer->loadInLang($iManufacturerLang, $sOXID);
if (!$oManufacturer->load($sOXID)) {
return;
}
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
$oManufacturer->assign($aParams);
if (false === is_null($this->d3GetLongdescParamValue())) {
$oManufacturer->d3SetLongdesc($this->d3GetLongdescParamValue());
$oManufacturer->save();
}
}
/**
2024-11-16 17:27:17 +01:00
* @param $oManufacturer
* @param $sField
* @return string
*/
2024-11-16 17:27:17 +01:00
protected function getEditValue($oManufacturer, $sField)
{
$sEditObjectValue = '';
2024-10-28 19:35:22 +01:00
if ($oManufacturer and $oManufacturer->getId()) {
2024-11-16 17:27:17 +01:00
$sEditObjectValue = $oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME);
}
return $sEditObjectValue;
}
/**
* @return string
*/
public function d3GetLongdescParamValue() :string
{
2024-10-28 19:35:22 +01:00
return (string) $aParams = Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__D3DESCRIPTION'];
2024-10-23 20:18:20 +02:00
}
2024-10-28 06:14:26 +01:00
/**
* inhaltliche Uebernahme analog Article_Main
* wird genutzt zum Abspeichern der Artikel-Langbeschreibung
*
* @param $sValue
*
* @return mixed
*/
2024-11-16 17:27:17 +01:00
protected function processLongDesc($sValue)
2024-10-28 06:14:26 +01:00
{
$aSearch = ['&amp;nbsp;', '&amp;', '&quot;', '&lang=', '<p>&nbsp;</p>', '<p>&nbsp; </p>'];
$aReplace = ['&nbsp;', '&', '"', '&amp;lang=', '', ''];
return str_replace($aSearch, $aReplace, $sValue);
}
2024-10-23 20:18:20 +02:00
}