ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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.

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

68  {
69  global $DIC;
70 
71  $this->eventHandler = $event_handler ?? $DIC['ilAppEventHandler'];
72 
73  $this->setOwnerId($ownerId);
75  }
setRepository(ilBuddySystemRelationRepository $repository)
Class ilBuddySystemRelationRepository.
global $DIC
Definition: shib_login.php:26
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)

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

References getRelations(), and getRepository().

381  : self
382  {
383  $this->getRepository()->destroy();
384  $this->getRelations()->clear();
385  return $this;
386  }
+ 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.

References $relation, 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.

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

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

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

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

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

176  {
177  return $this->getIgnoredRelations()->filter(
178  fn(ilBuddySystemRelation $relation): bool => $relation->getBuddyUsrId() === $this->getOwnerId()
179  );
180  }
$relation
getIgnoredRelations()
Gets all ignored relations: ilBuddySystemRelationCollection.
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ getInstanceByGlobalUser()

static ilBuddyList::getInstanceByGlobalUser ( ?ilObjUser  $user = null)
static

◆ getInstanceByUserId()

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

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

References ilObjUser\_isAnonymous().

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

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

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

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

References $ownerId.

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

127  : int
128  {
129  return $this->ownerId;
130  }
+ Here is the caller graph for this function:

◆ getRelationByUserId()

ilBuddyList::getRelationByUserId ( int  $usrId)

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

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

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

◆ getRelations()

ilBuddyList::getRelations ( )

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

References $relations, null, and performLazyLoading().

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

111  {
112  if (null === $this->relations) {
113  $this->performLazyLoading();
114  }
115 
116  return $this->relations;
117  }
ilBuddySystemRelationCollection $relations
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

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

216  : int
217  {
218  return ($relation->getUsrId() === $this->getOwnerId() ? $relation->getBuddyUsrId() : $relation->getUsrId());
219  }
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 206 of file class.ilBuddyList.php.

References getRelations().

206  : array
207  {
208  return $this->getRelations()->getKeys();
209  }
+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )

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

References $repository.

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

88  {
89  return $this->repository;
90  }
ilBuddySystemRelationRepository $repository
Class ilBuddySystemRelationRepository.
+ Here is the caller graph for this function:

◆ getRequestedRelations()

ilBuddyList::getRequestedRelations ( )

Gets all requested relations.

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

References $relation, 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.

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

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

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

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

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

146  {
147  return $this->getRequestedRelations()->filter(
148  fn(ilBuddySystemRelation $relation): bool => $relation->getBuddyUsrId() === $this->getOwnerId()
149  );
150  }
$relation
getRequestedRelations()
Gets all requested relations.
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ ignore()

ilBuddyList::ignore ( ilBuddySystemRelation  $relation)
Exceptions
ilBuddySystemException

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

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

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  }
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)
Exceptions
ilBuddySystemException

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

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

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  }
Class ilBuddySystemException.
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 102 of file class.ilBuddyList.php.

References readFromRepository().

Referenced by getRelations().

102  : void
103  {
104  if (!$this->relationsRead) {
105  $this->readFromRepository();
106  $this->relationsRead = true;
107  }
108  }
+ 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.

References getRepository(), and setRelations().

Referenced by performLazyLoading().

97  : void
98  {
99  $this->setRelations(new ilBuddySystemRelationCollection($this->getRepository()->getAll()));
100  }
setRelations(ilBuddySystemRelationCollection $relations)
+ 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.

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

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  }
Class ilBuddySystemException.
getRelationTargetUserId(ilBuddySystemRelation $relation)
static _isAnonymous(int $usr_id)
static _lookupLogin(int $a_user_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 80 of file class.ilBuddyList.php.

References getOwnerId(), and null.

80  : void
81  {
82  $this->relationsRead = false;
83  $this->relations = null;
84  unset(self::$instances[$this->getOwnerId()]);
85  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ setOwnerId()

ilBuddyList::setOwnerId ( int  $ownerId)

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

References $ownerId.

Referenced by __construct().

211  : void
212  {
213  $this->ownerId = $ownerId;
214  }
+ Here is the caller graph for this function:

◆ setRelations()

ilBuddyList::setRelations ( ilBuddySystemRelationCollection  $relations)

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

References $relations.

Referenced by readFromRepository().

119  : void
120  {
121  $this->relations = $relations;
122  }
ilBuddySystemRelationCollection $relations
+ Here is the caller graph for this function:

◆ setRepository()

ilBuddyList::setRepository ( ilBuddySystemRelationRepository  $repository)

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

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

Referenced by __construct().

92  : void
93  {
94  $this->repository = $repository;
95  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
ilBuddySystemRelationRepository $repository
+ 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.

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

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