• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / Yoast-SEO-for-TYPO3 / 13327579701

14 Feb 2025 10:43AM UTC coverage: 1.276%. First build
13327579701

push

github

web-flow
Merge pull request #597 from Yoast/feature/v11

[FEATURE] Release 11.0.0

21 of 894 new or added lines in 76 files covered. (2.35%)

35 of 2744 relevant lines covered (1.28%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/Service/Overview/OverviewService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Service\Overview;
6

7
use TYPO3\CMS\Backend\Utility\BackendUtility;
8
use TYPO3\CMS\Core\Type\Bitmask\Permission;
9
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
10
use YoastSeoForTypo3\YoastSeo\Controller\OverviewController;
11
use YoastSeoForTypo3\YoastSeo\DataProviders\OverviewDataProviderInterface;
12
use YoastSeoForTypo3\YoastSeo\Service\Overview\Dto\DataProviderRequest;
13
use YoastSeoForTypo3\YoastSeo\Service\Overview\Dto\OverviewData;
14
use YoastSeoForTypo3\YoastSeo\Service\Overview\Pagination\PaginationService;
15
use YoastSeoForTypo3\YoastSeo\Traits\BackendUserTrait;
16

17
class OverviewService
18
{
19
    use BackendUserTrait;
20

21
    /** @var array<string, OverviewDataProviderInterface> */
22
    protected array $filters;
23

24
    /**
25
     * @param iterable<string, OverviewDataProviderInterface> $filters
26
     */
27
    public function __construct(
28
        protected PaginationService $overviewPaginationService,
29
        iterable $filters
30
    ) {
NEW
31
        foreach ($filters as $key => $dataProvider) {
×
NEW
32
            $this->addFilter($key, $dataProvider);
×
33
        }
34
    }
35

36
    public function getOverviewData(RequestInterface $request, int $currentPage, int $itemsPerPage): OverviewData
37
    {
NEW
38
        $overviewData = new OverviewData($this->getPageInformation($request));
×
NEW
39
        if (empty($overviewData->getPageInformation())) {
×
NEW
40
            return $overviewData;
×
41
        }
42

NEW
43
        $overviewData->setFilters($this->getAvailableFilters($request));
×
NEW
44
        if (empty($overviewData->getFilters())) {
×
NEW
45
            return $overviewData;
×
46
        }
47

NEW
48
        $activeFilter = $this->getActiveFilter($request);
×
NEW
49
        $items = $activeFilter->process();
×
50

NEW
51
        $arrayPaginator = $this->overviewPaginationService->getArrayPaginator($items, $currentPage, $itemsPerPage);
×
52

NEW
53
        return $overviewData->setItems($items)
×
NEW
54
            ->setPaginator($arrayPaginator)
×
NEW
55
            ->setPagination($this->overviewPaginationService->getPagination($arrayPaginator))
×
NEW
56
            ->setActiveFilter($activeFilter)
×
NEW
57
            ->setParams($this->getDataProviderRequest($request));
×
58
    }
59

60
    /**
61
     * @return array<string, OverviewDataProviderInterface>|null
62
     */
63
    public function getAvailableFilters(RequestInterface $request): ?array
64
    {
NEW
65
        if ($this->filters === []) {
×
NEW
66
            return null;
×
67
        }
68

NEW
69
        $dataProviderRequest = $this->getDataProviderRequest($request);
×
NEW
70
        foreach ($this->filters as $dataProvider) {
×
NEW
71
            $dataProvider->initialize($dataProviderRequest);
×
72
        }
73

NEW
74
        return $this->filters;
×
75
    }
76

77
    protected function getActiveFilter(RequestInterface $request): OverviewDataProviderInterface
78
    {
NEW
79
        if ($this->filters === []) {
×
NEW
80
            throw new \RuntimeException('No filters available');
×
81
        }
82

NEW
83
        if ($request->hasArgument('filter')) {
×
NEW
84
            $activeFilter = $request->getArgument('filter');
×
NEW
85
            if (is_string($activeFilter) && isset($this->filters[$activeFilter])) {
×
NEW
86
                return $this->filters[$activeFilter];
×
87
            }
88
        }
89

NEW
90
        return current($this->filters);
×
91
    }
92

93
    protected function getDataProviderRequest(RequestInterface $request): DataProviderRequest
94
    {
NEW
95
        return new DataProviderRequest(
×
NEW
96
            (int)($request->getQueryParams()['id'] ?? 0),
×
NEW
97
            (int)($request->getQueryParams()[OverviewController::REQUEST_ARGUMENT]['language'] ?? $request->getQueryParams()['language'] ?? 0),
×
NEW
98
            'pages'
×
NEW
99
        );
×
100
    }
101

102
    /**
103
     * @return array<string, string|int>
104
     */
105
    protected function getPageInformation(RequestInterface $request): array
106
    {
NEW
107
        $id = (int)($request->getQueryParams()['id'] ?? 0);
×
NEW
108
        if ($id === 0) {
×
NEW
109
            return [];
×
110
        }
NEW
111
        $pageInformation = BackendUtility::readPageAccess(
×
NEW
112
            $id,
×
NEW
113
            $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
×
NEW
114
        );
×
NEW
115
        return is_array($pageInformation) ? $pageInformation : [];
×
116
    }
117

118
    protected function addFilter(string $key, OverviewDataProviderInterface $dataProvider): void
119
    {
NEW
120
        $this->filters[$key] = $dataProvider;
×
121
    }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc