ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTimingCache.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 private static array $instances = [];
27
28 private int $ref_id = 0;
29 private int $obj_id = 0;
30 private bool $timings_active = false;
31 private array $timings = array();
32 private array $timings_user = array();
33 private array $collection_items = array();
34 private array $completed_users = array();
35
36 public function __construct(int $ref_id)
37 {
38 $this->ref_id = $ref_id;
39 $this->obj_id = ilObject::_lookupObjId($this->ref_id);
40 $this->readObjectInformation();
41 }
42
43 public static function getInstanceByRefId(int $ref_id): ilTimingCache
44 {
45 if (!isset(self::$instances[$ref_id])) {
46 self::$instances[$ref_id] = new self($ref_id);
47 }
48 return self::$instances[$ref_id];
49 }
50
51 public function isWarningRequired(int $usr_id): bool
52 {
53 if (in_array($usr_id, $this->completed_users)) {
54 return false;
55 }
56 foreach ($this->collection_items as $item) {
57 $item_instance = self::getInstanceByRefId($item);
58 if ($item_instance->isWarningRequired($usr_id)) {
59 return true;
60 }
61 }
62 if (!$this->timings_active) {
63 return false;
64 }
65
66 // check constraints
67 if ($this->timings['changeable'] && isset($this->timings_user[$usr_id]['end'])) {
68 $end = $this->timings_user[$usr_id]['end'];
69 } else {
70 $end = $this->timings['suggestion_end'];
71 }
72 return $end < time();
73 }
74
75 protected function readObjectInformation(): void
76 {
77 $this->timings = ilObjectActivation::getItem($this->ref_id);
78 $this->timings_active = false;
79 if ($this->timings['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
80 $this->timings_active = true;
81 $this->timings_user = ilTimingPlaned::_getPlanedTimingsByItem($this->ref_id);
82 }
83
84 $olp = ilObjectLP::getInstance($this->obj_id);
85 $collection = $olp->getCollectionInstance();
86 if ($collection instanceof ilLPCollectionOfRepositoryObjects) {
87 $this->collection_items = $collection->getItems();
88 }
89 $this->completed_users = ilLPStatus::_getCompleted($this->obj_id);
90 }
91
92 public static function _getTimings(int $a_ref_id): array
93 {
94 static $cache = array();
95
96 if (isset($cache[$a_ref_id])) {
97 return $cache[$a_ref_id];
98 }
99 $cache[$a_ref_id]['item'] = ilObjectActivation::getItem($a_ref_id);
100 $cache[$a_ref_id]['user'] = ilTimingPlaned::_getPlanedTimingsByItem($a_ref_id);
101
102 return $cache[$a_ref_id];
103 }
104}
static _getCompleted(int $a_obj_id)
static getItem(int $ref_id)
static getInstance(int $obj_id)
static _lookupObjId(int $ref_id)
class ilTimingCache
static getInstanceByRefId(int $ref_id)
__construct(int $ref_id)
static array $instances
static _getTimings(int $a_ref_id)
isWarningRequired(int $usr_id)
static _getPlanedTimingsByItem($a_item_id)