ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilCourseObjective.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
15 var $db = null;
16
17 var $course_obj = null;
18 var $objective_id = null;
19
20 // begin-patch lok
21 protected $active = true;
22 protected $passes = 0;
23 // end-patch lok
24
25 function ilCourseObjective(&$course_obj,$a_objective_id = 0)
26 {
27 global $ilDB;
28
29 $this->db =& $ilDB;
30 $this->course_obj =& $course_obj;
31
32 $this->objective_id = $a_objective_id;
33 if($this->objective_id)
34 {
35 $this->__read();
36 }
37 }
38
47 public static function _lookupContainerIdByObjectiveId($a_objective_id)
48 {
49 global $ilDB;
50
51 $query = "SELECT crs_id FROM crs_objectives ".
52 "WHERE objective_id = ".$ilDB->quote($a_objective_id ,'integer');
53 $res = $ilDB->query($query);
54 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
55 {
56 return $row->crs_id;
57 }
58 return false;
59 }
60
69 // begin-patch lok
70 public static function _getCountObjectives($a_obj_id,$a_activated_only = false)
71 {
72 return count(ilCourseObjective::_getObjectiveIds($a_obj_id,$a_activated_only));
73 }
74
75 public static function lookupMaxPasses($a_objective_id)
76 {
77 global $ilDB;
78
79 $query = 'SELECT passes from crs_objectives '.
80 'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer');
81 $res = $ilDB->query($query);
82 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
83 {
84 return (int) $row->passes;
85 }
86 return 0;
87 }
88
89 public static function lookupObjectiveTitle($a_objective_id)
90 {
91 global $ilDB;
92
93 $query = 'SELECT title from crs_objectives '.
94 'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer');
95 $res = $ilDB->query($query);
96 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
97 {
98 return $row->title;
99 }
100 return "";
101
102 }
103 // end-patch lok
104
113 public function ilClone($a_target_id,$a_copy_id)
114 {
115 global $ilLog;
116
117 $ilLog->write(__METHOD__.': Start cloning learning objectives...');
118
119 $query = "SELECT * FROM crs_objectives ".
120 "WHERE crs_id = ".$this->db->quote($this->course_obj->getId() ,'integer').' '.
121 "ORDER BY position ";
122 $res = $this->db->query($query);
123 if(!$res->numRows())
124 {
125 $ilLog->write(__METHOD__.': ... no objectives found.');
126 return true;
127 }
128
129 if(!is_object($new_course = ilObjectFactory::getInstanceByRefId($a_target_id,false)))
130 {
131 $ilLog->write(__METHOD__.': Cannot init new course object.');
132 return true;
133 }
134 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
135 {
136 $new_objective = new ilCourseObjective($new_course);
137 $new_objective->setTitle($row->title);
138 $new_objective->setDescription($row->description);
139 $new_objective->setActive($row->active);
140 $objective_id = $new_objective->add();
141 $ilLog->write(__METHOD__.': Added new objective nr: '.$objective_id);
142
143 // Clone crs_objective_tst entries
144 include_once('Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
145 $objective_qst = new ilCourseObjectiveQuestion($row->objective_id);
146 $objective_qst->cloneDependencies($objective_id,$a_copy_id);
147
148
149 $ilLog->write(__METHOD__.': Finished objective question dependencies: '.$objective_id);
150
151 // Clone crs_objective_lm entries (assigned course materials)
152 include_once('Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
153 $objective_material = new ilCourseObjectiveMaterials($row->objective_id);
154 $objective_material->cloneDependencies($objective_id,$a_copy_id);
155 }
156 $ilLog->write(__METHOD__.': Finished cloning objectives.');
157 }
158
159 // begin-patch lok
160 public function setActive($a_stat)
161 {
162 $this->active = $a_stat;
163 }
164
165 public function isActive()
166 {
167 return $this->active;
168 }
169
170 public function setPasses($a_passes)
171 {
172 $this->passes = $a_passes;
173 }
174
175 public function getPasses()
176 {
177 return $this->passes;
178 }
179
180 public function arePassesLimited()
181 {
182 return $this->passes > 0;
183 }
184 // end-patch lok
185
186 function setTitle($a_title)
187 {
188 $this->title = $a_title;
189 }
190 function getTitle()
191 {
192 return $this->title;
193 }
194 function setDescription($a_description)
195 {
196 $this->description = $a_description;
197 }
198 function getDescription()
199 {
200 return $this->description;
201 }
202 function setObjectiveId($a_objective_id)
203 {
204 $this->objective_id = $a_objective_id;
205 }
206 function getObjectiveId()
207 {
208 return $this->objective_id;
209 }
210
211 function add()
212 {
213 global $ilDB;
214
215 // begin-patch lok
216 $next_id = $ilDB->nextId('crs_objectives');
217 $query = "INSERT INTO crs_objectives (crs_id,objective_id,active,title,description,position,created,passes) ".
218 "VALUES( ".
219 $ilDB->quote($this->course_obj->getId() ,'integer').", ".
220 $ilDB->quote($next_id,'integer').", ".
221 $ilDB->quote($this->isActive(),'integer').', '.
222 $ilDB->quote($this->getTitle() ,'text').", ".
223 $ilDB->quote($this->getDescription() ,'text').", ".
224 $ilDB->quote($this->__getLastPosition() + 1 ,'integer').", ".
225 $ilDB->quote(time() ,'integer').", ".
226 $ilDB->quote($this->getPasses(),'integer').' '.
227 ")";
228 $res = $ilDB->manipulate($query);
229 // end-patch lok
230
231 // refresh learning progress status after adding new objective
232 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
233 ilLPStatusWrapper::_refreshStatus($this->course_obj->getId());
234
235 return $this->objective_id = $next_id;
236 }
237
238 function update()
239 {
240 global $ilDB;
241
242 // begin-patch lok
243 $query = "UPDATE crs_objectives ".
244 "SET title = ".$ilDB->quote($this->getTitle() ,'text').", ".
245 'active = '.$ilDB->quote($this->isActive(),'integer').', '.
246 "description = ".$ilDB->quote($this->getDescription() ,'text').", ".
247 'passes = '.$ilDB->quote($this->getPasses(),'integer').' '.
248 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
249 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
250 $res = $ilDB->manipulate($query);
251 // end-patch lok
252
253 return true;
254 }
255
263 public function writePosition($a_position)
264 {
265 global $ilDB;
266
267 $query = "UPDATE crs_objectives ".
268 "SET position = ".$this->db->quote((string) $a_position ,'integer')." ".
269 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ";
270 $res = $ilDB->manipulate($query);
271 }
272
280 public function validate()
281 {
282 return (bool) strlen($this->getTitle());
283 }
284
285 function delete()
286 {
287 global $ilDB;
288
289 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
290
291 $tmp_obj_qst =& new ilCourseObjectiveQuestion($this->getObjectiveId());
292 $tmp_obj_qst->deleteAll();
293
294 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
295
296 $tmp_obj_lm =& new ilCourseObjectiveMaterials($this->getObjectiveId());
297 $tmp_obj_lm->deleteAll();
298
299
300 $query = "DELETE FROM crs_objectives ".
301 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ".
302 "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
303 $res = $ilDB->manipulate($query);
304
305 // refresh learning progress status after deleting objective
306 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
307 ilLPStatusWrapper::_refreshStatus($this->course_obj->getId());
308
309 return true;
310 }
311
312 function moveUp()
313 {
314 global $ilDB;
315
316 if(!$this->getObjectiveId())
317 {
318 return false;
319 }
320 // Stop if position is first
321 if($this->__getPosition() == 1)
322 {
323 return false;
324 }
325
326 $query = "UPDATE crs_objectives ".
327 "SET position = position + 1 ".
328 "WHERE position = ".$ilDB->quote($this->__getPosition() - 1 ,'integer')." ".
329 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
330 $res = $ilDB->manipulate($query);
331
332 $query = "UPDATE crs_objectives ".
333 "SET position = position - 1 ".
334 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
335 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
336 $res = $ilDB->manipulate($query);
337
338 $this->__read();
339
340 return true;
341 }
342
343 function moveDown()
344 {
345 global $ilDB;
346
347 if(!$this->getObjectiveId())
348 {
349 return false;
350 }
351 // Stop if position is last
352 if($this->__getPosition() == $this->__getLastPosition())
353 {
354 return false;
355 }
356
357 $query = "UPDATE crs_objectives ".
358 "SET position = position - 1 ".
359 "WHERE position = ".$ilDB->quote($this->__getPosition() + 1 ,'integer')." ".
360 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
361 $res = $ilDB->manipulate($query);
362
363 $query = "UPDATE crs_objectives ".
364 "SET position = position + 1 ".
365 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
366 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
367 $res = $ilDB->manipulate($query);
368
369 $this->__read();
370
371 return true;
372 }
373
374 // PRIVATE
375 function __setPosition($a_position)
376 {
377 $this->position = $a_position;
378 }
379 function __getPosition()
380 {
381 return $this->position;
382 }
383 function __setCreated($a_created)
384 {
385 $this->created = $a_created;
386 }
387 function __getCreated()
388 {
389 return $this->created;
390 }
391
392
393 function __read()
394 {
395 global $ilDB;
396
397 if($this->getObjectiveId())
398 {
399 $query = "SELECT * FROM crs_objectives ".
400 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ".
401 "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
402
403
404 $res = $this->db->query($query);
405 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
406 {
407 // begin-patch lok
408 $this->setActive($row->active);
409 $this->setPasses($row->passes);
410 // end-patch lok
411 $this->setObjectiveId($row->objective_id);
412 $this->setTitle($row->title);
413 $this->setDescription($row->description);
414 $this->__setPosition($row->position);
415 $this->__setCreated($row->created);
416 }
417 return true;
418 }
419 return false;
420 }
421
423 {
424 switch($this->course_obj->getOrderType())
425 {
427 return 'ORDER BY position';
428
430 return 'ORDER BY title';
431
433 return 'ORDER BY create';
434 }
435 return false;
436 }
437
438 function __updateTop()
439 {
440 global $ilDB;
441
442 $query = "UPDATE crs_objectives ".
443 "SET position = position - 1 ".
444 "WHERE position > ".$ilDB->quote($this->__getPosition() ,'integer')." ".
445 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
446 $res = $ilDB->manipulate($query);
447
448 return true;
449 }
450
452 {
453 global $ilDB;
454
455 $query = "SELECT MAX(position) pos FROM crs_objectives ".
456 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
457
458 $res = $this->db->query($query);
459 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
460 {
461 return $row->pos;
462 }
463 return 0;
464 }
465
466 // STATIC
467 // begin-patch lok
468 static function _getObjectiveIds($course_id, $a_activated_only = false)
469 {
470 global $ilDB;
471
472 if($a_activated_only)
473 {
474 $query = "SELECT objective_id FROM crs_objectives ".
475 "WHERE crs_id = ".$ilDB->quote($course_id ,'integer')." ".
476 'AND active = '.$ilDB->quote(1,'integer').' '.
477 "ORDER BY position";
478 }
479 else
480 {
481 $query = "SELECT objective_id FROM crs_objectives ".
482 "WHERE crs_id = ".$ilDB->quote($course_id ,'integer')." ".
483 "ORDER BY position";
484 }
485
486 $res = $ilDB->query($query);
487 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
488 {
489 $ids[] = $row->objective_id;
490 }
491
492 return $ids ? $ids : array();
493 }
494 // end-patch lok
495
496 function _deleteAll($course_id)
497 {
498 global $ilDB;
499
500 // begin-patch lok
501 $ids = ilCourseObjective::_getObjectiveIds($course_id,false);
502 // end-patch lok
503 if(!count($ids))
504 {
505 return true;
506 }
507
508 $in = $ilDB->in('objective_id',$ids,false,'integer');
509
510
511 $query = "DELETE FROM crs_objective_lm WHERE ".$in;
512 $res = $ilDB->manipulate($query);
513
514 $query = "DELETE FROM crs_objective_tst WHERE ".$in;
515 $res = $ilDB->manipulate($query);
516
517 $query = "DELETE FROM crs_objective_qst WHERE ".$in;
518 $res = $ilDB->manipulate($query);
519
520 $query = "DELETE FROM crs_objectives WHERE crs_id = ".$ilDB->quote($course_id ,'integer');
521 $res = $ilDB->manipulate($query);
522
523 // refresh learning progress status after deleting objectives
524 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
526
527 return true;
528 }
529}
530?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
class ilCourseObjectiveMaterials
class ilcourseobjectiveQuestion
class ilcourseobjective
static lookupObjectiveTitle($a_objective_id)
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
ilCourseObjective(&$course_obj, $a_objective_id=0)
static _getCountObjectives($a_obj_id, $a_activated_only=false)
get count objectives
static lookupMaxPasses($a_objective_id)
static _getObjectiveIds($course_id, $a_activated_only=false)
setDescription($a_description)
writePosition($a_position)
write position
setObjectiveId($a_objective_id)
ilClone($a_target_id, $a_copy_id)
clone objectives
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
global $ilDB