ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
5 
13 {
14  const SECTION_SETTINGS = 1;
15  const SECTION_MATERIALS = 2;
16  const SECTION_ITES = 3;
17  const SECTION_QTEST = 4;
18  const SECTION_OBJECTIVES = 5;
20 
21  protected static $instance = null;
22 
23 
24  protected $section = null;
25 
26  protected $failures_by_section = array();
27 
28  protected $objectives = array();
29 
30  protected $settings = null;
31  protected $assignments = null;
32  protected $parent_obj = null;
33  protected $cmd_class = null;
34  protected $html = '';
35 
36  protected $tpl = null;
37  protected $ctrl = null;
38  protected $lng = null;
39 
44  public function __construct(ilObject $a_parent)
45  {
46  $this->parent_obj = $a_parent;
47  $this->settings = ilLOSettings::getInstanceByObjId($this->getParentObject()->getId());
48  $this->assignments = ilLOTestAssignments::getInstance($this->getParentObject()->getId());
49 
50  $this->ctrl = $GLOBALS['ilCtrl'];
51  $this->lng = $GLOBALS['lng'];
52 
53  include_once './Modules/Course/classes/class.ilCourseObjective.php';
54  $this->objectives = ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId());
55  }
56 
61  public static function getInstance(ilObject $a_parent)
62  {
63  if (self::$instance) {
64  return self::$instance;
65  }
66  return self::$instance = new self($a_parent);
67  }
68 
72  public function getObjectives()
73  {
74  return $this->objectives;
75  }
76 
81  public function getAssignments()
82  {
83  return $this->assignments;
84  }
85 
86 
91  public function setSection($a_section)
92  {
93  $this->section = $a_section;
94  }
95 
96  public function getSection()
97  {
98  return $this->section;
99  }
100 
105  public function getFailures($a_section)
106  {
107  return (array) $this->failures_by_section[$a_section];
108  }
109 
115  protected function appendFailure($a_section, $a_failure_msg_key)
116  {
117  $this->failures_by_section[$a_section][] = $a_failure_msg_key;
118  }
119 
124  public function setCmdClass($a_cmd_class)
125  {
126  $this->cmd_class = $a_cmd_class;
127  }
128 
133  public function getCmdClass()
134  {
135  return $this->cmd_class;
136  }
137 
138 
143  public function getParentObject()
144  {
145  return $this->parent_obj;
146  }
147 
148  /*
149  * @return ilLOSettings
150  */
151  public function getSettings()
152  {
153  return $this->settings;
154  }
155 
159  public function getFirstFailedStep()
160  {
161  if (!$this->getSettingsStatus(false)) {
162  return 'settings';
163  }
164  #if(!$this->getMaterialsStatus(false))
165  #{
166  # return 'materials';
167  #}
168  if (!$this->getObjectivesAvailableStatus()) {
169  return 'showObjectiveCreation';
170  }
171  if ($this->getSettings()->worksWithInitialTest()) {
172  if (!$this->getInitialTestStatus(false)) {
173  $_REQUEST['tt'] = ilLOSettings::TYPE_TEST_INITIAL;
174  if ($this->getSettings()->hasSeparateInitialTests()) {
175  return 'testsOverview';
176  } else {
177  return 'testOverview';
178  }
179  }
180  }
181  if (!$this->getQualifiedTestStatus(false)) {
182  $_REQUEST['tt'] = ilLOSettings::TYPE_TEST_QUALIFIED;
183  if ($this->getSettings()->hasSeparateQualifiedTests()) {
184  return 'testsOverview';
185  } else {
186  return 'testOverview';
187  }
188  }
189  if (!$this->getObjectivesStatus(false)) {
190  return 'listObjectives';
191  }
192  return 'listObjectives';
193  }
194 
195 
199  public function getHTML()
200  {
201  include_once("./Services/UIComponent/Checklist/classes/class.ilChecklistGUI.php");
202  $list = new ilChecklistGUI();
203  $list->setHeading($this->lng->txt('crs_objective_status_configure'));
204 
205 
206  // Step 1
207  // course settings
208  $done = $this->getSettingsStatus();
209 
210  $list->addEntry(
211  $this->lng->txt('crs_objective_status_settings'),
212  $this->ctrl->getLinkTarget($this->getCmdClass(), 'settings'),
213  $done
216  ($this->section == self::SECTION_SETTINGS),
217  $this->getErrorMessages(self::SECTION_SETTINGS)
218  );
219 
220 
221  // Step 1.1
222  $done = $this->getObjectivesAvailableStatus(true);
223 
224  $list->addEntry(
225  $this->lng->txt('crs_objective_status_objective_creation'),
226  $done
227  ? $this->ctrl->getLinkTarget($this->getCmdClass(), 'listObjectives')
228  : $this->ctrl->getLinkTarget($this->getCmdClass(), 'showObjectiveCreation'),
229  $done
232  ($this->section == self::SECTION_OBJECTIVES_NEW),
233  $this->getErrorMessages(self::SECTION_OBJECTIVES_NEW)
234  );
235 
236  // Step 2
237  // course material
238  $done = $this->getMaterialsStatus(true);
239 
240  $this->ctrl->setParameterByClass('ilobjcoursegui', 'cmd', 'enableAdministrationPanel');
241  $list->addEntry(
242  $this->lng->txt('crs_objective_status_materials'),
243  $this->ctrl->getLinkTargetByClass('ilobjcoursegui', ''),
244  $done
247  ($this->section == self::SECTION_MATERIALS),
248  $this->getErrorMessages(self::SECTION_MATERIALS)
249  );
250 
251 
252  // Step 3
253  // course itest
254  if (ilLOSettings::getInstanceByObjId($this->getParentObject()->getId())->worksWithInitialTest()) {
255  $done = $this->getInitialTestStatus();
256 
257  $command = $this->getSettings()->hasSeparateInitialTests() ?
258  'testsOverview' :
259  'testOverview';
260 
261  $this->ctrl->setParameter($this->getCmdClass(), 'tt', ilLOSettings::TYPE_TEST_INITIAL);
262  $list->addEntry(
263  $this->lng->txt('crs_objective_status_itest'),
264  $this->ctrl->getLinkTarget($this->getCmdClass(), $command),
265  $done
268  ($this->section == self::SECTION_ITES),
269  $this->getErrorMessages(self::SECTION_ITES)
270  );
271  }
272 
273  // Step 4
274  // course qtest
275  $done = $this->getQualifiedTestStatus();
276 
277  $command = $this->getSettings()->hasSeparateQualifiedTests() ?
278  'testsOverview' :
279  'testOverview';
280 
281  $this->ctrl->setParameter($this->getCmdClass(), 'tt', ilLOSettings::TYPE_TEST_QUALIFIED);
282  $list->addEntry(
283  $this->lng->txt('crs_objective_status_qtest'),
284  $this->ctrl->getLinkTarget($this->getCmdClass(), $command),
285  $done
288  ($this->section == self::SECTION_QTEST),
289  $this->getErrorMessages(self::SECTION_QTEST)
290  );
291 
292  $this->ctrl->setParameter($this->getCmdClass(), 'tt', $_GET["tt"]);
293 
294  // Step 5
295  // course qtest
296  $done = $this->getObjectivesStatus();
297 
298  $list->addEntry(
299  $this->lng->txt('crs_objective_status_objectives'),
300  $this->ctrl->getLinkTarget($this->getCmdClass(), 'listObjectives'),
301  $done
304  ($this->section == self::SECTION_OBJECTIVES),
305  $this->getErrorMessages(self::SECTION_OBJECTIVES)
306  );
307 
308  return $list->getHTML();
309  }
310 
311 
312 
319  public function getErrorMessages($a_section)
320  {
321  $mess = array();
322  foreach ($this->getFailures($a_section) as $failure_code) {
323  $mess[] = $this->lng->txt($failure_code);
324  }
325  return $mess;
326  }
327 
328 
333  protected function getSettingsStatus()
334  {
335  return $this->getSettings()->settingsExist();
336  }
337 
344  protected function getObjectivesAvailableStatus($a_set_errors = false)
345  {
346  $ret = count($this->getObjectives());
347 
348  if (!$ret && $a_set_errors) {
349  $this->appendFailure(self::SECTION_OBJECTIVES_NEW, 'crs_no_objectives_created');
350  }
351 
352  return $ret;
353  }
354 
358  protected function getMaterialsStatus($a_set_errors = true)
359  {
360  $childs = $GLOBALS['tree']->getChilds($this->getParentObject()->getRefId());
361  foreach ((array) $childs as $tnode) {
362  if ($tnode['type'] == 'rolf') {
363  continue;
364  }
365  if ($tnode['child'] == $this->getSettings()->getInitialTest()) {
366  continue;
367  }
368  if ($tnode['child'] == $this->getSettings()->getQualifiedTest()) {
369  continue;
370  }
371  return true;
372  }
373  if ($a_set_errors) {
374  $this->appendFailure(self::SECTION_MATERIALS, 'crs_loc_err_stat_no_materials');
375  }
376  return false;
377  }
378 
384  protected function getInitialTestStatus($a_set_errors = true)
385  {
386  if ($this->getSettings()->hasSeparateInitialTests()) {
387  foreach ($this->getObjectives() as $objective_id) {
388  $tst_ref = $this->getAssignments()->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
389  if (!$GLOBALS['tree']->isInTree($tst_ref)) {
390  if ($a_set_errors) {
391  $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_no_it');
392  }
393  return false;
394  }
395  if (!$this->checkTestOnline($tst_ref)) {
396  if ($a_set_errors) {
397  $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_tst_offline');
398  }
399  return false;
400  }
401  }
402  return true;
403  }
404 
405 
406  $tst_ref = $this->getSettings()->getInitialTest();
407  if (!$GLOBALS['tree']->isInTree($tst_ref)) {
408  if ($a_set_errors) {
409  $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_no_it');
410  }
411  return false;
412  }
413  if (!$this->checkTestOnline($tst_ref)) {
414  if ($a_set_errors) {
415  $this->appendFailure(self::SECTION_ITES, 'crs_loc_err_stat_tst_offline');
416  }
417  return false;
418  }
419  return true;
420  }
421 
427  protected function getQualifiedTestStatus($a_set_errors = true)
428  {
429  if ($this->getSettings()->hasSeparateQualifiedTests()) {
430  foreach ($this->getObjectives() as $objective_id) {
431  $tst_ref = $this->getAssignments()->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
432  if (!$GLOBALS['tree']->isInTree($tst_ref)) {
433  if ($a_set_errors) {
434  $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_no_qt');
435  }
436  return false;
437  }
438  if (!$this->checkTestOnline($tst_ref)) {
439  if ($a_set_errors) {
440  $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_tst_offline');
441  }
442  return false;
443  }
444  }
445  return true;
446  }
447  $tst_ref = $this->getSettings()->getQualifiedTest();
448  if (!$GLOBALS['tree']->isInTree($tst_ref)) {
449  if ($a_set_errors) {
450  $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_no_qt');
451  }
452  return false;
453  }
454  if (!$this->checkTestOnline($tst_ref)) {
455  if ($a_set_errors) {
456  $this->appendFailure(self::SECTION_QTEST, 'crs_loc_err_stat_tst_offline');
457  }
458  return false;
459  }
460  return true;
461  }
462 
467  protected function lookupQuestionsAssigned($a_test_ref_id)
468  {
469  include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
471  foreach ($this->getObjectives() as $objective_id) {
472  include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
474  $this->parent_obj->getId(),
475  $objective_id,
476  ilObject::_lookupObjId($a_test_ref_id)
477  );
478  if (!$seq) {
479  return false;
480  }
481  }
482  } else {
483  foreach ($this->getObjectives() as $objective_id) {
484  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
486  if (!count($qsts)) {
487  return false;
488  }
489  }
490  }
491  return true;
492  }
493 
494 
495  protected function getObjectivesStatus($a_set_errors = true)
496  {
497  if (!$this->getObjectivesAvailableStatus($a_set_errors)) {
498  return false;
499  }
500 
501  include_once './Modules/Course/classes/class.ilCourseObjective.php';
502  $num_active = ilCourseObjective::_getCountObjectives($this->getParentObject()->getId(), true);
503  if (!$num_active) {
504  if ($a_set_errors) {
505  $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_lo');
506  }
507  return false;
508  }
509  foreach (ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId(), true) as $objective_id) {
510  include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
511  $obj = new ilCourseObjectiveMaterials($objective_id);
512  if (!count($obj->getMaterials())) {
513  if ($a_set_errors) {
514  $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_mat');
515  }
516  return false;
517  }
518  }
519  // check for assigned initial test questions
520  if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) {
521  // check for assigned questions
522  if (!$this->lookupQuestionsAssigned($this->getSettings()->getInitialTest())) {
523  if ($a_set_errors) {
524  $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_qst');
525  }
526  return false;
527  }
528  }
529  // check for assigned questions
530  if (!$this->getSettings()->hasSeparateQualifiedTests() and !$this->lookupQuestionsAssigned($this->getSettings()->getQualifiedTest())) {
531  if ($a_set_errors) {
532  $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_no_active_qst');
533  }
534  return false;
535  }
536 
537  // @deprecated
538  /*
539  if(!$this->checkNumberOfTries())
540  {
541  if($a_set_errors)
542  {
543  $this->appendFailure(self::SECTION_OBJECTIVES, 'crs_loc_err_nr_tries_exceeded');
544  }
545  return false;
546  }
547  */
548 
549  return true;
550  }
551 
552  protected function getStartStatus()
553  {
554  return true;
555  }
556 
557  protected function checkNumberOfTries()
558  {
559  $qt = $this->getSettings()->getQualifiedTest();
560  if (!$qt) {
561  return true;
562  }
563 
564  include_once './Services/Object/classes/class.ilObjectFactory.php';
565  $factory = new ilObjectFactory();
566  $tst = $factory->getInstanceByRefId($qt, false);
567 
568  if (!$tst instanceof ilObjTest) {
569  return true;
570  }
571  $tries = $tst->getNrOfTries();
572  if (!$tries) {
573  return true;
574  }
575 
576  $obj_tries = 0;
577  foreach ($this->getObjectives() as $objective) {
578  include_once './Modules/Course/classes/class.ilCourseObjective.php';
579  $obj_tries += ilCourseObjective::lookupMaxPasses($objective);
580  }
581  $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $obj_tries);
582  return $obj_tries <= $tries;
583  }
584 
589  protected function checkTestOnline($a_ref_id)
590  {
591  include_once './Modules/Test/classes/class.ilObjTestAccess.php';
593  }
594 }
getQualifiedTestStatus($a_set_errors=true)
Check status of qualified test.
static getInstanceByObjId($a_obj_id)
get singleton instance
getFailures($a_section)
Get failures by section.
static getInstance($a_container_id)
Get instance by container id.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
Class ilObjectFactory.
static lookupSequences($a_container_id, $a_objective_id, $a_test_id)
Lookup sequence ids type $ilDB.
getObjectivesAvailableStatus($a_set_errors=false)
getMaterialsStatus($a_set_errors=true)
Get status of materials.
static lookupMaxPasses($a_objective_id)
checkTestOnline($a_ref_id)
Check if test is online.
lookupQuestionsAssigned($a_test_ref_id)
Check if questions are assigned.
$_GET["client_id"]
Presentation of the status of single steps during the configuration process.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$factory
Definition: metadata.php:47
static _getObjectiveIds($course_id, $a_activated_only=false)
static _isOnline($a_obj_id)
returns the objects&#39;s ONline status
getFirstFailedStep()
Get first failed step.
class ilCourseObjectiveMaterials
setCmdClass($a_cmd_class)
Command class.
static lookupRandomTest($a_test_obj_id)
Check if test is a random test.
static getInstance(ilObject $a_parent)
Get instance.
static _lookupObjId($a_id)
appendFailure($a_section, $a_failure_msg_key)
Append failure.
setSection($a_section)
Set current section.
Create styles array
The data for the language used.
getParentObject()
Get parent object.
settings()
Definition: settings.php:2
getCmdClass()
Get cmd class.
static _getCountObjectives($a_obj_id, $a_activated_only=false)
get count objectives
$ret
Definition: parser.php:6
getErrorMessages($a_section)
Get error messages.
__construct(ilObject $a_parent)
Constructor.
getInitialTestStatus($a_set_errors=true)
Get initial test status.
static lookupQuestionsByObjective($a_test_id, $a_objective)
getSettingsStatus()
Check if course is lo confgured.
getObjectivesStatus($a_set_errors=true)