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