ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

83 {
84 $this->setOwnerId($owner_id);
86 }
getOwnerId()
Returns the user id of the buddy list owner.
setRepository($repository)
setOwnerId($owner_id)
Class ilBuddySystemRelationRepository.

References $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 454 of file class.ilBuddyList.php.

455 {
456 $this->getRepository()->destroy();
457 $this->getRelations()->clear();
458 return $this;
459 }

References getRelations(), and getRepository().

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

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

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.

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

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

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

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

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)

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

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

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

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

160 {
161 return $this->owner_id;
162 }

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

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 }

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

+ Here is the call graph for this function:

◆ getRelations()

ilBuddyList::getRelations ( )
Returns
ilBuddySystemRelationCollection

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

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

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

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

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

250 {
251 return $this->getRelations()->getKeys();
252 }

References getRelations().

+ Here is the call graph for this function:

◆ getRepository()

ilBuddyList::getRepository ( )
Returns
ilBuddySystemRelationRepository

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

102 {
103 return $this->repository;
104 }

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

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

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

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.

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

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

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

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)

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

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 }

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

126 {
127 if(!$this->relations_read)
128 {
129 $this->readFromRepository();
130 $this->relations_read = true;
131 }
132 }

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

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

372 {
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
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

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

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

92 {
93 $this->relations_read = false;
94 $this->relations = null;
95 unset(self::$instances[$this->getOwnerId()]);
96 }

References getOwnerId().

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

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 }

References $owner_id.

Referenced by __construct().

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

151 {
152 $this->relations = $relations;
153 }

References $relations.

Referenced by readFromRepository().

+ Here is the caller graph for this function:

◆ setRepository()

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

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

110 {
111 $this->repository = $repository;
112 }

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

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 }

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

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