From 5b0efb61a08535ab6799bb2e3ee900448a40b210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Fri, 23 Aug 2024 16:53:19 +0200 Subject: [PATCH] chore(Refactor): Use abstract instead of trait MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../AccountFile/SearchController.php | 41 +++------------- .../SearchController.php | 49 +++++-------------- .../AccountManager/SearchController.php | 8 ++- ...Trait.php => SearchGridControllerBase.php} | 16 ++---- 4 files changed, 26 insertions(+), 88 deletions(-) rename app/modules/web/Controllers/{Helpers/SearchViewTrait.php => SearchGridControllerBase.php} (83%) diff --git a/app/modules/web/Controllers/AccountFile/SearchController.php b/app/modules/web/Controllers/AccountFile/SearchController.php index 992e1d91..a9f00dea 100644 --- a/app/modules/web/Controllers/AccountFile/SearchController.php +++ b/app/modules/web/Controllers/AccountFile/SearchController.php @@ -24,7 +24,6 @@ namespace SP\Modules\Web\Controllers\AccountFile; -use JsonException; use SP\Core\Application; use SP\Domain\Account\Ports\AccountFileService; use SP\Domain\Auth\Services\AuthException; @@ -33,25 +32,20 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\Http\Dtos\JsonMessage; use SP\Html\DataGrid\DataGridInterface; -use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Helpers\Grid\FileGrid; -use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Modules\Web\Controllers\SearchGridControllerBase; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; -use function SP\__u; - /** * Class SearchController * * @package SP\Modules\Web\Controllers */ -final class SearchController extends ControllerBase +final class SearchController extends SearchGridControllerBase { use ItemTrait; - use JsonTrait; /** * @throws AuthException @@ -68,32 +62,6 @@ final class SearchController extends ControllerBase $this->checkLoggedIn(); } - /** - * Search action - * - * @return bool - * @throws JsonException - * @throws ConstraintException - * @throws QueryException - * @throws SPException - */ - public function searchAction(): bool - { - /** @noinspection DuplicatedCode */ - if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNT_FILE_SEARCH)) { - return $this->returnJsonResponse( - JsonMessage::JSON_ERROR, - __u('You don\'t have permission to do this operation') - ); - } - - $this->view->addTemplate('datagrid-table', 'grid'); - $this->view->assign('index', $this->request->analyzeInt('activetab', 0)); - $this->view->assign('data', $this->getSearchGrid()); - - return $this->returnJsonResponseData(['html' => $this->render()]); - } - /** * getSearchGrid * @@ -111,4 +79,9 @@ final class SearchController extends ControllerBase $itemSearchData ); } + + protected function getAclAction(): int + { + return AclActionsInterface::ACCOUNT_FILE_SEARCH; + } } diff --git a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php index af71ce98..808b4eca 100644 --- a/app/modules/web/Controllers/AccountHistoryManager/SearchController.php +++ b/app/modules/web/Controllers/AccountHistoryManager/SearchController.php @@ -31,66 +31,36 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SessionTimeout; -use SP\Domain\Core\Exceptions\SPException; -use SP\Domain\Http\Dtos\JsonMessage; use SP\Html\DataGrid\DataGridInterface; -use SP\Modules\Web\Controllers\ControllerBase; -use SP\Modules\Web\Controllers\Helpers; -use SP\Modules\Web\Controllers\Traits\JsonTrait; +use SP\Modules\Web\Controllers\Helpers\Grid\AccountHistoryGrid; +use SP\Modules\Web\Controllers\SearchGridControllerBase; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; -use function SP\__u; - /** * Class SearchController * * @package SP\Modules\Web\Controllers */ -final class SearchController extends ControllerBase +final class SearchController extends SearchGridControllerBase { use ItemTrait; - use JsonTrait; /** * @throws AuthException * @throws SessionTimeout */ public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - private readonly AccountHistoryService $accountHistoryService, - private readonly Helpers\Grid\AccountHistoryGrid $accountHistoryGrid + Application $application, + WebControllerHelper $webControllerHelper, + private readonly AccountHistoryService $accountHistoryService, + private readonly AccountHistoryGrid $accountHistoryGrid ) { parent::__construct($application, $webControllerHelper); $this->checkLoggedIn(); } - - /** - * @return bool - * @throws ConstraintException - * @throws QueryException - * @throws SPException - */ - public function searchAction(): bool - { - /** @noinspection DuplicatedCode */ - if (!$this->acl->checkUserAccess(AclActionsInterface::ACCOUNTMGR_HISTORY_SEARCH)) { - return $this->returnJsonResponse( - JsonMessage::JSON_ERROR, - __u('You don\'t have permission to do this operation') - ); - } - - $this->view->addTemplate('datagrid-table', 'grid'); - $this->view->assign('index', $this->request->analyzeInt('activetab', 0)); - $this->view->assign('data', $this->getSearchGrid()); - - return $this->returnJsonResponseData(['html' => $this->render()]); - } - /** * getSearchGrid * @@ -106,4 +76,9 @@ final class SearchController extends ControllerBase $itemSearchData ); } + + protected function getAclAction(): int + { + return AclActionsInterface::ACCOUNTMGR_HISTORY_SEARCH; + } } diff --git a/app/modules/web/Controllers/AccountManager/SearchController.php b/app/modules/web/Controllers/AccountManager/SearchController.php index 829062ee..061a923e 100644 --- a/app/modules/web/Controllers/AccountManager/SearchController.php +++ b/app/modules/web/Controllers/AccountManager/SearchController.php @@ -34,9 +34,8 @@ use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; use SP\Html\DataGrid\DataGridInterface; -use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid; -use SP\Modules\Web\Controllers\Helpers\SearchViewTrait; +use SP\Modules\Web\Controllers\SearchGridControllerBase; use SP\Mvc\Controller\ItemTrait; use SP\Mvc\Controller\WebControllerHelper; @@ -45,10 +44,9 @@ use SP\Mvc\Controller\WebControllerHelper; * * @package SP\Modules\Web\Controllers */ -final class SearchController extends ControllerBase +final class SearchController extends SearchGridControllerBase { use ItemTrait; - use SearchViewTrait; /** * @throws SessionTimeout @@ -87,7 +85,7 @@ final class SearchController extends ControllerBase ); } - private function getAclAction(): int + protected function getAclAction(): int { return AclActionsInterface::ACCOUNTMGR_SEARCH; } diff --git a/app/modules/web/Controllers/Helpers/SearchViewTrait.php b/app/modules/web/Controllers/SearchGridControllerBase.php similarity index 83% rename from app/modules/web/Controllers/Helpers/SearchViewTrait.php rename to app/modules/web/Controllers/SearchGridControllerBase.php index 72b17159..13def23a 100644 --- a/app/modules/web/Controllers/Helpers/SearchViewTrait.php +++ b/app/modules/web/Controllers/SearchGridControllerBase.php @@ -24,29 +24,21 @@ declare(strict_types=1); -namespace SP\Modules\Web\Controllers\Helpers; +namespace SP\Modules\Web\Controllers; -use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Http\Dtos\JsonMessage; -use SP\Domain\Http\Ports\RequestService; use SP\Html\DataGrid\DataGridInterface; use SP\Modules\Web\Controllers\Traits\JsonTrait; -use SP\Mvc\View\TemplateInterface; use function SP\__u; /** - * Trait SearchViewTrait - * - * @property AclInterface $acl - * @property TemplateInterface $view - * @property RequestService $request - * @method render() + * Class SearchGridControllerBase */ -trait SearchViewTrait +abstract class SearchGridControllerBase extends ControllerBase { use JsonTrait; @@ -72,7 +64,7 @@ trait SearchViewTrait return $this->returnJsonResponseData(['html' => $this->render()]); } - abstract private function getAclAction(): int; + abstract protected function getAclAction(): int; abstract protected function getSearchGrid(): DataGridInterface; }