. */ namespace SP\Modules\Web\Controllers; use DI\DependencyException; use DI\NotFoundException; use SP\Core\Acl\Acl; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Exceptions\ConstraintException; use SP\Core\Exceptions\QueryException; use SP\Core\Exceptions\SessionTimeout; use SP\DataModel\ItemSearchData; use SP\Html\DataGrid\DataGridTab; use SP\Modules\Web\Controllers\Helpers\Grid\AccountGrid; use SP\Modules\Web\Controllers\Helpers\Grid\AccountHistoryGrid; use SP\Modules\Web\Controllers\Helpers\Grid\CategoryGrid; use SP\Modules\Web\Controllers\Helpers\Grid\ClientGrid; use SP\Modules\Web\Controllers\Helpers\Grid\CustomFieldGrid; use SP\Modules\Web\Controllers\Helpers\Grid\FileGrid; use SP\Modules\Web\Controllers\Helpers\Grid\ItemPresetGrid; use SP\Modules\Web\Controllers\Helpers\Grid\TagGrid; use SP\Modules\Web\Controllers\Helpers\TabsGridHelper; use SP\Services\Account\AccountFileService; use SP\Services\Account\AccountHistoryService; use SP\Services\Account\AccountService; use SP\Services\Auth\AuthException; use SP\Services\Category\CategoryService; use SP\Services\Client\ClientService; use SP\Services\CustomField\CustomFieldDefService; use SP\Services\ItemPreset\ItemPresetService; use SP\Services\Tag\TagService; /** * Class ItemManagerController * * @package SP\Modules\Web\Controllers */ final class ItemManagerController extends ControllerBase { protected ?ItemSearchData $itemSearchData = null; protected ?TabsGridHelper $tabsGridHelper = null; /** * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ public function indexAction(): void { $this->getGridTabs(); } /** * Returns a tabbed grid with items * * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getGridTabs(): void { $this->itemSearchData = new ItemSearchData(); $this->itemSearchData->setLimitCount($this->configData->getAccountCount()); $this->tabsGridHelper = $this->dic->get(TabsGridHelper::class); if ($this->checkAccess(ActionsInterface::CATEGORY)) { $this->tabsGridHelper->addTab($this->getCategoriesList()); } if ($this->checkAccess(ActionsInterface::TAG)) { $this->tabsGridHelper->addTab($this->getTagsList()); } if ($this->checkAccess(ActionsInterface::CLIENT)) { $this->tabsGridHelper->addTab($this->getClientsList()); } if ($this->checkAccess(ActionsInterface::CUSTOMFIELD)) { $this->tabsGridHelper->addTab($this->getCustomFieldsList()); } if ($this->configData->isFilesEnabled() && $this->checkAccess(ActionsInterface::FILE)) { $this->tabsGridHelper->addTab($this->getAccountFilesList()); } if ($this->checkAccess(ActionsInterface::ACCOUNTMGR)) { $this->tabsGridHelper->addTab($this->getAccountsList()); } if ($this->checkAccess(ActionsInterface::ACCOUNTMGR_HISTORY)) { $this->tabsGridHelper->addTab($this->getAccountsHistoryList()); } if ($this->checkAccess(ActionsInterface::ITEMPRESET)) { $this->tabsGridHelper->addTab($this->getItemPresetList()); } $this->eventDispatcher->notifyEvent( 'show.itemlist.items', new Event($this) ); $this->tabsGridHelper->renderTabs( Acl::getActionRoute(ActionsInterface::ITEMS_MANAGE), $this->request->analyzeInt('tabIndex', 0) ); $this->view(); } /** * Returns categories' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getCategoriesList(): DataGridTab { return $this->dic->get(CategoryGrid::class) ->getGrid($this->dic->get(CategoryService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns tags' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getTagsList(): DataGridTab { return $this->dic->get(TagGrid::class) ->getGrid($this->dic->get(TagService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns clients' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getClientsList(): DataGridTab { return $this->dic->get(ClientGrid::class) ->getGrid($this->dic->get(ClientService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns custom fields' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getCustomFieldsList(): DataGridTab { return $this->dic->get(CustomFieldGrid::class) ->getGrid($this->dic->get(CustomFieldDefService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns account files' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getAccountFilesList(): DataGridTab { return $this->dic->get(FileGrid::class) ->getGrid($this->dic->get(AccountFileService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns accounts' data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getAccountsList(): DataGridTab { return $this->dic->get(AccountGrid::class) ->getGrid($this->dic->get(AccountService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns accounts' history data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getAccountsHistoryList(): DataGridTab { return $this->dic->get(AccountHistoryGrid::class) ->getGrid($this->dic->get(AccountHistoryService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * Returns API tokens data tab * * @return DataGridTab * @throws DependencyException * @throws NotFoundException * @throws ConstraintException * @throws QueryException */ protected function getItemPresetList(): DataGridTab { return $this->dic->get(ItemPresetGrid::class) ->getGrid($this->dic->get(ItemPresetService::class) ->search($this->itemSearchData)) ->updatePager(); } /** * @return TabsGridHelper */ public function getTabsGridHelper(): TabsGridHelper { return $this->tabsGridHelper; } /** * @throws AuthException * @throws DependencyException * @throws NotFoundException * @throws SessionTimeout */ protected function initialize(): void { $this->checkLoggedIn(); } }