ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBuddyList Class Reference

Class ilBuddyList. More...

+ Collaboration diagram for ilBuddyList:

Public Member Functions

 reset ()
 Remove the singleton instance from static array, used for unit tests. More...
 
 getRepository ()
 
 setRepository (ilBuddySystemRelationRepository $repository)
 
 readFromRepository ()
 
 getRelations ()
 
 setRelations (ilBuddySystemRelationCollection $relations)
 
 getOwnerId ()
 Returns the user id of the buddy list owner. More...
 
 getLinkedRelations ()
 Gets all linked/approved relations. More...
 
 getRequestRelationsForOwner ()
 Gets all requested relations the buddy list owner has to interact with. More...
 
 getRequestRelationsByOwner ()
 Gets all requested relations the buddy list owner initiated. More...
 
 getRequestedRelations ()
 Gets all requested relations. More...
 
 getIgnoredRelationsForOwner ()
 Gets all ignored relations the buddy list owner has to interact with. More...
 
 getIgnoredRelationsByOwner ()
 Gets all ignored relations the buddy list owner initiated. More...
 
 getIgnoredRelations ()
 Gets all ignored relations: ilBuddySystemRelationCollection. More...
 
 getRelationUserIds ()
 Returns an array of all user ids the buddy list owner has a relation with. More...
 
 setOwnerId (int $ownerId)
 
 getRelationByUserId (int $usrId)
 
 link (ilBuddySystemRelation $relation)
 
 unlink (ilBuddySystemRelation $relation)
 
 request (ilBuddySystemRelation $relation)
 
 ignore (ilBuddySystemRelation $relation)
 
 destroy ()
 Removes all buddy system references of the user (persistently) More...
 

Static Public Member Functions

static getInstanceByUserId (int $usrId)
 
static getInstanceByGlobalUser (?ilObjUser $user=null)
 

Protected Member Functions

 __construct (int $ownerId, ?ilAppEventHandler $event_handler=null)
 
 performLazyLoading ()
 
 getRelationTargetUserId (ilBuddySystemRelation $relation)
 

Protected Attributes

int $ownerId
 
ilBuddySystemRelationRepository $repository
 
bool $relationsRead = false
 
ilAppEventHandler $eventHandler
 
ilBuddySystemRelationCollection $relations = null
 

Static Protected Attributes

static array $instances = []
 

Detailed Description

Class ilBuddyList.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 25 of file class.ilBuddyList.php.

Constructor & Destructor Documentation

◆ __construct()

ilBuddyList::__construct ( int  $ownerId,
?ilAppEventHandler  $event_handler = null 
)
protected

Definition at line 67 of file class.ilBuddyList.php.

68 {
69 global $DIC;
70
71 $this->eventHandler = $event_handler ?? $DIC['ilAppEventHandler'];
72
73 $this->setOwnerId($ownerId);
75 }
setOwnerId(int $ownerId)
getOwnerId()
Returns the user id of the buddy list owner.
setRepository(ilBuddySystemRelationRepository $repository)
Class ilBuddySystemRelationRepository.
global $DIC
Definition: shib_login.php:26

References $DIC, getOwnerId(), setOwnerId(), and setRepository().

+ Here is the call graph for this function:

Member Function Documentation

◆ destroy()

ilBuddyList::destroy ( )

Removes all buddy system references of the user (persistently)

Definition at line 381 of file class.ilBuddyList.php.

381 : self
382 {
383 $this->getRepository()->destroy();
384 $this->getRelations()->clear();
385 return $this;
386 }

References getRelations(), and getRepository().

+ Here is the call graph for this function:

◆ getIgnoredRelations()

ilBuddyList::getIgnoredRelations ( )

Gets all ignored relations: ilBuddySystemRelationCollection.

Definition at line 195 of file class.ilBuddyList.php.

196 {
197 return $this->getRelations()->filter(
198 static fn(ilBuddySystemRelation $relation): bool => $relation->isIgnored()
199 );
200 }
$relation
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list.
Class ilBuddySystemRelation.

References $relation, and getRelations().

Referenced by getIgnoredRelationsByOwner(), and getIgnoredRelationsForOwner().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIgnoredRelationsByOwner()

ilBuddyList::getIgnoredRelationsByOwner ( )

Gets all ignored relations the buddy list owner initiated.

Definition at line 185 of file class.ilBuddyList.php.

186 {
187 return $this->getIgnoredRelations()->filter(
188 fn(ilBuddySystemRelation $relation): bool => $relation->getUsrId() === $this->getOwnerId()
189 );
190 }
getIgnoredRelations()
Gets all ignored relations: ilBuddySystemRelationCollection.

References $relation, and getIgnoredRelations().

+ Here is the call graph for this function:

◆ getIgnoredRelationsForOwner()

ilBuddyList::getIgnoredRelationsForOwner ( )

Gets all ignored relations the buddy list owner has to interact with.

Definition at line 175 of file class.ilBuddyList.php.

176 {
177 return $this->getIgnoredRelations()->filter(
178 fn(ilBuddySystemRelation $relation): bool => $relation->getBuddyUsrId() === $this->getOwnerId()
179 );
180 }

References $relation, and getIgnoredRelations().

+ Here is the call graph for this function:

◆ getInstanceByGlobalUser()

◆ getInstanceByUserId()

static ilBuddyList::getInstanceByUserId ( int  $usrId)
static
Exceptions
ilBuddySystemException

Definition at line 39 of file class.ilBuddyList.php.

39 : self
40 {
41 if (ilObjUser::_isAnonymous($usrId)) {
42 throw new ilBuddySystemException(sprintf(
43 'You cannot create an instance for the anonymous user (id: %s)',
44 $usrId
45 ));
46 }
47
48 if (isset(self::$instances[$usrId])) {
49 return self::$instances[$usrId];
50 }
51
52 self::$instances[$usrId] = new self($usrId);
53 return self::$instances[$usrId];
54 }
Class ilBuddySystemException.
static _isAnonymous(int $usr_id)

References ilObjUser\_isAnonymous().

Referenced by getInstanceByGlobalUser(), ilContactAppEventListener\handleEvent(), ilBuddyListTestCase\testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked(), ilBuddyListTestCase\testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored(), ilBuddyListTestCase\testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked(), ilBuddyListTestCase\testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested(), ilBuddyListTestCase\testDifferentRelationStatesCanBeRetrieved(), ilBuddyListTestCase\testInstanceByBeCreatedBySingletonMethod(), ilBuddyListTestCase\testListIsInitiallyEmpty(), ilBuddyListTestCase\testRelationCannotBeRequestedForAnonymous(), ilBuddyListTestCase\testRelationCannotBeRequestedForUnknownUserAccounts(), ilBuddyListTestCase\testRelationRequestCanBeApprovedByTheRelationTarget(), ilBuddyListTestCase\testRelationRequestCanBeIgnoredByTheRelationTarget(), ilBuddyListTestCase\testRelationRequestCannotBeApprovedByTheRelationOwner(), ilBuddyListTestCase\testRelationRequestCannotBeIgnoredByTheRelationOwner(), ilBuddyListTestCase\testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly(), ilBuddyListTestCase\testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly(), ilBuddyListTestCase\testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed(), ilBuddyListTestCase\testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored(), ilBuddyListTestCase\testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId(), and ilBuddyListTestCase\testValuesCanBeFetchedByGettersWhenSetBySetters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLinkedRelations()

ilBuddyList::getLinkedRelations ( )

Gets all linked/approved relations.

Definition at line 135 of file class.ilBuddyList.php.

136 {
137 return $this->getRelations()->filter(
138 static fn(ilBuddySystemRelation $relation): bool => $relation->isLinked()
139 );
140 }

References $relation, and getRelations().

+ Here is the call graph for this function:

◆ getOwnerId()

ilBuddyList::getOwnerId ( )

Returns the user id of the buddy list owner.

Definition at line 127 of file class.ilBuddyList.php.

127 : int
128 {
129 return $this->ownerId;
130 }

References $ownerId.

Referenced by __construct(), getRelationByUserId(), ignore(), link(), and reset().

+ Here is the caller graph for this function:

◆ getRelationByUserId()

ilBuddyList::getRelationByUserId ( int  $usrId)

Definition at line 221 of file class.ilBuddyList.php.

222 {
223 if ($this->getRelations()->containsKey($usrId)) {
224 return $this->getRelations()->get($usrId);
225 }
226
229 $this->getOwnerId(),
230 $usrId,
231 true,
232 time()
233 );
234
235 $this->getRelations()->set($usrId, $relation);
236
237 return $relation;
238 }

References $relation, ilBuddySystemRelationStateFactory\getInstance(), getOwnerId(), and getRelations().

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )

Definition at line 110 of file class.ilBuddyList.php.

111 {
112 if (null === $this->relations) {
113 $this->performLazyLoading();
114 }
115
116 return $this->relations;
117 }
ilBuddySystemRelationCollection $relations

References $relations, and performLazyLoading().

Referenced by destroy(), getIgnoredRelations(), getLinkedRelations(), getRelationByUserId(), getRelationUserIds(), getRequestedRelations(), ignore(), link(), request(), and unlink().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelationTargetUserId()

ilBuddyList::getRelationTargetUserId ( ilBuddySystemRelation  $relation)
protected

Definition at line 216 of file class.ilBuddyList.php.

216 : int
217 {
218 return ($relation->getUsrId() === $this->getOwnerId() ? $relation->getBuddyUsrId() : $relation->getUsrId());
219 }

References $relation.

Referenced by ignore(), link(), request(), and unlink().

+ Here is the caller graph for this function:

◆ getRelationUserIds()

ilBuddyList::getRelationUserIds ( )

Returns an array of all user ids the buddy list owner has a relation with.

Returns
int[]

Definition at line 206 of file class.ilBuddyList.php.

206 : array
207 {
208 return $this->getRelations()->getKeys();
209 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )

Definition at line 87 of file class.ilBuddyList.php.

88 {
89 return $this->repository;
90 }
ilBuddySystemRelationRepository $repository

References $repository.

Referenced by destroy(), ignore(), link(), readFromRepository(), request(), and unlink().

+ Here is the caller graph for this function:

◆ getRequestedRelations()

ilBuddyList::getRequestedRelations ( )

Gets all requested relations.

Definition at line 165 of file class.ilBuddyList.php.

166 {
167 return $this->getRelations()->filter(
168 static fn(ilBuddySystemRelation $relation): bool => $relation->isRequested()
169 );
170 }

References $relation, and getRelations().

Referenced by getRequestRelationsByOwner(), and getRequestRelationsForOwner().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRequestRelationsByOwner()

ilBuddyList::getRequestRelationsByOwner ( )

Gets all requested relations the buddy list owner initiated.

Definition at line 155 of file class.ilBuddyList.php.

156 {
157 return $this->getRequestedRelations()->filter(
158 fn(ilBuddySystemRelation $relation): bool => $relation->getUsrId() === $this->getOwnerId()
159 );
160 }
getRequestedRelations()
Gets all requested relations.

References $relation, and getRequestedRelations().

+ Here is the call graph for this function:

◆ getRequestRelationsForOwner()

ilBuddyList::getRequestRelationsForOwner ( )

Gets all requested relations the buddy list owner has to interact with.

Definition at line 145 of file class.ilBuddyList.php.

146 {
147 return $this->getRequestedRelations()->filter(
148 fn(ilBuddySystemRelation $relation): bool => $relation->getBuddyUsrId() === $this->getOwnerId()
149 );
150 }

References $relation, and getRequestedRelations().

+ Here is the call graph for this function:

◆ ignore()

ilBuddyList::ignore ( ilBuddySystemRelation  $relation)
Exceptions
ilBuddySystemException

Definition at line 344 of file class.ilBuddyList.php.

344 : self
345 {
346 try {
347 if ($relation->isLinked()) {
348 throw new ilBuddySystemRelationStateTransitionException('buddy_bs_action_already_linked');
349 }
350
351 if ($this->getOwnerId() === $relation->getUsrId()) {
352 throw new ilBuddySystemException('You can only ignore a request when you are not the initiator');
353 }
354
355 $relation->ignore();
356
357 $this->getRepository()->save($relation);
358 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
359 } catch (ilBuddySystemException $e) {
360 if ($relation->isIgnored()) {
361 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_ignored', $e->getCode(), $e);
362 }
363
364 throw $e;
365 }
366
367 $this->eventHandler->raise(
368 'components/ILIAS/Contact',
369 'contactIgnored',
370 [
371 'relation' => $relation
372 ]
373 );
374
375 return $this;
376 }
getRelationTargetUserId(ilBuddySystemRelation $relation)

References Vendor\Package\$e, $relation, getOwnerId(), getRelations(), getRelationTargetUserId(), getRepository(), and ilBuddySystemRelation\getUsrId().

+ Here is the call graph for this function:

◆ link()

ilBuddyList::link ( ilBuddySystemRelation  $relation)
Exceptions
ilBuddySystemException

Definition at line 243 of file class.ilBuddyList.php.

243 : self
244 {
245 if ($relation->isLinked()) {
246 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_linked');
247 }
248
249 if ($this->getOwnerId() === $relation->getUsrId()) {
250 throw new ilBuddySystemException('You can only accept a request when you are not the initiator');
251 }
252
253 $relation->link();
254
255 $this->getRepository()->save($relation);
256 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
257
258 $this->eventHandler->raise(
259 'components/ILIAS/Contact',
260 'relationLinked',
261 [
262 'relation' => $relation
263 ]
264 );
265
266 return $this;
267 }

References $relation, getOwnerId(), getRelations(), getRelationTargetUserId(), getRepository(), and ilBuddySystemRelation\getUsrId().

+ Here is the call graph for this function:

◆ performLazyLoading()

ilBuddyList::performLazyLoading ( )
protected

Definition at line 102 of file class.ilBuddyList.php.

102 : void
103 {
104 if (!$this->relationsRead) {
105 $this->readFromRepository();
106 $this->relationsRead = true;
107 }
108 }

References readFromRepository().

Referenced by getRelations().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFromRepository()

ilBuddyList::readFromRepository ( )

Definition at line 97 of file class.ilBuddyList.php.

97 : void
98 {
99 $this->setRelations(new ilBuddySystemRelationCollection($this->getRepository()->getAll()));
100 }
setRelations(ilBuddySystemRelationCollection $relations)

References getRepository(), and setRelations().

Referenced by performLazyLoading().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ request()

ilBuddyList::request ( ilBuddySystemRelation  $relation)
Exceptions
ilBuddySystemException

Definition at line 300 of file class.ilBuddyList.php.

300 : self
301 {
302 if (ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation))) {
303 throw new ilBuddySystemException(sprintf(
304 'You cannot add the anonymous user to the list (id: %s)',
305 $this->getRelationTargetUserId($relation)
306 ));
307 }
308
309 $login = ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation));
310 if ($login === '') {
311 throw new ilBuddySystemException(sprintf(
312 'You cannot add a non existing user (id: %s)',
313 $this->getRelationTargetUserId($relation)
314 ));
315 }
316
317 try {
318 $relation->request();
319 $this->getRepository()->save($relation);
320 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
321 } catch (ilBuddySystemException $e) {
322 if ($relation->isRequested()) {
323 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested', $e->getCode(), $e);
324 }
325
326 throw $e;
327 }
328
329 $this->eventHandler->raise(
330 'components/ILIAS/Contact',
331 'contactRequested',
332 [
333 'usr_id' => $this->getRelationTargetUserId($relation),
334 'relation' => $relation
335 ]
336 );
337
338 return $this;
339 }
static _lookupLogin(int $a_user_id)

References Vendor\Package\$e, $relation, ilObjUser\_isAnonymous(), ilObjUser\_lookupLogin(), getRelations(), getRelationTargetUserId(), and getRepository().

+ Here is the call graph for this function:

◆ reset()

ilBuddyList::reset ( )

Remove the singleton instance from static array, used for unit tests.

Definition at line 80 of file class.ilBuddyList.php.

80 : void
81 {
82 $this->relationsRead = false;
83 $this->relations = null;
84 unset(self::$instances[$this->getOwnerId()]);
85 }

References getOwnerId().

+ Here is the call graph for this function:

◆ setOwnerId()

ilBuddyList::setOwnerId ( int  $ownerId)

Definition at line 211 of file class.ilBuddyList.php.

211 : void
212 {
213 $this->ownerId = $ownerId;
214 }

References $ownerId.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRelations()

ilBuddyList::setRelations ( ilBuddySystemRelationCollection  $relations)

Definition at line 119 of file class.ilBuddyList.php.

119 : void
120 {
121 $this->relations = $relations;
122 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

ilBuddyList::setRepository ( ilBuddySystemRelationRepository  $repository)

Definition at line 92 of file class.ilBuddyList.php.

92 : void
93 {
94 $this->repository = $repository;
95 }

References $repository, and ILIAS\UI\examples\Deck\repository().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlink()

ilBuddyList::unlink ( ilBuddySystemRelation  $relation)
Exceptions
ilBuddySystemException

Definition at line 272 of file class.ilBuddyList.php.

272 : self
273 {
274 try {
275 $relation->unlink();
276 $this->getRepository()->save($relation);
277 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
278 } catch (ilBuddySystemException $e) {
279 if ($relation->isUnlinked()) {
280 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked', $e->getCode(), $e);
281 }
282
283 throw $e;
284 }
285
286 $this->eventHandler->raise(
287 'components/ILIAS/Contact',
288 'relationUnlinked',
289 [
290 'relation' => $relation
291 ]
292 );
293
294 return $this;
295 }

References Vendor\Package\$e, $relation, getRelations(), getRelationTargetUserId(), and getRepository().

+ Here is the call graph for this function:

Field Documentation

◆ $eventHandler

ilAppEventHandler ilBuddyList::$eventHandler
protected

Definition at line 33 of file class.ilBuddyList.php.

◆ $instances

array ilBuddyList::$instances = []
staticprotected

Definition at line 28 of file class.ilBuddyList.php.

◆ $ownerId

int ilBuddyList::$ownerId
protected

Definition at line 30 of file class.ilBuddyList.php.

Referenced by getOwnerId(), and setOwnerId().

◆ $relations

ilBuddySystemRelationCollection ilBuddyList::$relations = null
protected

Definition at line 34 of file class.ilBuddyList.php.

Referenced by getRelations(), and setRelations().

◆ $relationsRead

bool ilBuddyList::$relationsRead = false
protected

Definition at line 32 of file class.ilBuddyList.php.

◆ $repository

ilBuddySystemRelationRepository ilBuddyList::$repository
protected

Definition at line 31 of file class.ilBuddyList.php.

Referenced by getRepository(), and setRepository().


The documentation for this class was generated from the following file: