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.

83 {
84 global $DIC;
85
86 $this->setOwnerId($owner_id);
88
89 $this->event_handler = $DIC['ilAppEventHandler'];
90 }
getOwnerId()
Returns the user id of the buddy list owner.
setRepository($repository)
setOwnerId($owner_id)
Class ilBuddySystemRelationRepository.
global $DIC
Definition: saml.php:7

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

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

433 {
434 $this->getRepository()->destroy();
435 $this->getRelations()->clear();
436 return $this;
437 }

References getRelations(), and getRepository().

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

241 {
242 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
243 return $relation->isIgnored();
244 });
245 }
Class ilBuddySystemRelation.

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

Returns
ilBuddySystemRelationCollection

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

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.

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

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

217 {
218 $owner = $this->getOwnerId();
219 return $this->getIgnoredRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
220 return $relation->getBuddyUserId() == $owner;
221 });
222 }

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

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

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 }
sprintf('%.4f', $callTime)
static _isAnonymous($usr_id)

References ilObjUser\_isAnonymous(), and sprintf.

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

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

171 {
172 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
173 return $relation->isLinked();
174 });
175 }

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

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

162 {
163 return $this->owner_id;
164 }

References $owner_id.

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

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

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 }

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

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )
Returns
ilBuddySystemRelationCollection

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

141 {
142 if (null === $this->relations) {
143 $this->performLazyLoading();
144 }
145
146 return $this->relations;
147 }

References $relations, and performLazyLoading().

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

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

274 {
275 return ($relation->getUserId() == $this->getOwnerId() ? $relation->getBuddyUserId() : $relation->getUserId());
276 }

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

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

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

252 {
253 return $this->getRelations()->getKeys();
254 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

106 {
107 return $this->repository;
108 }

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 205 of file class.ilBuddyList.php.

206 {
207 return $this->getRelations()->filter(function (ilBuddySystemRelation $relation) {
208 return $relation->isRequested();
209 });
210 }

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

Returns
ilBuddySystemRelationCollection

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

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.

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

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

182 {
183 $owner = $this->getOwnerId();
184 return $this->getRequestedRelations()->filter(function (ilBuddySystemRelation $relation) use ($owner) {
185 return $relation->getBuddyUserId() == $owner;
186 });
187 }

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

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

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)

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

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

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 }

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

+ Here is the call graph for this function:

◆ performLazyLoading()

ilBuddyList::performLazyLoading ( )
protected

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

130 {
131 if (!$this->relations_read) {
132 $this->readFromRepository();
133 $this->relations_read = true;
134 }
135 }

References readFromRepository().

Referenced by getRelations().

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

122 {
123 $this->setRelations(new ilBuddySystemRelationCollection((array) $this->getRepository()->getAll()));
124 }
setRelations(ilBuddySystemRelationCollection $relations)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list.

References getRepository(), and setRelations().

Referenced by performLazyLoading().

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

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

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

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

96 {
97 $this->relations_read = false;
98 $this->relations = null;
99 unset(self::$instances[$this->getOwnerId()]);
100 }

References getOwnerId().

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

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 }

References $owner_id, and sprintf.

Referenced by __construct().

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

153 {
154 $this->relations = $relations;
155 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

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

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

114 {
115 $this->repository = $repository;
116 }

References $repository.

Referenced by __construct().

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

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 }

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

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