Skip to content

IBX-10458: Implemented new Content Type search PHP API #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: 4.6
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\Persistence\Content\Type;

use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;

/**
* @template TCriterion of \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface
*/
interface CriterionHandlerInterface
{
/**
* @param TCriterion $criterion
*/
public function supports(CriterionInterface $criterion): bool;

/**
* @param TCriterion $criterion
Comment on lines +21 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan types need to be prefixed with @phpstan-param instead of @param. Otherwise, most likely, it will crash phpDocumentor.

*
* @return string|\Doctrine\DBAL\Query\Expression\CompositeExpression
*/
public function apply(
CriterionVisitor $criterionVisitor,
QueryBuilder $qb,
CriterionInterface $criterion
);
}
6 changes: 6 additions & 0 deletions src/contracts/Persistence/Content/Type/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct as GroupCreateStruct;
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\UpdateStruct as GroupUpdateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;

interface Handler
{
Expand Down Expand Up @@ -91,6 +92,11 @@ public function loadContentTypes($groupId, $status = Type::STATUS_DEFINED);
*/
public function loadContentTypeList(array $contentTypeIds): array;

/**
* @return array{count: int, items: array<string, mixed>}
*/
public function findContentTypes(?ContentTypeQuery $query = null): array;

/**
* @return \Ibexa\Contracts\Core\Persistence\Content\Type[]
*/
Expand Down
7 changes: 7 additions & 0 deletions src/contracts/Repository/ContentTypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
use Ibexa\Contracts\Core\Repository\Values\ContentType\SearchResult;
use Ibexa\Contracts\Core\Repository\Values\User\User;

interface ContentTypeService
Expand Down Expand Up @@ -173,6 +175,11 @@ public function loadContentTypeDraft(int $contentTypeId, bool $ignoreOwnership =
*/
public function loadContentTypeList(array $contentTypeIds, array $prioritizedLanguages = []): iterable;

/**
* @param list<string> $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
*/
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): SearchResult;

/**
* Get content type objects which belong to the given content type group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
use Ibexa\Contracts\Core\Repository\Values\ContentType\SearchResult;
use Ibexa\Contracts\Core\Repository\Values\User\User;

abstract class ContentTypeServiceDecorator implements ContentTypeService
Expand Down Expand Up @@ -107,6 +109,11 @@ public function loadContentTypeList(
return $this->innerService->loadContentTypeList($contentTypeIds, $prioritizedLanguages);
}

public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): SearchResult
{
return $this->innerService->findContentTypes($query, $prioritizedLanguages);
}

public function loadContentTypes(
ContentTypeGroup $contentTypeGroup,
array $prioritizedLanguages = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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;

final class ContentTypeQuery
{
public const DEFAULT_LIMIT = 25;

private ?CriterionInterface $criterion;

/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] */
private array $sortClauses;

private int $offset;

private int $limit;

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] $sortClauses
*/
public function __construct(
?CriterionInterface $criterion = null,
array $sortClauses = [],
int $offset = 0,
int $limit = self::DEFAULT_LIMIT
) {
$this->criterion = $criterion;
$this->sortClauses = $sortClauses;
$this->offset = $offset;
$this->limit = $limit;
}

public function getCriterion(): ?CriterionInterface
{
return $this->criterion;
}

public function setCriterion(?CriterionInterface $criterion): void
{
$this->criterion = $criterion;
}

public function addSortClause(SortClause $sortClause): void
{
$this->sortClauses[] = $sortClause;
}

/**
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[]
*/
public function getSortClauses(): array
{
return $this->sortClauses;
}

public function getOffset(): int
{
return $this->offset;
}

public function setOffset(int $offset): void
{
$this->offset = $offset;
}

public function getLimit(): int
{
return $this->limit;
}

public function setLimit(int $limit): void
{
$this->limit = $limit;
}
}
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 ContainsFieldDefinitionId implements CriterionInterface
{
/** @var list<int>|int */
private $value;

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

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

/**
* @param list<int>|int $value
*/
public function setValue($value): void
{
$this->value = $value;
}
}
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 ContentTypeGroupId implements CriterionInterface
{
/** @var list<int>|int */
private $value;

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

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

/**
* @param list<int>|int $value
*/
public function setValue($value): void
{
$this->value = $value;
}
}
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 ContentTypeId implements CriterionInterface
{
/** @var list<int>|int */
private $value;

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

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

/**
* @param list<int>|int $value
*/
public function setValue($value): void
{
$this->value = $value;
}
}
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 ContentTypeIdentifier 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,31 @@
<?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 IsSystem implements CriterionInterface
{
private bool $value;

public function __construct(bool $value = true)
{
$this->value = $value;
}

public function getValue(): bool
{
return $this->value;
}

public function setValue(bool $value): void
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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;

final class LogicalAnd extends LogicalOperator
{
}
Loading
Loading