<?php
namespace Modules\Admin\Config\OAuth2\AuthCodes; class Controller extends \App\Mvc\Controller\Window\PaginatedListing\PaginatedEntityListing { protected $useSqlTransaction=false; protected $listOrderingColumns = ['expiresAt', 'addTime']; protected function initialize() { parent::initialize(); $this->actionsCfg['block'] = ['checkSection' => true,]; $this->actionsCfg['unblock'] = ['checkSection' => true,]; $this->actionsCfg['delete'] = ['checkSection' => true,]; } protected function optionDefineParams(\App\Mvc\View\Utils\RowOptions\Option\Option $option, $selection) { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); switch ($option->getId()) { case 'block': foreach ($selection as $selectedItem) { if (\Entity\OAuth2AuthCode::select($selectedItem)->isRevoked) { $option->setDisabled(); } } break; case 'unblock': foreach ($selection as $selectedItem) { if (!\Entity\OAuth2AuthCode::select($selectedItem)->isRevoked) { $option->setDisabled(); } } break; case 'delete': break; default: return false; } return true; } protected function optionGetEntityName($id) { return \Entity\OAuth2AuthCode::select($id)->codeId; } protected function insert_getDefaultFormData($R) { } protected function insert_createEntityObject($formData) { } protected function update_getDefaultFormData($idEntity) { } protected function update_createEntityObject($formData) { } protected function delete_createEntityObject($idRecord) { return \Entity\OAuth2AuthCode::delete($idRecord); } protected function actionBlock($R) { $msgs = \App\MessagesCollector::create(); if ($R['listing']['selection']) { $this->setListingSelection($R['listing']['selection']); } $selIds = $this->getListingSelection()->getList(); foreach ($selIds as $id) { \DB::startTransaction(); try { $cronEnt = \Entity\OAuth2AuthCode::update($id); $cronEnt->isRevoked = 1; $cronEnt->save(); \DB::commitTransaction(); $this->getListingSelection()->delete([$id]); $msgs->addSuccess($this->lang['block']['successMessage']); } catch (\App\Entity\Exception $ex) { \DB::rollbackTransaction(); $msgs->appendMessages($ex->getMessagesCollector()); } } return $this->executeListRecords($R, $msgs); } protected function actionUnblock($R) { $msgs = \App\MessagesCollector::create(); if ($R['listing']['selection']) { $this->setListingSelection($R['listing']['selection']); } $selIds = $this->getListingSelection()->getList(); foreach ($selIds as $id) { \DB::startTransaction(); try { $cronEnt = \Entity\OAuth2AuthCode::update($id); $cronEnt->isRevoked = 0; $cronEnt->save(); \DB::commitTransaction(); $this->getListingSelection()->delete([$id]); $msgs->addSuccess($this->lang['unblock']['successMessage']); } catch (\App\Entity\Exception $ex) { \DB::rollbackTransaction(); $msgs->appendMessages($ex->getMessagesCollector()); } } return $this->executeListRecords($R, $msgs); } } 