ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPObjSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  var $db = null;
17 
18  var $obj_id = null;
19  var $obj_type = null;
20  var $obj_mode = null;
21  var $visits = null;
22 
23  var $is_stored = false;
24 
26  const LP_MODE_TLT = 1;
27  const LP_MODE_VISITS = 2;
28  const LP_MODE_MANUAL = 3;
29  const LP_MODE_OBJECTIVES = 4;
30  const LP_MODE_COLLECTION = 5;
31  const LP_MODE_SCORM = 6;
35  const LP_MODE_EVENT = 10;
38  const LP_MODE_UNDEFINED = 13;
39  const LP_MODE_PLUGIN = 14;
42 
43  const LP_DEFAULT_VISITS = 30;
44 
45  function ilLPObjSettings($a_obj_id)
46  {
47  global $ilObjDataCache, $ilDB;
48 
49  $this->db = $ilDB;
50  $this->obj_id = $a_obj_id;
51 
52  if(!$this->__read())
53  {
54  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
55 
56  include_once "Services/Object/classes/class.ilObjectLP.php";
57  $olp = ilObjectLP::getInstance($this->obj_id);
58  $this->obj_mode = $olp->getDefaultMode();
59  }
60  }
61 
69  public function cloneSettings($a_new_obj_id)
70  {
71  global $ilDB;
72 
73  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
74  "VALUES( ".
75  $this->db->quote($a_new_obj_id ,'integer').", ".
76  $this->db->quote($this->getObjType() ,'text').", ".
77  $this->db->quote($this->getMode() ,'integer').", ".
78  $this->db->quote($this->getVisits() ,'integer').
79  ")";
80  $res = $ilDB->manipulate($query);
81  return true;
82  }
83 
84  function getVisits()
85  {
86  return (int) $this->visits ? $this->visits : self::LP_DEFAULT_VISITS;
87  }
88 
89  function setVisits($a_visits)
90  {
91  $this->visits = $a_visits;
92  }
93 
94  function setMode($a_mode)
95  {
96  $this->obj_mode = $a_mode;
97  }
98 
99  function getMode()
100  {
101  return $this->obj_mode;
102  }
103 
104  function getObjId()
105  {
106  return (int) $this->obj_id;
107  }
108 
109  function getObjType()
110  {
111  return $this->obj_type;
112  }
113 
114  function __read()
115  {
116  $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = ".
117  $this->db->quote($this->obj_id ,'integer'));
118  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
119  {
120  $this->is_stored = true;
121  $this->obj_type = $row->obj_type;
122  $this->obj_mode = $row->u_mode;
123  $this->visits = $row->visits;
124 
125  return true;
126  }
127 
128  return false;
129  }
130 
131  function update($a_refresh_lp = true)
132  {
133  global $ilDB;
134 
135  if(!$this->is_stored)
136  {
137  return $this->insert();
138  }
139  $query = "UPDATE ut_lp_settings SET u_mode = ".$ilDB->quote($this->getMode() ,'integer').", ".
140  "visits = ".$ilDB->quote($this->getVisits() ,'integer')." ".
141  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer');
142  $res = $ilDB->manipulate($query);
143  $this->__read();
144 
145  if($a_refresh_lp)
146  {
147  $this->doLPRefresh();
148  }
149 
150  return true;
151  }
152 
153  function insert()
154  {
155  global $ilDB,$ilLog;
156 
157  $ilLog->logStack();
158 
159  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
160  "VALUES(".
161  $ilDB->quote($this->getObjId() ,'integer').", ".
162  $ilDB->quote($this->getObjType(),'text').", ".
163  $ilDB->quote($this->getMode(),'integer').", ".
164  $ilDB->quote($this->getVisits(), 'integer'). // #12482
165  ")";
166  $res = $ilDB->manipulate($query);
167  $this->__read();
168 
169  $this->doLPRefresh();
170 
171  return true;
172  }
173 
174  protected function doLPRefresh()
175  {
176  // refresh learning progress
177  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
179  }
180 
181  function _delete($a_obj_id)
182  {
183  global $ilDB;
184 
185  $query = "DELETE FROM ut_lp_settings WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
186  $res = $ilDB->manipulate($query);
187 
188  return true;
189  }
190 
191 
192  // Static
193 
194  function _lookupVisits($a_obj_id)
195  {
196  global $ilDB;
197 
198  $query = "SELECT visits FROM ut_lp_settings ".
199  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
200 
201  $res = $ilDB->query($query);
202  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
203  {
204  return $row->visits;
205  }
207  }
208 
209  public static function _lookupDBModeForObjects(array $a_obj_ids)
210  {
211  global $ilDB;
212 
213  // this does NOT handle default mode!
214 
215  $res = array();
216 
217  $query = "SELECT obj_id, u_mode FROM ut_lp_settings".
218  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer");
219  $set = $ilDB->query($query);
220  while($row = $set->fetchRow(DB_FETCHMODE_OBJECT))
221  {
222  $res[$row->obj_id] = $row->u_mode;
223  }
224 
225  return $res;
226  }
227 
228  public static function _lookupDBMode($a_obj_id)
229  {
230  global $ilDB;
231 
232  // this does NOT handle default mode!
233 
234  $query = "SELECT u_mode FROM ut_lp_settings".
235  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
236  $set = $ilDB->query($query);
237  $row = $ilDB->fetchAssoc($set);
238  if(is_array($row))
239  {
240  return $row['u_mode'];
241  }
242  }
243 
244  public static function _mode2Text($a_mode)
245  {
246  global $lng;
247 
248  switch($a_mode)
249  {
250  case self::LP_MODE_DEACTIVATED:
251  return $lng->txt('trac_mode_deactivated');
252 
253  case self::LP_MODE_TLT:
254  return $lng->txt('trac_mode_tlt');
255 
256  case self::LP_MODE_VISITS:
257  return $lng->txt('trac_mode_visits');
258 
259  case self::LP_MODE_MANUAL:
260  return $lng->txt('trac_mode_manual');
261 
262  case self::LP_MODE_MANUAL_BY_TUTOR:
263  return $lng->txt('trac_mode_manual_by_tutor');
264 
265  case self::LP_MODE_OBJECTIVES:
266  return $lng->txt('trac_mode_objectives');
267 
268  case self::LP_MODE_COLLECTION:
269  return $lng->txt('trac_mode_collection');
270 
271  case self::LP_MODE_SCORM:
272  return $lng->txt('trac_mode_scorm');
273 
274  case self::LP_MODE_TEST_FINISHED:
275  return $lng->txt('trac_mode_test_finished');
276 
277  case self::LP_MODE_TEST_PASSED:
278  return $lng->txt('trac_mode_test_passed');
279 
280  case self::LP_MODE_EXERCISE_RETURNED:
281  return $lng->txt('trac_mode_exercise_returned');
282 
283  case self::LP_MODE_SCORM_PACKAGE:
284  return $lng->txt('trac_mode_scorm_package');
285 
286  case self::LP_MODE_EVENT:
287  return $lng->txt('trac_mode_event');
288 
289  case self::LP_MODE_PLUGIN:
290  return $lng->txt('trac_mode_plugin');
291 
292  case self::LP_MODE_COLLECTION_MANUAL:
293  return $lng->txt('trac_mode_collection_manual');
294 
295  case self::LP_MODE_COLLECTION_TLT:
296  return $lng->txt('trac_mode_collection_tlt');
297  }
298  }
299 
300  public static function _mode2InfoText($a_mode)
301  {
302  global $lng;
303 
304  switch($a_mode)
305  {
306  case self::LP_MODE_DEACTIVATED:
307  return $lng->txt('trac_mode_deactivated_info_new');
308 
309  case self::LP_MODE_TLT:
310  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
311  return sprintf($lng->txt('trac_mode_tlt_info'), ilObjUserTracking::_getValidTimeSpan());
312 
313  case self::LP_MODE_VISITS:
314  return $lng->txt('trac_mode_visits_info');
315 
316  case self::LP_MODE_MANUAL:
317  return $lng->txt('trac_mode_manual_info');
318 
319  case self::LP_MODE_MANUAL_BY_TUTOR:
320  return $lng->txt('trac_mode_manual_by_tutor_info');
321 
322  case self::LP_MODE_OBJECTIVES:
323  return $lng->txt('trac_mode_objectives_info');
324 
325  case self::LP_MODE_COLLECTION:
326  return $lng->txt('trac_mode_collection_info');
327 
328  case self::LP_MODE_SCORM:
329  return $lng->txt('trac_mode_scorm_info');
330 
331  case self::LP_MODE_TEST_FINISHED:
332  return $lng->txt('trac_mode_test_finished_info');
333 
334  case self::LP_MODE_TEST_PASSED:
335  return $lng->txt('trac_mode_test_passed_info');
336 
337  case self::LP_MODE_EXERCISE_RETURNED:
338  return $lng->txt('trac_mode_exercise_returned_info');
339 
340  case self::LP_MODE_SCORM_PACKAGE:
341  return $lng->txt('trac_mode_scorm_package_info');
342 
343  case self::LP_MODE_EVENT:
344  return $lng->txt('trac_mode_event_info');
345 
346  case self::LP_MODE_COLLECTION_MANUAL:
347  return $lng->txt('trac_mode_collection_manual_info');
348 
349  case self::LP_MODE_COLLECTION_TLT:
350  return $lng->txt('trac_mode_collection_tlt_info');
351  }
352  }
353 }
354 
355 ?>