<?php
namespace Modules\Admin\Config\SupplierProducts\Fields; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\ListingAbstract { protected $formSubmitButtonName = 'save'; protected $listOrderingColumns = ['addTime']; protected function initialize() { parent::initialize(); $this->actionsCfg['index'] = ['checkSection'=>true, 'checkOption'=>false]; $this->actionsCfg['list'] = ['checkSection'=>true, 'checkOption'=>false]; $this->actionsCfg['edit'] = ['checkSection'=>true, 'checkOption'=>false]; } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { switch($option->getId()){ case 'edit': foreach ($selection as $selectedItem) { $model = new \Modules\Admin\Config\SupplierProducts\Fields\Model(); if (!$model->isGroup($selectedItem)) { $option->setDisabled(true); $option->addMessage('warning', $this->lang['index']['options']['reasons']['edit']['notAllowedGroup']); } } break; default: return false; } return true; } protected function optionGetEntityName($id) { return NULL; } public function actionEdit($R) { $msgs = \App\MessagesCollector::create(); $formData = []; $modelOutput = null; if ($R[$this->formSubmitButtonName]) { $modelOutput = $this->editProcessFormData($R, $msgs); } $view = new View_Edit($this); $serviceName = \App\Config\Services_Basic::getInstance()->getServiceName($R['id']); $view->setPageTitle(sprintf($this->lang['edit']['pageTitle'], $serviceName)); if (!$R[$this->formSubmitButtonName]) { $formData = $this->editGetDefaultFormData($R); } else { $formData = $R; } if ($modelOutput) { $view->setClosePopup(true); } $view->addInput('formSubmitButtonName', $this->formSubmitButtonName); $view->addInput('formData', $formData); $view->getMessagesCollector()->appendMessages($msgs); return new \Engine\Mvc\Response\Html($view->render()); } private function editGetDefaultFormData($R) { $suppProductFields = \App\Config\SupplierProductFields::getInstance(); $formData = []; $formData['fields']['category'] = $suppProductFields->getFieldType($R['id'], 'category'); $formData['fields']['productName'] = $suppProductFields->getFieldType($R['id'], 'productName'); $formData['fields']['localization'] = $suppProductFields->getFieldType($R['id'], 'localization'); $formData['fields']['chain'] = $suppProductFields->getFieldType($R['id'], 'chain'); $formData['fields']['address'] = $suppProductFields->getFieldType($R['id'], 'address'); $formData['fields']['zipCode'] = $suppProductFields->getFieldType($R['id'], 'zipCode'); $formData['fields']['departure'] = $suppProductFields->getFieldType($R['id'], 'departure'); $formData['fields']['destination'] = $suppProductFields->getFieldType($R['id'], 'destination'); $formData['categoryDetails']= \App\Config\Services_GeneralAttributes::getInstance()->getServiceCategory($R['id']); $formData['productName'] = \App\Config\Services_GeneralAttributes::getInstance()->getServiceProductName($R['id']); return $formData; } private function editProcessFormData($R, $msgs) { $serviceCode = $R['id']; $supplierProductFields = \App\Config\SupplierProductFields::getAdmin(); try { $supplierProductFields->set($serviceCode, $R['fields']); $supplierProductFields->save(); $msgs->addSuccess($this->lang['edit']['messages']['success']); return true; } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } } }