<?php
namespace Modules\Admin\Config\Remarks; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedListing { protected $listOrderingColumns = ['name', 'category', 'assisted', 'order']; protected function initialize() { parent::initialize(); $this->actionsCfg['index'] = ['checkSection' => true, 'checkOption' => false]; $this->actionsCfg['delete'] = ['checkSection' => true, 'checkOption' => false]; $this->actionsCfg['moveUp'] = ['checkSection' => true, 'checkOption' => false]; $this->actionsCfg['moveDown'] = ['checkSection' => true, 'checkOption' => false]; $this->actionsCfg['save'] = ['checkSection' => true, 'checkOption' => false]; $this->actionsCfg['reset'] = ['checkSection' => true, 'checkOption' => false]; } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { switch ($option->getId()) { case 'insert': case 'update': case 'delete': case 'assistedInputs': break; case 'save': case 'reset': if (!\App\Config\Remarks::getAdmin()->getChangedFlag()) { $option->setDisabled(); } break; case 'moveUp': $id = $selection[0]; list($category, ) = explode('|',$id); $remarks = \App\Config\Remarks::getAdmin()->getAllRemarksFromCategory($category); reset($remarks); $firstElement = $remarks[0]; if ($firstElement['id'] == $id) { $option->setDisabled(true); $option->addMessage('info', $this->lang['index']['options']['reasons']['moveUp']['cannotMoveUp']); } break; case 'moveDown': $id = $selection[0]; list($category, ) = explode('|',$id); $remarks = \App\Config\Remarks::getAdmin()->getAllRemarksFromCategory($category); $lastElement = end($remarks); if ($lastElement['id'] == $id) { $option->setDisabled(true); $option->addMessage('info', $this->lang['index']['options']['reasons']['moveDown']['cannotMoveDown']); } break; default: return false; } return true; } protected function actionSave($R) { $msgs = \App\MessagesCollector::create(); try { \App\Config\Remarks::getAdmin()->save(); $msgs->addSuccess($this->lang['save']['successMessage']); } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } return $this->executeListRecords($R,$msgs); } protected function actionReset($R) { $msgs = \App\MessagesCollector::create(); $recordsIds = $this->getListingSelection()->getList(); if ($R['listing']['selection']) { $recordsIds = $this->setListingSelection($R['listing']['selection'])->getList(); } try { \App\Config\Remarks::getAdmin()->reset(); foreach ($recordsIds as $id ) { $this->getListingSelection()->delete([$id]); } $msgs->addSuccess($this->lang['reset']['successMessage']); } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } return $this->executeListRecords($R,$msgs); } protected function bulkActionMoveUp(array $recordsIds, \App\MessagesCollector $msgs, array $R) { $id = reset($recordsIds); list($category, $key) = explode('|', $id); try { \App\Config\Remarks::getAdmin()->setHandledCategory($category)->itemMoveUp($key); $msgs->addSuccess($this->lang['moveUp']['messages']['successMessage']); } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } } protected function bulkActionMoveDown(array $recordsIds, \App\MessagesCollector $msgs, array $R) { $id = reset($recordsIds); list($category, $key) = explode('|', $id); try { \App\Config\Remarks::getAdmin()->setHandledCategory($category)->itemMoveDown($key); $msgs->addSuccess($this->lang['moveDown']['messages']['successMessage']); } catch (\App\Config\MessageException $e) { $msgs->addError($e->getMessage()); } } protected function delete_doDelete(array $recordsIds, \App\MessagesCollector $msgs, array $R) { $delete = []; foreach($recordsIds as $record) { list($category, $key) = explode('|', $record); try { \App\Config\Remarks::getAdmin()->setHandledCategory($category)->itemDelete($key); $this->getListingSelection()->delete([$record]); $msgs->addSuccess($this->lang['delete']['messages']['successMessage']); } catch (\App\Config\MessageException $e) { $msgs->addError(sprintf($this->lang['delete']['messages']['errorMessage'], $e->getMessage())); } } } protected function optionGetEntityName($id) { list($category, $key) = explode('|', $id); $remark = \App\Config\Remarks::getAdmin()->setHandledCategory($category)->get($key); return $remark['format']; } protected function insert_doInsert($formData, \App\MessagesCollector $msgs) { return true; } protected function update_doUpdate($formData, \App\MessagesCollector $msgs) { return true; } protected function update_getDefaultFormData($id) { return true; } }