ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 84 of file class.ilBuddyList.php.

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

85  {
86  global $DIC;
87 
88  $this->setOwnerId($owner_id);
90 
91  $this->event_handler = $DIC['ilAppEventHandler'];
92  }
Class ilBuddySystemRelationRepository.
setRepository($repository)
global $DIC
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 460 of file class.ilBuddyList.php.

References getRelations(), and getRepository().

461  {
462  $this->getRepository()->destroy();
463  $this->getRelations()->clear();
464  return $this;
465  }
+ Here is the call graph for this function:

◆ getIgnoredRelations()

ilBuddyList::getIgnoredRelations ( )

Gets all ignored relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getIgnoredRelationsByOwner(), and getIgnoredRelationsForOwner().

245  {
246  return $this->getRelations()->filter(function(ilBuddySystemRelation $relation) {
247  return $relation->isIgnored();
248  });
249  }
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 232 of file class.ilBuddyList.php.

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

233  {
234  $owner = $this->getOwnerId();
235  return $this->getIgnoredRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
236  return $relation->getUserId() == $owner;
237  });
238  }
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 220 of file class.ilBuddyList.php.

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

221  {
222  $owner = $this->getOwnerId();
223  return $this->getIgnoredRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
224  return $relation->getBuddyUserId() == $owner;
225  });
226  }
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  {
59  throw new ilBuddySystemException(sprintf("You cannot create an instance for the anonymous user (id: %s)", $usr_id));
60  }
61 
62  if(isset(self::$instances[$usr_id]))
63  {
64  return self::$instances[$usr_id];
65  }
66 
67  self::$instances[$usr_id] = new self($usr_id);
68  return self::$instances[$usr_id];
69  }
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 174 of file class.ilBuddyList.php.

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

175  {
176  return $this->getRelations()->filter(function(ilBuddySystemRelation $relation) {
177  return $relation->isLinked();
178  });
179  }
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 165 of file class.ilBuddyList.php.

References $owner_id.

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

166  {
167  return $this->owner_id;
168  }
+ Here is the caller graph for this function:

◆ getRelationByUserId()

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

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

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

289  {
290  if(!is_numeric($usr_id))
291  {
292  throw new InvalidArgumentException(sprintf("Please pass a numeric owner id, given: %s", var_export($usr_id, 1)));
293  }
294 
295  if($this->getRelations()->containsKey($usr_id))
296  {
297  return $this->getRelations()->get($usr_id);
298  }
299 
300  require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
301  $relation = new ilBuddySystemRelation(ilBuddySystemRelationStateFactory::getInstance()->getInitialState());
302  $relation->setIsOwnedByRequest(true);
303  $relation->setUserId($this->getOwnerId());
304  $relation->setBuddyUserId($usr_id);
305  $relation->setTimestamp(time());
306 
307  $this->getRelations()->set($usr_id, $relation);
308 
309  return $relation;
310  }
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 143 of file class.ilBuddyList.php.

References $relations, and performLazyLoading().

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

144  {
145  if(null === $this->relations)
146  {
147  $this->performLazyLoading();
148  }
149 
150  return $this->relations;
151  }
+ 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 278 of file class.ilBuddyList.php.

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

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

279  {
280  return ($relation->getUserId() == $this->getOwnerId() ? $relation->getBuddyUserId() : $relation->getUserId());
281  }
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 255 of file class.ilBuddyList.php.

References getRelations().

256  {
257  return $this->getRelations()->getKeys();
258  }
+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

References $repository.

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

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

◆ getRequestedRelations()

ilBuddyList::getRequestedRelations ( )

Gets all requested relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getRequestRelationsByOwner(), and getRequestRelationsForOwner().

210  {
211  return $this->getRelations()->filter(function(ilBuddySystemRelation $relation) {
212  return $relation->isRequested();
213  });
214  }
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 197 of file class.ilBuddyList.php.

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

198  {
199  $owner = $this->getOwnerId();
200  return $this->getRequestedRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
201  return $relation->getUserId() == $owner;
202  });
203  }
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 185 of file class.ilBuddyList.php.

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

186  {
187  $owner = $this->getOwnerId();
188  return $this->getRequestedRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
189  return $relation->getBuddyUserId() == $owner;
190  });
191  }
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 422 of file class.ilBuddyList.php.

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

423  {
424  try
425  {
426  if($relation->isLinked())
427  {
428  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateTransitionException.php';
429  throw new ilBuddySystemRelationStateTransitionException('buddy_bs_action_already_linked');
430  }
431 
432  if($this->getOwnerId() == $relation->getUserId())
433  {
434  throw new ilBuddySystemException("You can only ignore a request when you are not the initiator");
435  }
436 
437  $relation->ignore();
438 
439  $this->getRepository()->save($relation);
440  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
441  }
442  catch(ilBuddySystemException $e)
443  {
444  if($relation->isIgnored())
445  {
446  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
447  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_ignored');
448  }
449 
450  throw $e;
451  }
452 
453  return $this;
454  }
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 317 of file class.ilBuddyList.php.

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

318  {
319  try
320  {
321  if($relation->isLinked())
322  {
323  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
324  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_linked');
325  }
326 
327  if($this->getOwnerId() == $relation->getUserId())
328  {
329  throw new ilBuddySystemException("You can only accept a request when you are not the initiator");
330  }
331 
332  $relation->link();
333 
334  $this->getRepository()->save($relation);
335  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
336  }
338  {
339  throw $e;
340  }
341 
342  return $this;
343  }
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 131 of file class.ilBuddyList.php.

References readFromRepository().

Referenced by getRelations().

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

◆ readFromRepository()

ilBuddyList::readFromRepository ( )

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

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

Referenced by performLazyLoading().

124  {
125  $this->setRelations(new ilBuddySystemRelationCollection((array)$this->getRepository()->getAll()));
126  }
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 377 of file class.ilBuddyList.php.

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

378  {
379  if(ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation)))
380  {
381  throw new ilBuddySystemException(sprintf("You cannot add the anonymous user to the list (id: %s)", $this->getRelationTargetUserId($relation)));
382  }
383 
384  if(!strlen(ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation))))
385  {
386  throw new ilBuddySystemException(sprintf("You cannot add a non existing user (id: %s)", $this->getRelationTargetUserId($relation)));
387  }
388 
389  try
390  {
391  $relation->request();
392  $this->getRepository()->save($relation);
393  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
394  }
395  catch(ilBuddySystemException $e)
396  {
397  if($relation->isRequested())
398  {
399  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
400  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested');
401  }
402 
403  throw $e;
404  }
405 
406  $this->event_handler->raise(
407  'Services/Contact',
408  'contactRequested',
409  array(
410  'usr_id' => $this->getRelationTargetUserId($relation)
411  )
412  );
413 
414  return $this;
415  }
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 97 of file class.ilBuddyList.php.

References getOwnerId().

98  {
99  $this->relations_read = false;
100  $this->relations = null;
101  unset(self::$instances[$this->getOwnerId()]);
102  }
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 264 of file class.ilBuddyList.php.

References $owner_id.

Referenced by __construct().

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

◆ setRelations()

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

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

References $relations.

Referenced by readFromRepository().

157  {
158  $this->relations = $relations;
159  }
+ Here is the caller graph for this function:

◆ setRepository()

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

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

References $repository.

Referenced by __construct().

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

◆ unlink()

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

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

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

351  {
352  try
353  {
354  $relation->unlink();
355  $this->getRepository()->save($relation);
356  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
357  }
358  catch(ilBuddySystemException $e)
359  {
360  if($relation->isUnlinked())
361  {
362  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
363  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked');
364  }
365 
366  throw $e;
367  }
368 
369  return $this;
370  }
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: