ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseObjectivesGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 {
36  const MODE_UNDEFINED = 0;
37  const MODE_CREATE = 1;
38  const MODE_UPDATE = 2;
39 
40 
41  var $ctrl;
42  var $ilias;
43  var $ilErr;
44  var $lng;
45  var $tpl;
46 
49 
50  function ilCourseObjectivesGUI($a_course_id)
51  {
52  include_once './Modules/Course/classes/class.ilCourseObjective.php';
53 
54  global $ilCtrl,$lng,$ilErr,$ilias,$tpl,$tree,$ilTabs;
55 
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this,array("ref_id"));
58 
59  $this->ilErr =& $ilErr;
60  $this->lng =& $lng;
61  $this->lng->loadLanguageModule('crs');
62  $this->tpl =& $tpl;
63  $this->tree =& $tree;
64  $this->tabs_gui =& $ilTabs;
65 
66  $this->course_id = $a_course_id;
67  $this->__initCourseObject();
68  }
69 
73  function &executeCommand()
74  {
75  global $ilTabs;
76 
77  $ilTabs->setTabActive('crs_objectives');
78 
79  $cmd = $this->ctrl->getCmd();
80 
81 
82  if (!$cmd = $this->ctrl->getCmd())
83  {
84  $cmd = "list";
85  }
86 
87  $this->setSubTabs();
88  $this->$cmd();
89  }
90 
98  protected function listObjectives()
99  {
100  global $ilAccess,$ilErr,$ilObjDataCache,$ilToolbar;
101 
102  $_SESSION['objective_mode'] = self::MODE_UNDEFINED;
103  if(!$ilAccess->checkAccess("write",'',$this->course_obj->getRefId()))
104  {
105  $this->ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilErr->MESSAGE);
106  }
107 
108  $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.crs_objectives.html','Modules/Course');
109 
110  $ilToolbar->addButton($this->lng->txt('crs_add_objective'),
111  $this->ctrl->getLinkTarget($this, "'create"));
112 
113  include_once('./Modules/Course/classes/class.ilCourseObjectivesTableGUI.php');
114  $table = new ilCourseObjectivesTableGUI($this,$this->course_obj);
115  $table->setTitle($this->lng->txt('crs_objectives'),'icon_lobj.png',$this->lng->txt('crs_objectives'));
116  $table->parse(ilCourseObjective::_getObjectiveIds($this->course_obj->getId()));
117 
118  $this->tpl->setVariable('OBJECTIVES_TABLE',$table->getHTML());
119  }
120 
127  protected function saveSorting()
128  {
129  global $ilAccess,$ilErr,$ilObjDataCache;
130 
131  if(!$ilAccess->checkAccess("write",'',$this->course_obj->getRefId()))
132  {
133  $this->ilErr->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilErr->MESSAGE);
134  }
135 
136  asort($_POST['position'],SORT_NUMERIC);
137 
138  $counter = 1;
139  foreach($_POST['position'] as $objective_id => $position)
140  {
141  $objective = new ilCourseObjective($this->course_obj,$objective_id);
142  $objective->writePosition($counter++);
143  }
144  ilUtil::sendSuccess($this->lng->txt('crs_objective_saved_sorting'));
145  $this->listObjectives();
146  }
147 
149  {
150  global $rbacsystem;
151 
152  // MINIMUM ACCESS LEVEL = 'write'
153  if(!$rbacsystem->checkAccess("write", $this->course_obj->getRefId()))
154  {
155  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilErr->MESSAGE);
156  }
157  if(!count($_POST['objective']))
158  {
159  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'));
160  $this->listObjectives();
161 
162  return true;
163  }
164 
165  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.crs_objectives.html",'Modules/Course');
166 
167  ilUtil::sendQuestion($this->lng->txt('crs_delete_objectve_sure'));
168 
169  $tpl =& new ilTemplate("tpl.table.html", true, true);
170  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.crs_objectives_delete_row.html",'Modules/Course');
171 
172  $counter = 0;
173  foreach($_POST['objective'] as $objective_id)
174  {
175  $objective_obj = $this->__initObjectivesObject($objective_id);
176 
177  $tpl->setCurrentBlock("tbl_content");
178  $tpl->setVariable("ROWCOL",ilUtil::switchColor(++$counter,"tblrow2","tblrow1"));
179  $tpl->setVariable("TITLE",$objective_obj->getTitle());
180  $tpl->setVariable("DESCRIPTION",$objective_obj->getDescription());
181  $tpl->parseCurrentBlock();
182  }
183 
184  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
185 
186  // Show action row
187  $tpl->setCurrentBlock("tbl_action_btn");
188  $tpl->setVariable("BTN_NAME",'deleteObjectives');
189  $tpl->setVariable("BTN_VALUE",$this->lng->txt('delete'));
190  $tpl->parseCurrentBlock();
191 
192  $tpl->setCurrentBlock("tbl_action_btn");
193  $tpl->setVariable("BTN_NAME",'listObjectives');
194  $tpl->setVariable("BTN_VALUE",$this->lng->txt('cancel'));
195  $tpl->parseCurrentBlock();
196 
197  $tpl->setCurrentBlock("tbl_action_row");
198  $tpl->setVariable("COLUMN_COUNTS",1);
199  $tpl->setVariable("IMG_ARROW",ilUtil::getImagePath('arrow_downright.png'));
200  $tpl->parseCurrentBlock();
201 
202 
203  // create table
204  $tbl = new ilTableGUI();
205  $tbl->setStyle('table','std');
206 
207  // title & header columns
208  $tbl->setTitle($this->lng->txt("crs_objectives"),"icon_lobj.png",$this->lng->txt("crs_objectives"));
209 
210  $tbl->setHeaderNames(array($this->lng->txt("title")));
211  $tbl->setHeaderVars(array("title"),
212  array("ref_id" => $this->course_obj->getRefId(),
213  "cmdClass" => "ilcourseobjectivesgui",
214  "cmdNode" => $_GET["cmdNode"]));
215  $tbl->setColumnWidth(array("50%"));
216 
217  $tbl->setLimit($_GET["limit"]);
218  $tbl->setOffset($_GET["offset"]);
219  $tbl->setMaxCount(count($_POST['objective']));
220 
221  // footer
222  $tbl->disable("footer");
223  $tbl->disable('sort');
224 
225  // render table
226  $tbl->setTemplate($tpl);
227  $tbl->render();
228 
229  $this->tpl->setVariable("OBJECTIVES_TABLE", $tpl->get());
230 
231 
232  // Save marked objectives
233  $_SESSION['crs_delete_objectives'] = $_POST['objective'];
234 
235  return true;
236  }
237 
238  function deleteObjectives()
239  {
240  global $rbacsystem;
241 
242  // MINIMUM ACCESS LEVEL = 'write'
243  if(!$rbacsystem->checkAccess("write", $this->course_obj->getRefId()))
244  {
245  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilErr->MESSAGE);
246  }
247  if(!count($_SESSION['crs_delete_objectives']))
248  {
249  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'));
250  $this->listObjectives();
251 
252  return true;
253  }
254 
255  foreach($_SESSION['crs_delete_objectives'] as $objective_id)
256  {
257  $objective_obj =& $this->__initObjectivesObject($objective_id);
258  $objective_obj->delete();
259  }
260 
261  ilUtil::sendSuccess($this->lng->txt('crs_objectives_deleted'));
262  $this->listObjectives();
263 
264  return true;
265  }
266 
273  protected function questionOverview()
274  {
275  global $ilAccess,$ilErr,$ilTabs;
276 
277  $ilTabs->setSubTabActive('crs_objective_overview_question_assignment');
278 
279  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
280  {
281  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
282  }
283 
284  include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestionsTableGUI.php');
285  $table = new ilCourseObjectiveQuestionsTableGUI($this,$this->course_obj);
286  $table->setTitle($this->lng->txt('crs_objectives_edit_question_assignments'),'icon_lobj.png',$this->lng->txt('crs_objectives'));
287  $table->parse(ilCourseObjective::_getObjectiveIds($this->course_obj->getId()));
288 
289  $this->tpl->setContent($table->getHTML());
290  }
291 
298  protected function saveQuestionOverview()
299  {
300  include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
301 
302  global $ilAccess,$ilErr;
303 
304  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
305  {
306  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
307  }
308  $error = false;
309 
310  $_POST['self'] = $_POST['self'] ? $_POST['self'] : array();
311  $_POST['final'] = $_POST['final'] ? $_POST['final'] : array();
312 
313  foreach($_POST['self'] as $objective_id => $limit)
314  {
315  $qst = new ilCourseObjectiveQuestion($objective_id);
316  $max_points = $qst->getSelfAssessmentPoints();
317 
318  if($limit < 0 or $limit > $max_points)
319  {
320  ilUtil::sendFailure($this->lng->txt('crs_objective_limit_err'));
321  $this->questionOverview();
322  return false;
323  }
324  }
325  foreach($_POST['final'] as $objective_id => $limit)
326  {
327  $qst = new ilCourseObjectiveQuestion($objective_id);
328  $max_points = $qst->getFinalTestPoints();
329 
330  if($limit < 0 or $limit > $max_points)
331  {
332  ilUtil::sendFailure($this->lng->txt('crs_objective_limit_err'));
333  $this->questionOverview();
334  return false;
335  }
336  }
337 
338  foreach($_POST['self'] as $objective_id => $limit)
339  {
341  }
342 
343  foreach($_POST['final'] as $objective_id => $limit)
344  {
346  }
347 
348  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
349  $this->questionOverview();
350  return true;
351  }
352 
353  // PRIVATE
355  {
356  if(!$this->course_obj =& ilObjectFactory::getInstanceByRefId($this->course_id,false))
357  {
358  $this->ilErr->raiseError("ilCourseObjectivesGUI: cannot create course object",$this->ilErr->MESSAGE);
359  exit;
360  }
361  return true;
362  }
363 
364  function __initObjectivesObject($a_id = 0)
365  {
366  return $this->objectives_obj = new ilCourseObjective($this->course_obj,$a_id);
367  }
368 
369  function __initLMObject($a_objective_id = 0)
370  {
371  include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
372  $this->objectives_lm_obj =& new ilCourseObjectiveMaterials($a_objective_id);
373 
374  return true;
375  }
376 
377  function __initQuestionObject($a_objective_id = 0)
378  {
379  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
380  $this->objectives_qst_obj =& new ilCourseObjectiveQuestion($a_objective_id);
381 
382  return true;
383  }
384 
388  function setSubTabs()
389  {
390  global $ilTabs;
391 
392  $ilTabs->addSubTabTarget("crs_objective_overview_objectives",
393  $this->ctrl->getLinkTarget($this, "listObjectives"),
394  array("listObjectives", "moveObjectiveUp", "moveObjectiveDown", "listAssignedLM"),
395  array(),
396  '',
397  true);
398  include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestion.php');
399 
400  if(ilCourseObjectiveQuestion::_hasTests($this->course_obj->getId()))
401  {
402  $ilTabs->addSubTabTarget("crs_objective_overview_question_assignment",
403  $this->ctrl->getLinkTarget($this, "questionOverview"),
404  "editQuestionAssignment",
405  array(),
406  '',
407  false);
408  }
409  }
410 
411 
419  public function create()
420  {
421  global $tpl;
422 
423  $_SESSION['objective_mode'] = self::MODE_CREATE;
424 
425  $this->ctrl->saveParameter($this,'objective_id');
426 
427  if(!is_object($this->objective))
428  {
429  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
430  }
431  $this->__initQuestionObject((int) $_GET['objective_id']);
432  $w_tpl = $this->initWizard(1);
433 
434  $this->initFormTitle('create',1);
435  $w_tpl->setVariable('WIZ_CONTENT',$this->form->getHtml());
436  $tpl->setContent($w_tpl->get());
437  }
438 
445  protected function edit()
446  {
447  global $tpl;
448 
449  $_SESSION['objective_mode'] = self::MODE_UPDATE;
450 
451  $this->ctrl->saveParameter($this,'objective_id');
452 
453  if(!$_GET['objective_id'])
454  {
455  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
456  $this->ctrl->redirect($this,'listObjectives');
457  }
458 
459  if(!is_object($this->objective))
460  {
461  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
462  }
463 
464  $this->__initQuestionObject((int) $_GET['objective_id']);
465  $w_tpl = $this->initWizard(1);
466  $this->initFormTitle('create',1);
467  $w_tpl->setVariable('WIZ_CONTENT',$this->form->getHtml());
468  $tpl->setContent($w_tpl->get());
469  }
470 
477  protected function save()
478  {
479  global $ilAccess,$ilErr;
480 
481  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
482  {
483  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
484  }
485 
486  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
487  $this->objective->setTitle(ilUtil::stripSlashes($_POST['title']));
488  $this->objective->setDescription(ilUtil::stripSlashes($_POST['description']));
489 
490  if(!$this->objective->validate())
491  {
492  ilUtil::sendFailure($this->lng->txt('crs_no_title_given'));
493  $this->create();
494  return false;
495  }
496 
497  if(!$_GET['objective_id'])
498  {
499  $objective_id = $this->objective->add();
500  ilUtil::sendSuccess($this->lng->txt('crs_added_objective'),true);
501  }
502  else
503  {
504  $this->objective->update();
505  ilUtil::sendSuccess($this->lng->txt('crs_objective_modified'),true);
506  $objective_id = $_GET['objective_id'];
507  }
508 
509  $this->ctrl->saveParameter($this,'objective_id');
510  $this->ctrl->setParameter($this,'objective_id',$objective_id);
511  $this->ctrl->redirect($this,'materialAssignment');
512  return true;
513  }
514 
521  protected function materialAssignment()
522  {
523  global $ilAccess,$ilErr,$tpl;
524 
525  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
526  {
527  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
528  }
529  if(!$_GET['objective_id'])
530  {
531  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
532  $this->ctrl->redirect($this,'listObjectives');
533  }
534 
535  $this->ctrl->saveParameter($this,'objective_id');
536 
537  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
538 
539  include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterialAssignmentTableGUI.php');
540  $table = new ilCourseObjectiveMaterialAssignmentTableGUI($this,$this->course_obj,(int) $_GET['objective_id']);
541  $table->setTitle($this->lng->txt('crs_objective_wiz_materials'),
542  'icon_lobj.png',$this->lng->txt('crs_objectives'));
543 
544  include_once('Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
545  $table->parse(ilCourseObjectiveMaterials::_getAssignableMaterials($this->course_obj->getRefId()));
546 
547  $this->__initQuestionObject((int) $_GET['objective_id']);
548  $w_tpl = $this->initWizard(2);
549  $w_tpl->setVariable('WIZ_CONTENT',$table->getHTML());
550  $tpl->setContent($w_tpl->get());
551  }
552 
560  protected function updateMaterialAssignment()
561  {
562  global $ilAccess,$ilErr,$ilObjDataCache;
563 
564  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
565  {
566  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
567  }
568  if(!$_GET['objective_id'])
569  {
570  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
571  $this->ctrl->redirect($this,'listObjectives');
572  }
573 
574  $this->__initLMObject((int) $_GET['objective_id']);
575  $this->objectives_lm_obj->deleteAll();
576 
577  if(is_array($_POST['materials']))
578  {
579  foreach($_POST['materials'] as $node_id)
580  {
581  $obj_id = $ilObjDataCache->lookupObjId($node_id);
582  $type = $ilObjDataCache->lookupType($obj_id);
583 
584  $this->objectives_lm_obj->setLMRefId($node_id);
585  $this->objectives_lm_obj->setLMObjId($obj_id);
586  $this->objectives_lm_obj->setType($type);
587  $this->objectives_lm_obj->add();
588  }
589  }
590  if(is_array($_POST['chapters']))
591  {
592  foreach($_POST['chapters'] as $chapter)
593  {
594  include_once('./Modules/LearningModule/classes/class.ilLMObject.php');
595 
596  list($ref_id,$chapter_id) = explode('_',$chapter);
597 
598  $this->objectives_lm_obj->setLMRefId($ref_id);
599  $this->objectives_lm_obj->setLMObjId($chapter_id);
600  $this->objectives_lm_obj->setType(ilLMObject::_lookupType($chapter_id));
601  $this->objectives_lm_obj->add();
602  }
603  }
604  ilUtil::sendSuccess($this->lng->txt('crs_objectives_assigned_lm'));
605  $this->selfAssessmentAssignment();
606 
607  }
608 
615  protected function selfAssessmentAssignment()
616  {
617  global $ilAccess,$ilErr,$tpl;
618 
619  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
620  {
621  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
622  }
623  if(!$_GET['objective_id'])
624  {
625  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
626  $this->ctrl->redirect($this,'listObjectives');
627  }
628 
629  $this->ctrl->saveParameter($this,'objective_id');
630 
631  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
632 
633  include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestionAssignmentTableGUI.php');
635  $this->course_obj,
636  (int) $_GET['objective_id'],
638  $table->setTitle($this->lng->txt('crs_objective_wiz_self'),
639  'icon_lobj.png',$this->lng->txt('crs_objective'));
640  $table->parse(ilCourseObjectiveQuestion::_getAssignableTests($this->course_obj->getRefId()));
641 
642  $this->__initQuestionObject((int) $_GET['objective_id']);
643  $w_tpl = $this->initWizard(3);
644  $w_tpl->setVariable('WIZ_CONTENT',$table->getHTML());
645  $tpl->setContent($w_tpl->get());
646  }
647 
655  protected function updateSelfAssessmentAssignment()
656  {
657  global $ilAccess,$ilErr,$ilObjDataCache;
658 
659  $checked_questions = $_POST['questions'] ? $_POST['questions'] : array();
660 
661 
662  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
663  {
664  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
665  }
666  if(!$_GET['objective_id'])
667  {
668  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
669  $this->ctrl->redirect($this,'listObjectives');
670  }
671 
672  $this->__initQuestionObject((int) $_GET['objective_id']);
673 
674  // Delete unchecked
675  foreach($this->objectives_qst_obj->getSelfAssessmentQuestions() as $question)
676  {
677  $id = $question['ref_id'].'_'.$question['question_id'];
678  if(!in_array($id,$checked_questions))
679  {
680  $this->objectives_qst_obj->delete($question['qst_ass_id']);
681  }
682  }
683  // Add checked
684  foreach($checked_questions as $question_id)
685  {
686  list($test_ref_id,$qst_id) = explode('_',$question_id);
687  $test_obj_id = $ilObjDataCache->lookupObjId($test_ref_id);
688 
689  if($this->objectives_qst_obj->isSelfAssessmentQuestion($qst_id))
690  {
691  continue;
692  }
693  $this->objectives_qst_obj->setTestStatus(ilCourseObjectiveQuestion::TYPE_SELF_ASSESSMENT);
694  $this->objectives_qst_obj->setTestRefId($test_ref_id);
695  $this->objectives_qst_obj->setTestObjId($test_obj_id);
696  $this->objectives_qst_obj->setQuestionId($qst_id);
697  $this->objectives_qst_obj->add();
698  }
699 
700  // TODO: not nice
701  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
702  $this->questions = new ilCourseObjectiveQuestion((int) $_GET['objective_id']);
703  $this->questions->updateLimits();
704 
705  if($checked_questions)
706  {
707  ilUtil::sendSuccess($this->lng->txt('crs_objectives_assigned_lm'));
708  $this->selfAssessmentLimits();
709  return true;
710  }
711  else
712  {
713  switch($_SESSION['objective_mode'])
714  {
715  case self::MODE_CREATE:
716  $this->finalTestAssignment();
717  return true;
718 
719  case self::MODE_UPDATE:
720  $this->selfAssessmentAssignment();
721  ilUtil::sendSuccess($this->lng->txt('crs_objectives_assigned_lm'));
722  return true;
723  }
724  }
725  }
726 
734  protected function selfAssessmentLimits()
735  {
736  global $ilAccess,$ilErr,$tpl;
737 
738  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
739  {
740  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
741  }
742  if(!$_GET['objective_id'])
743  {
744  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
745  $this->ctrl->redirect($this,'listObjectives');
746  }
747 
748  $this->ctrl->saveParameter($this,'objective_id');
749  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
750 
751  $this->__initQuestionObject((int) $_GET['objective_id']);
752  $w_tpl = $this->initWizard(4);
753 
754  $this->initFormLimits('selfAssessment');
755  $w_tpl->setVariable('WIZ_CONTENT',$this->form->getHtml());
756  $tpl->setContent($w_tpl->get());
757  }
758 
766  protected function updateSelfAssessmentLimits()
767  {
768  global $ilAccess,$ilErr,$ilObjDataCache;
769 
770  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
771  {
772  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
773  }
774  if(!$_GET['objective_id'])
775  {
776  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
777  $this->ctrl->redirect($this,'listObjectives');
778  }
779 
780  $this->__initQuestionObject((int) $_GET['objective_id']);
781 
782  if((int) $_POST['limit'] < 0 or (int) $_POST['limit'] > $this->objectives_qst_obj->getSelfAssessmentPoints())
783  {
784  ilUtil::sendFailure(sprintf($this->lng->txt('crs_objective_err_limit'),0,$this->objectives_qst_obj->getSelfAssessmentPoints()));
785  $this->selfAssessmentLimits();
786  return false;
787  }
788 
789  foreach($this->objectives_qst_obj->getSelfAssessmentTests() as $test)
790  {
791  $this->objectives_qst_obj->setTestStatus(ilCourseObjectiveQuestion::TYPE_SELF_ASSESSMENT);
792  $this->objectives_qst_obj->setTestSuggestedLimit((int) $_POST['limit']);
793  $this->objectives_qst_obj->updateTest($test['test_objective_id']);
794  }
795 
796  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
797  $this->finalTestAssignment();
798 
799  }
800 
801 
809  protected function finalTestAssignment()
810  {
811  global $ilAccess,$ilErr,$tpl;
812 
813  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
814  {
815  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
816  }
817  if(!$_GET['objective_id'])
818  {
819  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
820  $this->ctrl->redirect($this,'listObjectives');
821  }
822 
823  $this->ctrl->saveParameter($this,'objective_id');
824 
825  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
826 
827  include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestionAssignmentTableGUI.php');
829  $this->course_obj,
830  (int) $_GET['objective_id'],
832 
833  $table->setTitle($this->lng->txt('crs_objective_wiz_final'),
834  'icon_lobj.png',$this->lng->txt('crs_objective'));
835  $table->parse(ilCourseObjectiveQuestion::_getAssignableTests($this->course_obj->getRefId()));
836 
837  $this->__initQuestionObject((int) $_GET['objective_id']);
838  $w_tpl = $this->initWizard(5);
839  $w_tpl->setVariable('WIZ_CONTENT',$table->getHTML());
840  $tpl->setContent($w_tpl->get());
841 
842  }
843 
851  protected function updateFinalTestAssignment()
852  {
853  global $ilAccess,$ilErr,$ilObjDataCache;
854 
855  $checked_questions = $_POST['questions'] ? $_POST['questions'] : array();
856 
857 
858  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
859  {
860  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
861  }
862  if(!$_GET['objective_id'])
863  {
864  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
865  $this->ctrl->redirect($this,'listObjectives');
866  }
867 
868  $this->__initQuestionObject((int) $_GET['objective_id']);
869 
870  // Delete unchecked
871  foreach($this->objectives_qst_obj->getFinalTestQuestions() as $question)
872  {
873  $id = $question['ref_id'].'_'.$question['question_id'];
874  if(!in_array($id,$checked_questions))
875  {
876  $this->objectives_qst_obj->delete($question['qst_ass_id']);
877  }
878  }
879  // Add checked
880  foreach($checked_questions as $question_id)
881  {
882  list($test_ref_id,$qst_id) = explode('_',$question_id);
883  $test_obj_id = $ilObjDataCache->lookupObjId($test_ref_id);
884 
885  if($this->objectives_qst_obj->isFinalTestQuestion($qst_id))
886  {
887  continue;
888  }
889 
890  $this->objectives_qst_obj->setTestStatus(ilCourseObjectiveQuestion::TYPE_FINAL_TEST);
891  $this->objectives_qst_obj->setTestRefId($test_ref_id);
892  $this->objectives_qst_obj->setTestObjId($test_obj_id);
893  $this->objectives_qst_obj->setQuestionId($qst_id);
894  $this->objectives_qst_obj->add();
895  }
896 
897  // TODO: not nice
898  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
899  $this->questions = new ilCourseObjectiveQuestion((int) $_GET['objective_id']);
900  $this->questions->updateLimits();
901 
902  ilUtil::sendSuccess($this->lng->txt('crs_objectives_assigned_lm'));
903  $this->finalTestLimits();
904  }
905 
913  protected function finalTestLimits()
914  {
915  global $ilAccess,$ilErr,$tpl;
916 
917  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
918  {
919  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
920  }
921  if(!$_GET['objective_id'])
922  {
923  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
924  $this->ctrl->redirect($this,'listObjectives');
925  }
926 
927  $this->ctrl->saveParameter($this,'objective_id');
928  $this->objective = new ilCourseObjective($this->course_obj,(int) $_GET['objective_id']);
929 
930  $this->__initQuestionObject((int) $_GET['objective_id']);
931  $w_tpl = $this->initWizard(6);
932 
933  $this->initFormLimits('final');
934  $w_tpl->setVariable('WIZ_CONTENT',$this->form->getHtml());
935  $tpl->setContent($w_tpl->get());
936  }
937 
945  protected function updateFinalTestLimits()
946  {
947  global $ilAccess,$ilErr,$ilObjDataCache;
948 
949  if(!$ilAccess->checkAccess('write','',$this->course_obj->getRefId()))
950  {
951  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
952  }
953  if(!$_GET['objective_id'])
954  {
955  ilUtil::sendFailure($this->lng->txt('crs_no_objective_selected'),true);
956  $this->ctrl->redirect($this,'listObjectives');
957  }
958 
959  $this->__initQuestionObject((int) $_GET['objective_id']);
960 
961  if((int) $_POST['limit'] < 0 or (int) $_POST['limit'] > $this->objectives_qst_obj->getFinalTestPoints())
962  {
963  ilUtil::sendFailure(sprintf($this->lng->txt('crs_objective_err_limit'),0,$this->objectives_qst_obj->getFinalTestPoints()));
964  $this->finalTestLimits();
965  return false;
966  }
967 
968  foreach($this->objectives_qst_obj->getFinalTests() as $test)
969  {
970  $this->objectives_qst_obj->setTestStatus(ilCourseObjectiveQuestion::TYPE_FINAL_TEST);
971  $this->objectives_qst_obj->setTestSuggestedLimit((int) $_POST['limit']);
972  $this->objectives_qst_obj->updateTest($test['test_objective_id']);
973  }
974 
975  ilUtil::sendSuccess($this->lng->txt('crs_added_objective'));
976  $this->listObjectives();
977  }
978 
986  protected function initFormLimits($a_mode)
987  {
988  if(!is_object($this->form))
989  {
990  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
991  $this->form = new ilPropertyFormGUI();
992  }
993  $this->form->setFormAction($this->ctrl->getFormAction($this));
994  $this->form->setTableWidth('100%');
995  $this->form->setTitleIcon(ilUtil::getImagePath('icon_lobj.png'),$this->lng->txt('crs_objective'));
996 
997  switch($a_mode)
998  {
999  case 'selfAssessment':
1000  $this->form->setTitle($this->lng->txt('crs_objective_wiz_self_limit'));
1001  $this->form->addCommandButton('updateSelfAssessmentLimits',$this->lng->txt('crs_wiz_next'));
1002  $this->form->addCommandButton('selfAssessmentAssignment',$this->lng->txt('crs_wiz_back'));
1003 
1004  $tests = $this->objectives_qst_obj->getSelfAssessmentTests();
1005  $max_points = $this->objectives_qst_obj->getSelfAssessmentPoints();
1006 
1007  break;
1008 
1009  case 'final':
1010  $this->form->setTitle($this->lng->txt('crs_objective_wiz_final_limit'));
1011  $this->form->addCommandButton('updateFinalTestLimits',$this->lng->txt('crs_wiz_next'));
1012  $this->form->addCommandButton('finalTestAssignment',$this->lng->txt('crs_wiz_back'));
1013 
1014  $tests = $this->objectives_qst_obj->getFinalTests();
1015  $max_points = $this->objectives_qst_obj->getFinalTestPoints();
1016 
1017  break;
1018  }
1019 
1020  $over = new ilCustomInputGUI($this->lng->txt('crs_objective_qst_summary'),'');
1021 
1022  $tpl = new ilTemplate('tpl.crs_objective_qst_summary.html',true,true,'Modules/Course');
1023 
1024 
1025  $limit = 0;
1026 
1027  foreach($tests as $test)
1028  {
1029  $limit = $test['limit'];
1030 
1031  foreach($this->objectives_qst_obj->getQuestionsOfTest($test['obj_id']) as $question)
1032  {
1033  $tpl->setCurrentBlock('qst');
1034  $tpl->setVariable('QST_TITLE',$question['title']);
1035  if(strlen($question['description']))
1036  {
1037  $tpl->setVariable('QST_DESCRIPTION',$question['description']);
1038  }
1039  $tpl->setVariable('QST_POINTS',$question['points'].' '.
1040  $this->lng->txt('crs_objective_points'));
1041  $tpl->parseCurrentBlock();
1042  }
1043  $tpl->setCurrentBlock('tst');
1044  $tpl->setVariable('TST_TITLE',ilObject::_lookupTitle($test['obj_id']));
1045  if($desc = ilObject::_lookupDescription($test['obj_id']))
1046  {
1047  $tpl->setVariable('TST_DESC',$desc);
1048  }
1049  $tpl->setVariable('TST_TYPE_IMG',ilUtil::getTypeIconPath('tst',$test['obj_id'],'tiny'));
1050  $tpl->setVariable('TST_ALT_IMG',$this->lng->txt('obj_tst'));
1051  $tpl->parseCurrentBlock();
1052  }
1053 
1054  $tpl->setVariable('TXT_ALL_POINTS',$this->lng->txt('crs_objective_all_points'));
1055  $tpl->setVariable('TXT_POINTS',$this->lng->txt('crs_objective_points'));
1056  $tpl->setVariable('POINTS',$max_points);
1057 
1058  $over->setHtml($tpl->get());
1059  $this->form->addItem($over);
1060 
1061  $req = new ilTextInputGUI($this->lng->txt('crs_obj_required_points'),'limit');
1062  $req->setValue($limit);
1063  $req->setMaxLength(5);
1064  $req->setSize(3);
1065  $req->setRequired(true);
1066  switch($a_mode)
1067  {
1068  case 'selfAssessment':
1069  $req->setInfo($this->lng->txt('crs_obj_initial_req_info'));
1070  break;
1071 
1072  case 'final':
1073  $req->setInfo($this->lng->txt('crs_obj_final_req_info'));
1074  break;
1075  }
1076 
1077 
1078  $this->form->addItem($req);
1079 
1080  }
1081 
1082 
1089  protected function initFormTitle($a_mode,$a_step_number)
1090  {
1091  if(!is_object($this->form))
1092  {
1093  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
1094  $this->form = new ilPropertyFormGUI();
1095  }
1096  $this->form->setFormAction($this->ctrl->getFormAction($this));
1097  $this->form->setTitleIcon(ilUtil::getImagePath('icon_lobj.png'),$this->lng->txt('crs_objective'));
1098 
1099  switch($a_mode)
1100  {
1101  case 'create':
1102  $this->form->setTitle($this->lng->txt('crs_objective_wiz_title'));
1103  $this->form->addCommandButton('save',$this->lng->txt('crs_wiz_next'));
1104  $this->form->addCommandButton('listObjectives',$this->lng->txt('cancel'));
1105  break;
1106 
1107  case 'update':
1108  break;
1109  }
1110 
1111  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
1112  $title->setValue($this->objective->getTitle());
1113  $title->setRequired(true);
1114  $title->setSize(40);
1115  $title->setMaxLength(70);
1116  $this->form->addItem($title);
1117 
1118  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
1119  $desc->setValue($this->objective->getDescription());
1120  $desc->setCols(40);
1121  $desc->setRows(5);
1122  $this->form->addItem($desc);
1123 
1124 
1125  }
1126 
1127 
1135  protected function initWizard($a_step_number)
1136  {
1137  $options = array(
1138  1 => $this->lng->txt('crs_objective_wiz_title'),
1139  2 => $this->lng->txt('crs_objective_wiz_materials'),
1140  3 => $this->lng->txt('crs_objective_wiz_self'),
1141  4 => $this->lng->txt('crs_objective_wiz_self_limit'),
1142  5 => $this->lng->txt('crs_objective_wiz_final'),
1143  6 => $this->lng->txt('crs_objective_wiz_final_limit'));
1144 
1145  $info = array(
1146  1 => $this->lng->txt('crs_objective_wiz_title_info'),
1147  2 => $this->lng->txt('crs_objective_wiz_materials_info'),
1148  3 => $this->lng->txt('crs_objective_wiz_self_info'),
1149  4 => $this->lng->txt('crs_objective_wiz_self_limit_info'),
1150  5 => $this->lng->txt('crs_objective_wiz_final_info'),
1151  6 => $this->lng->txt('crs_objective_wiz_final_limit_info'));
1152 
1153  $links = array(
1154  1 => $this->ctrl->getLinkTarget($this,'edit'),
1155  2 => $this->ctrl->getLinkTarget($this,'materialAssignment'),
1156  3 => $this->ctrl->getLinkTarget($this,'selfAssessmentAssignment'),
1157  4 => $this->ctrl->getLinkTarget($this,'selfAssessmentLimits'),
1158  5 => $this->ctrl->getLinkTarget($this,'finalTestAssignment'),
1159  6 => $this->ctrl->getLinkTarget($this,'finalTestLimits'));
1160 
1161 
1162  $tpl = new ilTemplate('tpl.objective_wizard.html',true,true,'Modules/Course');
1163 
1164  if($_SESSION['objective_mode'] == self::MODE_CREATE or 1)
1165  {
1166  $tpl->setCurrentBlock('step_info');
1167 
1168  if(is_object($this->objective) and strlen($this->objective->getTitle()))
1169  {
1170  $tpl->setVariable('STEP_SEPARATOR','-');
1171  $tpl->setVariable('STEP_TITLE',$this->objective->getTitle());
1172  }
1173 
1174  $tpl->setVariable('STEP_INFO_STEP',$this->lng->txt('crs_objective_step'));
1175  $tpl->setVariable('STEP_INFO_NUM',$a_step_number);
1176  $tpl->setVariable('STEP_INFO_INFO',$info[$a_step_number]);
1177  $tpl->parseCurrentBlock();
1178  }
1179 
1180 
1181  $tpl->setVariable('WIZ_IMG',ilUtil::getImagePath('icon_lobj.png'));
1182  $tpl->setVariable('WIZ_IMG_ALT',$this->lng->txt('crs_objectives'));
1183 
1184  if($_SESSION['objective_mode'] == self::MODE_CREATE)
1185  {
1186  $tpl->setVariable('WIZ_NAV_TITLE',$this->lng->txt('crs_add_objective'));
1187  }
1188  else
1189  {
1190  $tpl->setVariable('WIZ_NAV_TITLE',$this->lng->txt('crs_update_objective'));
1191  }
1192 
1193  foreach($options as $step => $title)
1194  {
1195  if($_SESSION['objective_mode'] == self::MODE_UPDATE)
1196  {
1197  $hide_link = false;
1198  if($step == 4 and !count($this->objectives_qst_obj->getSelfAssessmentQuestions()))
1199  {
1200  $hide_link = true;
1201  }
1202  if($step == 6 and !count($this->objectives_qst_obj->getFinalTestQuestions()))
1203  {
1204  $hide_link = true;
1205  }
1206  if(!$hide_link)
1207  {
1208  $tpl->setCurrentBlock('begin_link_option');
1209  $tpl->setVariable('WIZ_OPTION_LINK',$links[$step]);
1210  $tpl->parseCurrentBlock();
1211 
1212  $tpl->touchBlock('end_link_option');
1213  }
1214  }
1215 
1216 
1217  $tpl->setCurrentBlock('nav_option');
1218  $tpl->setVariable('OPTION_CLASS',$step == $a_step_number ? 'option_value_details' : 'std');
1219  $tpl->setVariable('WIZ_NUM',$step.'.');
1220  $tpl->setVariable('WIZ_OPTION',$title);
1221  $tpl->parseCurrentBlock();
1222  }
1223 
1224 
1225  return $tpl;
1226  }
1227 
1228 }
1229 ?>