Skip to content

Commit

Permalink
[FEATURE] Add filter for linktype
Browse files Browse the repository at this point in the history
Related: sypets#163
  • Loading branch information
sypets committed Feb 19, 2022
1 parent dd50926 commit 3913560
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 26 deletions.
13 changes: 9 additions & 4 deletions Classes/Controller/BrokenLinkListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand All @@ -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);
Expand Down
37 changes: 26 additions & 11 deletions Classes/Controller/Filter/BrokenLinkListFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,59 @@ 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
{
$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;
Expand Down
24 changes: 13 additions & 11 deletions Classes/Repository/BrokenLinkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

Expand Down
12 changes: 12 additions & 0 deletions Resources/Private/Language/Module/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
<trans-unit id="list.filter.title" resname="list.filter.title">
<source>Title</source>
</trans-unit>
<trans-unit id="list.filter.linktype.all" resname="list.filter.linktype.all">
<source>All</source>
</trans-unit>
<trans-unit id="list.filter.linktype.external" resname="list.filter.linktype.external">
<source>External</source>
</trans-unit>
<trans-unit id="list.filter.linktype.db" resname="list.filter.linktype.db">
<source>Internal</source>
</trans-unit>
<trans-unit id="list.filter.linktype.file" resname="list.filter.linktype.file">
<source>File</source>
</trans-unit>

<trans-unit id="list.recheck.links.title" resname="list.recheck.links.title">
<source>Recheck links</source>
Expand Down
13 changes: 13 additions & 0 deletions Resources/Private/Templates/Backend/ReportTab.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
</div>
</div>

<f:if condition="{linktypes}">
<div class="form-group">
<label for="linktype_searchFilter">Link type:</label>
<select id="linktype_searchFilter" name="linktype_searchFilter" class="form-control tceforms-select">
<f:for each="{linktypes}" as="linktype">
<option value="{linktype}" {f:if(condition:'{linktype} == {linktype_filter}', then: 'selected')}>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.linktype.{linktype}">{linktype}</f:translate>
</option>
</f:for>
</select>
</div>
</f:if>

<div class="form-group">
<label for="url_searchFilter"><f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.url"/>:</label>
<div class="form-control-clearable">
Expand Down

0 comments on commit 3913560

Please sign in to comment.