<?php
namespace Modules\Admin\BankAccounts; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedEntityListing { protected $useSqlTransaction=true; protected function initialize() { parent::initialize(); $this->actionsCfg['insert'] = []; $this->actionsCfg['update'] = []; $this->actionsCfg['delete'] = []; $this->actionsCfg['setDefault'] = ['checkSection' => false, 'checkOption' => false,]; } protected $listOrderingColumns = ['account', 'currency', 'addTime']; protected function update_getDefaultFormData($idRecord) { $bankAcc = \Entity\AgencyBankAccount::select($idRecord); $formData = []; $formData['idBank'] = ['id'=>sprintf("%s|%s", $bankAcc->idBank,$bankAcc->idBankOffice)]; $formData['account'] = $bankAcc->account; $formData['description'] = $bankAcc->description; $formData['currency'] = $bankAcc->currency; return $formData; } protected function insert_createEntityObject($formData) { $bankAcc = \Entity\AgencyBankAccount::insert(); list($idBank, $idBankOffice) = explode("|", $formData['idBank']['id']); $bankAcc->idBank = $idBank; $bankAcc->idBankOffice = $idBankOffice; $bankAcc->account = $formData['account']; $bankAcc->description = $formData['description']; $bankAcc->currency = $formData['currency']; return $bankAcc; } protected function update_createEntityObject($formData) { $bankAcc = \Entity\AgencyBankAccount::update($this->updateIdRecord); list($idBank, $idBankOffice) = explode("|", $formData['idBank']['id']); $bankAcc->idBank = $idBank; $bankAcc->idBankOffice = $idBankOffice; $bankAcc->account = $formData['account']; $bankAcc->description = $formData['description']; $bankAcc->currency = $formData['currency']; return $bankAcc; } protected function delete_createEntityObject($idRecord) { return \Entity\AgencyBankAccount::delete($idRecord); } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { switch($option->getId()){ case 'insert': break; case 'update': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\AgencyBankAccount::update($selectedItem))) { break; } } break; case 'setDefault': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\AgencyBankAccount::setDefault($selectedItem))) { break; } } break; case 'delete': foreach ($selection as $selectedItem) { if (!$option->determineOperationAvailability(\Entity\AgencyBankAccount::delete($selectedItem))) { break; } } break; default: return false; } return true; } protected function optionGetEntityName($id) { return \Entity\AgencyBankAccount::select($id)->account; } protected function bulkActionSetDefault(array $recordsIds, \App\MessagesCollector $msgs, array $R) { foreach($recordsIds as $id) { $setDefaultAgencyBankAccountEnt = \Entity\AgencyBankAccount::setDefault($id); \App\Mvc\Controller\Helpers\EntityOperations::executeSave($setDefaultAgencyBankAccountEnt, $msgs, $this->useSqlTransaction); } } } 