ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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;
31 const LP_MODE_SCORM = 6;
35 const LP_MODE_EVENT = 10;
39 const LP_MODE_PLUGIN = 14;
43 // const LP_MODE_SURVEY_FINISHED = 18; (placeholder for 4.6.x)
44
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 {
253 return $lng->txt('trac_mode_deactivated');
254
256 return $lng->txt('trac_mode_tlt');
257
259 return $lng->txt('trac_mode_visits');
260
262 return $lng->txt('trac_mode_manual');
263
265 return $lng->txt('trac_mode_manual_by_tutor');
266
268 return $lng->txt('trac_mode_objectives');
269
271 return $lng->txt('trac_mode_collection');
272
274 return $lng->txt('trac_mode_scorm');
275
277 return $lng->txt('trac_mode_test_finished');
278
280 return $lng->txt('trac_mode_test_passed');
281
283 return $lng->txt('trac_mode_exercise_returned');
284
286 return $lng->txt('trac_mode_scorm_package');
287
289 return $lng->txt('trac_mode_event');
290
292 return $lng->txt('trac_mode_plugin');
293
295 return $lng->txt('trac_mode_collection_manual');
296
298 return $lng->txt('trac_mode_collection_tlt');
299
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 {
312 return $lng->txt('trac_mode_deactivated_info_new');
313
315 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
316 return sprintf($lng->txt('trac_mode_tlt_info'), ilObjUserTracking::_getValidTimeSpan());
317
319 return $lng->txt('trac_mode_visits_info');
320
322 return $lng->txt('trac_mode_manual_info');
323
325 return $lng->txt('trac_mode_manual_by_tutor_info');
326
328 return $lng->txt('trac_mode_objectives_info');
329
331 return $lng->txt('trac_mode_collection_info');
332
334 return $lng->txt('trac_mode_scorm_info');
335
337 return $lng->txt('trac_mode_test_finished_info');
338
340 return $lng->txt('trac_mode_test_passed_info');
341
343 return $lng->txt('trac_mode_exercise_returned_info');
344
346 return $lng->txt('trac_mode_scorm_package_info');
347
349 return $lng->txt('trac_mode_event_info');
350
352 return $lng->txt('trac_mode_collection_manual_info');
353
355 return $lng->txt('trac_mode_collection_tlt_info');
356
358 return $lng->txt('trac_mode_questions_info');
359 }
360 }
361}
362
363?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
update($a_refresh_lp=true)
cloneSettings($a_new_obj_id)
Clone settings.
static _mode2Text($a_mode)
static _lookupDBMode($a_obj_id)
static _lookupDBModeForObjects(array $a_obj_ids)
static _mode2InfoText($a_mode)
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
static getInstance($a_obj_id)
global $lng
Definition: privfeed.php:40
global $ilDB