- Documentation >
- Content management >
- Collaborative editing >
- Collaborative editing API
Collaborative editing API
Ibexa DXP's Collaborative editing API provides two services for managing sessions and invitations, which differ in function:
Managing sessions
Create session
You can create new collaboration session with SessionService::createSession
:
| $versionInfo = $this->contentService->loadContent(52)->getVersionInfo();
$createStruct = new ContentSessionCreateStruct(
$versionInfo,
$versionInfo->getInitialLanguage()
);
$createStruct->setHasPublicLink(false);
$token = 'my-secret-token-12345';
$createStruct->setToken($token);
$sessionId = $this->sessionService->createSession($createStruct)->getId();
|
Get session
You can get an existing collaboration session with SessionService::getSession
:
| $session = $this->sessionService->getSession($sessionId);
|
| $session = $this->sessionService->getSessionByToken($token);
|
Find sessions
You can find an existing session with SessionService::findSessions
by:
| $sessionQuery = new SessionQuery(new Token($token));
$session = $this->sessionService->findSessions($sessionQuery)->getFirst();
|
Update session
You can update existing invitation with SessionService::updateSession
:
| $updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setHasPublicLink(true);
$this->sessionService->updateSession($session, $updateStruct);
|
Deactivate session
You can deactivate session with SessionService::deleteSession
:
| $updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setIsActive(false);
$this->sessionService->updateSession($session, $updateStruct);
|
Delete session
You can delete session with SessionService::deleteSession
:
| $this->sessionService->deleteSession($session);
|
Managing participants
Add participant
You can add participant to the collaboration session with SessionService::addParticipant
:
1
2
3
4
5
6
7
8
9
10
11
12
13 | $user = $this->userService->loadUserByLogin('another_user');
$internalParticipantCreateStruct = new InternalParticipantCreateStruct(
$user,
ContentSessionScope::VIEW
);
$externalParticipantCreateStruct = new ExternalParticipantCreateStruct(
'external@example.com',
ContentSessionScope::VIEW,
'personal-secret-token-12345'
);
$internalParticipant = $this->sessionService->addParticipant($session, $internalParticipantCreateStruct);
$externalParticipant = $this->sessionService->addParticipant($session, $externalParticipantCreateStruct);
|
Get and update participant
You can update participant added to the collaboration session with SessionService::updateParticipant
:
| $participant = $this->sessionService
->getSession($session->getId())
->getParticipants()
->getByEmail($user->email);
$internalParticipantUpdateStruct = new InternalParticipantUpdateStruct(ContentSessionScope::EDIT);
$this->sessionService->updateParticipant($session, $participant, $internalParticipantUpdateStruct);
|
Remove participant
You can remove participant from the collaboration session with SessionService::removeParticipant
:
| $this->sessionService->removeParticipant($session, $externalParticipant);
|
Check session owner
You can check the owner of the collaboration session with SessionService::isSessionOwner
:
| $this->sessionService->isSessionOwner(
$session,
$this->userService->loadUserByLogin('another_user')
);
|
If no user is provided, current user is used.
Check session participant
You can check the participant of the collaboration session with SessionService::isSessionParticipant
:
| $this->sessionService->isSessionParticipant(
$session,
$this->permissionResolver->getCurrentUserReference()
);
|
Managing invitations
Manage invitation
You can get an invitation with InvitationService::getInvitation
:
| $invitationQuery = new InvitationQuery(new Session($session));
$invitations = $this->invitationService->findInvitations($invitationQuery)->getInvitations();
foreach ($invitations as $invitation) {
$output->writeln('Invitation ID: ' . $invitation->getId() . ' Status: ' . $invitation->getStatus());
}
$invitation = $this->invitationService->getInvitationByParticipant($participant);
|
You can select the parameter that you can read from an invitation:
| $invitation->getSession()->getId();
|
| $invitation->getParticipant()->getId();
|
| $invitation->getStatus();
|
Create invitation
You can create new invitation for the collaborative session using the InvitationService::createInvitation
method:
| $invitationCreateStruct = new InvitationCreateStruct(
$session,
$internalParticipant
);
$this->invitationService->createInvitation($invitationCreateStruct);
|
You can use it when auto-inviting participants is not enabled.
Update invitation
You can update existing invitation with InvitationService::updateInvitation
:
| $invitationUpdateStruct = new InvitationUpdateStruct();
$invitationUpdateStruct->setStatus(InvitationStatus::STATUS_REJECTED);
$this->invitationService->updateInvitation($invitation, $invitationUpdateStruct);
|
Delete invitation
You can delete an invitation with InvitationService::deleteInvitation
:
| $invitation = $this->invitationService->getInvitation(2);
$this->invitationService->deleteInvitation($invitation);
|
Find invitations
You can find an invitation with InvitationService::findInvitations
.
To learn more about the available search options, see Search Criteria and Sort Clauses for Collaborative editing.
Example API usage
Below you can see an example of API usage for Collaborative editing:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 | <?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 App\Command;
use Ibexa\Contracts\Collaboration\Invitation\InvitationCreateStruct;
use Ibexa\Contracts\Collaboration\Invitation\InvitationQuery;
use Ibexa\Contracts\Collaboration\Invitation\InvitationStatus;
use Ibexa\Contracts\Collaboration\Invitation\InvitationUpdateStruct;
use Ibexa\Contracts\Collaboration\Invitation\Query\Criterion\Session;
use Ibexa\Contracts\Collaboration\InvitationServiceInterface;
use Ibexa\Contracts\Collaboration\Participant\ExternalParticipantCreateStruct;
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantCreateStruct;
use Ibexa\Contracts\Collaboration\Participant\InternalParticipantUpdateStruct;
use Ibexa\Contracts\Collaboration\Session\Query\Criterion\Token;
use Ibexa\Contracts\Collaboration\Session\SessionQuery;
use Ibexa\Contracts\Collaboration\SessionServiceInterface;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Contracts\Share\Collaboration\ContentSessionCreateStruct;
use Ibexa\Contracts\Share\Collaboration\ContentSessionScope;
use Ibexa\Contracts\Share\Collaboration\ContentSessionUpdateStruct;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class ManageSessionsCommand extends Command
{
protected static $defaultName = 'app:manage-sessions';
private InvitationServiceInterface $invitationService;
private SessionServiceInterface $sessionService;
private ContentService $contentService;
private UserService $userService;
private PermissionResolver $permissionResolver;
public function __construct(
InvitationServiceInterface $invitationService,
SessionServiceInterface $sessionService,
ContentService $contentService,
UserService $userService,
PermissionResolver $permissionResolver
) {
parent::__construct(self::$defaultName);
$this->invitationService = $invitationService;
$this->sessionService = $sessionService;
$this->contentService = $contentService;
$this->userService = $userService;
$this->permissionResolver = $permissionResolver;
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->permissionResolver->setCurrentUserReference(
$this->userService->loadUserByLogin('admin')
);
// Create a sharing session for Content
$versionInfo = $this->contentService->loadContent(52)->getVersionInfo();
$createStruct = new ContentSessionCreateStruct(
$versionInfo,
$versionInfo->getInitialLanguage()
);
$createStruct->setHasPublicLink(false);
$token = 'my-secret-token-12345';
$createStruct->setToken($token);
$sessionId = $this->sessionService->createSession($createStruct)->getId();
// Get a session by ID or token
$session = $this->sessionService->getSession($sessionId);
$session = $this->sessionService->getSessionByToken($token);
// Find sessions
$sessionQuery = new SessionQuery(new Token($token));
$session = $this->sessionService->findSessions($sessionQuery)->getFirst();
// Update a session
$updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setHasPublicLink(true);
$this->sessionService->updateSession($session, $updateStruct);
// Deactivate a session
$updateStruct = new ContentSessionUpdateStruct();
$updateStruct->setIsActive(false);
$this->sessionService->updateSession($session, $updateStruct);
// Manage participants
$user = $this->userService->loadUserByLogin('another_user');
$internalParticipantCreateStruct = new InternalParticipantCreateStruct(
$user,
ContentSessionScope::VIEW
);
$externalParticipantCreateStruct = new ExternalParticipantCreateStruct(
'external@example.com',
ContentSessionScope::VIEW,
'personal-secret-token-12345'
);
$internalParticipant = $this->sessionService->addParticipant($session, $internalParticipantCreateStruct);
$externalParticipant = $this->sessionService->addParticipant($session, $externalParticipantCreateStruct);
// Get and update participants
$participant = $this->sessionService
->getSession($session->getId())
->getParticipants()
->getByEmail($user->email);
$internalParticipantUpdateStruct = new InternalParticipantUpdateStruct(ContentSessionScope::EDIT);
$this->sessionService->updateParticipant($session, $participant, $internalParticipantUpdateStruct);
// Remove participant
$this->sessionService->removeParticipant($session, $externalParticipant);
// Check ownerships. If no user is provided, current user is used.
$this->sessionService->isSessionOwner(
$session,
$this->userService->loadUserByLogin('another_user')
);
// Check participation
$this->sessionService->isSessionParticipant(
$session,
$this->permissionResolver->getCurrentUserReference()
);
// Manage invitations
$invitationQuery = new InvitationQuery(new Session($session));
$invitations = $this->invitationService->findInvitations($invitationQuery)->getInvitations();
foreach ($invitations as $invitation) {
$output->writeln('Invitation ID: ' . $invitation->getId() . ' Status: ' . $invitation->getStatus());
}
$invitation = $this->invitationService->getInvitationByParticipant($participant);
// Create invitation - use when auto-inviting participants is not enabled
$invitationCreateStruct = new InvitationCreateStruct(
$session,
$internalParticipant
);
$this->invitationService->createInvitation($invitationCreateStruct);
// Update invitation
$invitationUpdateStruct = new InvitationUpdateStruct();
$invitationUpdateStruct->setStatus(InvitationStatus::STATUS_REJECTED);
$this->invitationService->updateInvitation($invitation, $invitationUpdateStruct);
// Delete invitation
$invitation = $this->invitationService->getInvitation(2);
$this->invitationService->deleteInvitation($invitation);
// Delete a session
$this->sessionService->deleteSession($session);
return Command::SUCCESS;
}
}
|