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