Exemplo n.º 1
0
 /**
 * Returns true, if a test is complete for use
 *
 * @return boolean True, if the test is complete for use, otherwise false
 * @access public
 */
 function _isComplete($obj_id)
 {
     global $tree, $ilDB, $ilPluginAdmin;
     $test = new ilObjTest($obj_id, false);
     $test->loadFromDb();
     require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
     $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $test);
     return $test->isComplete($testQuestionSetConfigFactory->getQuestionSetConfig());
 }
Exemplo n.º 2
0
 /**
  * Questions per page
  *
  * @param
  * @return
  */
 function buildPageViewToolbar($qid = 0)
 {
     if ($this->create_question_mode) {
         return;
     }
     global $ilToolbar, $ilCtrl, $lng;
     require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
     $this->getQuestionsSubTabs();
     $ilCtrl->saveParameter($this, 'q_mode');
     $ilCtrl->setParameterByClass('iltestexpresspageobjectgui', 'test_express_mode', 1);
     $ilCtrl->setParameter($this, 'test_express_mode', 1);
     $ilCtrl->setParameterByClass('iltestexpresspageobjectgui', 'q_id', $_REQUEST['q_id']);
     $ilCtrl->setParameter($this, 'q_id', $_REQUEST['q_id']);
     $ilToolbar->setFormAction($ilCtrl->getFormActionByClass('iltestexpresspageobjectgui', 'edit'));
     if ($this->object->evalTotalPersons() == 0) {
         /*
         include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
         $pool = new ilObjQuestionPool();
         $questionTypes = $pool->getQuestionTypes();$options = array();
         foreach($questionTypes as $label => $data) {
         $options[$data['question_type_id']] = $label;
         }
         
         		include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
         		$si = new ilSelectInputGUI($lng->txt("test_add_new_question"), "qtype");
         		$si->setOptions($options);
         		$ilToolbar->addInputItem($si, true);
         /*
         		// use pool
         		if ($this->object->isExpressModeQuestionPoolAllowed()) {
         			include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php");
         			$cb = new ilCheckboxInputGUI($lng->txt("test_use_pool"), "use_pool");
         			$ilToolbar->addInputItem($cb, true);
         		}
         */
         $ilToolbar->addFormButton($lng->txt("ass_create_question"), "addQuestion");
         $ilToolbar->addSeparator();
         if ($this->object->getPoolUsage()) {
             require_once 'Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php';
             $this->populateQuestionBrowserToolbarButtons($ilToolbar, ilTestQuestionBrowserTableGUI::CONTEXT_PAGE_VIEW);
             $show_separator = true;
         }
     }
     $questions = $this->object->getQuestionTitlesAndIndexes();
     // desc
     $options = array();
     foreach ($questions as $id => $label) {
         $options[$id] = $label . ' [' . $this->lng->txt('question_id_short') . ': ' . $id . ']';
     }
     $optionKeys = array_keys($options);
     if (!$options) {
         $options[] = $lng->txt('none');
     }
     //else if (count($options) > 1) {
     //                    $addSeparator = false;
     //                    if ($optionKeys[0] != $qid) {
     //                        //$ilToolbar->addFormButton($lng->txt("test_prev_question"), "prevQuestion");
     //                        $ilToolbar->addLink($lng->txt("test_prev_question"), $ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'prevQuestion'));
     //                        $addSeparator = true;
     //                    }
     //		    else {
     //			$ilToolbar->addSpacer(45);
     //		    }
     //
     //                    if ($optionKeys[count($optionKeys)-1] != $qid) {
     //                        //$ilToolbar->addFormButton($lng->txt("test_next_question"), "nextQuestion");
     //                        $ilToolbar->addLink($lng->txt("test_next_question"), $ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'nextQuestion'));
     //			$addSeparator = true;
     //                    }
     //		    else {
     //			$ilToolbar->addSpacer(45);
     //		    }
     //
     //                    //if ($addSeparator) {
     //                        $ilToolbar->addSeparator();
     //                    //}
     if (count($questions)) {
         if (isset($show_separator) && $show_separator) {
             $ilToolbar->addSeparator();
         }
         $btn = ilLinkButton::getInstance();
         $btn->setCaption("test_prev_question");
         $btn->setUrl($ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'prevQuestion'));
         $ilToolbar->addButtonInstance($btn);
         if (count($options) <= 1 || $optionKeys[0] == $qid) {
             $btn->setDisabled(true);
         }
         $btn = ilLinkButton::getInstance();
         $btn->setCaption("test_next_question");
         $btn->setUrl($ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'nextQuestion'));
         $ilToolbar->addButtonInstance($btn);
         if (count($options) <= 1 || $optionKeys[count($optionKeys) - 1] == $qid) {
             $btn->setDisabled(true);
         }
     }
     if (count($questions) > 1) {
         $ilToolbar->addSeparator();
         include_once "./Services/Form/classes/class.ilSelectInputGUI.php";
         $si = new ilSelectInputGUI($lng->txt("test_jump_to"), "q_id");
         $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\"");
         $si->setOptions($options);
         if ($qid) {
             $si->setValue($qid);
         }
         $ilToolbar->addInputItem($si, true);
     }
     $total = $this->object->evalTotalPersons();
     /*if (count($options)) {
     			include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
     			$si = new ilSelectInputGUI($lng->txt("test_jump_to"), "q_id");
     			$si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\"");
     			$si->setOptions($options);
     
     			if ($qid) {
     				$si->setValue($qid);
     			}
     
     			$ilToolbar->addInputItem($si, true);
     		}*/
     if (count($questions) && !$total) {
         $ilCtrl->setParameter($this, 'q_id', $_REQUEST['q_id']);
         $ilToolbar->addSeparator();
         $ilToolbar->addButton($lng->txt("test_delete_page"), $ilCtrl->getLinkTarget($this, "removeQuestions"));
     }
     if (count($questions) > 1 && !$total) {
         $ilToolbar->addSeparator();
         $ilToolbar->addButton($lng->txt("test_move_page"), $ilCtrl->getLinkTarget($this, "movePageForm"));
     }
     global $ilAccess, $ilUser;
     $online_access = false;
     if ($this->object->getFixedParticipants()) {
         include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
         $online_access_result = ilObjTestAccess::_lookupOnlineTestAccess($this->object->getId(), $ilUser->getId());
         if ($online_access_result === true) {
             $online_access = true;
         }
     }
     if ($this->object->isOnline() && $this->object->isComplete($this->testQuestionSetConfigFactory->getQuestionSetConfig())) {
         if ((!$this->object->getFixedParticipants() || $online_access) && $ilAccess->checkAccess("read", "", $this->ref_id)) {
             $testSession = $this->testSessionFactory->getSession();
             $executable = $this->object->isExecutable($testSession, $ilUser->getId(), $allowPassIncrease = TRUE);
             if ($executable["executable"]) {
                 $player_factory = new ilTestPlayerFactory($this->object);
                 $player_instance = $player_factory->getPlayerGUI();
                 if ($testSession->getActiveId() > 0) {
                     $ilToolbar->addSeparator();
                     $ilToolbar->addButton($lng->txt('tst_resume_test'), $ilCtrl->getLinkTarget($player_instance, 'resumePlayer'));
                 } else {
                     $ilToolbar->addSeparator();
                     $ilToolbar->addButton($lng->txt('tst_start_test'), $ilCtrl->getLinkTarget($player_instance, 'startTest'));
                 }
             }
         }
     }
 }
 private function saveFormCmd($isConfirmedSave = false)
 {
     $form = $this->buildForm();
     // form validation and initialisation
     $errors = !$form->checkInput();
     // ALWAYS CALL BEFORE setValuesByPost()
     $form->setValuesByPost();
     // NEVER CALL THIS BEFORE checkInput()
     // Sarcasm? No. Because checkInput checks the form graph against the POST without
     // actually setting the values into the form. Sounds ridiculous? Indeed, and it is.
     // return to form when any form validation errors exist
     if ($errors) {
         ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
         return $this->showFormCmd($form);
     }
     // return to form when online is to be set, but no questions are configured
     $currentQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfig();
     if ($form->getItemByPostVar('online')->getChecked() && !$this->testOBJ->isComplete($currentQuestionSetConfig)) {
         $form->getItemByPostVar('online')->setAlert($this->lng->txt("cannot_switch_to_online_no_questions_andor_no_mark_steps"));
         ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
         return $this->showFormCmd($form);
     }
     // solve conflicts with question set type setting with confirmation screen if required
     // determine wether question set type relating data is to be removed (questions/pools)
     $questionSetTypeRelatingDataCleanupRequired = false;
     if ($form->getItemByPostVar('question_set_type') instanceof ilFormPropertyGUI) {
         $oldQuestionSetType = $this->testOBJ->getQuestionSetType();
         $newQuestionSetType = $form->getItemByPostVar('question_set_type')->getValue();
         if (!$this->testOBJ->participantDataExist() && $newQuestionSetType != $oldQuestionSetType) {
             $oldQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfigByType($oldQuestionSetType);
             if ($oldQuestionSetConfig->doesQuestionSetRelatedDataExist()) {
                 if (!$isConfirmedSave) {
                     if ($oldQuestionSetType == ilObjTest::QUESTION_SET_TYPE_FIXED) {
                         return $this->showConfirmation($form, $oldQuestionSetType, $newQuestionSetType, $this->testOBJ->hasQuestionsWithoutQuestionpool());
                     }
                     return $this->showConfirmation($form, $oldQuestionSetType, $newQuestionSetType, false);
                 }
                 $questionSetTypeRelatingDataCleanupRequired = true;
             }
             if ($form->getItemByPostVar('online')->getChecked()) {
                 $form->getItemByPostVar('online')->setChecked(false);
                 if ($this->testOBJ->isOnline()) {
                     $infoMsg = $this->lng->txt("tst_set_offline_due_to_switched_question_set_type_setting");
                 } else {
                     $infoMsg = $this->lng->txt("tst_cannot_online_due_to_switched_quest_set_type_setting");
                 }
                 ilUtil::sendInfo($infoMsg, true);
             }
         }
     }
     // adjust use previous answers setting due to desired question set type
     if ($newQuestionSetType != ilObjTest::QUESTION_SET_TYPE_FIXED) {
         $form->getItemByPostVar('chb_use_previous_answers')->setValue(0);
     }
     // perform saving the form data
     $this->performSaveForm($form);
     // clean up test mode relating configuration data (questions/questionpools)
     if ($questionSetTypeRelatingDataCleanupRequired) {
         $oldQuestionSetConfig->removeQuestionSetRelatedData();
     }
     // disinvite all invited users if required
     if (!$this->testOBJ->participantDataExist() && !$this->testOBJ->getFixedParticipants()) {
         foreach ($this->testOBJ->getInvitedUsers() as $usrId => $usrData) {
             $this->testOBJ->disinviteUser($usrId);
         }
     }
     // redirect to form output
     ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
     $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
 }
 /**
 * Returns true, if a test is complete for use
 *
 * @return boolean True, if the test is complete for use, otherwise false
 * @access public
 */
 function _isComplete($obj_id)
 {
     $test = new ilObjTest($obj_id, false);
     $test->loadFromDb();
     return $test->isComplete();
 }