ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 ($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. More...
 
 getRelationUserIds ()
 Returns an array of all user ids the buddy list owner has a relation with. More...
 
 setOwnerId ($owner_id)
 
 getRelationByUserId ($usr_id)
 
 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 ($usr_id)
 
static getInstanceByGlobalUser ()
 

Protected Member Functions

 __construct ($owner_id)
 
 performLazyLoading ()
 
 getRelationTargetUserId (ilBuddySystemRelation $relation)
 

Protected Attributes

 $owner_id
 
 $relations
 
 $repository
 
 $relations_read = false
 
 $event_handler
 

Static Protected Attributes

static $instances = array()
 

Detailed Description

Class ilBuddyList.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBuddyList::__construct (   $owner_id)
protected

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

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

83  {
84  global $DIC;
85 
86  $this->setOwnerId($owner_id);
88 
89  $this->event_handler = $DIC['ilAppEventHandler'];
90  }
global $DIC
Definition: saml.php:7
Class ilBuddySystemRelationRepository.
setRepository($repository)
setOwnerId($owner_id)
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 432 of file class.ilBuddyList.php.

References getRelations(), and getRepository().

433  {
434  $this->getRepository()->destroy();
435  $this->getRelations()->clear();
436  return $this;
437  }
+ Here is the call graph for this function:

◆ getIgnoredRelations()

ilBuddyList::getIgnoredRelations ( )

Gets all ignored relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getIgnoredRelationsByOwner(), and getIgnoredRelationsForOwner().

241  {
242  return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
243  return $relation->isIgnored();
244  });
245  }
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 228 of file class.ilBuddyList.php.

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

229  {
230  $owner = $this->getOwnerId();
231  return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
232  return $relation->getUserId() == $owner;
233  });
234  }
getIgnoredRelations()
Gets all ignored relations.
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 216 of file class.ilBuddyList.php.

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

217  {
218  $owner = $this->getOwnerId();
219  return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
220  return $relation->getBuddyUserId() == $owner;
221  });
222  }
getIgnoredRelations()
Gets all ignored relations.
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 (   $usr_id)
static
Parameters
int$usr_id
Returns
self
Exceptions
ilBuddySystemException

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

References ilObjUser\_isAnonymous().

Referenced by ilContactAppEventListener\handleEvent(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenALinkedRelationShouldBeMarkedAsLinked(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenAnIgnoredRelationShouldBeMarkedAsIgnored(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenAnUnlinkedRelationShouldBeMarkedAsUnlinked(), ilBuddyListTest\testAlreadyGivenStateExceptionIsThrownWhenARequestedRelationShouldBeMarkedAsRequested(), ilBuddyListTest\testDifferentRelationStatesCanBeRetrieved(), ilBuddyListTest\testExceptionIsThrownWhenNonNumericOwnerIdIsPassed(), ilBuddyListTest\testExceptionIsThrownWhenRelationIsRequestedForANonNumericUserId(), 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\testUnlinkedRelationIsReturnedWhenRelationWasRequestedForAUknownBuddyId(), and ilBuddyListTest\testValuesCanBeFetchedByGettersWhenSetBySetters().

56  {
57  if (ilObjUser::_isAnonymous($usr_id)) {
58  throw new ilBuddySystemException(sprintf("You cannot create an instance for the anonymous user (id: %s)", $usr_id));
59  }
60 
61  if (isset(self::$instances[$usr_id])) {
62  return self::$instances[$usr_id];
63  }
64 
65  self::$instances[$usr_id] = new self($usr_id);
66  return self::$instances[$usr_id];
67  }
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 170 of file class.ilBuddyList.php.

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

171  {
172  return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
173  return $relation->isLinked();
174  });
175  }
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 161 of file class.ilBuddyList.php.

References $owner_id.

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

162  {
163  return $this->owner_id;
164  }
+ Here is the caller graph for this function:

◆ getRelationByUserId()

ilBuddyList::getRelationByUserId (   $usr_id)
Parameters
int$usr_id
Exceptions
InvalidArgumentException
Returns
ilBuddySystemRelation

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

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

284  {
285  if (!is_numeric($usr_id)) {
286  throw new InvalidArgumentException(sprintf("Please pass a numeric owner id, given: %s", var_export($usr_id, 1)));
287  }
288 
289  if ($this->getRelations()->containsKey($usr_id)) {
290  return $this->getRelations()->get($usr_id);
291  }
292 
293  require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
294  $relation = new ilBuddySystemRelation(ilBuddySystemRelationStateFactory::getInstance()->getInitialState());
295  $relation->setIsOwnedByRequest(true);
296  $relation->setUserId($this->getOwnerId());
297  $relation->setBuddyUserId($usr_id);
298  $relation->setTimestamp(time());
299 
300  $this->getRelations()->set($usr_id, $relation);
301 
302  return $relation;
303  }
Class ilBuddySystemRelation.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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 140 of file class.ilBuddyList.php.

References $relations, and performLazyLoading().

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

141  {
142  if (null === $this->relations) {
143  $this->performLazyLoading();
144  }
145 
146  return $this->relations;
147  }
+ 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 273 of file class.ilBuddyList.php.

References ilBuddySystemRelation\getBuddyUserId(), getOwnerId(), and ilBuddySystemRelation\getUserId().

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

274  {
275  return ($relation->getUserId() == $this->getOwnerId() ? $relation->getBuddyUserId() : $relation->getUserId());
276  }
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 251 of file class.ilBuddyList.php.

References getRelations().

252  {
253  return $this->getRelations()->getKeys();
254  }
+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

References $repository.

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

106  {
107  return $this->repository;
108  }
+ Here is the caller graph for this function:

◆ getRequestedRelations()

ilBuddyList::getRequestedRelations ( )

Gets all requested relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getRequestRelationsByOwner(), and getRequestRelationsForOwner().

206  {
207  return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
208  return $relation->isRequested();
209  });
210  }
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 193 of file class.ilBuddyList.php.

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

194  {
195  $owner = $this->getOwnerId();
196  return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
197  return $relation->getUserId() == $owner;
198  });
199  }
getRequestedRelations()
Gets all requested relations.
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 181 of file class.ilBuddyList.php.

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

182  {
183  $owner = $this->getOwnerId();
184  return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
185  return $relation->getBuddyUserId() == $owner;
186  });
187  }
getRequestedRelations()
Gets all requested relations.
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 400 of file class.ilBuddyList.php.

References getOwnerId(), getRelations(), getRelationTargetUserId(), getRepository(), ilBuddySystemRelation\getUserId(), ilBuddySystemRelation\ignore(), ilBuddySystemRelation\isIgnored(), and ilBuddySystemRelation\isLinked().

401  {
402  try {
403  if ($relation->isLinked()) {
404  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateTransitionException.php';
405  throw new ilBuddySystemRelationStateTransitionException('buddy_bs_action_already_linked');
406  }
407 
408  if ($this->getOwnerId() == $relation->getUserId()) {
409  throw new ilBuddySystemException("You can only ignore a request when you are not the initiator");
410  }
411 
412  $relation->ignore();
413 
414  $this->getRepository()->save($relation);
415  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
416  } catch (ilBuddySystemException $e) {
417  if ($relation->isIgnored()) {
418  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
419  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_ignored');
420  }
421 
422  throw $e;
423  }
424 
425  return $this;
426  }
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 310 of file class.ilBuddyList.php.

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

311  {
312  try {
313  if ($relation->isLinked()) {
314  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
315  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_linked');
316  }
317 
318  if ($this->getOwnerId() == $relation->getUserId()) {
319  throw new ilBuddySystemException("You can only accept a request when you are not the initiator");
320  }
321 
322  $relation->link();
323 
324  $this->getRepository()->save($relation);
325  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
327  throw $e;
328  }
329 
330  return $this;
331  }
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 129 of file class.ilBuddyList.php.

References readFromRepository().

Referenced by getRelations().

130  {
131  if (!$this->relations_read) {
132  $this->readFromRepository();
133  $this->relations_read = true;
134  }
135  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFromRepository()

ilBuddyList::readFromRepository ( )

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

References array, getRepository(), and setRelations().

Referenced by performLazyLoading().

122  {
123  $this->setRelations(new ilBuddySystemRelationCollection((array) $this->getRepository()->getAll()));
124  }
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
Create styles array
The data for the language used.
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 361 of file class.ilBuddyList.php.

References ilObjUser\_isAnonymous(), ilObjUser\_lookupLogin(), array, getRelations(), getRelationTargetUserId(), getRepository(), ilBuddySystemRelation\isRequested(), and ilBuddySystemRelation\request().

362  {
363  if (ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation))) {
364  throw new ilBuddySystemException(sprintf("You cannot add the anonymous user to the list (id: %s)", $this->getRelationTargetUserId($relation)));
365  }
366 
367  if (!strlen(ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation)))) {
368  throw new ilBuddySystemException(sprintf("You cannot add a non existing user (id: %s)", $this->getRelationTargetUserId($relation)));
369  }
370 
371  try {
372  $relation->request();
373  $this->getRepository()->save($relation);
374  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
375  } catch (ilBuddySystemException $e) {
376  if ($relation->isRequested()) {
377  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
378  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested');
379  }
380 
381  throw $e;
382  }
383 
384  $this->event_handler->raise(
385  'Services/Contact',
386  'contactRequested',
387  array(
388  'usr_id' => $this->getRelationTargetUserId($relation)
389  )
390  );
391 
392  return $this;
393  }
static _lookupLogin($a_user_id)
lookup login
getRelationTargetUserId(ilBuddySystemRelation $relation)
Create styles array
The data for the language used.
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 95 of file class.ilBuddyList.php.

References getOwnerId().

96  {
97  $this->relations_read = false;
98  $this->relations = null;
99  unset(self::$instances[$this->getOwnerId()]);
100  }
getOwnerId()
Returns the user id of the buddy list owner.
+ Here is the call graph for this function:

◆ setOwnerId()

ilBuddyList::setOwnerId (   $owner_id)
Parameters
int$owner_id
Exceptions
InvalidArgumentException

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

References $owner_id.

Referenced by __construct().

261  {
262  if (!is_numeric($owner_id)) {
263  throw new InvalidArgumentException(sprintf("Please pass a numeric owner id, given: %s", var_export($owner_id, 1)));
264  }
265 
266  $this->owner_id = $owner_id;
267  }
+ Here is the caller graph for this function:

◆ setRelations()

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

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

References $relations.

Referenced by readFromRepository().

153  {
154  $this->relations = $relations;
155  }
+ Here is the caller graph for this function:

◆ setRepository()

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

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

References $repository.

Referenced by __construct().

114  {
115  $this->repository = $repository;
116  }
+ Here is the caller graph for this function:

◆ unlink()

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

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

References getRelations(), getRelationTargetUserId(), getRepository(), ilBuddySystemRelation\isUnlinked(), and ilBuddySystemRelation\unlink().

339  {
340  try {
341  $relation->unlink();
342  $this->getRepository()->save($relation);
343  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
344  } catch (ilBuddySystemException $e) {
345  if ($relation->isUnlinked()) {
346  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
347  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked');
348  }
349 
350  throw $e;
351  }
352 
353  return $this;
354  }
getRelationTargetUserId(ilBuddySystemRelation $relation)
+ Here is the call graph for this function:

Field Documentation

◆ $event_handler

ilBuddyList::$event_handler
protected

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

◆ $instances

ilBuddyList::$instances = array()
staticprotected

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

◆ $owner_id

int ilBuddyList::$owner_id
protected

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

Referenced by __construct(), getOwnerId(), and setOwnerId().

◆ $relations

ilBuddyList::$relations
protected

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

Referenced by getRelations(), and setRelations().

◆ $relations_read

ilBuddyList::$relations_read = false
protected

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

◆ $repository

ilBuddyList::$repository
protected

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

Referenced by getRepository(), and setRepository().


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