Skip to content

Commit 3f90ff6

Browse files
committed
IBX-9103: Add RelationType for filtering purposes to fetch relations methods
1 parent 89bf6e0 commit 3f90ff6

File tree

7 files changed

+210
-51
lines changed

7 files changed

+210
-51
lines changed

src/contracts/Repository/ContentService.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Ibexa\Contracts\Core\Repository\Values\Content\LocationCreateStruct;
2020
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
2121
use Ibexa\Contracts\Core\Repository\Values\Content\RelationList;
22+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2223
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
2324
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
2425
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
@@ -419,7 +420,8 @@ public function loadRelations(VersionInfo $versionInfo): iterable;
419420
public function loadRelationList(
420421
VersionInfo $versionInfo,
421422
int $offset = 0,
422-
int $limit = self::DEFAULT_PAGE_SIZE
423+
int $limit = self::DEFAULT_PAGE_SIZE,
424+
?RelationType $type = null,
423425
): RelationList;
424426

425427
/**
@@ -428,7 +430,7 @@ public function loadRelationList(
428430
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
429431
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
430432
*/
431-
public function countRelations(VersionInfo $versionInfo): int;
433+
public function countRelations(VersionInfo $versionInfo, ?RelationType $type = null): int;
432434

433435
/**
434436
* Counts all incoming relations for the given content object.
@@ -437,7 +439,7 @@ public function countRelations(VersionInfo $versionInfo): int;
437439
*
438440
* @return int The number of reverse relations ({@see \Ibexa\Contracts\Core\Repository\Values\Content\Relation})
439441
*/
440-
public function countReverseRelations(ContentInfo $contentInfo): int;
442+
public function countReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): int;
441443

442444
/**
443445
* Loads all incoming relations for a content object.
@@ -446,26 +448,23 @@ public function countReverseRelations(ContentInfo $contentInfo): int;
446448
*
447449
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
448450
*
449-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
450-
*
451451
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Relation[]
452452
*/
453-
public function loadReverseRelations(ContentInfo $contentInfo): iterable;
453+
public function loadReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): iterable;
454454

455455
/**
456456
* Loads all incoming relations for a content object.
457457
*
458458
* The relations come only from published versions of the source content objects.
459459
* If the user is not allowed to read specific version then UnauthorizedRelationListItem is returned
460460
* {@see \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\UnauthorizedRelationListItem}
461-
*
462-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
463-
* @param int $offset
464-
* @param int $limit
465-
*
466-
* @return \Ibexa\Contracts\Core\Repository\Values\Content\RelationList
467461
*/
468-
public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList;
462+
public function loadReverseRelationList(
463+
ContentInfo $contentInfo,
464+
int $offset = 0,
465+
int $limit = -1,
466+
?RelationType $type = null
467+
): RelationList;
469468

470469
/**
471470
* Adds a relation of type common.

src/contracts/Repository/Decorator/ContentServiceDecorator.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Ibexa\Contracts\Core\Repository\Values\Content\LocationCreateStruct;
2121
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
2222
use Ibexa\Contracts\Core\Repository\Values\Content\RelationList;
23+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
2324
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
2425
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
2526
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
@@ -193,29 +194,37 @@ public function loadRelations(VersionInfo $versionInfo): iterable
193194
return $this->innerService->loadRelations($versionInfo);
194195
}
195196

196-
public function countRelations(VersionInfo $versionInfo): int
197+
public function countRelations(VersionInfo $versionInfo, ?RelationType $type = null): int
197198
{
198-
return $this->innerService->countRelations($versionInfo);
199+
return $this->innerService->countRelations($versionInfo, $type);
199200
}
200201

201-
public function loadRelationList(VersionInfo $versionInfo, int $offset = 0, int $limit = self::DEFAULT_PAGE_SIZE): RelationList
202-
{
203-
return $this->innerService->loadRelationList($versionInfo, $offset, $limit);
202+
public function loadRelationList(
203+
VersionInfo $versionInfo,
204+
int $offset = 0,
205+
int $limit = self::DEFAULT_PAGE_SIZE,
206+
?RelationType $type = null
207+
): RelationList {
208+
return $this->innerService->loadRelationList($versionInfo, $offset, $limit, $type);
204209
}
205210

206-
public function countReverseRelations(ContentInfo $contentInfo): int
211+
public function countReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): int
207212
{
208-
return $this->innerService->countReverseRelations($contentInfo);
213+
return $this->innerService->countReverseRelations($contentInfo, $type);
209214
}
210215

211-
public function loadReverseRelations(ContentInfo $contentInfo): iterable
216+
public function loadReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): iterable
212217
{
213-
return $this->innerService->loadReverseRelations($contentInfo);
218+
return $this->innerService->loadReverseRelations($contentInfo, $type);
214219
}
215220

216-
public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList
217-
{
218-
return $this->innerService->loadReverseRelationList($contentInfo, $offset, $limit);
221+
public function loadReverseRelationList(
222+
ContentInfo $contentInfo,
223+
int $offset = 0,
224+
int $limit = -1,
225+
?RelationType $type = null
226+
): RelationList {
227+
return $this->innerService->loadReverseRelationList($contentInfo, $offset, $limit, $type);
219228
}
220229

221230
public function addRelation(

src/contracts/Repository/Values/Content/Relation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,44 @@ abstract class Relation extends ValueObject
2525
* The relation type COMMON is a general relation between object set by a user.
2626
*
2727
* @var int
28+
*
29+
* @deprecated 5.0.0 accessing magic getter is deprecated and will be removed in 6.0.0. Use {@see RelationType::COMMON} instead.
2830
*/
2931
public const COMMON = 1;
3032

3133
/**
3234
* the relation type EMBED is set for a relation which is anchored as embedded link in an attribute value.
3335
*
3436
* @var int
37+
*
38+
* @deprecated 5.0.0 accessing magic getter is deprecated and will be removed in 6.0.0. Use {@see RelationType::EMBED} instead.
3539
*/
3640
public const EMBED = 2;
3741

3842
/**
3943
* the relation type LINK is set for a relation which is anchored as link in an attribute value.
4044
*
4145
* @var int
46+
*
47+
* @deprecated 5.0.0 accessing magic getter is deprecated and will be removed in 6.0.0. Use {@see RelationType::LINK} instead.
4248
*/
4349
public const LINK = 4;
4450

4551
/**
4652
* the relation type FIELD is set for a relation which is part of an relation attribute value.
4753
*
4854
* @var int
55+
*
56+
* @deprecated 5.0.0 accessing magic getter is deprecated and will be removed in 6.0.0. Use {@see RelationType::FIELD} instead.
4957
*/
5058
public const FIELD = 8;
5159

5260
/**
5361
* the relation type ASSET is set for a relation to asset in an attribute value.
5462
*
5563
* @var int
64+
*
65+
* @deprecated 5.0.0 accessing magic getter is deprecated and will be removed in 6.0.0. Use {@see RelationType::ASSET} instead.
5666
*/
5767
public const ASSET = 16;
5868

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\Content;
10+
11+
enum RelationType: int
12+
{
13+
/**
14+
* The relation type COMMON is a general relation between object set by a user.
15+
*/
16+
case COMMON = 1;
17+
18+
/**
19+
* the relation type EMBED is set for a relation which is anchored as embedded link in an attribute value.
20+
*/
21+
case EMBED = 2;
22+
23+
/**
24+
* the relation type LINK is set for a relation which is anchored as link in an attribute value.
25+
*/
26+
case LINK = 4;
27+
28+
/**
29+
* the relation type FIELD is set for a relation which is part of an relation attribute value.
30+
*/
31+
case FIELD = 8;
32+
33+
/**
34+
* the relation type ASSET is set for a relation to asset in an attribute value.
35+
*/
36+
case ASSET = 16;
37+
}

src/lib/Repository/ContentService.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use Ibexa\Contracts\Core\Repository\Values\Content\RelationList;
4747
use Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\RelationListItem;
4848
use Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\UnauthorizedRelationListItem;
49+
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType;
4950
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo as APIVersionInfo;
5051
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
5152
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
@@ -2045,7 +2046,7 @@ protected function internalLoadRelations(APIVersionInfo $versionInfo): array
20452046
return $relations;
20462047
}
20472048

2048-
public function countRelations(APIVersionInfo $versionInfo): int
2049+
public function countRelations(APIVersionInfo $versionInfo, ?RelationType $type = null): int
20492050
{
20502051
$function = $versionInfo->isPublished() ? 'read' : 'versionread';
20512052

@@ -2057,12 +2058,17 @@ public function countRelations(APIVersionInfo $versionInfo): int
20572058

20582059
return $this->persistenceHandler->contentHandler()->countRelations(
20592060
$contentInfo->id,
2060-
$versionInfo->versionNo
2061+
$versionInfo->versionNo,
2062+
$type?->value
20612063
);
20622064
}
20632065

2064-
public function loadRelationList(APIVersionInfo $versionInfo, int $offset = 0, int $limit = self::DEFAULT_PAGE_SIZE): RelationList
2065-
{
2066+
public function loadRelationList(
2067+
APIVersionInfo $versionInfo,
2068+
int $offset = 0,
2069+
int $limit = self::DEFAULT_PAGE_SIZE,
2070+
?RelationType $type = null
2071+
): RelationList {
20662072
$function = $versionInfo->isPublished() ? 'read' : 'versionread';
20672073

20682074
$list = new RelationList();
@@ -2074,7 +2080,8 @@ public function loadRelationList(APIVersionInfo $versionInfo, int $offset = 0, i
20742080
$contentInfo = $versionInfo->getContentInfo();
20752081
$list->totalCount = $this->persistenceHandler->contentHandler()->countRelations(
20762082
$contentInfo->id,
2077-
$versionInfo->versionNo
2083+
$versionInfo->versionNo,
2084+
$type?->value
20782085
);
20792086

20802087
if ($list->totalCount === 0) {
@@ -2086,6 +2093,7 @@ public function loadRelationList(APIVersionInfo $versionInfo, int $offset = 0, i
20862093
$limit,
20872094
$offset,
20882095
$versionInfo->versionNo,
2096+
$type?->value
20892097
);
20902098

20912099
$destinationContentIds = array_column($persistenceRelationList, 'destinationContentId');
@@ -2120,13 +2128,13 @@ public function loadRelationList(APIVersionInfo $versionInfo, int $offset = 0, i
21202128
/**
21212129
* {@inheritdoc}
21222130
*/
2123-
public function countReverseRelations(ContentInfo $contentInfo): int
2131+
public function countReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): int
21242132
{
21252133
if (!$this->permissionResolver->canUser('content', 'reverserelatedlist', $contentInfo)) {
21262134
return 0;
21272135
}
21282136

2129-
return $this->persistenceHandler->contentHandler()->countReverseRelations($contentInfo->getId());
2137+
return $this->persistenceHandler->contentHandler()->countReverseRelations($contentInfo->getId(), $type?->value);
21302138
}
21312139

21322140
/**
@@ -2136,18 +2144,17 @@ public function countReverseRelations(ContentInfo $contentInfo): int
21362144
*
21372145
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
21382146
*
2139-
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
2140-
*
21412147
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Relation[]
21422148
*/
2143-
public function loadReverseRelations(ContentInfo $contentInfo): iterable
2149+
public function loadReverseRelations(ContentInfo $contentInfo, ?RelationType $type = null): iterable
21442150
{
21452151
if (!$this->permissionResolver->canUser('content', 'reverserelatedlist', $contentInfo)) {
21462152
throw new UnauthorizedException('content', 'reverserelatedlist', ['contentId' => $contentInfo->id]);
21472153
}
21482154

21492155
$spiRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations(
2150-
$contentInfo->id
2156+
$contentInfo->id,
2157+
$type?->value
21512158
);
21522159

21532160
$returnArray = [];
@@ -2169,22 +2176,33 @@ public function loadReverseRelations(ContentInfo $contentInfo): iterable
21692176

21702177
/**
21712178
* {@inheritdoc}
2179+
*
2180+
* @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo
2181+
* @param int $offset
2182+
* @param int $limit
2183+
* @param \Ibexa\Contracts\Core\Repository\Values\Content\RelationType|null $type
21722184
*/
2173-
public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList
2174-
{
2185+
public function loadReverseRelationList(
2186+
ContentInfo $contentInfo,
2187+
int $offset = 0,
2188+
int $limit = -1,
2189+
?RelationType $type = null
2190+
): RelationList {
21752191
$list = new RelationList();
21762192
if (!$this->repository->getPermissionResolver()->canUser('content', 'reverserelatedlist', $contentInfo)) {
21772193
return $list;
21782194
}
21792195

21802196
$list->totalCount = $this->persistenceHandler->contentHandler()->countReverseRelations(
2181-
$contentInfo->id
2197+
$contentInfo->id,
2198+
$type?->value
21822199
);
21832200
if ($list->totalCount > 0) {
21842201
$spiRelationList = $this->persistenceHandler->contentHandler()->loadReverseRelationList(
21852202
$contentInfo->id,
21862203
$offset,
2187-
$limit
2204+
$limit,
2205+
$type?->value
21882206
);
21892207
foreach ($spiRelationList as $spiRelation) {
21902208
$sourceContentInfo = $this->internalLoadContentInfoById($spiRelation->sourceContentId);

0 commit comments

Comments
 (0)