From 3913560d885236091bf035d31d06f222befb664c Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Sat, 19 Feb 2022 13:03:19 +0100 Subject: [PATCH] [FEATURE] Add filter for linktype Related: #163 --- .../Controller/BrokenLinkListController.php | 13 +++++-- .../Filter/BrokenLinkListFilter.php | 37 +++++++++++++------ Classes/Repository/BrokenLinkRepository.php | 24 ++++++------ .../Private/Language/Module/locallang.xlf | 12 ++++++ .../Private/Templates/Backend/ReportTab.html | 13 +++++++ 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/Classes/Controller/BrokenLinkListController.php b/Classes/Controller/BrokenLinkListController.php index b9be34e21..b5f4dc67d 100644 --- a/Classes/Controller/BrokenLinkListController.php +++ b/Classes/Controller/BrokenLinkListController.php @@ -305,9 +305,8 @@ protected function getSettingsFromQueryParameters(): void // store filter parameters in the Filter Object $this->filter = new BrokenLinkListFilter(); $this->filter->setUidFilter(GeneralUtility::_GP('uid_searchFilter') ?? ''); - $this->filter->setUrlFilter(GeneralUtility::_GP('url_searchFilter') ?? ''); - + $this->filter->setLinktypeFilter(GeneralUtility::_GP('linktype_searchFilter') ?? 'all'); $this->filter->setTitleFilter(GeneralUtility::_GP('title_searchFilter') ?? ''); // to prevent deleting session, when user sort the records @@ -563,6 +562,7 @@ protected function createViewForBrokenLinksTab(): StandaloneView // build the search filter from the backendSession session $searchFilter = new BrokenLinkListFilter(); $searchFilter->setUrlFilter($this->backendSession->get('filterKey')->getUrlFilter()); + $searchFilter->setLinktypeFilter($this->backendSession->get('filterKey')->getLinktypeFilter()); $searchFilter->setUidFilter($this->backendSession->get('filterKey')->getUidFilter()); $searchFilter->setTitleFilter($this->backendSession->get('filterKey')->getTitleFilter()); @@ -589,15 +589,20 @@ protected function createViewForBrokenLinksTab(): StandaloneView } $view->assign('totalCount', $totalCount); // send the search filters to the view - $view->assign('url_filter', $this->backendSession->get('filterKey')->getUrlFilter()); $view->assign('uid_filter', $this->backendSession->get('filterKey')->getUidFilter()); - $view->assign('title_filter', $this->backendSession->get('filterKey')->getTitleFilter()); + $view->assign('linktype_filter', $this->backendSession->get('filterKey')->getLinktypeFilter()); + $view->assign('url_filter', $this->backendSession->get('filterKey')->getUrlFilter()); + //$view->assign('title_filter', $this->backendSession->get('filterKey')->getTitleFilter()); if ($this->id === 0) { $this->createFlashMessagesForRootPage(); } elseif (empty($items)) { $this->createFlashMessagesForNoBrokenLinks(); } $view->assign('brokenLinks', $items); + $linktypes = array_merge(['all' => 'all'], $this->linkTypes); + if (count($linktypes) > 2) { + $view->assign('linktypes', $linktypes); + } $view->assign('pagination', $this->pagination); $view->assign('orderBy', $this->orderBy); diff --git a/Classes/Controller/Filter/BrokenLinkListFilter.php b/Classes/Controller/Filter/BrokenLinkListFilter.php index 7a6e2d5d9..7f8780b22 100644 --- a/Classes/Controller/Filter/BrokenLinkListFilter.php +++ b/Classes/Controller/Filter/BrokenLinkListFilter.php @@ -9,32 +9,45 @@ class BrokenLinkListFilter /** * @var string */ - protected $url_filtre = ''; + protected $uid_filtre = ''; + + /** @var string */ + protected $linktype_filter = 'all'; /** * @var string */ - protected $uid_filtre = ''; + protected $url_filtre = ''; /** * @var string + * @deprecated */ protected $title_filter = ''; - // Getters and Setters + public function getUidFilter(): string + { + return $this->uid_filtre; + } - public function getUrlFilter(): string + public function setUidFilter(string $uid_filter): void { - return $this->url_filtre; + $this->uid_filtre = $uid_filter; } - public function getUidFilter(): string + + public function getLinktypeFilter(): string { - return $this->uid_filtre; + return $this->linktype_filter; } - public function getTitleFilter(): string + public function setLinktypeFilter(string $linktype_filter): void { - return $this->title_filter; + $this->linktype_filter = $linktype_filter; + } + + public function getUrlFilter(): string + { + return $this->url_filtre; } public function setUrlFilter(string $url_filter): void @@ -42,11 +55,13 @@ public function setUrlFilter(string $url_filter): void $this->url_filtre = $url_filter; } - public function setUidFilter(string $uid_filter): void + /** @deprecated */ + public function getTitleFilter(): string { - $this->uid_filtre = $uid_filter; + return $this->title_filter; } + /** @var @deprecated */ public function setTitleFilter(string $title_filter): void { $this->title_filter = $title_filter; diff --git a/Classes/Repository/BrokenLinkRepository.php b/Classes/Repository/BrokenLinkRepository.php index bc49c45c7..3f409e07f 100644 --- a/Classes/Repository/BrokenLinkRepository.php +++ b/Classes/Repository/BrokenLinkRepository.php @@ -103,23 +103,25 @@ public function getBrokenLinks(array $pageList, array $linkTypes, array $searchF $queryBuilder->expr()->neq('table_name', $queryBuilder->createNamedParameter('pages')) ) ) - ) - // SQL Filter - ->andWhere( + ); + + if ($filter->getUidFilter() != '') { + $queryBuilder->andWhere( + $queryBuilder->expr()->eq(self::TABLE . '.record_uid', $queryBuilder->createNamedParameter($filter->getUidFilter(), \PDO::PARAM_INT)) + ); + } + if ($filter->getUrlFilter() != '') { + $queryBuilder->andWhere( $queryBuilder->expr()->like( self::TABLE . '.url', $queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($filter->getUrlFilter()) . '%') ) - ) - ->andWhere( - $queryBuilder->expr()->like( - self::TABLE . '.headline', - $queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($filter->getTitleFilter()) . '%') - ) ); - if ($filter->getUidFilter() != '') { + } + $linktypeFilter = $filter->getLinkTypeFilter() ?: 'all'; + if ($linktypeFilter != 'all') { $queryBuilder->andWhere( - $queryBuilder->expr()->eq(self::TABLE . '.record_uid', $queryBuilder->createNamedParameter($filter->getUidFilter(), \PDO::PARAM_INT)) + $queryBuilder->expr()->eq(self::TABLE . '.link_type', $queryBuilder->createNamedParameter($linktypeFilter)) ); } diff --git a/Resources/Private/Language/Module/locallang.xlf b/Resources/Private/Language/Module/locallang.xlf index 51d28b5b2..6812cbc14 100644 --- a/Resources/Private/Language/Module/locallang.xlf +++ b/Resources/Private/Language/Module/locallang.xlf @@ -57,6 +57,18 @@ Title + + All + + + External + + + Internal + + + File + Recheck links diff --git a/Resources/Private/Templates/Backend/ReportTab.html b/Resources/Private/Templates/Backend/ReportTab.html index 3299a2d55..b0c0633fc 100644 --- a/Resources/Private/Templates/Backend/ReportTab.html +++ b/Resources/Private/Templates/Backend/ReportTab.html @@ -56,6 +56,19 @@ + +
+ + +
+
+