ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilObjStudyProgrammeCache Class Reference

Cache for ilObjStudyProgrammes. More...

+ Collaboration diagram for ilObjStudyProgrammeCache:

Public Member Functions

 getInstanceByRefId (int $ref_id)
 
 addInstance (ilObjStudyProgramme $prg)
 
 test_clear ()
 For testing purpose. More...
 
 test_isEmpty ()
 

Static Public Member Functions

static singleton ()
 

Protected Attributes

array $instances
 

Private Member Functions

 __construct ()
 

Static Private Attributes

static ilObjStudyProgrammeCache $instance = null
 

Detailed Description

Cache for ilObjStudyProgrammes.

Implemented as singleton.

Definition at line 26 of file class.ilObjStudyProgrammeCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjStudyProgrammeCache::__construct ( )
private

Definition at line 35 of file class.ilObjStudyProgrammeCache.php.

36 {
37 $this->instances = array();
38 }

Member Function Documentation

◆ addInstance()

ilObjStudyProgrammeCache::addInstance ( ilObjStudyProgramme  $prg)

Definition at line 70 of file class.ilObjStudyProgrammeCache.php.

70 : void
71 {
72 if (!$prg->getRefId()) {
73 throw new ilException("ilObjStudyProgrammeCache::addInstance: Can't add instance without ref_id.");
74 }
75 $this->instances[$prg->getRefId()] = $prg;
76 }
Base class for ILIAS Exception handling.

References ilObject\getRefId().

+ Here is the call graph for this function:

◆ getInstanceByRefId()

ilObjStudyProgrammeCache::getInstanceByRefId ( int  $ref_id)

Definition at line 48 of file class.ilObjStudyProgrammeCache.php.

49 {
50 // TODO: Maybe this should be done via obj_id instead of ref_id, since two
51 // ref_ids could point to the same object, hence leading to two instances of
52 // the same object. Since ilObjStudyProgramme is a container, it should (??)
53 // only have one ref_id...
54 if (!array_key_exists($ref_id, $this->instances)) {
55 $type = ilObject::_lookupType($ref_id, true);
56 if ($type === 'prg') {
57 $this->instances[$ref_id] = new ilObjStudyProgramme($ref_id);
58 }
59 if ($type === 'prgr') {
60 $prg_reference = new ilObjStudyProgrammeReference($ref_id, true);
61 $this->instances[$ref_id] = $prg_reference->getReferencedObject();
62 }
63 if ($type !== 'prgr' && $type !== 'prg') {
64 throw new \Exception('invalid ref_id: ' . $ref_id);
65 }
66 }
67 return $this->instances[$ref_id];
68 }
static _lookupType(int $id, bool $reference=false)
$ref_id
Definition: ltiauth.php:66

References $ref_id, and ilObject\_lookupType().

+ Here is the call graph for this function:

◆ singleton()

static ilObjStudyProgrammeCache::singleton ( )
static

Definition at line 40 of file class.ilObjStudyProgrammeCache.php.

41 {
42 if (self::$instance === null) {
43 self::$instance = new ilObjStudyProgrammeCache();
44 }
45 return self::$instance;
46 }
Cache for ilObjStudyProgrammes.
static ilObjStudyProgrammeCache $instance

References $instance.

Referenced by ilObjStudyProgramme\initStudyProgrammeCache(), and ilObjStudyProgrammeCacheTest\testCreateBySingleton().

+ Here is the caller graph for this function:

◆ test_clear()

ilObjStudyProgrammeCache::test_clear ( )

For testing purpose.

TODO: Move to mock class in tests.

Definition at line 83 of file class.ilObjStudyProgrammeCache.php.

83 : void
84 {
85 $this->instances = array();
86 }

◆ test_isEmpty()

ilObjStudyProgrammeCache::test_isEmpty ( )

Definition at line 88 of file class.ilObjStudyProgrammeCache.php.

88 : bool
89 {
90 return count($this->instances) === 0;
91 }

Field Documentation

◆ $instance

ilObjStudyProgrammeCache ilObjStudyProgrammeCache::$instance = null
staticprivate

Definition at line 28 of file class.ilObjStudyProgrammeCache.php.

Referenced by singleton().

◆ $instances

array ilObjStudyProgrammeCache::$instances
protected

Definition at line 33 of file class.ilObjStudyProgrammeCache.php.


The documentation for this class was generated from the following file: