-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
293 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sonar.exclusions=**/Tests/**/_fixtures/* | ||
sonar.exclusions=tests/**/_fixtures/**/* |
32 changes: 32 additions & 0 deletions
32
src/contracts/Repository/Values/Content/Query/Criterion/IsContainer.php
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,32 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator\Specifications; | ||
use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; | ||
|
||
final class IsContainer extends Criterion implements FilteringCriterion | ||
{ | ||
public function __construct(bool $value = true) | ||
{ | ||
parent::__construct(null, null, $value); | ||
} | ||
|
||
public function getSpecifications(): array | ||
{ | ||
return [ | ||
new Specifications( | ||
Operator::EQ, | ||
Specifications::FORMAT_SINGLE, | ||
Specifications::TYPE_BOOLEAN | ||
), | ||
]; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/lib/Persistence/Legacy/Filter/CriterionQueryBuilder/Content/IsContainerQueryBuilder.php
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,52 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Core\Persistence\Legacy\Filter\CriterionQueryBuilder\Content; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Ibexa\Contracts\Core\Persistence\Filter\Doctrine\FilteringQueryBuilder; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer; | ||
use Ibexa\Contracts\Core\Repository\Values\Filter\CriterionQueryBuilder; | ||
use Ibexa\Contracts\Core\Repository\Values\Filter\FilteringCriterion; | ||
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway; | ||
|
||
/** | ||
* @internal for internal use by Repository Filtering | ||
*/ | ||
final class IsContainerQueryBuilder implements CriterionQueryBuilder | ||
{ | ||
public function accepts(FilteringCriterion $criterion): bool | ||
{ | ||
return $criterion instanceof IsContainer; | ||
} | ||
|
||
/** | ||
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer $criterion | ||
*/ | ||
public function buildQueryConstraint( | ||
FilteringQueryBuilder $queryBuilder, | ||
FilteringCriterion $criterion | ||
): ?string { | ||
$queryBuilder | ||
->joinOnce( | ||
'content', | ||
Gateway::CONTENT_TYPE_TABLE, | ||
'content_type', | ||
'content.contentclass_id = content_type.id', | ||
); | ||
|
||
/** @var array{bool} $criterionValue */ | ||
$criterionValue = $criterion->value; | ||
$isContainer = reset($criterionValue); | ||
|
||
return $queryBuilder->expr()->in( | ||
'content_type.is_container', | ||
$queryBuilder->createNamedParameter((int)$isContainer, ParameterType::INTEGER) | ||
); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler/IsContainer.php
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,56 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Query\QueryBuilder; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway; | ||
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; | ||
use Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler; | ||
|
||
final class IsContainer extends CriterionHandler | ||
{ | ||
public function accept(Criterion $criterion): bool | ||
{ | ||
return $criterion instanceof Criterion\IsContainer; | ||
} | ||
|
||
/** | ||
* @phpstan-param array{languages: string[]} $languageSettings | ||
*/ | ||
public function handle( | ||
CriteriaConverter $converter, | ||
QueryBuilder $queryBuilder, | ||
Criterion $criterion, | ||
array $languageSettings | ||
) { | ||
/** @var array{bool} $criterionValue */ | ||
$criterionValue = $criterion->value; | ||
$isContainer = reset($criterionValue); | ||
|
||
$subSelect = $this->connection->createQueryBuilder(); | ||
$subSelect | ||
->select( | ||
'id' | ||
)->from( | ||
ContentTypeGateway::CONTENT_TYPE_TABLE | ||
)->where( | ||
$queryBuilder->expr()->eq( | ||
'is_container', | ||
$queryBuilder->createNamedParameter((int)$isContainer, ParameterType::INTEGER) | ||
) | ||
); | ||
|
||
return $queryBuilder->expr()->in( | ||
'c.contentclass_id', | ||
$subSelect->getSQL() | ||
); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
tests/integration/Core/Repository/_fixtures/Legacy/IsContainerFalse.php
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,59 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; | ||
|
||
return new SearchResult([ | ||
'facets' => [], | ||
'searchHits' => [ | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 10, | ||
'title' => 'Anonymous User', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 14, | ||
'title' => 'Administrator User', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 52, | ||
'title' => 'Common INI settings', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 54, | ||
'title' => 'Ibexa Demo Design (without demo content)', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
], | ||
'spellSuggestion' => null, | ||
'time' => 1, | ||
'timedOut' => null, | ||
'maxScore' => null, | ||
'totalCount' => 4, | ||
]); |
69 changes: 69 additions & 0 deletions
69
tests/integration/Core/Repository/_fixtures/Legacy/IsContainerTrue.php
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,69 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; | ||
|
||
return new SearchResult([ | ||
'facets' => [], | ||
'searchHits' => [ | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 4, | ||
'title' => 'Users', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 11, | ||
'title' => 'Members', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 12, | ||
'title' => 'Administrator users', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 13, | ||
'title' => 'Editors', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
new SearchHit([ | ||
'valueObject' => [ | ||
'id' => 41, | ||
'title' => 'Media', | ||
], | ||
'score' => null, | ||
'index' => null, | ||
'highlight' => null, | ||
'matchedTranslation' => 'eng-US', | ||
]), | ||
], | ||
'spellSuggestion' => null, | ||
'time' => 1, | ||
'timedOut' => null, | ||
'maxScore' => null, | ||
'totalCount' => 14, | ||
]); |