ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTimingCache.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
33{
37 private static $instances = array();
38
42 private $ref_id = 0;
43
47 private $obj_id = 0;
48
52 private $timings_active = false;
53
57 private $timings = array();
58
62 private $timings_user = array();
63
67 private $collection_items = array();
68
72 private $completed_users = array();
73
77 public function __construct($ref_id)
78 {
79 $this->ref_id = $ref_id;
80 $this->obj_id = ilObject::_lookupObjId($this->ref_id);
81 $this->readObjectInformation();
82 }
83
88 public static function getInstanceByRefId($ref_id)
89 {
90 if (!isset(self::$instances[$ref_id])) {
91 self::$instances[$ref_id] = new self($ref_id);
92 }
93 return self::$instances[$ref_id];
94 }
95
100 public function isWarningRequired($usr_id)
101 {
102 if (in_array($usr_id, $this->completed_users)) {
103 return false;
104 }
105 foreach ($this->collection_items as $item) {
106 $item_instance = self::getInstanceByRefId($item);
107 if ($item_instance->isWarningRequired($usr_id)) {
108 return true;
109 }
110 }
111 if (!$this->timings_active) {
112 return false;
113 }
114
115 // check constraints
116 if ($this->timings['changeable'] && isset($this->timings_user[$usr_id]['end'])) {
117 $end = $this->timings_user[$usr_id]['end'];
118 } else {
119 $end = $this->timings['suggestion_end'];
120 }
121 return $end < time();
122 }
123
127 protected function readObjectInformation()
128 {
129 $this->timings = ilObjectActivation::getItem($this->ref_id);
130 $this->timings_active = false;
131 if ($this->timings['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
132 $this->timings_active = true;
133 $this->timings_user = ilTimingPlaned::_getPlanedTimingsByItem($this->ref_id);
134 }
135
136 $olp = ilObjectLP::getInstance($this->obj_id);
137 $collection = $olp->getCollectionInstance();
138 if ($collection instanceof ilLPCollectionOfRepositoryObjects) {
139 $this->collection_items = $collection->getItems();
140 }
141 $this->completed_users = ilLPStatus::_getCompleted($this->obj_id);
142 }
143
144
150 public static function &_getTimings($a_ref_id)
151 {
152 static $cache = array();
153
154 if (isset($cache[$a_ref_id])) {
155 return $cache[$a_ref_id];
156 }
157 $cache[$a_ref_id]['item'] = ilObjectActivation::getItem($a_ref_id);
158 $cache[$a_ref_id]['user'] = ilTimingPlaned::_getPlanedTimingsByItem($a_ref_id);
159
160 return $cache[$a_ref_id];
161 }
162
169 public static function _showWarning($a_ref_id, $a_usr_id)
170 {
171 global $ilObjDataCache;
172
173 $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
174
175 // if completed no warning
176 include_once './Services/Tracking/classes/class.ilLPStatus.php';
177 if (ilLPStatus::_hasUserCompleted($obj_id, $a_usr_id)) {
178 return false;
179 }
180
181 // if editing time reached => show warning
183 if ($timings['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
184 if ($timings['item']['changeable'] and $timings['user'][$a_usr_id]['end']) {
185 $end = $timings['user'][$a_usr_id]['end'];
186 } else {
187 $end = $timings['item']['suggestion_end'];
188 }
189 if ($end < time()) {
190 return true;
191 }
192 }
193
194 include_once './Services/Object/classes/class.ilObjectLP.php';
196 $collection = $olp->getCollectionInstance();
197 if ($collection instanceof ilLPCollectionOfRepositoryObjects) {
198 foreach ($collection->getItems() as $item) {
199 if (ilTimingCache::_showWarning($item, $a_usr_id)) {
200 return true;
201 }
202 }
203 }
204
205 // Really ???
206 return false;
207 }
208}
An exception for terminatinating execution or to throw for unit testing.
static _getCompleted($a_obj_id)
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static getItem($a_ref_id)
Get item data.
static getInstance($a_obj_id)
static _lookupObjId($a_id)
class ilTimingCache
static getInstanceByRefId($ref_id)
static _showWarning($a_ref_id, $a_usr_id)
__construct($ref_id)
ilTimingCache constructor.
static & _getTimings($a_ref_id)
readObjectInformation()
Read timing information for object.
static _getPlanedTimingsByItem($a_item_id)
$end
Definition: saml1-acs.php:18