ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

85 {
86 global $DIC;
87
88 $this->setOwnerId($owner_id);
90
91 $this->event_handler = $DIC['ilAppEventHandler'];
92 }
getOwnerId()
Returns the user id of the buddy list owner.
setRepository($repository)
setOwnerId($owner_id)
Class ilBuddySystemRelationRepository.
global $DIC

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

461 {
462 $this->getRepository()->destroy();
463 $this->getRelations()->clear();
464 return $this;
465 }

References getRelations(), and getRepository().

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

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

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.

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

221 {
222 $owner = $this->getOwnerId();
223 return $this->getIgnoredRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
224 return $relation->getBuddyUserId() == $owner;
225 });
226 }

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 {
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 }
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 174 of file class.ilBuddyList.php.

175 {
176 return $this->getRelations()->filter(function(ilBuddySystemRelation $relation) {
177 return $relation->isLinked();
178 });
179 }

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

166 {
167 return $this->owner_id;
168 }

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

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 }

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

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )
Returns
ilBuddySystemRelationCollection

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

144 {
145 if(null === $this->relations)
146 {
147 $this->performLazyLoading();
148 }
149
150 return $this->relations;
151 }

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

279 {
280 return ($relation->getUserId() == $this->getOwnerId() ? $relation->getBuddyUserId() : $relation->getUserId());
281 }

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

256 {
257 return $this->getRelations()->getKeys();
258 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

108 {
109 return $this->repository;
110 }

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

210 {
211 return $this->getRelations()->filter(function(ilBuddySystemRelation $relation) {
212 return $relation->isRequested();
213 });
214 }

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

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.

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

186 {
187 $owner = $this->getOwnerId();
188 return $this->getRequestedRelations()->filter(function(ilBuddySystemRelation $relation) use ($owner) {
189 return $relation->getBuddyUserId() == $owner;
190 });
191 }

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

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)

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

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 }

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

132 {
133 if(!$this->relations_read)
134 {
135 $this->readFromRepository();
136 $this->relations_read = true;
137 }
138 }

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

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

378 {
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

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

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

References getOwnerId().

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

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 }

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

157 {
158 $this->relations = $relations;
159 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

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

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

116 {
117 $this->repository = $repository;
118 }

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

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 }

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: