ILIAS  release_8 Revision v8.24
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 ()
 

Protected Member Functions

 __construct (int $ownerId)
 
 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)
protected

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

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

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)

Returns
self

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

400 : self
401 {
402 $this->getRepository()->destroy();
403 $this->getRelations()->clear();
404 return $this;
405 }

References getRelations(), and getRepository().

+ Here is the call graph for this function:

◆ getIgnoredRelations()

ilBuddyList::getIgnoredRelations ( )

Gets all ignored relations: ilBuddySystemRelationCollection.

Returns
ilBuddySystemRelationCollection

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

206 {
207 return $this->getRelations()->filter(static function (ilBuddySystemRelation $relation): bool {
208 return $relation->isIgnored();
209 });
210 }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list.
Class ilBuddySystemRelation.

References getRelations(), and ilBuddySystemRelation\isIgnored().

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.

Returns
ilBuddySystemRelationCollection

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

195 {
196 return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation): bool {
197 return $relation->getUsrId() === $this->getOwnerId();
198 });
199 }
getIgnoredRelations()
Gets all ignored relations: ilBuddySystemRelationCollection.

References getIgnoredRelations(), getOwnerId(), and ilBuddySystemRelation\getUsrId().

+ Here is the call graph for this function:

◆ getIgnoredRelationsForOwner()

ilBuddyList::getIgnoredRelationsForOwner ( )

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

Returns
ilBuddySystemRelationCollection

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

184 {
185 return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation): bool {
186 return $relation->getBuddyUsrId() === $this->getOwnerId();
187 });
188 }

References ilBuddySystemRelation\getBuddyUsrId(), getIgnoredRelations(), and getOwnerId().

+ Here is the call graph for this function:

◆ getInstanceByGlobalUser()

◆ getInstanceByUserId()

static ilBuddyList::getInstanceByUserId ( int  $usrId)
static
Parameters
int$usrId
Returns
self
Exceptions
ilBuddySystemException

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

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

References ilObjUser\_isAnonymous().

Referenced by getInstanceByGlobalUser(), ilContactAppEventListener\handleEvent(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested(), ilBuddyListTest\testDifferentRelationStatesCanBeRetrieved(), ilBuddyListTest\testInstanceByBeCreatedBySingletonMethod(), ilBuddyListTest\testListIsInitiallyEmpty(), ilBuddyListTest\testRelationCannotBeRequestedForAnonymous(), ilBuddyListTest\testRelationCannotBeRequestedForUnknownUserAccounts(), ilBuddyListTest\testRelationRequestCanBeApprovedByTheRelationTarget(), ilBuddyListTest\testRelationRequestCanBeIgnoredByTheRelationTarget(), ilBuddyListTest\testRelationRequestCannotBeApprovedByTheRelationOwner(), ilBuddyListTest\testRelationRequestCannotBeIgnoredByTheRelationOwner(), ilBuddyListTest\testRepositoryIsEnquiredOnlyOnceToFetchRelationsWhenCalledImplicitly(), ilBuddyListTest\testRepositoryIsEnquiredToFetchRelationsWhenRequestedExplicitly(), ilBuddyListTest\testRepositoryIsEnquiredWhenBuddyListShouldBeDestroyed(), ilBuddyListTest\testStateTransitionExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsIgnored(), ilBuddyListTest\testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAnUnknownBuddyId(), and ilBuddyListTest\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.

Returns
ilBuddySystemRelationCollection

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

140 {
141 return $this->getRelations()->filter(static function (ilBuddySystemRelation $relation): bool {
142 return $relation->isLinked();
143 });
144 }

References getRelations(), and ilBuddySystemRelation\isLinked().

+ Here is the call graph for this function:

◆ getOwnerId()

ilBuddyList::getOwnerId ( )

Returns the user id of the buddy list owner.

Returns
int

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

130 : int
131 {
132 return $this->ownerId;
133 }

References $ownerId.

Referenced by __construct(), getIgnoredRelationsByOwner(), getIgnoredRelationsForOwner(), getRelationByUserId(), getRequestRelationsByOwner(), getRequestRelationsForOwner(), ignore(), link(), and reset().

+ Here is the caller graph for this function:

◆ getRelationByUserId()

ilBuddyList::getRelationByUserId ( int  $usrId)

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

232 {
233 if ($this->getRelations()->containsKey($usrId)) {
234 return $this->getRelations()->get($usrId);
235 }
236
237 $relation = new ilBuddySystemRelation(
239 $this->getOwnerId(),
240 $usrId,
241 true,
242 time()
243 );
244
245 $this->getRelations()->set($usrId, $relation);
246
247 return $relation;
248 }

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

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )

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

113 {
114 if (null === $this->relations) {
115 $this->performLazyLoading();
116 }
117
118 return $this->relations;
119 }
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 226 of file class.ilBuddyList.php.

226 : int
227 {
228 return ($relation->getUsrId() === $this->getOwnerId() ? $relation->getBuddyUsrId() : $relation->getUsrId());
229 }

References ilBuddySystemRelation\getBuddyUsrId(), and ilBuddySystemRelation\getUsrId().

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

+ Here is the call graph for this function:
+ 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 216 of file class.ilBuddyList.php.

216 : array
217 {
218 return $this->getRelations()->getKeys();
219 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )

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

90 {
91 return $this->repository;
92 }
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.

Returns
ilBuddySystemRelationCollection

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

173 {
174 return $this->getRelations()->filter(static function (ilBuddySystemRelation $relation): bool {
175 return $relation->isRequested();
176 });
177 }

References getRelations(), and ilBuddySystemRelation\isRequested().

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.

Returns
ilBuddySystemRelationCollection

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

162 {
163 return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation): bool {
164 return $relation->getUsrId() === $this->getOwnerId();
165 });
166 }
getRequestedRelations()
Gets all requested relations.

References getOwnerId(), getRequestedRelations(), and ilBuddySystemRelation\getUsrId().

+ Here is the call graph for this function:

◆ getRequestRelationsForOwner()

ilBuddyList::getRequestRelationsForOwner ( )

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

Returns
ilBuddySystemRelationCollection

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

151 {
152 return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation): bool {
153 return $relation->getBuddyUsrId() === $this->getOwnerId();
154 });
155 }

References ilBuddySystemRelation\getBuddyUsrId(), getOwnerId(), and getRequestedRelations().

+ Here is the call graph for this function:

◆ ignore()

ilBuddyList::ignore ( ilBuddySystemRelation  $relation)
Parameters
ilBuddySystemRelation$relation
Returns
self
Exceptions
ilBuddySystemException

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

362 : self
363 {
364 try {
365 if ($relation->isLinked()) {
366 throw new ilBuddySystemRelationStateTransitionException('buddy_bs_action_already_linked');
367 }
368
369 if ($this->getOwnerId() === $relation->getUsrId()) {
370 throw new ilBuddySystemException('You can only ignore a request when you are not the initiator');
371 }
372
373 $relation->ignore();
374
375 $this->getRepository()->save($relation);
376 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
377 } catch (ilBuddySystemException $e) {
378 if ($relation->isIgnored()) {
379 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_ignored');
380 }
381
382 throw $e;
383 }
384
385 $this->eventHandler->raise(
386 'Services/Contact',
387 'contactIgnored',
388 [
389 'relation' => $relation
390 ]
391 );
392
393 return $this;
394 }
getRelationTargetUserId(ilBuddySystemRelation $relation)

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

+ Here is the call graph for this function:

◆ link()

ilBuddyList::link ( ilBuddySystemRelation  $relation)
Parameters
ilBuddySystemRelation$relation
Returns
self
Exceptions
ilBuddySystemException

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

255 : self
256 {
257 if ($relation->isLinked()) {
258 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_linked');
259 }
260
261 if ($this->getOwnerId() === $relation->getUsrId()) {
262 throw new ilBuddySystemException('You can only accept a request when you are not the initiator');
263 }
264
265 $relation->link();
266
267 $this->getRepository()->save($relation);
268 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
269
270 $this->eventHandler->raise(
271 'Services/Contact',
272 'relationLinked',
273 [
274 'relation' => $relation
275 ]
276 );
277
278 return $this;
279 }

References getOwnerId(), getRelations(), getRelationTargetUserId(), getRepository(), ilBuddySystemRelation\getUsrId(), ilBuddySystemRelation\isLinked(), and ilBuddySystemRelation\link().

+ Here is the call graph for this function:

◆ performLazyLoading()

ilBuddyList::performLazyLoading ( )
protected

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

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

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 99 of file class.ilBuddyList.php.

99 : void
100 {
101 $this->setRelations(new ilBuddySystemRelationCollection($this->getRepository()->getAll()));
102 }
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)
Parameters
ilBuddySystemRelation$relation
Returns
self
Exceptions
ilBuddySystemException

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

316 : self
317 {
318 if (ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation))) {
319 throw new ilBuddySystemException(sprintf(
320 'You cannot add the anonymous user to the list (id: %s)',
321 $this->getRelationTargetUserId($relation)
322 ));
323 }
324
325 $login = ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation));
326 if ($login === '') {
327 throw new ilBuddySystemException(sprintf(
328 'You cannot add a non existing user (id: %s)',
329 $this->getRelationTargetUserId($relation)
330 ));
331 }
332
333 try {
334 $relation->request();
335 $this->getRepository()->save($relation);
336 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
337 } catch (ilBuddySystemException $e) {
338 if ($relation->isRequested()) {
339 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested');
340 }
341
342 throw $e;
343 }
344
345 $this->eventHandler->raise(
346 'Services/Contact',
347 'contactRequested',
348 [
349 'usr_id' => $this->getRelationTargetUserId($relation),
350 'relation' => $relation
351 ]
352 );
353
354 return $this;
355 }
static _lookupLogin(int $a_user_id)

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

+ 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 82 of file class.ilBuddyList.php.

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

References getOwnerId().

+ Here is the call graph for this function:

◆ setOwnerId()

ilBuddyList::setOwnerId ( int  $ownerId)

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

221 : void
222 {
223 $this->ownerId = $ownerId;
224 }

References $ownerId.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRelations()

ilBuddyList::setRelations ( ilBuddySystemRelationCollection  $relations)

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

121 : void
122 {
123 $this->relations = $relations;
124 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

ilBuddyList::setRepository ( ilBuddySystemRelationRepository  $repository)

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

94 : void
95 {
96 $this->repository = $repository;
97 }

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)
Parameters
ilBuddySystemRelation$relation
Returns
self
Exceptions
ilBuddySystemException

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

286 : self
287 {
288 try {
289 $relation->unlink();
290 $this->getRepository()->save($relation);
291 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
292 } catch (ilBuddySystemException $e) {
293 if ($relation->isUnlinked()) {
294 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked');
295 }
296
297 throw $e;
298 }
299
300 $this->eventHandler->raise(
301 'Services/Contact',
302 'relationUnlinked',
303 [
304 'relation' => $relation
305 ]
306 );
307
308 return $this;
309 }

References Vendor\Package\$e, getRelations(), getRelationTargetUserId(), getRepository(), ilBuddySystemRelation\isUnlinked(), and ilBuddySystemRelation\unlink().

+ 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: