Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add filter support for list #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Classes/Controller/TermController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public function __construct(TermRepository $termRepository)
public function listAction(string $currentCharacter = null): ResponseInterface
{
$listMode = $this->settings['listmode'] ?? 'normal';
$terms = $this->termRepository->findAll();

$searchTerm = $this->request->hasArgument('searchTerm')
? trim((string)$this->request->getArgument('searchTerm'))
: null
;
$terms = empty($searchTerm)
? $terms = $this->termRepository->findAll()
: $this->termRepository->findByTerm($searchTerm)
;

switch ($listMode) {
case 'character':
Expand Down Expand Up @@ -96,6 +104,7 @@ public function listAction(string $currentCharacter = null): ResponseInterface
$this->view->assignMultiple([
'listmode' => $listMode,
'terms' => $terms,
'searchTerm' => $searchTerm,
]);

return $this->htmlResponse();
Expand Down
23 changes: 23 additions & 0 deletions Classes/Domain/Repository/TermRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
***/

use Featdd\DpnGlossary\Domain\Model\Term;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;

Expand All @@ -23,6 +25,27 @@
*/
class TermRepository extends AbstractTermRepository
{
public function findByTerm(
string $term
): QueryResultInterface {
$query = $this->createQuery();

$queryParser = GeneralUtility::makeInstance(Typo3DbQueryParser::class);
$queryBuilder = $queryParser->convertQueryToDoctrineQueryBuilder($query);

$searchTerm = $queryBuilder->getConnection()->escapeLikeWildcards($term) . '%';

$query->matching($query->logicalOr(
$query->like('name', $searchTerm),
$query->like('synonyms.name', $searchTerm),
$query->like('descriptions.meaning', $searchTerm),
));
$queryBuilder = $queryParser->convertQueryToDoctrineQueryBuilder($query);

$result = $query->execute();
return $result;
}

/**
* finds the newest terms
*
Expand Down
4 changes: 4 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ plugin.tx_dpnglossary {

groupedListCharacters < .pagination.characters

list {
enableSearchForm = 0
}

termWraps = CASE
termWraps {
key.field = term_type
Expand Down
6 changes: 6 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@
<trans-unit id="tt_content.parse_for_glossary">
<target>Inhalt parsen</target>
</trans-unit>


<trans-unit id="list.searchform.submitButton.label">
<source>Submit</source>
<target>Absenden</target>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
<trans-unit id="tt_content.parse_for_glossary">
<source>Parse content element for glossary terms</source>
</trans-unit>


<trans-unit id="list.searchform.submitButton.label">
<source>Submit</source>
</trans-unit>
</body>
</file>
</xliff>
16 changes: 16 additions & 0 deletions Resources/Private/Partials/Utilities/SearchForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html data-namespace-typo3-fluid="true" lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">

<f:if condition="{settings.list.enableSearchForm}">
<f:form action="list">
<div class="mb-3">
<f:form.textfield name="searchTerm" value="{searchTerm}" class="form-control" />
<f:form.button type="submit" class="btn btn-primary">
{f:translate(key: 'list.searchform.submitButton.label')}
</f:form.button>
</div>
</f:form>
</f:if>

</html>
2 changes: 2 additions & 0 deletions Resources/Private/Templates/Term/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<h1>{f:translate(key: 'tx_dpnglossary_domain_model_term.listheadline')}</h1>

<f:render partial="Utilities/SearchForm" arguments="{_all}" />

<f:if condition="{listmode} == 'character'">

<div>
Expand Down