ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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;
45  const LP_MODE_DOWNLOADED = 20;
48 
49  const LP_DEFAULT_VISITS = 30; // ???
50 
51  protected static $map = array(
52 
53  self::LP_MODE_DEACTIVATED => array('ilLPStatus',
54  'trac_mode_deactivated', 'trac_mode_deactivated_info_new')
55 
56  ,self::LP_MODE_TLT => array('ilLPStatusTypicalLearningTime',
57  'trac_mode_tlt', 'trac_mode_tlt_info') // info has dynamic part!
58 
59  ,self::LP_MODE_VISITS => array('ilLPStatusVisits',
60  'trac_mode_visits', 'trac_mode_visits_info')
61 
62  ,self::LP_MODE_MANUAL => array('ilLPStatusManual',
63  'trac_mode_manual', 'trac_mode_manual_info')
64 
65  ,self::LP_MODE_OBJECTIVES => array('ilLPStatusObjectives',
66  'trac_mode_objectives', 'trac_mode_objectives_info')
67 
68  ,self::LP_MODE_COLLECTION => array('ilLPStatusCollection',
69  'trac_mode_collection', 'trac_mode_collection_info')
70 
71  ,self::LP_MODE_SCORM => array('ilLPStatusSCORM',
72  'trac_mode_scorm', 'trac_mode_scorm_info')
73 
74  ,self::LP_MODE_TEST_FINISHED => array('ilLPStatusTestFinished',
75  'trac_mode_test_finished', 'trac_mode_test_finished_info')
76 
77  ,self::LP_MODE_TEST_PASSED => array('ilLPStatusTestPassed',
78  'trac_mode_test_passed', 'trac_mode_test_passed_info')
79 
80  ,self::LP_MODE_EXERCISE_RETURNED => array('ilLPStatusExerciseReturned',
81  'trac_mode_exercise_returned', 'trac_mode_exercise_returned_info')
82 
83  ,self::LP_MODE_EVENT => array('ilLPStatusEvent',
84  'trac_mode_event', 'trac_mode_event_info')
85 
86  ,self::LP_MODE_MANUAL_BY_TUTOR => array('ilLPStatusManualByTutor',
87  'trac_mode_manual_by_tutor', 'trac_mode_manual_by_tutor_info')
88 
89  ,self::LP_MODE_SCORM_PACKAGE => array('ilLPStatusSCORMPackage',
90  'trac_mode_scorm_package', 'trac_mode_scorm_package_info')
91 
92  ,self::LP_MODE_UNDEFINED => null
93 
94  ,self::LP_MODE_PLUGIN => array('ilLPStatusPlugin',
95  'trac_mode_plugin', '') // no settings screen, so no info needed
96 
97  ,self::LP_MODE_COLLECTION_TLT => array('ilLPStatusCollectionTLT',
98  'trac_mode_collection_tlt', 'trac_mode_collection_tlt_info')
99 
100  ,self::LP_MODE_COLLECTION_MANUAL => array('ilLPStatusCollectionManual',
101  'trac_mode_collection_manual', 'trac_mode_collection_manual_info')
102 
103  ,self::LP_MODE_QUESTIONS => array('ilLPStatusQuestions',
104  'trac_mode_questions', 'trac_mode_questions_info')
105 
106  ,self::LP_MODE_SURVEY_FINISHED => array('ilLPStatusSurveyFinished',
107  'trac_mode_survey_finished', 'trac_mode_survey_finished_info')
108 
109  ,self::LP_MODE_VISITED_PAGES => array('ilLPStatusVisitedPages',
110  'trac_mode_visited_pages', 'trac_mode_visited_pages_info')
111 
112  ,self::LP_MODE_DOWNLOADED => array('ilLPStatusDownloaded',
113  'trac_mode_downloaded', 'trac_mode_downloaded_info')
114 
115  ,self::LP_MODE_COLLECTION_MOBS => array('ilLPStatusCollectionMobs',
116  'trac_mode_collection_mobs', 'trac_mode_collection_mobs_info')
117 
118  ,self::LP_MODE_STUDY_PROGRAMME => array('ilLPStatusStudyProgramme',
119  'trac_mode_study_programme', '')
120  );
121 
122  function ilLPObjSettings($a_obj_id)
123  {
124  global $ilObjDataCache, $ilDB;
125 
126  $this->db = $ilDB;
127  $this->obj_id = $a_obj_id;
128 
129  if(!$this->__read())
130  {
131  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
132 
133  include_once "Services/Object/classes/class.ilObjectLP.php";
134  $olp = ilObjectLP::getInstance($this->obj_id);
135  $this->obj_mode = $olp->getDefaultMode();
136  }
137  }
138 
146  public function cloneSettings($a_new_obj_id)
147  {
148  global $ilDB;
149 
150  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
151  "VALUES( ".
152  $this->db->quote($a_new_obj_id ,'integer').", ".
153  $this->db->quote($this->getObjType() ,'text').", ".
154  $this->db->quote($this->getMode() ,'integer').", ".
155  $this->db->quote($this->getVisits() ,'integer').
156  ")";
157  $res = $ilDB->manipulate($query);
158  return true;
159  }
160 
161  function getVisits()
162  {
163  return (int) $this->visits ? $this->visits : self::LP_DEFAULT_VISITS;
164  }
165 
166  function setVisits($a_visits)
167  {
168  $this->visits = $a_visits;
169  }
170 
171  function setMode($a_mode)
172  {
173  $this->obj_mode = $a_mode;
174  }
175 
176  function getMode()
177  {
178  return $this->obj_mode;
179  }
180 
181  function getObjId()
182  {
183  return (int) $this->obj_id;
184  }
185 
186  function getObjType()
187  {
188  return $this->obj_type;
189  }
190 
191  function __read()
192  {
193  $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = ".
194  $this->db->quote($this->obj_id ,'integer'));
195  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
196  {
197  $this->is_stored = true;
198  $this->obj_type = $row->obj_type;
199  $this->obj_mode = $row->u_mode;
200  $this->visits = $row->visits;
201 
202  return true;
203  }
204 
205  return false;
206  }
207 
208  function update($a_refresh_lp = true)
209  {
210  global $ilDB;
211 
212  if(!$this->is_stored)
213  {
214  return $this->insert();
215  }
216  $query = "UPDATE ut_lp_settings SET u_mode = ".$ilDB->quote($this->getMode() ,'integer').", ".
217  "visits = ".$ilDB->quote($this->getVisits() ,'integer')." ".
218  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer');
219  $res = $ilDB->manipulate($query);
220  $this->__read();
221 
222  if($a_refresh_lp)
223  {
224  $this->doLPRefresh();
225  }
226 
227  return true;
228  }
229 
230  function insert()
231  {
232  global $ilDB,$ilLog;
233 
234  $ilLog->logStack();
235 
236  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
237  "VALUES(".
238  $ilDB->quote($this->getObjId() ,'integer').", ".
239  $ilDB->quote($this->getObjType(),'text').", ".
240  $ilDB->quote($this->getMode(),'integer').", ".
241  $ilDB->quote($this->getVisits(), 'integer'). // #12482
242  ")";
243  $res = $ilDB->manipulate($query);
244  $this->__read();
245 
246  $this->doLPRefresh();
247 
248  return true;
249  }
250 
251  protected function doLPRefresh()
252  {
253  // refresh learning progress
254  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
256  }
257 
258  function _delete($a_obj_id)
259  {
260  global $ilDB;
261 
262  $query = "DELETE FROM ut_lp_settings WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
263  $res = $ilDB->manipulate($query);
264 
265  return true;
266  }
267 
268 
269  // Static
270 
271  function _lookupVisits($a_obj_id)
272  {
273  global $ilDB;
274 
275  $query = "SELECT visits FROM ut_lp_settings ".
276  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
277 
278  $res = $ilDB->query($query);
279  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
280  {
281  return $row->visits;
282  }
283  return self::LP_DEFAULT_VISITS;
284  }
285 
286  public static function _lookupDBModeForObjects(array $a_obj_ids)
287  {
288  global $ilDB;
289 
290  // this does NOT handle default mode!
291 
292  $res = array();
293 
294  $query = "SELECT obj_id, u_mode FROM ut_lp_settings".
295  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer");
296  $set = $ilDB->query($query);
297  while($row = $set->fetchRow(DB_FETCHMODE_OBJECT))
298  {
299  $res[$row->obj_id] = $row->u_mode;
300  }
301 
302  return $res;
303  }
304 
305  public static function _lookupDBMode($a_obj_id)
306  {
307  global $ilDB;
308 
309  // this does NOT handle default mode!
310 
311  $query = "SELECT u_mode FROM ut_lp_settings".
312  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
313  $set = $ilDB->query($query);
314  $row = $ilDB->fetchAssoc($set);
315  if(is_array($row))
316  {
317  return $row['u_mode'];
318  }
319  }
320 
321  public static function _mode2Text($a_mode)
322  {
323  global $lng;
324 
325  if(array_key_exists($a_mode, self::$map) &&
326  is_array(self::$map[$a_mode]))
327  {
328  return $lng->txt(self::$map[$a_mode][1]);
329  }
330  }
331 
332  public static function _mode2InfoText($a_mode)
333  {
334  global $lng;
335 
336  if(array_key_exists($a_mode, self::$map) &&
337  is_array(self::$map[$a_mode]))
338  {
339  $info = $lng->txt(self::$map[$a_mode][2]);
340 
341  if($a_mode == self::LP_MODE_TLT)
342  {
343  // dynamic content
344  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
346  }
347 
348  return $info;
349  }
350  }
351 
352  public static function getClassMap()
353  {
354  $res = array();
355  foreach(self::$map as $mode => $item)
356  {
357  $res[$mode] = $item[0];
358  }
359  return $res;
360  }
361 
362  public static function _deleteByObjId($a_obj_id)
363  {
364  global $ilDB;
365 
366  // we are only removing settings for now
367  // invalid ut_lp_collections-entries are filtered
368  // ut_lp_marks is deemed private user data
369 
370  $ilDB->manipulate("DELETE FROM ut_lp_settings".
371  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer"));
372  }
373 }
374 
375 ?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
update($a_refresh_lp=true)
$info
Definition: example_052.php:80
static _lookupDBMode($a_obj_id)
static _lookupDBModeForObjects(array $a_obj_ids)
static _mode2InfoText($a_mode)
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
global $lng
Definition: privfeed.php:40
global $ilDB
static _deleteByObjId($a_obj_id)
cloneSettings($a_new_obj_id)
Clone settings.
static getInstance($a_obj_id)
static _mode2Text($a_mode)