ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public $db = null;
17 
18  public $obj_id = null;
19  public $obj_type = null;
20  public $obj_mode = null;
21  public $visits = null;
22 
23  public $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;
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_CONTENT_VISITED => array('ilLPStatusContentVisited',
114  'trac_mode_content_visited', 'trac_mode_content_visited_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  public function __construct($a_obj_id)
127  {
128  global $DIC;
129 
130  $ilObjDataCache = $DIC['ilObjDataCache'];
131  $ilDB = $DIC['ilDB'];
132 
133  $this->db = $ilDB;
134  $this->obj_id = $a_obj_id;
135 
136  if (!$this->__read()) {
137  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
138 
139  include_once "Services/Object/classes/class.ilObjectLP.php";
140  $olp = ilObjectLP::getInstance($this->obj_id);
141  $this->obj_mode = $olp->getDefaultMode();
142  }
143  }
144 
152  public function cloneSettings($a_new_obj_id)
153  {
154  global $DIC;
155 
156  $ilDB = $DIC['ilDB'];
157 
158  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) " .
159  "VALUES( " .
160  $this->db->quote($a_new_obj_id, 'integer') . ", " .
161  $this->db->quote($this->getObjType(), 'text') . ", " .
162  $this->db->quote($this->getMode(), 'integer') . ", " .
163  $this->db->quote($this->getVisits(), 'integer') .
164  ")";
165  $res = $ilDB->manipulate($query);
166  return true;
167  }
168 
169  public function getVisits()
170  {
171  return (int) $this->visits ? $this->visits : self::LP_DEFAULT_VISITS;
172  }
173 
174  public function setVisits($a_visits)
175  {
176  $this->visits = $a_visits;
177  }
178 
179  public function setMode($a_mode)
180  {
181  $this->obj_mode = $a_mode;
182  }
183 
184  public function getMode()
185  {
186  return $this->obj_mode;
187  }
188 
189  public function getObjId()
190  {
191  return (int) $this->obj_id;
192  }
193 
194  public function getObjType()
195  {
196  return $this->obj_type;
197  }
198 
199  public function __read()
200  {
201  $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = " .
202  $this->db->quote($this->obj_id, 'integer'));
203  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
204  $this->is_stored = true;
205  $this->obj_type = $row->obj_type;
206  $this->obj_mode = $row->u_mode;
207  $this->visits = $row->visits;
208 
209  return true;
210  }
211 
212  return false;
213  }
214 
215  public function update($a_refresh_lp = true)
216  {
217  global $DIC;
218 
219  $ilDB = $DIC['ilDB'];
220 
221  if (!$this->is_stored) {
222  return $this->insert();
223  }
224  $query = "UPDATE ut_lp_settings SET u_mode = " . $ilDB->quote($this->getMode(), 'integer') . ", " .
225  "visits = " . $ilDB->quote($this->getVisits(), 'integer') . " " .
226  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer');
227  $res = $ilDB->manipulate($query);
228  $this->__read();
229 
230  if ($a_refresh_lp) {
231  $this->doLPRefresh();
232  }
233 
234  return true;
235  }
236 
237  public function insert()
238  {
239  global $DIC;
240 
241  $ilDB = $DIC['ilDB'];
242 
243  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) " .
244  "VALUES(" .
245  $ilDB->quote($this->getObjId(), 'integer') . ", " .
246  $ilDB->quote($this->getObjType(), 'text') . ", " .
247  $ilDB->quote($this->getMode(), 'integer') . ", " .
248  $ilDB->quote($this->getVisits(), 'integer') . // #12482
249  ")";
250  $res = $ilDB->manipulate($query);
251  $this->__read();
252 
253  $this->doLPRefresh();
254 
255  return true;
256  }
257 
258  protected function doLPRefresh()
259  {
260  // refresh learning progress
261  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
263  }
264 
265  public static function _delete($a_obj_id)
266  {
267  global $DIC;
268 
269  $ilDB = $DIC['ilDB'];
270 
271  $query = "DELETE FROM ut_lp_settings WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
272  $res = $ilDB->manipulate($query);
273 
274  return true;
275  }
276 
277 
278  // Static
279 
280  public static function _lookupVisits($a_obj_id)
281  {
282  global $DIC;
283 
284  $ilDB = $DIC['ilDB'];
285 
286  $query = "SELECT visits FROM ut_lp_settings " .
287  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
288 
289  $res = $ilDB->query($query);
290  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
291  return $row->visits;
292  }
293  return self::LP_DEFAULT_VISITS;
294  }
295 
296  public static function _lookupDBModeForObjects(array $a_obj_ids)
297  {
298  global $DIC;
299 
300  $ilDB = $DIC['ilDB'];
301 
302  // this does NOT handle default mode!
303 
304  $res = array();
305 
306  $query = "SELECT obj_id, u_mode FROM ut_lp_settings" .
307  " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer");
308  $set = $ilDB->query($query);
309  while ($row = $set->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
310  $res[$row->obj_id] = $row->u_mode;
311  }
312 
313  return $res;
314  }
315 
316  public static function _lookupDBMode($a_obj_id)
317  {
318  global $DIC;
319 
320  $ilDB = $DIC['ilDB'];
321 
322  // this does NOT handle default mode!
323 
324  $query = "SELECT u_mode FROM ut_lp_settings" .
325  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
326  $set = $ilDB->query($query);
327  $row = $ilDB->fetchAssoc($set);
328  if (is_array($row)) {
329  return $row['u_mode'];
330  }
331  }
332 
333  public static function _mode2Text($a_mode)
334  {
335  global $DIC;
336 
337  $lng = $DIC['lng'];
338 
339  if (array_key_exists($a_mode, self::$map) &&
340  is_array(self::$map[$a_mode])) {
341  return $lng->txt(self::$map[$a_mode][1]);
342  }
343  }
344 
345  public static function _mode2InfoText($a_mode)
346  {
347  global $DIC;
348 
349  $lng = $DIC['lng'];
350 
351  if (array_key_exists($a_mode, self::$map) &&
352  is_array(self::$map[$a_mode])) {
353  $info = $lng->txt(self::$map[$a_mode][2]);
354 
355  if ($a_mode == self::LP_MODE_TLT) {
356  // dynamic content
357  include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
359  }
360 
361  return $info;
362  }
363  }
364 
365  public static function getClassMap()
366  {
367  $res = array();
368  foreach (self::$map as $mode => $item) {
369  $res[$mode] = $item[0];
370  }
371  return $res;
372  }
373 
374  public static function _deleteByObjId($a_obj_id)
375  {
376  global $DIC;
377 
378  $ilDB = $DIC['ilDB'];
379 
380  // we are only removing settings for now
381  // invalid ut_lp_collections-entries are filtered
382  // ut_lp_marks is deemed private user data
383 
384  $ilDB->manipulate("DELETE FROM ut_lp_settings" .
385  " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer"));
386  }
387 }
global $DIC
Definition: saml.php:7
static _delete($a_obj_id)
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
update($a_refresh_lp=true)
static _lookupDBMode($a_obj_id)
foreach($_POST as $key=> $value) $res
$lng
$query
static _lookupDBModeForObjects(array $a_obj_ids)
$row
static _mode2InfoText($a_mode)
static _lookupVisits($a_obj_id)
global $ilDB
static _deleteByObjId($a_obj_id)
$info
Definition: index.php:5
cloneSettings($a_new_obj_id)
Clone settings.
static getInstance($a_obj_id)
static _mode2Text($a_mode)