ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

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

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

References getRelations(), and getRepository().

401  : self
402  {
403  $this->getRepository()->destroy();
404  $this->getRelations()->clear();
405  return $this;
406  }
+ 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.

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

Referenced by getIgnoredRelationsByOwner(), and getIgnoredRelationsForOwner().

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

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

209  {
210  return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) {
211  return $relation->getUsrId() === $this->getOwnerId();
212  });
213  }
getIgnoredRelations()
Gets all ignored relations: ilBuddySystemRelationCollection.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

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

198  {
199  return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) {
200  return $relation->getBuddyUsrId() === $this->getOwnerId();
201  });
202  }
getIgnoredRelations()
Gets all ignored relations: ilBuddySystemRelationCollection.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

References ilObjUser\_isAnonymous().

Referenced by 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().

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)
+ 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.

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

154  {
155  return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
156  return $relation->isLinked();
157  });
158  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
+ 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.

References $ownerId.

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

144  : int
145  {
146  return $this->ownerId;
147  }
+ 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.

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

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  }
Class ilBuddySystemRelation.
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )
Returns
ilBuddySystemRelationCollection

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

References $relations, and performLazyLoading().

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

124  {
125  if (null === $this->relations) {
126  $this->performLazyLoading();
127  }
128 
129  return $this->relations;
130  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
+ 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.

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

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

247  : int
248  {
249  return ($relation->getUsrId() === $this->getOwnerId() ? $relation->getBuddyUsrId() : $relation->getUsrId());
250  }
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

References getRelations().

230  : array
231  {
232  return $this->getRelations()->getKeys();
233  }
+ 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.

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

Referenced by getRequestRelationsByOwner(), and getRequestRelationsForOwner().

187  {
188  return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
189  return $relation->isRequested();
190  });
191  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
+ 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.

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

176  {
177  return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) {
178  return $relation->getUsrId() === $this->getOwnerId();
179  });
180  }
getRequestedRelations()
Gets all requested relations.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

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

165  {
166  return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) {
167  return $relation->getBuddyUsrId() === $this->getOwnerId();
168  });
169  }
getRequestedRelations()
Gets all requested relations.
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Class ilBuddySystemRelation.
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

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

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  }
Class ilBuddySystemException.
getRelationTargetUserId(ilBuddySystemRelation $relation)
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

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

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  }
Class ilBuddySystemException.
Class ilBuddySystemRelationStateException.
getRelationTargetUserId(ilBuddySystemRelation $relation)
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ performLazyLoading()

ilBuddyList::performLazyLoading ( )
protected

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

References readFromRepository().

Referenced by getRelations().

112  : void
113  {
114  if (!$this->relationsRead) {
115  $this->readFromRepository();
116  $this->relationsRead = true;
117  }
118  }
+ 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.

References getRepository(), and setRelations().

Referenced by performLazyLoading().

104  : void
105  {
106  $this->setRelations(new ilBuddySystemRelationCollection((array) $this->getRepository()->getAll()));
107  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
setRelations(ilBuddySystemRelationCollection $relations)
+ 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.

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

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
Class ilBuddySystemException.
getRelationTargetUserId(ilBuddySystemRelation $relation)
static _isAnonymous($usr_id)
+ 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.

References getOwnerId().

78  : void
79  {
80  $this->relationsRead = false;
81  $this->relations = null;
82  unset(self::$instances[$this->getOwnerId()]);
83  }
getOwnerId()
Returns the user id of the buddy list owner.
+ 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.

References $ownerId.

Referenced by __construct().

238  : void
239  {
240  $this->ownerId = $ownerId;
241  }
+ 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.

References $relations.

Referenced by readFromRepository().

135  : void
136  {
137  $this->relations = $relations;
138  }
+ 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.

References $repository, and repository().

Referenced by __construct().

96  : void
97  {
98  $this->repository = $repository;
99  }
repository()
Definition: repository.php:5
+ 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.

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

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  }
Class ilBuddySystemException.
getRelationTargetUserId(ilBuddySystemRelation $relation)
+ 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: