ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLOEditorStatus.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
6include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
7
15{
18 const SECTION_ITES = 3;
19 const SECTION_QTEST = 4;
22
24 protected static $instance = null;
25
27 protected $section = null;
28
30 protected $failures_by_section = array();
32 protected $error_by_section = array();
33
35 protected $objectives = array();
36
38 protected $settings = null;
40 protected $assignments = null;
42 protected $parent_obj = null;
44 protected $cmd_class = null;
46 protected $html = '';
47
49 protected $tpl = null;
51 protected $ctrl = null;
53 protected $lng = null;
54
59 public function __construct(ilObject $a_parent)
60 {
61 $this->parent_obj = $a_parent;
63 $this->assignments = ilLOTestAssignments::getInstance($this->getParentObject()->getId());
64
65 $this->ctrl = $GLOBALS['DIC']['ilCtrl'];
66 $this->lng = $GLOBALS['DIC']['lng'];
67
68 include_once './Modules/Course/classes/class.ilCourseObjective.php';
69 $this->objectives = ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId());
70 }
71
77 public static function getInstance(ilObject $a_parent)
78 {
79 if (self::$instance) {
80 return self::$instance;
81 }
82 return self::$instance = new self($a_parent);
83 }
84
88 public function getObjectives()
89 {
90 return $this->objectives;
91 }
92
97 public function getAssignments()
98 {
99 return $this->assignments;
100 }
101
102
107 public function setSection(int $a_section)
108 {
109 $this->section = $a_section;
110 }
111
115 public function getSection()
116 {
117 return $this->section;
118 }
119
125 public function getFailures($a_section)
126 {
127 return (array) $this->failures_by_section[$a_section];
128 }
129
136 protected function appendFailure(int $a_section, string $a_failure_msg_key, bool $is_error = false)
137 {
138 $this->failures_by_section[$a_section][] = $a_failure_msg_key;
139 if ($is_error) {
140 $this->error_by_section[$a_section] = $a_section;
141 }
142 }
143
148 public function setCmdClass($a_cmd_class)
149 {
150 $this->cmd_class = $a_cmd_class;
151 }
152
157 public function getCmdClass()
158 {
159 return $this->cmd_class;
160 }
161
162
167 public function getParentObject()
168 {
169 return $this->parent_obj;
170 }
171
175 public function getSettings()
176 {
177 return $this->settings;
178 }
179
185 public function getFirstFailedStep() : string
186 {
187 if (!$this->getSettingsStatus()) {
188 return 'settings';
189 }
190 #if(!$this->getMaterialsStatus(false))
191 #{
192 # return 'materials';
193 #}
194 if (!$this->getObjectivesAvailableStatus()) {
195 return 'showObjectiveCreation';
196 }
197 if ($this->getSettings()->worksWithInitialTest()) {
198 if (!$this->getInitialTestStatus(false)) {
199 $_REQUEST['tt'] = ilLOSettings::TYPE_TEST_INITIAL;
200 if ($this->getSettings()->hasSeparateInitialTests()) {
201 return 'testsOverview';
202 } else {
203 return 'testOverview';
204 }
205 }
206 }
207 if (!$this->getQualifiedTestStatus(false)) {
208 $_REQUEST['tt'] = ilLOSettings::TYPE_TEST_QUALIFIED;
209 if ($this->getSettings()->hasSeparateQualifiedTests()) {
210 return 'testsOverview';
211 } else {
212 return 'testOverview';
213 }
214 }
215 if (!$this->getObjectivesStatus(false)) {
216 return 'listObjectives';
217 }
218 return 'listObjectives';
219 }
220
221
227 public function getHTML() : string
228 {
229 global $DIC;
230 $steps = [];
231 $workflow = $DIC->ui()->factory()->listing()->workflow();
232 // Step 1
233 // course settings
234 $done = $this->getSettingsStatus();
235
236 $steps[] = $workflow->step(
237 $this->lng->txt('crs_objective_status_settings'),
238 implode(" ", $this->getFailureMessages(self::SECTION_SETTINGS)),
239 $this->ctrl->getLinkTarget($this->getCmdClass(), 'settings')
240 )->withStatus($this->determineStatus($done, self::SECTION_SETTINGS));
241
242
243 // Step 1.1
244 $done = $this->getObjectivesAvailableStatus(true);
245
246 $steps[] = $workflow->step(
247 $this->lng->txt('crs_objective_status_objective_creation'),
248 implode(" ", $this->getFailureMessages(self::SECTION_OBJECTIVES_NEW)),
249 $done
250 ? $this->ctrl->getLinkTarget($this->getCmdClass(), 'listObjectives')
251 : $this->ctrl->getLinkTarget($this->getCmdClass(), 'showObjectiveCreation')
252 )->withStatus($this->determineStatus($done, self::SECTION_OBJECTIVES_NEW));
253
254 // Step 2
255 // course material
256 $done = $this->getMaterialsStatus(true);
257 $this->ctrl->setParameterByClass('ilobjcoursegui', 'cmd', 'enableAdministrationPanel');
258
259 $steps[] = $workflow->step(
260 $this->lng->txt('crs_objective_status_materials'),
261 implode(" ", $this->getFailureMessages(self::SECTION_MATERIALS)),
262 $this->ctrl->getLinkTargetByClass('ilobjcoursegui', '')
263 )->withStatus($this->determineStatus($done, self::SECTION_MATERIALS));
264
265 // Step 3
266 // course itest
267 if (ilLOSettings::getInstanceByObjId($this->getParentObject()->getId())->worksWithInitialTest()) {
268 $done = $this->getInitialTestStatus();
269 $command = $this->getSettings()->hasSeparateInitialTests() ?
270 'testsOverview' :
271 'testOverview';
272 $this->ctrl->setParameter($this->getCmdClass(), 'tt', ilLOSettings::TYPE_TEST_INITIAL);
273
274 $steps[] = $workflow->step(
275 $this->lng->txt('crs_objective_status_itest'),
276 implode(" ", $this->getFailureMessages(self::SECTION_ITES)),
277 $this->ctrl->getLinkTarget($this->getCmdClass(), $command)
278 )->withStatus($this->determineStatus($done, self::SECTION_ITES));
279 }
280
281 // Step 4
282 // course qtest
283 $done = $this->getQualifiedTestStatus();
284 $command = $this->getSettings()->hasSeparateQualifiedTests() ?
285 'testsOverview' :
286 'testOverview';
287 $this->ctrl->setParameter($this->getCmdClass(), 'tt', ilLOSettings::TYPE_TEST_QUALIFIED);
288
289 $steps[] = $workflow->step(
290 $this->lng->txt('crs_objective_status_qtest'),
291 implode(" ", $this->getFailureMessages(self::SECTION_QTEST)),
292 $this->ctrl->getLinkTarget($this->getCmdClass(), $command)
293 )->withStatus($this->determineStatus($done, self::SECTION_QTEST));
294
295 // Step 5
296 // course qtest
297 $done = $this->getObjectivesStatus();
298 $this->ctrl->setParameter($this->getCmdClass(), 'tt', $_GET["tt"]);
299
300 $steps[] = $workflow->step(
301 $this->lng->txt('crs_objective_status_objectives'),
302 implode(" ", $this->getFailureMessages(self::SECTION_OBJECTIVES)),
303 $this->ctrl->getLinkTarget($this->getCmdClass(), 'listObjectives')
304 )->withStatus($this->determineStatus($done, self::SECTION_OBJECTIVES));
305
306 $list = $workflow->linear(
307 $this->lng->txt('crs_objective_status_configure'),
308 $steps
309 )
310 ->withActive($this->determineActiveSection());
311
312 $renderer = $DIC->ui()->renderer();
313 return $renderer->render($list);
314 }
315
316
323 public function getFailureMessages($a_section)
324 {
325 $mess = array();
326 foreach ($this->getFailures($a_section) as $failure_code) {
327 $mess[] = $this->lng->txt($failure_code);
328 }
329 return $mess;
330 }
331
339 public function determineStatus(bool $done, int $section) : int
340 {
341 if ($done) {
342 return Step::SUCCESSFULLY;
343 } elseif ($this->hasSectionErrors($section)) {
344 return Step::UNSUCCESSFULLY;
345 } else {
346 if ($this->section == $section) {
347 return Step::IN_PROGRESS;
348 } else {
349 return Step::NOT_STARTED;
350 }
351 }
352 }
353
359 public function determineActiveSection() : int
360 {
361 $itest_enabled = ilLOSettings::getInstanceByObjId($this->getParentObject()->getId())->worksWithInitialTest();
362 $active_map = array(
363 self::SECTION_SETTINGS => 0,
364 self::SECTION_OBJECTIVES_NEW => 1,
365 self::SECTION_MATERIALS => 2,
366 self::SECTION_ITES => 3,
367 self::SECTION_QTEST => $itest_enabled ? 4 : 3,
368 self::SECTION_OBJECTIVES => $itest_enabled ? 5 : 4
369 );
370
371 return $active_map[$this->section];
372 }
373
378 public function hasSectionErrors($a_section) : bool
379 {
380 return isset($this->error_by_section[$a_section]);
381 }
382
387 protected function getSettingsStatus() : bool
388 {
389 return $this->getSettings()->settingsExist();
390 }
391
398 protected function getObjectivesAvailableStatus($a_set_errors = false)
399 {
400 $ret = count($this->getObjectives());
401
402 if (!$ret && $a_set_errors) {
403 $this->appendFailure(self::SECTION_OBJECTIVES_NEW, 'crs_no_objectives_created');
404 }
405
406 return $ret;
407 }
408
414 protected function getMaterialsStatus($a_set_errors = true) : bool
415 {
416 $childs = $GLOBALS['DIC']['tree']->getChilds($this->getParentObject()->getRefId());
417 foreach ((array) $childs as $tnode) {
418 if ($tnode['type'] == 'rolf') {
419 continue;
420 }
421 if ($tnode['child'] == $this->getSettings()->getInitialTest()) {
422 continue;
423 }
424 if ($tnode['child'] == $this->getSettings()->getQualifiedTest()) {
425 continue;
426 }
427 return true;
428 }
429 if ($a_set_errors) {
430 $this->appendFailure(self::SECTION_MATERIALS, 'crs_loc_err_stat_no_materials');
431 }
432 return false;
433 }
434
440 protected function getInitialTestStatus($a_set_errors = true) : bool
441 {
442 if ($this->getSettings()->hasSeparateInitialTests()) {
443 if (count($this->objectives) <= 0) {
444 return false;
445 }
446
447 foreach ($this->getObjectives() as $objective_id) {
448 $tst_ref = $this->getAssignments()->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
449 if (!$GLOBALS['DIC']['tree']->isInTree($tst_ref)) {
450 if ($a_set_errors) {
451 $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_no_it');
452 }
453 return false;
454 }
455 if (!$this->checkTestOnline($tst_ref)) {
456 if ($a_set_errors) {
457 $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_tst_offline', true);
458 }
459 return false;
460 }
461 }
462 return true;
463 }
464
465
466 $tst_ref = $this->getSettings()->getInitialTest();
467 if (!$GLOBALS['DIC']['tree']->isInTree($tst_ref)) {
468 if ($a_set_errors) {
469 $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_no_it');
470 }
471 return false;
472 }
473 if (!$this->checkTestOnline($tst_ref)) {
474 if ($a_set_errors) {
475 $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_tst_offline', true);
476 }
477 return false;
478 }
479 return true;
480 }
481
487 protected function getQualifiedTestStatus($a_set_errors = true) : bool
488 {
489 if ($this->getSettings()->hasSeparateQualifiedTests()) {
490 if (count($this->objectives) <= 0) {
491 return false;
492 }
493
494 foreach ($this->getObjectives() as $objective_id) {
495 $tst_ref = $this->getAssignments()->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
496 if (!$GLOBALS['DIC']['tree']->isInTree($tst_ref)) {
497 if ($a_set_errors) {
498 $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_no_qt');
499 }
500 return false;
501 }
502 if (!$this->checkTestOnline($tst_ref)) {
503 if ($a_set_errors) {
504 $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_tst_offline', true);
505 }
506 return false;
507 }
508 }
509 return true;
510 }
511 $tst_ref = $this->getSettings()->getQualifiedTest();
512 if (!$GLOBALS['DIC']['tree']->isInTree($tst_ref)) {
513 if ($a_set_errors) {
514 $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_no_qt');
515 }
516 return false;
517 }
518 if (!$this->checkTestOnline($tst_ref)) {
519 if ($a_set_errors) {
520 $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_tst_offline', true);
521 }
522 return false;
523 }
524 return true;
525 }
526
532 protected function lookupQuestionsAssigned($a_test_ref_id) : bool
533 {
534 include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
536 foreach ($this->getObjectives() as $objective_id) {
537 include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
539 $this->parent_obj->getId(),
540 $objective_id,
541 ilObject::_lookupObjId($a_test_ref_id)
542 );
543 if (!$seq) {
544 return false;
545 }
546 }
547 } else {
548 foreach ($this->getObjectives() as $objective_id) {
549 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
551 if (!count($qsts)) {
552 return false;
553 }
554 }
555 }
556 return true;
557 }
558
563 protected function getObjectivesStatus($a_set_errors = true) : bool
564 {
565 if (!$this->getObjectivesAvailableStatus($a_set_errors)) {
566 return false;
567 }
568
569 include_once './Modules/Course/classes/class.ilCourseObjective.php';
570 $num_active = ilCourseObjective::_getCountObjectives($this->getParentObject()->getId(), true);
571 if (!$num_active) {
572 if ($a_set_errors) {
573 $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_lo');
574 }
575 return false;
576 }
577 foreach (ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId(), true) as $objective_id) {
578 include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
579 $obj = new ilCourseObjectiveMaterials($objective_id);
580 if (!count($obj->getMaterials())) {
581 if ($a_set_errors) {
582 $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_mat');
583 }
584 return false;
585 }
586 }
587 // check for assigned initial test questions
588 if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) {
589 // check for assigned questions
590 if (!$this->lookupQuestionsAssigned($this->getSettings()->getInitialTest())) {
591 if ($a_set_errors) {
592 $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_qst');
593 }
594 return false;
595 }
596 }
597 // check for assigned questions
598 if (!$this->getSettings()->hasSeparateQualifiedTests() and !$this->lookupQuestionsAssigned($this->getSettings()->getQualifiedTest())) {
599 if ($a_set_errors) {
600 $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_qst');
601 }
602 return false;
603 }
604
605 // @deprecated
606 /*
607 if(!$this->checkNumberOfTries())
608 {
609 if($a_set_errors)
610 {
611 $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_nr_tries_exceeded');
612 }
613 return false;
614 }
615 */
616
617 return true;
618 }
619
620 protected function getStartStatus()
621 {
622 return true;
623 }
624
625 protected function checkNumberOfTries()
626 {
627 $qt = $this->getSettings()->getQualifiedTest();
628 if (!$qt) {
629 return true;
630 }
631
632 include_once './Services/Object/classes/class.ilObjectFactory.php';
634 $tst = $factory->getInstanceByRefId($qt, false);
635
636 if (!$tst instanceof ilObjTest) {
637 return true;
638 }
639 $tries = $tst->getNrOfTries();
640 if (!$tries) {
641 return true;
642 }
643
644 $obj_tries = 0;
645 foreach ($this->getObjectives() as $objective) {
646 include_once './Modules/Course/classes/class.ilCourseObjective.php';
647 $obj_tries += ilCourseObjective::lookupMaxPasses($objective);
648 }
649 $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ' . $obj_tries);
650 return $obj_tries <= $tries;
651 }
652
658 protected function checkTestOnline($a_ref_id) : bool
659 {
660 include_once './Modules/Test/classes/class.ilObjTestAccess.php';
662 }
663}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
class ilCourseObjectiveMaterials
static lookupQuestionsByObjective($a_test_id, $a_objective)
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)
Presentation of the status of single steps during the configuration process.
getSettingsStatus()
Check if course is lo confgured.
lookupQuestionsAssigned($a_test_ref_id)
Check if questions are assigned.
checkTestOnline($a_ref_id)
Check if test is online.
setSection(int $a_section)
Set current section.
getMaterialsStatus($a_set_errors=true)
Get status of materials.
getInitialTestStatus($a_set_errors=true)
Get initial test status.
getQualifiedTestStatus($a_set_errors=true)
Check status of qualified test.
static getInstance(ilObject $a_parent)
Get instance.
determineStatus(bool $done, int $section)
Determines workflow status of section.
getFirstFailedStep()
Get first failed step.
getFailures($a_section)
Get failures by section.
getCmdClass()
Get cmd class.
setCmdClass($a_cmd_class)
Command class.
appendFailure(int $a_section, string $a_failure_msg_key, bool $is_error=false)
Append failure.
getObjectivesAvailableStatus($a_set_errors=false)
getParentObject()
Get parent object.
getFailureMessages($a_section)
Get error messages.
getObjectivesStatus($a_set_errors=true)
__construct(ilObject $a_parent)
Constructor.
determineActiveSection()
Determines active section position of workflow.
static lookupSequences($a_container_id, $a_objective_id, $a_test_id)
Lookup sequence ids @global type $ilDB.
static getInstanceByObjId($a_obj_id)
get singleton instance
static getInstance($a_container_id)
Get instance by container id.
static lookupRandomTest($a_test_obj_id)
Check if test is a random test.
static _isOffline($a_obj_id)
returns the objects's OFFline status
Class ilObjectFactory.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
$factory
Definition: metadata.php:58
$ret
Definition: parser.php:6
settings()
Definition: settings.php:2
$steps
Definition: latex.php:3
$DIC
Definition: xapitoken.php:46