ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjStudyProgrammeCache.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private static ?ilObjStudyProgrammeCache $instance = null;
29
33 protected array $instances;
34
35 private function __construct()
36 {
37 $this->instances = array();
38 }
39
40 public static function singleton(): ilObjStudyProgrammeCache
41 {
42 if (self::$instance === null) {
43 self::$instance = new ilObjStudyProgrammeCache();
44 }
45 return self::$instance;
46 }
47
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 }
69
70 public function addInstance(ilObjStudyProgramme $prg): 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 }
77
83 public function test_clear(): void
84 {
85 $this->instances = array();
86 }
87
88 public function test_isEmpty(): bool
89 {
90 return count($this->instances) === 0;
91 }
92}
Base class for ILIAS Exception handling.
Cache for ilObjStudyProgrammes.
static ilObjStudyProgrammeCache $instance
addInstance(ilObjStudyProgramme $prg)
static _lookupType(int $id, bool $reference=false)
$ref_id
Definition: ltiauth.php:66