-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add a filter plugin that combines category and tag
More filters are possible via filter interface.
- Loading branch information
Showing
27 changed files
with
912 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Domain\Factory; | ||
|
||
use T3G\AgencyPack\Blog\Domain\Filter\Post\CategoryTag; | ||
use T3G\AgencyPack\Blog\Domain\Filter\PostFilter; | ||
use T3G\AgencyPack\Blog\Domain\Repository\CategoryRepository; | ||
use T3G\AgencyPack\Blog\Domain\Repository\TagRepository; | ||
use TYPO3\CMS\Core\SingletonInterface; | ||
use TYPO3\CMS\Extbase\Mvc\RequestInterface; | ||
|
||
/** | ||
* The post filter factory sets filter values from the request. | ||
*/ | ||
class PostFilterFactory implements SingletonInterface | ||
{ | ||
protected CategoryRepository $categoryRepository; | ||
|
||
protected TagRepository $tagRepository; | ||
|
||
public function __construct(CategoryRepository $categoryRepository, TagRepository $tagRepository) | ||
{ | ||
$this->categoryRepository = $categoryRepository; | ||
$this->tagRepository = $tagRepository; | ||
} | ||
|
||
public function getFilterFromRequest(RequestInterface $request): PostFilter | ||
{ | ||
// Currently there is only one filter implementation. | ||
$filter = new CategoryTag(); | ||
if ($request->hasArgument('category')) { | ||
$filter->setCategory($this->categoryRepository->findByUid((int)$request->getArgument('category'))); | ||
} | ||
if ($request->hasArgument('tag')) { | ||
$filter->setTag($this->tagRepository->findByUid((int)$request->getArgument('tag'))); | ||
} | ||
return $filter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Domain\Filter\Post; | ||
|
||
use T3G\AgencyPack\Blog\Domain\Filter\PostFilter; | ||
|
||
/** | ||
* Base class for all post filters. | ||
*/ | ||
abstract class AbstractBase implements PostFilter | ||
{ | ||
/** | ||
* The class name (without namespace) is used as the filter's name. | ||
*/ | ||
public function getName(): string | ||
{ | ||
$classWithNamespace = get_class($this); | ||
$rightBackslash = strrpos($classWithNamespace, '\\') ?? 0; | ||
return substr($classWithNamespace, $rightBackslash > 0 ? ++$rightBackslash : $rightBackslash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Domain\Filter\Post; | ||
|
||
use T3G\AgencyPack\Blog\Domain\Model\Category; | ||
use T3G\AgencyPack\Blog\Domain\Model\Tag; | ||
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface; | ||
use TYPO3\CMS\Extbase\Persistence\QueryInterface; | ||
|
||
/** | ||
* This filter combines one selected Category and one selected Tag (both optional). | ||
*/ | ||
class CategoryTag extends AbstractBase | ||
{ | ||
protected ?Category $category = null; | ||
|
||
protected ?Tag $tag = null; | ||
|
||
/** | ||
* Title is simply the concatenated Category and Tag titles (separated by a SPACE character). | ||
*/ | ||
public function getTitle(): string | ||
{ | ||
if ($this->category) { | ||
if ($this->tag) { | ||
return trim($this->category->getTitle() . ' ' . $this->tag->getTitle()); | ||
} else { | ||
return $this->category->getTitle(); | ||
} | ||
} | ||
if ($this->tag) { | ||
return $this->tag->getTitle(); | ||
} | ||
return ''; | ||
} | ||
|
||
/** | ||
* Description is simply the concatenated Category and Tag titles (separated by a SPACE character). | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
if ($this->category) { | ||
if ($this->tag) { | ||
return trim($this->category->getDescription() . ' ' . $this->tag->getDescription()); | ||
} else { | ||
return $this->category->getDescription(); | ||
} | ||
} | ||
if ($this->tag) { | ||
return $this->tag->getDescription(); | ||
} | ||
return ''; | ||
} | ||
|
||
/** | ||
* @return array<ComparisonInterface> | ||
* @throws InvalidQueryException | ||
*/ | ||
public function getConstraints(QueryInterface $query): array | ||
{ | ||
$constraints = []; | ||
if ($this->category) { | ||
$constraints[] = $query->contains('categories', $this->category); | ||
} | ||
if ($this->tag) { | ||
$constraints[] = $query->contains('tags', $this->tag); | ||
} | ||
return $constraints; | ||
} | ||
|
||
public function getCategory(): ?Category | ||
{ | ||
return $this->category; | ||
} | ||
|
||
public function setCategory(?Category $category): void | ||
{ | ||
$this->category = $category; | ||
} | ||
|
||
public function getTag(): ?Tag | ||
{ | ||
return $this->tag; | ||
} | ||
|
||
public function setTag(?Tag $tag): void | ||
{ | ||
$this->tag = $tag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Domain\Filter; | ||
|
||
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface; | ||
use TYPO3\CMS\Extbase\Persistence\QueryInterface; | ||
|
||
/** | ||
* Interface for post filters used in the listPostsByFilterAction. | ||
*/ | ||
interface PostFilter | ||
{ | ||
/** | ||
* The name of this filter, used for rendering the corresponding Fluid partial. | ||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* The title of the filter result, used in MetaTagService. | ||
*/ | ||
public function getTitle(): string; | ||
|
||
/** | ||
* A description of the filter result, used in MetaTagService. | ||
*/ | ||
public function getDescription(): string; | ||
|
||
/** | ||
* Apply current filter values in given Posts query. | ||
* | ||
* @return array<ComparisonInterface> | ||
*/ | ||
public function getConstraints(QueryInterface $query): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.