<?php
namespace ModulesAbstract\PluginReports\Config; abstract class ControllerAbstract extends \App\Mvc\ControllerAbstract { protected $absLang= []; protected function initialize() { parent::initialize(); $this->absLang = \App\Loader_Lang::getInstance()->loadAppFolder('_customLoad/modulesAbstract/pluginReports/config')->getSection('ModulesAbstract/PluginReports/Config'); $this->actionsCfg['index']= []; $this->actionsCfg['save']= []; } abstract protected function createModel(); protected function actionIndex($R) { $view = $this->buildViewObjectFromCurrentModuleForAction('index'); $model = $this->createModel(); if (SHOW_DEBUGS && isset($R['config']['ignoreConfigs'])) { $view->addInput('formFields', []); } else { $view->addInput('formFields', $model->getConfigVariables()); } if (\Engine\Storage\General::getInstance('session')->get(sprintf("%s:saved", __CLASS__))) { $view->getMessagesCollector()->addSuccess($this->absLang['index']['action']['save']['success']); \Engine\Storage\General::getInstance('session')->delete(sprintf("%s:saved", __CLASS__)); } return new \Engine\Mvc\Response\Html($view->render()); } protected function actionSave($R) { $view = $this->buildViewObjectFromCurrentModuleForAction('index'); $model = $this->createModel(); $model->setMessagesCollector($view->getMessagesCollector()); $saved = false; if ($_POST) { try { $model->setConfigVariables($R); $saved = true; $view->getMessagesCollector()->addSuccess($this->absLang['index']['action']['save']['success']); } catch (\App\Config\MessageException $e) { $view->getMessagesCollector()->addWarning($e->getMessage()); } catch(\App\MessagesException $e) { $view->getMessagesCollector()->appendMessages($e->getMessagesCollector()); } } else { $saved = true; } if ($saved) { \Engine\Storage\General::getInstance('session')->set(sprintf("%s:saved", __CLASS__), true); return new \Engine\Mvc\Response\HtmlRedirect(\Engine\Mvc\Dispatcher::getInstance()->getAppUrl($this->getModule(), '')); } $view->addInput('formFields', $R); return new \Engine\Mvc\Response\Html($view->render()); } protected function actionGenerateInputMatrixRow($R) { $matrix = \Engine\Cache\General::getInstance('disk')->get($R['inputMatrixStorageId']); if (!$matrix) { throw new \Engine\Mvc\ControllerException("Matrix not found"); } $view = $this->buildViewObjectFromCurrentModuleForAction('index'); return new \Engine\Mvc\Response\Json(['responseRow' => $view->renderInputMatrixRowOnAjaxRequest($matrix, $R['index'], $R['counter'])]); } } 