ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
30 public function __construct($course_obj,$a_objective_id = 0)
31 {
32 global $ilDB;
33
34 $this->db = $ilDB;
35 $this->course_obj = $course_obj;
36
37 $this->objective_id = $a_objective_id;
38 if($this->objective_id)
39 {
40 $this->__read();
41 }
42 }
43
47 public function getCourse()
48 {
49 return $this->course_obj;
50 }
51
60 public static function _lookupContainerIdByObjectiveId($a_objective_id)
61 {
62 global $ilDB;
63
64 $query = "SELECT crs_id FROM crs_objectives ".
65 "WHERE objective_id = ".$ilDB->quote($a_objective_id ,'integer');
66 $res = $ilDB->query($query);
67 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
68 {
69 return $row->crs_id;
70 }
71 return false;
72 }
73
82 // begin-patch lok
83 public static function _getCountObjectives($a_obj_id,$a_activated_only = false)
84 {
85 return count(ilCourseObjective::_getObjectiveIds($a_obj_id,$a_activated_only));
86 }
87
88 public static function lookupMaxPasses($a_objective_id)
89 {
90 global $ilDB;
91
92 $query = 'SELECT passes from crs_objectives '.
93 'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer');
94 $res = $ilDB->query($query);
95 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
96 {
97 return (int) $row->passes;
98 }
99 return 0;
100 }
101
102 public static function lookupObjectiveTitle($a_objective_id, $a_add_description = false)
103 {
104 global $ilDB;
105
106 $query = 'SELECT title,description from crs_objectives '.
107 'WHERE objective_id = '.$ilDB->quote($a_objective_id,'integer');
108 $res = $ilDB->query($query);
109 while($row = $ilDB->fetchAssoc($res))
110 {
111 if(!$a_add_description)
112 {
113 return $row['title'];
114 }
115 else
116 {
117 return $row;
118 }
119 }
120 return "";
121 }
122 // end-patch lok
123
132 public function ilClone($a_target_id,$a_copy_id)
133 {
134 global $ilLog;
135
136 ilLoggerFactory::getLogger('crs')->debug('Start cloning learning objectives');
137
138 $query = "SELECT * FROM crs_objectives ".
139 "WHERE crs_id = ".$this->db->quote($this->course_obj->getId() ,'integer').' '.
140 "ORDER BY position ";
141 $res = $this->db->query($query);
142 if(!$res->numRows())
143 {
144 ilLoggerFactory::getLogger('crs')->debug('.. no objectives found');
145 return true;
146 }
147
148 if(!is_object($new_course = ilObjectFactory::getInstanceByRefId($a_target_id,false)))
149 {
150 ilLoggerFactory::getLogger('crs')->warning('Cannot create course instance');
151 return true;
152 }
153 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
154 {
155 $new_objective = new ilCourseObjective($new_course);
156 $new_objective->setTitle($row->title);
157 $new_objective->setDescription($row->description);
158 $new_objective->setActive($row->active);
159 $objective_id = $new_objective->add();
160 ilLoggerFactory::getLogger('crs')->debug('Added new objective nr: ' . $objective_id);
161
162 // Clone crs_objective_tst entries
163 include_once('Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
164 $objective_qst = new ilCourseObjectiveQuestion($row->objective_id);
165 $objective_qst->cloneDependencies($objective_id,$a_copy_id);
166
167 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
168 include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
169 $random_i = new ilLORandomTestQuestionPools(
170 $this->getCourse()->getId(),
171 $row->objective_id,
173 );
174 $random_i->copy($a_copy_id, $new_course->getId(), $objective_id);
175
176 $random_q = new ilLORandomTestQuestionPools(
177 $this->getCourse()->getId(),
178 $row->objective_id,
180 );
181 $random_q->copy($a_copy_id, $new_course->getId(), $objective_id);
182
183 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
184 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
185 $assignment_it = $assignments->getAssignmentByObjective($row->objective_id, ilLOSettings::TYPE_TEST_INITIAL);
186 if($assignment_it)
187 {
188 $assignment_it->cloneSettings($a_copy_id, $new_course->getId(), $objective_id);
189 }
190
191 $assignment_qt = $assignments->getAssignmentByObjective($row->objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
192 if($assignment_qt)
193 {
194 $assignment_qt->cloneSettings($a_copy_id, $new_course->getId(), $objective_id);
195 }
196
197 ilLoggerFactory::getLogger('crs')->debug('Finished copying question dependencies');
198
199 // Clone crs_objective_lm entries (assigned course materials)
200 include_once('Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
201 $objective_material = new ilCourseObjectiveMaterials($row->objective_id);
202 $objective_material->cloneDependencies($objective_id,$a_copy_id);
203 }
204 ilLoggerFactory::getLogger('crs')->debug('Finished copying objectives');
205 }
206
207 // begin-patch lok
208 public function setActive($a_stat)
209 {
210 $this->active = $a_stat;
211 }
212
213 public function isActive()
214 {
215 return $this->active;
216 }
217
218 public function setPasses($a_passes)
219 {
220 $this->passes = $a_passes;
221 }
222
223 public function getPasses()
224 {
225 return $this->passes;
226 }
227
228 public function arePassesLimited()
229 {
230 return $this->passes > 0;
231 }
232 // end-patch lok
233
234 function setTitle($a_title)
235 {
236 $this->title = $a_title;
237 }
238 function getTitle()
239 {
240 return $this->title;
241 }
242 function setDescription($a_description)
243 {
244 $this->description = $a_description;
245 }
246 function getDescription()
247 {
248 return $this->description;
249 }
250 function setObjectiveId($a_objective_id)
251 {
252 $this->objective_id = $a_objective_id;
253 }
254 function getObjectiveId()
255 {
256 return $this->objective_id;
257 }
258
259 // begin-patch optes_lok_export
260 public function setPosition($a_pos)
261 {
262 $this->position = $a_pos;
263 }
264 // end-patch optes_lok_export
265
266 function add()
267 {
268 global $ilDB;
269
270 // begin-patch lok
271 $next_id = $ilDB->nextId('crs_objectives');
272 $query = "INSERT INTO crs_objectives (crs_id,objective_id,active,title,description,position,created,passes) ".
273 "VALUES( ".
274 $ilDB->quote($this->course_obj->getId() ,'integer').", ".
275 $ilDB->quote($next_id,'integer').", ".
276 $ilDB->quote($this->isActive(),'integer').', '.
277 $ilDB->quote($this->getTitle() ,'text').", ".
278 $ilDB->quote($this->getDescription() ,'text').", ".
279 $ilDB->quote($this->__getLastPosition() + 1 ,'integer').", ".
280 $ilDB->quote(time() ,'integer').", ".
281 $ilDB->quote($this->getPasses(),'integer').' '.
282 ")";
283 $res = $ilDB->manipulate($query);
284 // end-patch lok
285
286 // refresh learning progress status after adding new objective
287 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
288 ilLPStatusWrapper::_refreshStatus($this->course_obj->getId());
289
290 return $this->objective_id = $next_id;
291 }
292
293 function update()
294 {
295 global $ilDB;
296
297 // begin-patch lok
298 $query = "UPDATE crs_objectives ".
299 "SET title = ".$ilDB->quote($this->getTitle() ,'text').", ".
300 'active = '.$ilDB->quote($this->isActive(),'integer').', '.
301 "description = ".$ilDB->quote($this->getDescription() ,'text').", ".
302 'passes = '.$ilDB->quote($this->getPasses(),'integer').' '.
303 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
304 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
305 $res = $ilDB->manipulate($query);
306 // end-patch lok
307
308 return true;
309 }
310
318 public function writePosition($a_position)
319 {
320 global $ilDB;
321
322 $query = "UPDATE crs_objectives ".
323 "SET position = ".$this->db->quote((string) $a_position ,'integer')." ".
324 "WHERE objective_id = ".$this->db->quote($this->getObjectiveId() ,'integer')." ";
325 $res = $ilDB->manipulate($query);
326 }
327
335 public function validate()
336 {
337 return (bool) strlen($this->getTitle());
338 }
339
340 function delete()
341 {
342 global $ilDB;
343
344 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
345
346 $tmp_obj_qst = new ilCourseObjectiveQuestion($this->getObjectiveId());
347 $tmp_obj_qst->deleteAll();
348
349 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
350
351 $tmp_obj_lm = new ilCourseObjectiveMaterials($this->getObjectiveId());
352 $tmp_obj_lm->deleteAll();
353
354
355 $query = "DELETE FROM crs_objectives ".
356 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ".
357 "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
358 $res = $ilDB->manipulate($query);
359
360 // refresh learning progress status after deleting objective
361 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
362 ilLPStatusWrapper::_refreshStatus($this->course_obj->getId());
363
364 return true;
365 }
366
367 function moveUp()
368 {
369 global $ilDB;
370
371 if(!$this->getObjectiveId())
372 {
373 return false;
374 }
375 // Stop if position is first
376 if($this->__getPosition() == 1)
377 {
378 return false;
379 }
380
381 $query = "UPDATE crs_objectives ".
382 "SET position = position + 1 ".
383 "WHERE position = ".$ilDB->quote($this->__getPosition() - 1 ,'integer')." ".
384 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
385 $res = $ilDB->manipulate($query);
386
387 $query = "UPDATE crs_objectives ".
388 "SET position = position - 1 ".
389 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
390 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
391 $res = $ilDB->manipulate($query);
392
393 $this->__read();
394
395 return true;
396 }
397
398 function moveDown()
399 {
400 global $ilDB;
401
402 if(!$this->getObjectiveId())
403 {
404 return false;
405 }
406 // Stop if position is last
407 if($this->__getPosition() == $this->__getLastPosition())
408 {
409 return false;
410 }
411
412 $query = "UPDATE crs_objectives ".
413 "SET position = position - 1 ".
414 "WHERE position = ".$ilDB->quote($this->__getPosition() + 1 ,'integer')." ".
415 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
416 $res = $ilDB->manipulate($query);
417
418 $query = "UPDATE crs_objectives ".
419 "SET position = position + 1 ".
420 "WHERE objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ".
421 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
422 $res = $ilDB->manipulate($query);
423
424 $this->__read();
425
426 return true;
427 }
428
429 // PRIVATE
430 function __setPosition($a_position)
431 {
432 $this->position = $a_position;
433 }
434 function __getPosition()
435 {
436 return $this->position;
437 }
438 function __setCreated($a_created)
439 {
440 $this->created = $a_created;
441 }
442 function __getCreated()
443 {
444 return $this->created;
445 }
446
447
448 function __read()
449 {
450 global $ilDB;
451
452 if($this->getObjectiveId())
453 {
454 $query = "SELECT * FROM crs_objectives ".
455 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ".
456 "AND objective_id = ".$ilDB->quote($this->getObjectiveId() ,'integer')." ";
457
458
459 $res = $this->db->query($query);
460 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
461 {
462 // begin-patch lok
463 $this->setActive($row->active);
464 $this->setPasses($row->passes);
465 // end-patch lok
466 $this->setObjectiveId($row->objective_id);
467 $this->setTitle($row->title);
468 $this->setDescription($row->description);
469 $this->__setPosition($row->position);
470 $this->__setCreated($row->created);
471 }
472 return true;
473 }
474 return false;
475 }
476
478 {
479 switch($this->course_obj->getOrderType())
480 {
482 return 'ORDER BY position';
483
485 return 'ORDER BY title';
486
488 return 'ORDER BY create';
489 }
490 return false;
491 }
492
493 function __updateTop()
494 {
495 global $ilDB;
496
497 $query = "UPDATE crs_objectives ".
498 "SET position = position - 1 ".
499 "WHERE position > ".$ilDB->quote($this->__getPosition() ,'integer')." ".
500 "AND crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
501 $res = $ilDB->manipulate($query);
502
503 return true;
504 }
505
507 {
508 global $ilDB;
509
510 $query = "SELECT MAX(position) pos FROM crs_objectives ".
511 "WHERE crs_id = ".$ilDB->quote($this->course_obj->getId() ,'integer')." ";
512
513 $res = $this->db->query($query);
514 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
515 {
516 return $row->pos;
517 }
518 return 0;
519 }
520
521 // STATIC
522 // begin-patch lok
523 static function _getObjectiveIds($course_id, $a_activated_only = false)
524 {
525 global $ilDB;
526
527 if($a_activated_only)
528 {
529 $query = "SELECT objective_id FROM crs_objectives ".
530 "WHERE crs_id = ".$ilDB->quote($course_id ,'integer')." ".
531 'AND active = '.$ilDB->quote(1,'integer').' '.
532 "ORDER BY position";
533 }
534 else
535 {
536 $query = "SELECT objective_id FROM crs_objectives ".
537 "WHERE crs_id = ".$ilDB->quote($course_id ,'integer')." ".
538 "ORDER BY position";
539 }
540
541 $res = $ilDB->query($query);
542 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
543 {
544 $ids[] = $row->objective_id;
545 }
546
547 return $ids ? $ids : array();
548 }
549 // end-patch lok
550
551 static function _deleteAll($course_id)
552 {
553 global $ilDB;
554
555 // begin-patch lok
556 $ids = ilCourseObjective::_getObjectiveIds($course_id,false);
557 // end-patch lok
558 if(!count($ids))
559 {
560 return true;
561 }
562
563 $in = $ilDB->in('objective_id',$ids,false,'integer');
564
565
566 $query = "DELETE FROM crs_objective_lm WHERE ".$in;
567 $res = $ilDB->manipulate($query);
568
569 $query = "DELETE FROM crs_objective_tst WHERE ".$in;
570 $res = $ilDB->manipulate($query);
571
572 $query = "DELETE FROM crs_objective_qst WHERE ".$in;
573 $res = $ilDB->manipulate($query);
574
575 $query = "DELETE FROM crs_objectives WHERE crs_id = ".$ilDB->quote($course_id ,'integer');
576 $res = $ilDB->manipulate($query);
577
578 // refresh learning progress status after deleting objectives
579 include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
581
582 return true;
583 }
584
585 // begin-patch optes_lok_export
590 public function toXml(ilXmlWriter $writer)
591 {
592 $writer->xmlStartTag(
593 'Objective',
594 array(
595 'online' => (int) $this->isActive(),
596 'position' => (int) $this->position,
597 'id' => (int) $this->getObjectiveId()
598 )
599 );
600 $writer->xmlElement('Title',array(), $this->getTitle());
601 $writer->xmlElement('Description',array(), $this->getDescription());
602
603 // materials
604 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
605 $materials = new ilCourseObjectiveMaterials($this->getObjectiveId());
606 $materials->toXml($writer);
607
608 // test/questions
609 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
611 $test->toXml($writer);
612
613 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
614 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId());
615 $assignments->toXml($writer, $this->getObjectiveId());
616
617 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
619
620 $writer->xmlEndTag('Objective');
621 }
622 // end-patch optes_lok_export
623}
624?>
$test
Definition: Utf8Test.php:84
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
An exception for terminatinating execution or to throw for unit testing.
class ilCourseObjectiveMaterials
class ilcourseobjectiveQuestion
class ilcourseobjective
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
static _lookupContainerIdByObjectiveId($a_objective_id)
Get container of object.
static _getCountObjectives($a_obj_id, $a_activated_only=false)
get count objectives
static _deleteAll($course_id)
static lookupMaxPasses($a_objective_id)
static _getObjectiveIds($course_id, $a_activated_only=false)
setDescription($a_description)
toXml(ilXmlWriter $writer)
write objective xml
__construct($course_obj, $a_objective_id=0)
Constructor.
writePosition($a_position)
write position
setObjectiveId($a_objective_id)
ilClone($a_target_id, $a_copy_id)
clone objectives
static toXml(ilXmlWriter $writer, $a_objective_id)
static getInstance($a_container_id)
Get instance by container id.
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
static getLogger($a_component_id)
Get component logger.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
global $ilDB