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