<?php
namespace ModulesAbstract\PluginReports\ConfigUDEFListing; abstract class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedListing { protected $listOrderingColumns = []; protected $absLang = []; protected $model = null; protected function initialize() { parent::initialize(); $this->absLang = \App\Loader_Lang::getInstance()->loadAppFile('_customLoad/modulesAbstract/pluginReports/configUdefListing/ConfigUDEFListing.lang.php')->getSection("ModulesAbstract/PluginReports/ConfigUDEFListing"); $this->actionsCfg['insert'] = [ 'checkOption' => false, ]; $this->actionsCfg['update'] = [ 'checkOption' => false, ]; $this->actionsCfg['delete'] = [ 'checkOption' => false, ]; } public function buildModel() { if ($this->model) { return $this->model; } $class = getClassNamespace(get_class($this)).'\Model'; $model = new $class(); $this->model = $model; return $model; } protected function actionIndex($R) { if (SHOW_DEBUGS && isset($R['config']['ignoreConfigs'])) { $this->buildModel()->saveUDEFConfigs([]); } return parent::actionIndex($R); } protected function insert_getDefaultFormData($R) { return []; } protected function insert_doInsert($formData, \App\MessagesCollector $msgs) { $UDEFConfigs = $this->buildModel()->getUDEFConfigs(); $UDEFConfigs[] = [ 'corporateFilter' => $formData['corporateFilter'], 'corporate' => $formData['corporate'], 'corporateSegmentId' => $formData['corporateSegmentId'], 'corporateGroupIds' => $formData['corporateGroupIds'], 'UDEF' => $formData['UDEF'], ]; $this->buildModel()->saveUDEFConfigs($UDEFConfigs); $msgs->addSuccess($this->absLang['index']['action']['save']['success']); $this->insertIdRecord = count($UDEFConfigs); return true; } protected function update_getDefaultFormData($idEntity) { $UDEFConfigs = $this->buildModel()->getUDEFConfigs(); return (array)$UDEFConfigs[$idEntity]; } protected function update_doUpdate($formData, \App\MessagesCollector $msgs) { $idEntity = (int)$formData['id']; $UDEFConfigs = $this->buildModel()->getUDEFConfigs(); $UDEFConfigs[$idEntity] = [ 'corporateFilter' => $formData['corporateFilter'], 'corporate' => $formData['corporate'], 'corporateSegmentId' => $formData['corporateSegmentId'], 'corporateGroupIds' => $formData['corporateGroupIds'], 'UDEF' => $formData['UDEF'], ]; $this->buildModel()->saveUDEFConfigs($UDEFConfigs); $msgs->addSuccess($this->absLang['index']['saveOk']); return true; } protected function list_getDefaultParams() { $cfg = (array)$this->cfg['listingParams']; return $cfg; } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { $selectionSize = count($selection); switch ($option->getId()) { case 'insert': break; case 'update': break; case 'delete': break; default: return false; } return true; } protected function delete_doDelete(array $recordsIds, \App\MessagesCollector $msgs, array $R) { } protected function optionGetEntityName($id) { $UDEFConfigs = $this->buildModel()->getUDEFConfigs(); $UDEFConfig = $UDEFConfigs[$id]; switch ($UDEFConfig['corporateFilter']) { case 'corporate': $corporate = \Entity\Corporate::select($UDEFConfig['corporate']['id']); return ($corporate->recordExists()?$corporate->company:''); case 'segment': $corporateSegment = \Entity\CorporateSegment::select($UDEFConfig['corporateSegmentId']); return ($corporateSegment->recordExists()?$corporateSegment->name:''); case 'group': $groups = []; foreach ($UDEFConfig['corporateGroupIds'] as $groupId) { $groupElemDetails = \App\Config\CorporateGroups::getInstance()->getGroupElementDetailsById($groupId); $groups[$groupElemDetails['groupName']][] = $groupElemDetails['groupElementName']; } return implode(', ', array_map(function($groupName, $groupElements) { return "$groupName: " . implode(', ', $groupElements); }, array_keys($groups), $groups)); case 'any': return 'any'; } return $id; } protected function bulkActionDelete(array $recordsIds, \App\MessagesCollector $msgs, $R) { $UDEFConfigs = $this->buildModel()->getUDEFConfigs(); foreach ($recordsIds as $id) { unset($UDEFConfigs[$id]); } $this->getListingSelection()->delete($recordsIds); $this->buildModel()->saveUDEFConfigs($UDEFConfigs); $msgs->addSuccess($this->absLang['index']['deleteOk']); } }