ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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)
 

Protected Member Functions

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

Protected Attributes

 $owner_id
 
 $relations
 
 $repository
 
 $relations_read = false
 

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 $owner_id, getOwnerId(), setOwnerId(), and setRepository().

83  {
84  $this->setOwnerId($owner_id);
86  }
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 454 of file class.ilBuddyList.php.

References getRelations(), and getRepository().

455  {
456  $this->getRepository()->destroy();
457  $this->getRelations()->clear();
458  return $this;
459  }
+ Here is the call graph for this function:

◆ getIgnoredRelations()

ilBuddyList::getIgnoredRelations ( )

Gets all ignored relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getIgnoredRelationsByOwner(), and getIgnoredRelationsForOwner().

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

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

227  {
228  $owner = $this->getOwnerId();
229  return $this->getIgnoredRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
230  return $relation->getUserId() == $owner;
231  });
232  }
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 214 of file class.ilBuddyList.php.

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

215  {
216  $owner = $this->getOwnerId();
217  return $this->getIgnoredRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
218  return $relation->getBuddyUserId() == $owner;
219  });
220  }
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:

◆ getInstanceByUserId()

static ilBuddyList::getInstanceByUserId (   $usr_id)
static
Parameters
int$usr_id
Returns
self
Exceptions
ilBuddySystemException

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

References $ilUser, and ilObjUser\_isAnonymous().

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

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

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

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

References $owner_id.

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

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

◆ getRelationByUserId()

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

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

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

283  {
284  if(!is_numeric($usr_id))
285  {
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  {
291  return $this->getRelations()->get($usr_id);
292  }
293 
294  require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
295  $relation = new ilBuddySystemRelation(ilBuddySystemRelationStateFactory::getInstance()->getInitialState());
296  $relation->setIsOwnedByRequest(true);
297  $relation->setUserId($this->getOwnerId());
298  $relation->setBuddyUserId($usr_id);
299  $relation->setTimestamp(time());
300 
301  $this->getRelations()->set($usr_id, $relation);
302 
303  return $relation;
304  }
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 137 of file class.ilBuddyList.php.

References $relations, and performLazyLoading().

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

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

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

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

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

References getRelations().

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

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

References $repository.

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

102  {
103  return $this->repository;
104  }
+ Here is the caller graph for this function:

◆ getRequestedRelations()

ilBuddyList::getRequestedRelations ( )

Gets all requested relations.

Returns
ilBuddySystemRelationCollection

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

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

Referenced by getRequestRelationsByOwner(), and getRequestRelationsForOwner().

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

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

192  {
193  $owner = $this->getOwnerId();
194  return $this->getRequestedRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
195  return $relation->getUserId() == $owner;
196  });
197  }
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 179 of file class.ilBuddyList.php.

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

180  {
181  $owner = $this->getOwnerId();
182  return $this->getRequestedRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
183  return $relation->getBuddyUserId() == $owner;
184  });
185  }
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 416 of file class.ilBuddyList.php.

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

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

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

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

References readFromRepository().

Referenced by getRelations().

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

◆ readFromRepository()

ilBuddyList::readFromRepository ( )

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

References getRepository(), and setRelations().

Referenced by performLazyLoading().

118  {
119  $this->setRelations(new ilBuddySystemRelationCollection((array)$this->getRepository()->getAll()));
120  }
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 371 of file class.ilBuddyList.php.

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

372  {
373  if(ilObjUser::_isAnonymous($this->getRelationTargetUserId($relation)))
374  {
375  throw new ilBuddySystemException(sprintf("You cannot add the anonymous user to the list (id: %s)", $this->getRelationTargetUserId($relation)));
376  }
377 
378  if(!strlen(ilObjUser::_lookupLogin($this->getRelationTargetUserId($relation))))
379  {
380  throw new ilBuddySystemException(sprintf("You cannot add a non existing user (id: %s)", $this->getRelationTargetUserId($relation)));
381  }
382 
383  try
384  {
385  $relation->request();
386  $this->getRepository()->save($relation);
387  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
388  }
389  catch(ilBuddySystemException $e)
390  {
391  if($relation->isRequested())
392  {
393  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
394  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_requested');
395  }
396 
397  throw $e;
398  }
399 
400  $GLOBALS['ilAppEventHandler']->raise(
401  'Services/Contact',
402  'contactRequested',
403  array(
404  'usr_id' => $this->getRelationTargetUserId($relation)
405  )
406  );
407 
408  return $this;
409  }
static _lookupLogin($a_user_id)
lookup login
getRelationTargetUserId(ilBuddySystemRelation $relation)
static _isAnonymous($usr_id)
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ 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 91 of file class.ilBuddyList.php.

References getOwnerId().

92  {
93  $this->relations_read = false;
94  $this->relations = null;
95  unset(self::$instances[$this->getOwnerId()]);
96  }
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 258 of file class.ilBuddyList.php.

References $owner_id.

Referenced by __construct().

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

◆ setRelations()

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

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

References $relations.

Referenced by readFromRepository().

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

◆ setRepository()

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

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

References $repository.

Referenced by __construct().

110  {
111  $this->repository = $repository;
112  }
+ Here is the caller graph for this function:

◆ unlink()

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

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

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

345  {
346  try
347  {
348  $relation->unlink();
349  $this->getRepository()->save($relation);
350  $this->getRelations()->set($this->getRelationTargetUserId($relation), $relation);
351  }
352  catch(ilBuddySystemException $e)
353  {
354  if($relation->isUnlinked())
355  {
356  require_once 'Services/Contact/BuddySystem/exceptions/class.ilBuddySystemRelationStateAlreadyGivenException.php';
357  throw new ilBuddySystemRelationStateAlreadyGivenException('buddy_bs_action_already_unlinked');
358  }
359 
360  throw $e;
361  }
362 
363  return $this;
364  }
getRelationTargetUserId(ilBuddySystemRelation $relation)
+ Here is the call graph for this function:

Field Documentation

◆ $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: