ILIAS  release_7 Revision v7.30-3-g800a261c036
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)
 ilBuddyList constructor. More...
 
 performLazyLoading ()
 
 getRelationTargetUserId (ilBuddySystemRelation $relation)
 

Protected Attributes

 $ownerId
 
 $relations
 
 $repository
 
 $relationsRead = false
 
 $eventHandler
 

Static Protected Attributes

static $instances = []
 

Detailed Description

Class ilBuddyList.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBuddyList::__construct ( int  $ownerId)
protected

ilBuddyList constructor.

Parameters
int$ownerId

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

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

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

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

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

220 {
221 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
222 return $relation->isIgnored();
223 });
224 }
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 208 of file class.ilBuddyList.php.

209 {
210 return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) {
211 return $relation->getUsrId() === $this->getOwnerId();
212 });
213 }
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 197 of file class.ilBuddyList.php.

198 {
199 return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) {
200 return $relation->getBuddyUsrId() === $this->getOwnerId();
201 });
202 }

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

33 : self
34 {
35 if (ilObjUser::_isAnonymous($usrId)) {
36 throw new ilBuddySystemException(sprintf(
37 "You cannot create an instance for the anonymous user (id: %s)",
38 $usrId
39 ));
40 }
41
42 if (isset(self::$instances[$usrId])) {
43 return self::$instances[$usrId];
44 }
45
46 self::$instances[$usrId] = new self($usrId);
47 return self::$instances[$usrId];
48 }
Class ilBuddySystemException.
static _isAnonymous($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 153 of file class.ilBuddyList.php.

154 {
155 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
156 return $relation->isLinked();
157 });
158 }

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

144 : int
145 {
146 return $this->ownerId;
147 }

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)
Parameters
int$usrId
Returns
ilBuddySystemRelation

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

257 {
258 if ($this->getRelations()->containsKey($usrId)) {
259 return $this->getRelations()->get($usrId);
260 }
261
262 $relation = new ilBuddySystemRelation(ilBuddySystemRelationStateFactory::getInstance()->getInitialState());
263 $relation->setIsOwnedByActor(true);
264 $relation->setUsrId($this->getOwnerId());
265 $relation->setBuddyUsrId($usrId);
266 $relation->setTimestamp(time());
267
268 $this->getRelations()->set($usrId, $relation);
269
270 return $relation;
271 }

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

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )
Returns
ilBuddySystemRelationCollection

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

124 {
125 if (null === $this->relations) {
126 $this->performLazyLoading();
127 }
128
129 return $this->relations;
130 }

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
Parameters
ilBuddySystemRelation$relation
Returns
int

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

247 : int
248 {
249 return ($relation->getUsrId() === $this->getOwnerId() ? $relation->getBuddyUsrId() : $relation->getUsrId());
250 }

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

230 : array
231 {
232 return $this->getRelations()->getKeys();
233 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

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

187 {
188 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
189 return $relation->isRequested();
190 });
191 }

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

176 {
177 return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) {
178 return $relation->getUsrId() === $this->getOwnerId();
179 });
180 }
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 164 of file class.ilBuddyList.php.

165 {
166 return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) {
167 return $relation->getBuddyUsrId() === $this->getOwnerId();
168 });
169 }

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

371 : self
372 {
373 try {
374 if ($relation->isLinked()) {
375 throw new ilBuddySystemRelationStateTransitionException('buddy_bs_action_already_linked');
376 }
377
378 if ($this->getOwnerId() == $relation->getUsrId()) {
379 throw new ilBuddySystemException("You can only ignore a request when you are not the initiator");
380 }
381
382 $relation->ignore();
383
384 $this->getRepository()->save($relation);
385 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
386 } catch (ilBuddySystemException $e) {
387 if ($relation->isIgnored()) {
388 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_ignored');
389 }
390
391 throw $e;
392 }
393
394 return $this;
395 }
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 278 of file class.ilBuddyList.php.

278 : self
279 {
280 try {
281 if ($relation->isLinked()) {
282 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_linked');
283 }
284
285 if ($this->getOwnerId() == $relation->getUsrId()) {
286 throw new ilBuddySystemException("You can only accept a request when you are not the initiator");
287 }
288
289 $relation->link();
290
291 $this->getRepository()->save($relation);
292 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
294 throw $e;
295 }
296
297 return $this;
298 }

References Vendor\Package\$e, 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 112 of file class.ilBuddyList.php.

112 : void
113 {
114 if (!$this->relationsRead) {
115 $this->readFromRepository();
116 $this->relationsRead = true;
117 }
118 }

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

104 : void
105 {
106 $this->setRelations(new ilBuddySystemRelationCollection((array) $this->getRepository()->getAll()));
107 }
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 327 of file class.ilBuddyList.php.

327 : self
328 {
329 if (ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation))) {
330 throw new ilBuddySystemException(sprintf(
331 "You cannot add the anonymous user to the list (id: %s)",
332 $this->getRelationTargetUserId($relation)
333 ));
334 }
335
336 if (!strlen((string) ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation)))) {
337 throw new ilBuddySystemException(sprintf(
338 "You cannot add a non existing user (id: %s)",
339 $this->getRelationTargetUserId($relation)
340 ));
341 }
342
343 try {
344 $relation->request();
345 $this->getRepository()->save($relation);
346 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
347 } catch (ilBuddySystemException $e) {
348 if ($relation->isRequested()) {
349 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested');
350 }
351
352 throw $e;
353 }
354
355 $this->eventHandler->raise(
356 'Services/Contact',
357 'contactRequested',
358 [
359 'usr_id' => $this->getRelationTargetUserId($relation)
360 ]
361 );
362
363 return $this;
364 }
static _lookupLogin($a_user_id)
lookup login

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

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

References getOwnerId().

+ Here is the call graph for this function:

◆ setOwnerId()

ilBuddyList::setOwnerId ( int  $ownerId)
Parameters
int$ownerId

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

238 : void
239 {
240 $this->ownerId = $ownerId;
241 }

References $ownerId.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setRelations()

ilBuddyList::setRelations ( ilBuddySystemRelationCollection  $relations)
Parameters
ilBuddySystemRelationCollection$relations

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

135 : void
136 {
137 $this->relations = $relations;
138 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

ilBuddyList::setRepository ( ilBuddySystemRelationRepository  $repository)
Parameters
ilBuddySystemRelationRepository$repository

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

96 : void
97 {
98 $this->repository = $repository;
99 }
repository()
Definition: repository.php:5

References $repository, and 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 305 of file class.ilBuddyList.php.

305 : self
306 {
307 try {
308 $relation->unlink();
309 $this->getRepository()->save($relation);
310 $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
311 } catch (ilBuddySystemException $e) {
312 if ($relation->isUnlinked()) {
313 throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked');
314 }
315
316 throw $e;
317 }
318
319 return $this;
320 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $eventHandler

ilBuddyList::$eventHandler
protected

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

◆ $instances

ilBuddyList::$instances = []
staticprotected

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

◆ $ownerId

ilBuddyList::$ownerId
protected

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

Referenced by getOwnerId(), and setOwnerId().

◆ $relations

ilBuddyList::$relations
protected

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

Referenced by getRelations(), and setRelations().

◆ $relationsRead

ilBuddyList::$relationsRead = false
protected

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

◆ $repository

ilBuddyList::$repository
protected

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

Referenced by getRepository(), and setRepository().


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