ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
172 
173  $ilObjDataCache = $DIC['ilObjDataCache'];
174 
175  $obj_id = $ilObjDataCache->lookupObjId($a_ref_id);
176 
177  // if completed no warning
178  include_once './Services/Tracking/classes/class.ilLPStatus.php';
179  if (ilLPStatus::_hasUserCompleted($obj_id, $a_usr_id)) {
180  return false;
181  }
182 
183  // if editing time reached => show warning
184  $timings = &ilTimingCache::_getTimings($a_ref_id);
185  if ($timings['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
186  if ($timings['item']['changeable'] and $timings['user'][$a_usr_id]['end']) {
187  $end = $timings['user'][$a_usr_id]['end'];
188  } else {
189  $end = $timings['item']['suggestion_end'];
190  }
191  if ($end < time()) {
192  return true;
193  }
194  }
195 
196  include_once './Services/Object/classes/class.ilObjectLP.php';
198  $collection = $olp->getCollectionInstance();
199  if ($collection instanceof ilLPCollectionOfRepositoryObjects) {
200  foreach ($collection->getItems() as $item) {
201  if (ilTimingCache::_showWarning($item, $a_usr_id)) {
202  return true;
203  }
204  }
205  }
206 
207  // Really ???
208  return false;
209  }
210 }
readObjectInformation()
Read timing information for object.
__construct($ref_id)
ilTimingCache constructor.
global $DIC
Definition: saml.php:7
static getItem($a_ref_id)
Get item data.
static _getPlanedTimingsByItem($a_item_id)
static _getCompleted($a_obj_id)
class ilTimingCache
static _showWarning($a_ref_id, $a_usr_id)
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static _lookupObjId($a_id)
static getInstanceByRefId($ref_id)
static getInstance($a_obj_id)
static & _getTimings($a_ref_id)