diff --git a/src/bundle/Resources/config/services/dashboard.yaml b/src/bundle/Resources/config/services/dashboard.yaml index 47cdb58e37..c614bf3495 100644 --- a/src/bundle/Resources/config/services/dashboard.yaml +++ b/src/bundle/Resources/config/services/dashboard.yaml @@ -11,39 +11,44 @@ services: parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab public: false arguments: - $contentSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType' + $contentLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType' tags: - { name: ezplatform.tab, group: dashboard-my } - EzSystems\EzPlatformAdminUi\Tab\Dashboard\MyMediaTab: + EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneContentTab: parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab public: false arguments: - $mediaSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType' + $contentLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType' tags: - - { name: ezplatform.tab, group: dashboard-my } + - { name: ezplatform.tab, group: dashboard-everyone } - EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneMediaTab: + EzSystems\EzPlatformAdminUi\Tab\Dashboard\MyMediaTab: parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab public: false arguments: - $mediaSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType' + $mediaLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType' tags: - - { name: ezplatform.tab, group: dashboard-everyone } + - { name: ezplatform.tab, group: dashboard-my } - EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneContentTab: + EzSystems\EzPlatformAdminUi\Tab\Dashboard\EveryoneMediaTab: parent: EzSystems\EzPlatformAdminUi\Tab\AbstractTab public: false arguments: - $contentSubtreeQueryType: '@EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType' + $mediaLocationSubtreeQueryType: '@Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType' tags: - { name: ezplatform.tab, group: dashboard-everyone } EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper: + deprecated: 'Service "%service_id%" is deprecated. Use "Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper" instead' parent: EzSystems\EzPlatformAdminUi\Search\AbstractPagerContentToDataMapper autowire: true public: false + Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper: + autowire: true + public: false + ezplatform.adminui.dashboard.me: parent: EzSystems\EzPlatformAdminUi\Component\TwigComponent arguments: diff --git a/src/bundle/Resources/config/services/query_types.yaml b/src/bundle/Resources/config/services/query_types.yaml index 65c51ff3a0..d3e18c9da1 100644 --- a/src/bundle/Resources/config/services/query_types.yaml +++ b/src/bundle/Resources/config/services/query_types.yaml @@ -8,8 +8,12 @@ services: EzSystems\EzPlatformAdminUi\QueryType\ContentSubtreeQueryType: ~ + Ibexa\AdminUi\QueryType\ContentLocationSubtreeQueryType: ~ + EzSystems\EzPlatformAdminUi\QueryType\MediaSubtreeQueryType: ~ + Ibexa\AdminUi\QueryType\MediaLocationSubtreeQueryType: ~ + EzSystems\EzPlatformAdminUi\QueryType\SearchQueryType: deprecated: 'Service "%service_id%" is deprecated since 3.1 and will be removed in 3.2. Use "Ibexa\Platform\Search\QueryType\SearchQueryType" instead' arguments: diff --git a/src/lib/QueryType/ContentLocationSubtreeQueryType.php b/src/lib/QueryType/ContentLocationSubtreeQueryType.php new file mode 100644 index 0000000000..4bcc1594b2 --- /dev/null +++ b/src/lib/QueryType/ContentLocationSubtreeQueryType.php @@ -0,0 +1,24 @@ +configResolver->getParameter(SubtreePath::CONTENT_SUBTREE_PATH); + } +} diff --git a/src/lib/QueryType/LocationSubtreeQueryType.php b/src/lib/QueryType/LocationSubtreeQueryType.php new file mode 100644 index 0000000000..173c74c39c --- /dev/null +++ b/src/lib/QueryType/LocationSubtreeQueryType.php @@ -0,0 +1,75 @@ +configResolver = $configResolver; + $this->permissionResolver = $permissionResolver; + } + + public function doGetQuery(array $parameters): LocationQuery + { + $subtreeCriterion = new Query\Criterion\Subtree($parameters[self::SUBTREE_OPTION_NAME]); + + $ownerId = $parameters[self::OWNED_OPTION_NAME] + ? $this->permissionResolver->getCurrentUserReference()->getUserId() + : null; + + if ($ownerId !== null) { + $filter = new Query\Criterion\LogicalAnd([ + $subtreeCriterion, + new Query\Criterion\UserMetadata( + Query\Criterion\UserMetadata::OWNER, + Query\Criterion\Operator::EQ, + $ownerId + ), + ]); + } else { + $filter = $subtreeCriterion; + } + + return new LocationQuery([ + 'filter' => $filter, + 'sortClauses' => [new Query\SortClause\DateModified(Query::SORT_DESC)], + ]); + } + + protected function configureOptions(OptionsResolver $optionsResolver): void + { + $optionsResolver->setDefined([self::SUBTREE_OPTION_NAME, self::OWNED_OPTION_NAME]); + $optionsResolver->setAllowedTypes(self::SUBTREE_OPTION_NAME, 'string'); + $optionsResolver->setAllowedTypes(self::OWNED_OPTION_NAME, 'bool'); + $optionsResolver->setDefault(self::SUBTREE_OPTION_NAME, $this->getSubtreePathFromConfiguration()); + $optionsResolver->setDefault(self::OWNED_OPTION_NAME, false); + } + + abstract protected function getSubtreePathFromConfiguration(): string; +} diff --git a/src/lib/QueryType/MediaLocationSubtreeQueryType.php b/src/lib/QueryType/MediaLocationSubtreeQueryType.php new file mode 100644 index 0000000000..baf255d81a --- /dev/null +++ b/src/lib/QueryType/MediaLocationSubtreeQueryType.php @@ -0,0 +1,24 @@ +configResolver->getParameter(SubtreePath::MEDIA_SUBTREE_PATH); + } +} diff --git a/src/lib/Tab/Dashboard/AbstractContentTab.php b/src/lib/Tab/Dashboard/AbstractContentTab.php new file mode 100644 index 0000000000..c593313745 --- /dev/null +++ b/src/lib/Tab/Dashboard/AbstractContentTab.php @@ -0,0 +1,42 @@ +pagerLocationToDataMapper = $pagerLocationToDataMapper; + $this->searchService = $searchService; + $this->contentLocationSubtreeQueryType = $contentLocationSubtreeQueryType; + } +} diff --git a/src/lib/Tab/Dashboard/AbstractMediaTab.php b/src/lib/Tab/Dashboard/AbstractMediaTab.php new file mode 100644 index 0000000000..619174803e --- /dev/null +++ b/src/lib/Tab/Dashboard/AbstractMediaTab.php @@ -0,0 +1,42 @@ +pagerLocationToDataMapper = $pagerLocationToDataMapper; + $this->searchService = $searchService; + $this->mediaLocationSubtreeQueryType = $mediaLocationSubtreeQueryType; + } +} diff --git a/src/lib/Tab/Dashboard/EveryoneContentTab.php b/src/lib/Tab/Dashboard/EveryoneContentTab.php index 31d2425445..183d90153c 100644 --- a/src/lib/Tab/Dashboard/EveryoneContentTab.php +++ b/src/lib/Tab/Dashboard/EveryoneContentTab.php @@ -8,47 +8,13 @@ namespace EzSystems\EzPlatformAdminUi\Tab\Dashboard; -use eZ\Publish\API\Repository\SearchService; -use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; -use eZ\Publish\Core\QueryType\QueryType; -use EzSystems\EzPlatformAdminUi\Tab\AbstractTab; +use eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchAdapter; use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface; +use Ibexa\AdminUi\Tab\Dashboard\AbstractContentTab; use Pagerfanta\Pagerfanta; -use Symfony\Contracts\Translation\TranslatorInterface; -use Twig\Environment; -class EveryoneContentTab extends AbstractTab implements OrderedTabInterface +class EveryoneContentTab extends AbstractContentTab implements OrderedTabInterface { - /** @var \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper */ - protected $pagerContentToDataMapper; - - /** @var \eZ\Publish\API\Repository\SearchService */ - protected $searchService; - - /** @var \eZ\Publish\Core\QueryType\QueryType */ - private $contentSubtreeQueryType; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper $pagerContentToDataMapper - * @param \eZ\Publish\API\Repository\SearchService $searchService - * @param \eZ\Publish\Core\QueryType\QueryType $contentSubtreeQueryType - */ - public function __construct( - Environment $twig, - TranslatorInterface $translator, - PagerContentToDataMapper $pagerContentToDataMapper, - SearchService $searchService, - QueryType $contentSubtreeQueryType - ) { - parent::__construct($twig, $translator); - - $this->pagerContentToDataMapper = $pagerContentToDataMapper; - $this->searchService = $searchService; - $this->contentSubtreeQueryType = $contentSubtreeQueryType; - } - public function getIdentifier(): string { return 'everyone-content'; @@ -65,6 +31,9 @@ public function getOrder(): int return 100; } + /** + * @inheritdoc + */ public function renderView(array $parameters): string { /** @todo Handle pagination */ @@ -72,8 +41,8 @@ public function renderView(array $parameters): string $limit = 10; $pager = new Pagerfanta( - new ContentSearchAdapter( - $this->contentSubtreeQueryType->getQuery(), + new LocationSearchAdapter( + $this->contentLocationSubtreeQueryType->getQuery(), $this->searchService ) ); @@ -81,7 +50,7 @@ public function renderView(array $parameters): string $pager->setCurrentPage($page); return $this->twig->render('@ezdesign/ui/dashboard/tab/all_content.html.twig', [ - 'data' => $this->pagerContentToDataMapper->map($pager), + 'data' => $this->pagerLocationToDataMapper->map($pager, true), ]); } } diff --git a/src/lib/Tab/Dashboard/EveryoneMediaTab.php b/src/lib/Tab/Dashboard/EveryoneMediaTab.php index c2b4fd8378..89ee9012ff 100644 --- a/src/lib/Tab/Dashboard/EveryoneMediaTab.php +++ b/src/lib/Tab/Dashboard/EveryoneMediaTab.php @@ -8,47 +8,13 @@ namespace EzSystems\EzPlatformAdminUi\Tab\Dashboard; -use eZ\Publish\API\Repository\SearchService; -use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; -use eZ\Publish\Core\QueryType\QueryType; -use EzSystems\EzPlatformAdminUi\Tab\AbstractTab; +use eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchAdapter; use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface; +use Ibexa\AdminUi\Tab\Dashboard\AbstractMediaTab; use Pagerfanta\Pagerfanta; -use Symfony\Contracts\Translation\TranslatorInterface; -use Twig\Environment; -class EveryoneMediaTab extends AbstractTab implements OrderedTabInterface +class EveryoneMediaTab extends AbstractMediaTab implements OrderedTabInterface { - /** @var \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper */ - protected $pagerContentToDataMapper; - - /** @var \eZ\Publish\API\Repository\SearchService */ - protected $searchService; - - /** @var \eZ\Publish\Core\QueryType\QueryType */ - private $mediaSubtreeQueryType; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper $pagerContentToDataMapper - * @param \eZ\Publish\API\Repository\SearchService $searchService - * @param \eZ\Publish\Core\QueryType\QueryType $mediaSubtreeQueryType - */ - public function __construct( - Environment $twig, - TranslatorInterface $translator, - PagerContentToDataMapper $pagerContentToDataMapper, - SearchService $searchService, - QueryType $mediaSubtreeQueryType - ) { - parent::__construct($twig, $translator); - - $this->pagerContentToDataMapper = $pagerContentToDataMapper; - $this->searchService = $searchService; - $this->mediaSubtreeQueryType = $mediaSubtreeQueryType; - } - public function getIdentifier(): string { return 'everyone-media'; @@ -65,6 +31,9 @@ public function getOrder(): int return 200; } + /** + * @inheritdoc + */ public function renderView(array $parameters): string { /** @todo Handle pagination */ @@ -72,8 +41,8 @@ public function renderView(array $parameters): string $limit = 10; $pager = new Pagerfanta( - new ContentSearchAdapter( - $this->mediaSubtreeQueryType->getQuery(), + new LocationSearchAdapter( + $this->mediaLocationSubtreeQueryType->getQuery(), $this->searchService ) ); @@ -81,7 +50,7 @@ public function renderView(array $parameters): string $pager->setCurrentPage($page); return $this->twig->render('@ezdesign/ui/dashboard/tab/all_media.html.twig', [ - 'data' => $this->pagerContentToDataMapper->map($pager), + 'data' => $this->pagerLocationToDataMapper->map($pager, true), ]); } } diff --git a/src/lib/Tab/Dashboard/MyContentTab.php b/src/lib/Tab/Dashboard/MyContentTab.php index c6faac49ba..f7a344839d 100644 --- a/src/lib/Tab/Dashboard/MyContentTab.php +++ b/src/lib/Tab/Dashboard/MyContentTab.php @@ -8,47 +8,13 @@ namespace EzSystems\EzPlatformAdminUi\Tab\Dashboard; -use eZ\Publish\API\Repository\SearchService; -use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; -use eZ\Publish\Core\QueryType\QueryType; -use EzSystems\EzPlatformAdminUi\Tab\AbstractTab; +use eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchAdapter; use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface; +use Ibexa\AdminUi\Tab\Dashboard\AbstractContentTab; use Pagerfanta\Pagerfanta; -use Symfony\Contracts\Translation\TranslatorInterface; -use Twig\Environment; -class MyContentTab extends AbstractTab implements OrderedTabInterface +class MyContentTab extends AbstractContentTab implements OrderedTabInterface { - /** @var \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper */ - protected $pagerContentToDataMapper; - - /** @var \eZ\Publish\API\Repository\SearchService */ - protected $searchService; - - /** @var \eZ\Publish\Core\QueryType\QueryType */ - private $contentSubtreeQueryType; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper $pagerContentToDataMapper - * @param \eZ\Publish\API\Repository\SearchService $searchService - * @param \eZ\Publish\Core\QueryType\QueryType $contentSubtreeQueryType - */ - public function __construct( - Environment $twig, - TranslatorInterface $translator, - PagerContentToDataMapper $pagerContentToDataMapper, - SearchService $searchService, - QueryType $contentSubtreeQueryType - ) { - parent::__construct($twig, $translator); - - $this->pagerContentToDataMapper = $pagerContentToDataMapper; - $this->searchService = $searchService; - $this->contentSubtreeQueryType = $contentSubtreeQueryType; - } - public function getIdentifier(): string { return 'my-content'; @@ -65,6 +31,9 @@ public function getOrder(): int return 200; } + /** + * @inheritdoc + */ public function renderView(array $parameters): string { /** @todo Handle pagination */ @@ -72,8 +41,8 @@ public function renderView(array $parameters): string $limit = 10; $pager = new Pagerfanta( - new ContentSearchAdapter( - $this->contentSubtreeQueryType->getQuery(['owned' => true]), + new LocationSearchAdapter( + $this->contentLocationSubtreeQueryType->getQuery(['owned' => true]), $this->searchService ) ); @@ -81,7 +50,7 @@ public function renderView(array $parameters): string $pager->setCurrentPage($page); return $this->twig->render('@ezdesign/ui/dashboard/tab/my_content.html.twig', [ - 'data' => $this->pagerContentToDataMapper->map($pager), + 'data' => $this->pagerLocationToDataMapper->map($pager), ]); } } diff --git a/src/lib/Tab/Dashboard/MyMediaTab.php b/src/lib/Tab/Dashboard/MyMediaTab.php index ef33275cc0..44c61d5a25 100644 --- a/src/lib/Tab/Dashboard/MyMediaTab.php +++ b/src/lib/Tab/Dashboard/MyMediaTab.php @@ -8,47 +8,13 @@ namespace EzSystems\EzPlatformAdminUi\Tab\Dashboard; -use eZ\Publish\API\Repository\SearchService; -use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter; -use eZ\Publish\Core\QueryType\QueryType; -use EzSystems\EzPlatformAdminUi\Tab\AbstractTab; +use eZ\Publish\Core\Pagination\Pagerfanta\LocationSearchAdapter; use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface; +use Ibexa\AdminUi\Tab\Dashboard\AbstractMediaTab; use Pagerfanta\Pagerfanta; -use Symfony\Contracts\Translation\TranslatorInterface; -use Twig\Environment; -class MyMediaTab extends AbstractTab implements OrderedTabInterface +class MyMediaTab extends AbstractMediaTab implements OrderedTabInterface { - /** @var \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper */ - protected $pagerContentToDataMapper; - - /** @var \eZ\Publish\API\Repository\SearchService */ - protected $searchService; - - /** @var \eZ\Publish\Core\QueryType\QueryType */ - private $mediaSubtreeQueryType; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \EzSystems\EzPlatformAdminUi\Tab\Dashboard\PagerContentToDataMapper $pagerContentToDataMapper - * @param \eZ\Publish\API\Repository\SearchService $searchService - * @param \eZ\Publish\Core\QueryType\QueryType $mediaSubtreeQueryType - */ - public function __construct( - Environment $twig, - TranslatorInterface $translator, - PagerContentToDataMapper $pagerContentToDataMapper, - SearchService $searchService, - QueryType $mediaSubtreeQueryType - ) { - parent::__construct($twig, $translator); - - $this->pagerContentToDataMapper = $pagerContentToDataMapper; - $this->searchService = $searchService; - $this->mediaSubtreeQueryType = $mediaSubtreeQueryType; - } - public function getIdentifier(): string { return 'my-media'; @@ -65,6 +31,9 @@ public function getOrder(): int return 300; } + /** + * @inheritdoc + */ public function renderView(array $parameters): string { /** @todo Handle pagination */ @@ -72,8 +41,8 @@ public function renderView(array $parameters): string $limit = 10; $pager = new Pagerfanta( - new ContentSearchAdapter( - $this->mediaSubtreeQueryType->getQuery(['owned' => true]), + new LocationSearchAdapter( + $this->mediaLocationSubtreeQueryType->getQuery(['owned' => true]), $this->searchService ) ); @@ -81,7 +50,7 @@ public function renderView(array $parameters): string $pager->setCurrentPage($page); return $this->twig->render('@ezdesign/ui/dashboard/tab/my_media.html.twig', [ - 'data' => $this->pagerContentToDataMapper->map($pager), + 'data' => $this->pagerLocationToDataMapper->map($pager), ]); } } diff --git a/src/lib/Tab/Dashboard/PagerContentToDataMapper.php b/src/lib/Tab/Dashboard/PagerContentToDataMapper.php index 61a73221af..3e8d8b0306 100644 --- a/src/lib/Tab/Dashboard/PagerContentToDataMapper.php +++ b/src/lib/Tab/Dashboard/PagerContentToDataMapper.php @@ -18,6 +18,10 @@ use EzSystems\EzPlatformAdminUi\Pagination\Mapper\AbstractPagerContentToDataMapper; use Pagerfanta\Pagerfanta; +/** + * @deprecated in favour of PagerLocationToDataMapper + * @see \Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper + */ class PagerContentToDataMapper extends AbstractPagerContentToDataMapper { /** @var \eZ\Publish\API\Repository\ContentService */ @@ -50,6 +54,15 @@ public function __construct( LanguageService $languageService, LocationResolver $locationResolver ) { + @trigger_error( + sprintf( + 'The "%s" class is deprecated. Use "%s" instead.', + __CLASS__, + 'Ibexa\AdminUi\Tab\Dashboard\PagerLocationToDataMapper' + ), + E_DEPRECATED + ); + $this->contentService = $contentService; $this->contentTypeService = $contentTypeService; $this->userService = $userService; diff --git a/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php new file mode 100644 index 0000000000..2ebdc23f43 --- /dev/null +++ b/src/lib/Tab/Dashboard/PagerLocationToDataMapper.php @@ -0,0 +1,87 @@ +contentService = $contentService; + $this->contentTypeService = $contentTypeService; + $this->userService = $userService; + $this->locationResolver = $locationResolver; + } + + /** + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + */ + public function map(Pagerfanta $pager, bool $doMapVersionInfoData = false): array + { + $data = []; + + /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */ + foreach ($pager as $location) { + $contentInfo = $location->contentInfo; + $versionInfo = $doMapVersionInfoData ? $this->contentService->loadVersionInfo($contentInfo) : null; + $contentType = $location->getContentInfo()->getContentType(); + + $data[] = [ + 'contentTypeId' => $contentInfo->contentTypeId, + 'contentId' => $contentInfo->id, + 'name' => $contentInfo->name, + 'type' => $contentType->getName(), + 'language' => $contentInfo->mainLanguageCode, + 'available_enabled_translations' => [], + 'contributor' => $versionInfo !== null ? $this->getVersionContributor($versionInfo) : null, + 'content_type' => $contentType, + 'modified' => $contentInfo->modificationDate, + 'resolvedLocation' => $this->locationResolver->resolveLocation($contentInfo), + ]; + } + + return $data; + } + + private function getVersionContributor(VersionInfo $versionInfo): ?User + { + try { + return $this->userService->loadUser($versionInfo->creatorId); + } catch (NotFoundException $e) { + return null; + } + } +}