. */ namespace SP\Modules\Web\Controllers\Account; use Exception; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Account\Ports\AccountServiceInterface; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\WebControllerHelper; /** * Class SaveEditRestoreController */ final class SaveEditRestoreController extends AccountControllerBase { use JsonTrait; private \SP\Domain\Account\Ports\AccountServiceInterface $accountService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountServiceInterface $accountService ) { parent::__construct( $application, $webControllerHelper ); $this->accountService = $accountService; } /** * Saves restore action * * @param int $historyId Account's history ID * @param int $id Account's ID * * @return bool * @throws \JsonException */ public function saveEditRestoreAction(int $historyId, int $id): bool { try { $this->accountService->editRestore($historyId, $id); $accountDetails = $this->accountService->getById($id)->getAccountVData(); $this->eventDispatcher->notifyEvent( 'edit.account.restore', new Event( $this, EventMessage::factory() ->addDescription(__u('Account restored')) ->addDetail(__u('Account'), $accountDetails->getName()) ->addDetail(__u('Client'), $accountDetails->getClientName()) ) ); return $this->returnJsonResponseData( [ 'itemId' => $id, 'nextAction' => Acl::getActionRoute(ActionsInterface::ACCOUNT_VIEW), ], JsonResponse::JSON_SUCCESS, __u('Account restored') ); } catch (Exception $e) { processException($e); $this->eventDispatcher->notifyEvent('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }