Skip to content

Commit 631bdb3

Browse files
fixes
1 parent d2add64 commit 631bdb3

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

code_samples/collaboration/src/Collaboration/Cart/CartSession.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,32 @@
66
*/
77
declare(strict_types=1);
88

9-
namespace App\Collaboration\Cart;
9+
namespace App\Collaboration\Cart\Persistence\Values;
1010

11-
use DateTimeInterface;
12-
use Ibexa\Contracts\Cart\Value\CartInterface;
13-
use Ibexa\Contracts\Collaboration\Participant\ParticipantCollectionInterface;
14-
use Ibexa\Contracts\Collaboration\Session\AbstractSession;
15-
use Ibexa\Contracts\Core\Repository\Values\User\User;
11+
use DateTimeImmutable;
12+
use Ibexa\Collaboration\Persistence\Values\AbstractSession;
1613

1714
final class CartSession extends AbstractSession
1815
{
19-
private CartInterface $cart;
16+
private string $cartIdentifier;
2017

2118
public function __construct(
2219
int $id,
23-
CartInterface $cart,
20+
string $cartIdentifier,
2421
string $token,
25-
User $owner,
26-
ParticipantCollectionInterface $participants,
22+
int $userId,
2723
bool $isActive,
2824
bool $hasPublicLink,
29-
DateTimeInterface $createdAt,
30-
DateTimeInterface $updatedAt
25+
DateTimeImmutable $createdAt,
26+
DateTimeImmutable $updatedAt
3127
) {
32-
parent::__construct($id, $token, $owner, $participants, $isActive, $hasPublicLink, $createdAt, $updatedAt);
28+
parent::__construct($id, $token, $userId, $isActive, $hasPublicLink, $createdAt, $updatedAt);
3329

34-
$this->cart = $cart;
30+
$this->cartIdentifier = $cartIdentifier;
3531
}
3632

37-
public function getCart(): CartInterface
33+
public function getCartIdentifier(): string
3834
{
39-
return $this->cart;
35+
return $this->cartIdentifier;
4036
}
4137
}

code_samples/collaboration/src/Collaboration/Cart/Persistence/Values/CartSessionCreateStruct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
?DateTimeImmutable $createdAt = null,
2626
?DateTimeImmutable $updatedAt = null
2727
) {
28-
parent::__construct($token, $ownerId, $isActive, $hasPublicLink, $createdAt, $updatedAt);
28+
parent::__construct( $token, $ownerId,$isActive, $hasPublicLink, $createdAt, $updatedAt);
2929

3030
$this->cartIdentifier = $cartIdentifier;
3131
}

docs/content_management/collaborative_editing/extend_collaborative_editing.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ When creating the Database Gateways and mappers, you can use the build-in servic
7171
7272
In the `Collaboration/Cart/Persistence/Gateway` directory create the following files:
7373

74-
- `DatabaseGateway` - implements the gateway logic for getting and retrieving shared Cart collaboration data from the database, using a Discriminator to indicate the type of session (in this case, a Cart session):
74+
- `DatabaseSchema` - defines and creates the database tables needed to store shared Cart collaboration session data:
7575

7676
``` php
77-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Gateway/DatabaseGateway.php') =]]
77+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Gateway/DatabaseSchema.php') =]]
7878
```
7979

80-
- `DatabaseSchema` - defines and creates the database tables needed to store shared Cart collaboration session data:
80+
- `DatabaseGateway` - implements the gateway logic for getting and retrieving shared Cart collaboration data from the database, using a Discriminator to indicate the type of session (in this case, a Cart session):
8181

8282
``` php
83-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Gateway/DatabaseSchema.php') =]]
83+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Gateway/DatabaseGateway.php') =]]
8484
```
8585

86-
### Define database Value objects
86+
### Define persistence Value objects
8787

8888
Value objects describe how collaboration session data is represented in the database.
8989
Persistence gateway uses them to store, retrieve, and manipulate session information, such as the session ID, associated Cart, participants, and scopes.
@@ -93,19 +93,19 @@ In the `Collaboration/Cart/Persistence/Values` directory create the following Va
9393
- `CartSession` - represents the Cart collaboration session data:
9494

9595
``` php
96-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartSession.php') =]]
96+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Values/CartSession.php') =]]
9797
```
9898

9999
- `CartSessionCreateStruct` - defines the data needed to create a new Cart collaboration session:
100100

101101
``` php
102-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartSessionCreateStruct.php') =]]
102+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Values/CartSessionCreateStruct.php') =]]
103103
```
104104

105105
- `CartSessionUpdateStruct` - defines the data used to update an existing Cart collaboration session:
106106

107107
``` php
108-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartSessionUpdateStruct.php') =]]
108+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Persistence/Values/CartSessionUpdateStruct.php') =]]
109109
```
110110

111111
### Create the Cart session Struct objects
@@ -139,32 +139,7 @@ In the `Collaboration/Cart` directory create the following Session Structs:
139139
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartSessionType.php') =]]
140140
```
141141

142-
## Allow participants to access the Cart
143-
144-
To start collaborating, you need to work on permissions.
145-
This involves decorating the `PermissionResolver` and `CartResolver`.
146-
147-
This step makes sure that if a Cart is part of a Cart collaboration session, users can access it due to the given permission, and in all other cases, it falls back to the default implementation.
148-
149-
!!! caution "Decorating permissions"
150-
151-
Be careful when decorating permissions to change the behavior only as necessary, ensuring the Cart is shared only with the intended users.
152-
153-
In the `src/Collaboration/Cart` directory, create the following files:
154-
155-
- `PermissionResolverDecorator` – customizes the permission resolver to handle access rules for Cart collaboration sessions, allowing participants to view or edit shared Carts while preserving default permission checks for all other cases. Here you can decide what scope is available for this collaboration session by choosing between `view` or `edit`.
156-
157-
``` php
158-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/PermissionResolverDecorator.php') =]]
159-
```
160-
161-
- `CartResolverDecorator` – extends the permission resolver to allow access to shared Carts in collaboration sessions, it checks if a Cart belongs to a collaboration session.
162-
163-
``` php
164-
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartResolverDecorator.php') =]]
165-
```
166-
167-
### Create mappers
142+
## Create mappers
168143

169144
Mappers are used to return session data into the format the database needs and to send it to the repository.
170145

@@ -194,6 +169,31 @@ In the `src\Collaboration\Cart\Mapper` folder create four mappers:
194169
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/Mapper/CartSessionPersistenceMapper.php') =]]
195170
```
196171

172+
## Allow participants to access the Cart
173+
174+
To start collaborating, you need to work on permissions.
175+
This involves decorating the `PermissionResolver` and `CartResolver`.
176+
177+
This step makes sure that if a Cart is part of a Cart collaboration session, users can access it due to the given permission, and in all other cases, it falls back to the default implementation.
178+
179+
!!! caution "Decorating permissions"
180+
181+
Be careful when decorating permissions to change the behavior only as necessary, ensuring the Cart is shared only with the intended users.
182+
183+
In the `src/Collaboration/Cart` directory, create the following files:
184+
185+
- `PermissionResolverDecorator` – customizes the permission resolver to handle access rules for Cart collaboration sessions, allowing participants to view or edit shared Carts while preserving default permission checks for all other cases. Here you can decide what scope is available for this collaboration session by choosing between `view` or `edit`.
186+
187+
``` php
188+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/PermissionResolverDecorator.php') =]]
189+
```
190+
191+
- `CartResolverDecorator` – extends the permission resolver to allow access to shared Carts in collaboration sessions, it checks if a Cart belongs to a collaboration session.
192+
193+
``` php
194+
[[= include_file('code_samples/collaboration/src/Collaboration/Cart/CartResolverDecorator.php') =]]
195+
```
196+
197197
## Build dedicated controllers to manage the Cart sharing flow
198198

199199
To support Cart sharing, you need to create controllers which handle the collaboration flow.
@@ -232,8 +232,8 @@ Finally, `redirectToRoute` redirects the user to the Cart view and passes the id
232232
!!! caution "Session parameter"
233233

234234
Avoid using a generic session parameter name such as `current_collaboration_session` (it's used here only for example purposes).
235-
If multiple collaboration session types exist, for example, Content and Cart sessions, the parameter may be overwritten when another session is started.
236-
Try to use more specific and unique parameter name to prevent conflicts between different session types.
235+
The user can participate in multiple sessions simultaneously (of one or many types), so using this parameter would cause it to be constantly overwritten.
236+
Therefore, active sessions should not be resolved based on such parameter.
237237

238238
## Integrate with Symfony forms by adding forms and templates
239239

0 commit comments

Comments
 (0)