Skip to content

Commit 97383b0

Browse files
committed
Merge branch '4.6'
2 parents 163b111 + d1bfbf7 commit 97383b0

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
12+
13+
final class ContentTypeGroupName implements CriterionInterface
14+
{
15+
/** @var list<string>|string */
16+
private $value;
17+
18+
/**
19+
* @param list<string>|string $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<string>|string
28+
*/
29+
public function getValue()
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<string>|string $value
36+
*/
37+
public function setValue($value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionHandler;
10+
11+
use Doctrine\DBAL\Connection;
12+
use Doctrine\DBAL\Query\QueryBuilder;
13+
use Ibexa\Contracts\Core\Persistence\Content\Type\CriterionHandlerInterface;
14+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName as ContentTypeGroupNameCriterion;
15+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
16+
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway;
17+
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;
18+
19+
/**
20+
* @implements \Ibexa\Contracts\Core\Persistence\Content\Type\CriterionHandlerInterface<\Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName>
21+
*/
22+
final class ContentTypeGroupName implements CriterionHandlerInterface
23+
{
24+
public function supports(CriterionInterface $criterion): bool
25+
{
26+
return $criterion instanceof ContentTypeGroupNameCriterion;
27+
}
28+
29+
/**
30+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName $criterion
31+
*/
32+
public function apply(
33+
CriterionVisitor $criterionVisitor,
34+
QueryBuilder $qb,
35+
CriterionInterface $criterion
36+
): string {
37+
$subQuery = $qb->getConnection()->createQueryBuilder();
38+
$value = $criterion->getValue();
39+
if (!is_array($value)) {
40+
$value = [$value];
41+
}
42+
43+
$whereClause = $subQuery->expr()->in(
44+
'LOWER(ctg.name)',
45+
$qb->createNamedParameter(array_map('strtolower', $value), Connection::PARAM_STR_ARRAY)
46+
);
47+
48+
$subQuery
49+
->select('g.content_type_id')
50+
->from(Gateway::CONTENT_TYPE_GROUP_TABLE, 'ctg')
51+
->leftJoin('ctg', Gateway::CONTENT_TYPE_TO_GROUP_ASSIGNMENT_TABLE, 'c_group', 'ctg.id = c_group.group_id')
52+
->andWhere($whereClause)
53+
->andWhere('c_group.content_type_id = c.id');
54+
55+
return sprintf('EXISTS (%s)', $subQuery->getSQL());
56+
}
57+
}

tests/integration/Core/Repository/ContentTypeService/FindContentTypesTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
1313
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionId;
1414
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupId;
15+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName;
1516
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeId;
1617
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeIdentifier;
1718
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\IsSystem;
@@ -194,6 +195,20 @@ public function dataProviderForTestFindContentTypes(): iterable
194195
['folder'],
195196
];
196197

198+
yield 'content type group name' => [
199+
new ContentTypeQuery(
200+
new ContentTypeGroupName('Media'),
201+
),
202+
['file', 'image', 'video'],
203+
];
204+
205+
yield 'content type group name array' => [
206+
new ContentTypeQuery(
207+
new ContentTypeGroupName(['Media']),
208+
),
209+
['file', 'image', 'video'],
210+
];
211+
197212
yield 'system group' => [
198213
new ContentTypeQuery(
199214
new IsSystem(true),

0 commit comments

Comments
 (0)