Skip to content

Commit

Permalink
Minor improvements in MetadataRepository
Browse files Browse the repository at this point in the history
- add function for getting query builder
- use namespaces
  • Loading branch information
beatrycze-volk committed May 5, 2023
1 parent 078b1ff commit 654cfae
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions Classes/Domain/Repository/MetadataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

class MetadataRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
class MetadataRepository extends Repository
{
/**
* Finds all collection for the given settings
*
* @param array $settings
*
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
* @return array|QueryResultInterface
*/
public function findBySettings($settings = [])
{
Expand Down Expand Up @@ -64,15 +67,7 @@ public function findBySettings($settings = [])
*/
public function findWithFormat($pid, $type)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_metadata');

// Get hidden records, too.
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);

$query = $queryBuilder
$query = $this->getQueryBuilder()
->select(
'tx_dlf_metadata.index_name AS index_name',
'tx_dlf_metadataformat_joins.xpath AS xpath',
Expand Down Expand Up @@ -118,15 +113,7 @@ public function findWithFormat($pid, $type)
*/
public function findWithoutFormat($pid)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_metadata');

// Get hidden records, too.
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);

$query = $queryBuilder
$query = $this->getQueryBuilder()
->select(
'tx_dlf_metadata.index_name AS index_name',
'tx_dlf_metadata.is_sortable AS is_sortable',
Expand Down Expand Up @@ -161,15 +148,7 @@ public function findQueryPath($pid, $iiifVersion)
* check the configuration.
* TODO Saving / indexing should still work - check!
*/
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_metadata');

// Get hidden records, too.
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);

$query = $queryBuilder
$query = $this->getQueryBuilder()
->select('tx_dlf_metadataformat.xpath AS querypath')
->from('tx_dlf_metadata')
->from('tx_dlf_metadataformat')
Expand Down Expand Up @@ -201,15 +180,7 @@ public function findQueryPath($pid, $iiifVersion)
*/
public function findForIiif($pid, $iiifVersion)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_metadata');

// Get hidden records, too.
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);

$query = $queryBuilder
$query = $this->getQueryBuilder()
->select(
'tx_dlf_metadata.index_name AS index_name',
'tx_dlf_metadataformat.xpath AS xpath',
Expand All @@ -236,4 +207,21 @@ public function findForIiif($pid, $iiifVersion)

return $query->execute()->fetchAll();
}

/**
* Get query builder for tx_dlf_metadata table.
*
* @return QueryBuilder
*/
private function getQueryBuilder() : QueryBuilder {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_metadata');

// Get hidden records, too.
$queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);

return $queryBuilder;
}
}

0 comments on commit 654cfae

Please sign in to comment.