Skip to content

Commit 701a49c

Browse files
committed
IBX-10458: Implemented new Content Type search PHP API
1 parent 1c05b96 commit 701a49c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1632
-9
lines changed

src/contracts/Persistence/Content/Type/Handler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Ibexa\Contracts\Core\Persistence\Content\Type;
1010
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct as GroupCreateStruct;
1111
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\UpdateStruct as GroupUpdateStruct;
12+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
1213

1314
interface Handler
1415
{
@@ -91,6 +92,13 @@ public function loadContentTypes($groupId, $status = Type::STATUS_DEFINED);
9192
*/
9293
public function loadContentTypeList(array $contentTypeIds): array;
9394

95+
public function countContentTypes(?ContentTypeQuery $query = null): int;
96+
97+
/**
98+
* @return \Ibexa\Contracts\Core\Persistence\Content\Type[]
99+
*/
100+
public function findContentTypes(?ContentTypeQuery $query = null): array;
101+
94102
/**
95103
* @return \Ibexa\Contracts\Core\Persistence\Content\Type[]
96104
*/

src/contracts/Repository/ContentTypeService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1919
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
2020
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
21+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
2122
use Ibexa\Contracts\Core\Repository\Values\User\User;
2223

2324
interface ContentTypeService
@@ -173,6 +174,13 @@ public function loadContentTypeDraft(int $contentTypeId, bool $ignoreOwnership =
173174
*/
174175
public function loadContentTypeList(array $contentTypeIds, array $prioritizedLanguages = []): iterable;
175176

177+
/**
178+
* @param list<string> $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
179+
*
180+
* @return array<\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType>
181+
*/
182+
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): array;
183+
176184
/**
177185
* Get content type objects which belong to the given content type group.
178186
*

src/contracts/Repository/Decorator/ContentTypeServiceDecorator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
2020
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
2121
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
22+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
2223
use Ibexa\Contracts\Core\Repository\Values\User\User;
2324

2425
abstract class ContentTypeServiceDecorator implements ContentTypeService
@@ -107,6 +108,11 @@ public function loadContentTypeList(
107108
return $this->innerService->loadContentTypeList($contentTypeIds, $prioritizedLanguages);
108109
}
109110

111+
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): array
112+
{
113+
return $this->innerService->findContentTypes($query, $prioritizedLanguages);
114+
}
115+
110116
public function loadContentTypes(
111117
ContentTypeGroup $contentTypeGroup,
112118
array $prioritizedLanguages = []
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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;
10+
11+
use Doctrine\DBAL\Query\QueryBuilder;
12+
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway;
13+
14+
abstract class Base implements CriterionHandlerInterface
15+
{
16+
/**
17+
* Inner join the `ezcontentclassgroup` table if not joined yet.
18+
*/
19+
protected function joinContentTypeGroup(QueryBuilder $query): void
20+
{
21+
if (!$this->hasJoinedTable($query, Gateway::CONTENT_TYPE_GROUP_TABLE)) {
22+
$query->innerJoin(
23+
'g',
24+
Gateway::CONTENT_TYPE_GROUP_TABLE,
25+
'ctg',
26+
'g.contentclass_id = ctg.id'
27+
);
28+
}
29+
}
30+
31+
protected function hasJoinedTable(QueryBuilder $queryBuilder, string $tableName): bool
32+
{
33+
// find table name in a structure: ['fromAlias' => [['joinTable' => '<table_name>'], ...]]
34+
$joinedParts = $queryBuilder->getQueryPart('join');
35+
foreach ($joinedParts as $joinedTables) {
36+
foreach ($joinedTables as $join) {
37+
if ($join['joinTable'] === $tableName) {
38+
return true;
39+
}
40+
}
41+
}
42+
43+
return false;
44+
}
45+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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;
10+
11+
final class ContentTypeQuery
12+
{
13+
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface[] */
14+
private array $criteria;
15+
16+
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] */
17+
private array $sortClauses;
18+
19+
private int $offset;
20+
21+
private int $limit;
22+
23+
/**
24+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface[] $criteria
25+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] $sortClauses
26+
*/
27+
public function __construct(
28+
array $criteria = [],
29+
array $sortClauses = [],
30+
int $offset = 0,
31+
int $limit = 25
32+
) {
33+
$this->criteria = $criteria;
34+
$this->sortClauses = $sortClauses;
35+
$this->offset = $offset;
36+
$this->limit = $limit;
37+
}
38+
39+
public function addCriterion(CriterionInterface $criterion): void
40+
{
41+
$this->criteria[] = $criterion;
42+
}
43+
44+
/**
45+
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface[]
46+
*/
47+
public function getCriteria(): array
48+
{
49+
return $this->criteria;
50+
}
51+
52+
public function addSortClause(SortClause $sortClause): void
53+
{
54+
$this->sortClauses[] = $sortClause;
55+
}
56+
57+
/**
58+
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[]
59+
*/
60+
public function getSortClauses(): array
61+
{
62+
return $this->sortClauses;
63+
}
64+
65+
public function getOffset(): int
66+
{
67+
return $this->offset;
68+
}
69+
70+
public function setOffset(int $offset): void
71+
{
72+
$this->offset = $offset;
73+
}
74+
75+
public function getLimit(): int
76+
{
77+
return $this->limit;
78+
}
79+
80+
public function setLimit(int $limit): void
81+
{
82+
$this->limit = $limit;
83+
}
84+
}
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 ContainsFieldDefinitionIds implements CriterionInterface
14+
{
15+
/** @var list<int> */
16+
private array $value;
17+
18+
/**
19+
* @param list<int> $value
20+
*/
21+
public function __construct(array $value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<int>
28+
*/
29+
public function getValue(): array
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<int> $value
36+
*/
37+
public function setValue(array $value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
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 ContentTypeGroupIds implements CriterionInterface
14+
{
15+
/** @var list<string> */
16+
private array $value;
17+
18+
/**
19+
* @param list<string> $value
20+
*/
21+
public function __construct(array $value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<string>
28+
*/
29+
public function getValue(): array
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<string> $value
36+
*/
37+
public function setValue(array $value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
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 Identifiers implements CriterionInterface
14+
{
15+
/** @var list<string> */
16+
private array $value;
17+
18+
/**
19+
* @param list<string> $value
20+
*/
21+
public function __construct(array $value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<string>
28+
*/
29+
public function getValue(): array
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<string> $value
36+
*/
37+
public function setValue(array $value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
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 Ids implements CriterionInterface
14+
{
15+
/** @var list<int> */
16+
private array $value;
17+
18+
/**
19+
* @param list<int> $value
20+
*/
21+
public function __construct(array $value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<int>
28+
*/
29+
public function getValue(): array
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<int> $value
36+
*/
37+
public function setValue(array $value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 IsSystem implements CriterionInterface
14+
{
15+
private bool $value;
16+
17+
public function __construct(bool $value)
18+
{
19+
$this->value = $value;
20+
}
21+
22+
public function getValue(): bool
23+
{
24+
return $this->value;
25+
}
26+
27+
public function setValue(bool $value): void
28+
{
29+
$this->value = $value;
30+
}
31+
}

0 commit comments

Comments
 (0)