<?php
 namespace Modules\Admin\Config\Remarks\AssistedInputs; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function initialize() { parent::initialize(); $this->actionsCfg['index'] = [ 'checkSection' => 'Modules/Admin/Config/Remarks', 'checkOption' => false ]; } protected function getDefaultFormData($R) { $formData = []; list($category, $key) = explode('|',$R['id']); $remark = \App\Config\Remarks::getAdmin()->setHandledCategory($category)->get($key); $formData['format'] = $remark['format']; $formData['vars'] = $remark['vars']; $services = []; if($remark['visibilityConditions']) { foreach ($remark['visibilityConditions'] as $condition) { if ($condition['field'] == 'serviceType') { $services[] = $condition['value']; } } } $formData['services'] = $services; return $formData; } protected function processFormData(Array $R, \App\MessagesCollector $msgs) { list($category, $key) = explode('|',$R['id']); $remark = \App\Config\Remarks::getAdmin()->setHandledCategory($category)->get($key); $varsListToSet = $remark['vars']; foreach ($remark['vars'] as $indexVar => $varDetails) { $varsListToSet[$indexVar]['assistedInput'] = $R['vars'][$indexVar]['assistedInput']; $varsListToSet[$indexVar]['assistedInputDetails'] = $R['vars'][$indexVar]['assistedInputDetails']; } if($remark['visibilityConditions']) { foreach($remark['visibilityConditions'] as $idxCond => $condition) { if($condition['field'] == 'serviceType') { unset($remark['visibilityConditions'][$idxCond]); } } } $services = $R['services']; if($services) { foreach($services as $serviceCode) { $remark['visibilityConditions'][] = [ 'field' => 'serviceType', 'value' => $serviceCode ]; } } try { \App\Config\Remarks::getAdmin()->itemUpdate($key, [ 'format' => $remark['format'], 'vars' => $varsListToSet, 'comments' => $remark['comments'], 'visibilityConditions' => $remark['visibilityConditions'] ] ); $msgs->addSuccess($this->lang['successMessage']['remarkUpdated']); } catch (\App\Config\MessageException $e) { $msgs->addError(sprintf($this->lang['errorMessage']['cannotUpdateRemark'], $e->getMessage())); } return !$msgs->hasErrorOrWarning(); } }