Skip to content

Commit

Permalink
[BUGFIX] Enable creation of filter options from categories for hidden…
Browse files Browse the repository at this point in the history
… and time restricted categories. fixes #144
  • Loading branch information
christianbltr committed Jan 27, 2023
1 parent 8469e99 commit d388aa1
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 183 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Upcoming version

Version 4.6.2, 13 January 2023
[BUGFIX] Fix SQL query for assigning tags from page properties to work with sql_mode ONLY_FULL_GROUP_BY. Thanks to p-view. https://github.com/teaminmedias-pluswerk/ke_search/issues/448
[BUGFIX] Enable creation of filter options from categories for hidden and time restricted categories. Thanks to Andreas Kessel. https://github.com/tpwd/ke_search/pull/144

Version 4.6.1, 13 January 2023
[TASK] Respect workspace flag for content elements. Thanks to alexmari81. https://github.com/tpwd/ke_search/issues/139
Expand Down
33 changes: 25 additions & 8 deletions Classes/Domain/Repository/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use PDO;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/***************************************************************
Expand Down Expand Up @@ -36,14 +40,28 @@ class BaseRepository
*/
protected $tableName = '';

/**
* @return mixed
*/
public function findAll()
public function getQueryBuilder(bool $includeHiddenAndTimeRestricted = false): QueryBuilder
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);
if ($includeHiddenAndTimeRestricted) {
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class)
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);
}
return $queryBuilder;
}

/**
* @param bool $includeHiddenAndTimeRestricted
* @return mixed
*/
public function findAll(bool $includeHiddenAndTimeRestricted = false)
{
$queryBuilder = $this->getQueryBuilder($includeHiddenAndTimeRestricted);
return $queryBuilder
->select('*')
->from($this->tableName)
Expand All @@ -53,13 +71,12 @@ public function findAll()

/**
* @param $uid
* @param bool $includeHiddenAndTimeRestricted
* @return mixed
*/
public function findOneByUid($uid)
public function findByUid($uid, bool $includeHiddenAndTimeRestricted = false)
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);
$queryBuilder = $this->getQueryBuilder($includeHiddenAndTimeRestricted);
return $queryBuilder
->select('*')
->from($this->tableName)
Expand Down
61 changes: 10 additions & 51 deletions Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use PDO;
use Tpwd\KeSearch\Lib\SearchHelper;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/***************************************************************
* Copyright notice
Expand All @@ -28,59 +26,21 @@
/**
* @author Christian Bülter
*/
class CategoryRepository
class CategoryRepository extends BaseRepository
{
/**
* @var string
*/
protected $tableName = 'sys_category';

/**
* @return mixed
*/
public function findAll()
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);
return $queryBuilder
->select('*')
->from($this->tableName)
->execute()
->fetchAll();
}

/**
* @param $categoryUid
* @param bool $includeHiddenAndTimeRestricted
* @return mixed
*/
public function findOneByUid($categoryUid)
public function findAllSubcategoriesByParentUid($categoryUid, bool $includeHiddenAndTimeRestricted = false)
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);
return $queryBuilder
->select('*')
->from($this->tableName)
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($categoryUid, PDO::PARAM_INT)
)
)
->execute()
->fetch();
}

/**
* @param $categoryUid
* @return mixed
*/
public function findAllSubcategoriesByParentUid($categoryUid)
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);
$queryBuilder = $this->getQueryBuilder($includeHiddenAndTimeRestricted);
return $queryBuilder
->select('*')
->from($this->tableName)
Expand All @@ -96,11 +56,13 @@ public function findAllSubcategoriesByParentUid($categoryUid)

/**
* @param string $tag
* @param bool $includeHiddenAndTimeRestricted
* @return mixed
*/
public function findByTag(string $tag)
public function findByTag(string $tag, bool $includeHiddenAndTimeRestricted = false)
{
$uid = (int)(str_replace(SearchHelper::$systemCategoryPrefix, '', $tag));
return $this->findOneByUid($uid);
return $this->findByUid($uid, $includeHiddenAndTimeRestricted);
}

/**
Expand All @@ -110,12 +72,9 @@ public function findByTag(string $tag)
* @param int $uid
* @return mixed
*/
public function findAssignedToRecord(string $tableName, int $uid)
public function findAssignedToRecord(string $tableName, int $uid, bool $includeHiddenAndTimeRestricted = false)
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);

$queryBuilder = $this->getQueryBuilder($includeHiddenAndTimeRestricted);
return $queryBuilder
->select('sys_category.*')
->from('sys_category')
Expand Down
7 changes: 1 addition & 6 deletions Classes/Domain/Repository/FileMetaDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace Tpwd\KeSearch\Domain\Repository;

use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -43,10 +41,7 @@ class FileMetaDataRepository extends BaseRepository
*/
public function findByFileUidAndLanguageUid(int $fileUid, $languageUid)
{
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable($this->tableName);

$queryBuilder = $this->getQueryBuilder();
$record = $queryBuilder
->select('*')
->from($this->tableName)
Expand Down
7 changes: 1 addition & 6 deletions Classes/Domain/Repository/FileReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

use Doctrine\DBAL\Connection as DoctrineDbalConnection;
use PDO;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -43,9 +40,7 @@ public function findOneByTableAndFieldnameAndUidForeignAndLanguage(
string $uid_foreign,
array $languageIds = [0, -1]
) {
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($this->tableName);
$queryBuilder = $this->getQueryBuilder();
return $queryBuilder
->select('*')
->from($this->tableName)
Expand Down
Loading

0 comments on commit d388aa1

Please sign in to comment.