Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\ContentType\Query\Criterion;

use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;

final class ContentTypeGroupName implements CriterionInterface
{
/** @var list<string>|string */
private $value;

/**
* @param list<string>|string $value
*/
public function __construct($value)
{
$this->value = $value;
}

/**
* @return list<string>|string
*/
public function getValue()
{
return $this->value;
}

/**
* @param list<string>|string $value
*/
public function setValue($value): void
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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\Content\Type\Gateway\CriterionHandler;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\Core\Persistence\Content\Type\CriterionHandlerInterface;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName as ContentTypeGroupNameCriterion;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway;
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;

/**
* @implements \Ibexa\Contracts\Core\Persistence\Content\Type\CriterionHandlerInterface<\Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName>
*/
final class ContentTypeGroupName implements CriterionHandlerInterface
{
public function supports(CriterionInterface $criterion): bool
{
return $criterion instanceof ContentTypeGroupNameCriterion;
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName $criterion
*/
public function apply(
CriterionVisitor $criterionVisitor,
QueryBuilder $qb,
CriterionInterface $criterion
): string {
$subQuery = $qb->getConnection()->createQueryBuilder();
$value = $criterion->getValue();
if (!is_array($value)) {
$value = [$value];
}

$whereClause = $subQuery->expr()->in(
'LOWER(ctg.name)',
$qb->createNamedParameter(array_map('strtolower', $value), Connection::PARAM_STR_ARRAY)
);

$subQuery
->select('g.contentclass_id')
->from(Gateway::CONTENT_TYPE_GROUP_TABLE, 'ctg')
->leftJoin('ctg', Gateway::CONTENT_TYPE_TO_GROUP_ASSIGNMENT_TABLE, 'c_group', 'ctg.id = c_group.group_id')
->andWhere($whereClause)
->andWhere('c_group.contentclass_id = c.id');

return sprintf('EXISTS (%s)', $subQuery->getSQL());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContainsFieldDefinitionId;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupId;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeGroupName;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeId;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\ContentTypeIdentifier;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion\IsSystem;
Expand Down Expand Up @@ -194,6 +195,20 @@ public function dataProviderForTestFindContentTypes(): iterable
['folder'],
];

yield 'content type group name' => [
new ContentTypeQuery(
new ContentTypeGroupName('Media'),
),
['file', 'image', 'video'],
];

yield 'content type group name array' => [
new ContentTypeQuery(
new ContentTypeGroupName(['Media']),
),
['file', 'image', 'video'],
];

yield 'system group' => [
new ContentTypeQuery(
new IsSystem(true),
Expand Down
Loading