Skip to content

Commit

Permalink
lok3 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Heyser committed Aug 20, 2015
1 parent 01922d4 commit a9334af
Show file tree
Hide file tree
Showing 18 changed files with 1,259 additions and 123 deletions.
118 changes: 73 additions & 45 deletions Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,72 @@ public function __construct($a_user_id, $a_course_id)

$this->settings = ilLOSettings::getInstanceByObjId($this->container_id);
}




/**
* Called from learning objective test on actual test start
* @param ilTestSession $a_test_session
* @param integer $a_test_obj_id
*/
public function notifyTestStart(ilTestSession $a_test_session, $a_test_obj_id)
{
$userId = $a_test_session->getUserId();
$testId = $a_test_session->getTestId();
$testRefId = $a_test_session->getRefId();
$testObjId = $a_test_obj_id;
$parentCrsRefId = $a_test_session->getObjectiveOrientedContainerId();

// make some noise on actual test start
}

/**
* Called from learning objective test
* @param ilTestSession $a_test_session
* @param ilTestSequence $a_test_sequence
*/
public static function filterQuestions(ilTestSession $a_test_session, ilTestSequence $a_test_sequence)
public function prepareTestPass(ilTestSession $a_test_session, ilTestSequence $a_test_sequence)
{

$adapter = new self(
$a_test_session->getUserId(),
$a_test_session->getObjectiveOrientedContainerId()
);
$adapter->initTestRun($a_test_session);
$adapter->updateQuestions($a_test_session, $a_test_sequence);
$adapter->hideQuestions($a_test_sequence);
$adapter->storeTestRun();
$adapter->initUserResult($a_test_session);
$this->updateQuestions($a_test_session, $a_test_sequence);

// TODO: following if requires real condition
if($markQuestionsOptionalWhenRelatedToPassedObjective = true)
{
$this->setQuestionsOptional($a_test_sequence);
}
// TODO: following if requires real condition
elseif($hideQuestionsWhenRelatedToPassedObjective = false)
{
$this->hideQuestions($a_test_sequence);
}

$this->storeTestRun();
$this->initUserResult($a_test_session);

// Save test sequence
$a_test_sequence->saveToDb();

$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($a_test_sequence,true));
return true;
}

/**
* Store result and update objective status
* @param ilTestSession $a_test_session
* @param ilTestSequence $a_test_sequence
* @param assQuestion $a_question
* @param ilTestQuestionRelatedObjectivesList $a_objectives_list
*/
public static function updateObjectiveStatus(ilTestSession $a_test_session, ilTestSequence $a_test_sequence, assQuestion $a_question)
public function buildQuestionRelatedObjectiveList(ilTestQuestionRelatedObjectivesList $a_objectives_list)
{
$adapter = new self(
$a_test_session->getUserId(),
$a_test_session->getObjectiveOrientedContainerId()
);
$adapter->initTestRun($a_test_session);
$adapter->updateQuestionResult($a_test_session,$a_question);
return true;

/*
$usr_id = $a_test_session->getUserId();
$crs_id = $a_test_session->getObjectiveOrientedContainerId();
$question_id = $a_question->getId();
$points_reached = $a_question->getReachedPoints($a_test_session->getActiveId(), $a_test_session->getPass());
//$points_max = $a_question->getMaxPoints();
if( $a_test_sequence instanceof ilTestSequenceFixedQuestionSet )
{
// make some noise (with question id only)
}
elseif( $a_test_sequence instanceof ilTestSequenceRandomQuestionSet )
foreach( $a_objectives_list->getQuestionIds() as $qid )
{
$respSrcPoolDefId = $a_test_sequence->getResponsibleSourcePoolDefinitionId($question_id);
foreach( $this->run as $run )
{
/* @var ilLOTestRun $run */

// make some noise (with question id and responsible source pool definition)
if( $run->questionExists($qid) )
{
$a_objectives_list->addQuestionRelatedObjective($qid, $run->getObjectiveId());
}
}
}
*/
}

protected function getUserId()
Expand Down Expand Up @@ -230,7 +231,7 @@ protected function isQualifiedStartRun(ilTestSession $session)
* @param ilTestSession $session
* @param assQuestion $qst
*/
protected function updateQuestionResult(ilTestSession $session, assQuestion $qst)
public function updateQuestionResult(ilTestSession $session, assQuestion $qst)
{
foreach($this->run as $run)
{
Expand Down Expand Up @@ -284,6 +285,22 @@ protected function updateQuestionResult(ilTestSession $session, assQuestion $qst
return false;
}

/**
* set questions optional
* @param ilTestSequence $seq
*/
protected function setQuestionsOptional(ilTestSequence $seq)
{
// first unset optional on all questions
$seq->clearOptionalQuestions();
foreach($seq->getQuestionIds() as $qid)
{
if(!$this->isInRun($qid))
{
$seq->setQuestionOptional($qid);
}
}
}

/**
* Hide questions
Expand All @@ -302,7 +319,6 @@ protected function hideQuestions(ilTestSequence $seq)
}
}


protected function initTestRun(ilTestSession $session)
{
include_once './Modules/Course/classes/Objectives/class.ilLOTestRun.php';
Expand Down Expand Up @@ -418,5 +434,17 @@ private static function getQuestionData($testObjId, $questionIds)

return $questionList->getQuestionDataArray();
}

public static function getInstance(ilTestSession $a_test_session)
{
$adapter = new self(
$a_test_session->getUserId(),
$a_test_session->getObjectiveOrientedContainerId()
);

$adapter->initTestRun($a_test_session);

return $adapter;
}
}
?>
126 changes: 94 additions & 32 deletions Modules/Test/classes/class.ilTestEvaluationGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function __construct(ilObjTest $a_object)
*/
public function &executeCommand()
{
$this->determineObjectiveContainer();

$cmd = $this->ctrl->getCmd();
$next_class = $this->ctrl->getNextClass($this);
$this->ctrl->saveParameter($this, "sequence");
Expand Down Expand Up @@ -973,7 +975,7 @@ function outParticipantsResultsOverview()
$toolbar->build();
$template->setVariable('RESULTS_TOOLBAR', $this->ctrl->getHTML($toolbar));

$overview = $this->getPassOverview($active_id, "iltestevaluationgui", "outParticipantsPassDetails");
$overview = $this->getPassOverview($testSession, "iltestevaluationgui", "outParticipantsPassDetails");
$template->setVariable("PASS_OVERVIEW", $overview);

$user_id = $this->object->_getUserIdFromActiveId($active_id);
Expand Down Expand Up @@ -1039,7 +1041,7 @@ public function outUserPassDetailsResetTableFilter()
*/
function outUserPassDetails()
{
global $ilTabs, $ilUser;
global $ilTabs, $ilUser, $ilObjDataCache;

if ($this->object->getNrOfTries() == 1)
{
Expand Down Expand Up @@ -1068,6 +1070,32 @@ function outUserPassDetails()
$this->ctrl->saveParameter($this, "pass");
$pass = $_GET["pass"];

require_once 'Modules/Test/classes/class.ilTestResultHeaderLabelBuilder.php';
$testResultHeaderLabelBuilder = new ilTestResultHeaderLabelBuilder($this->lng, $ilObjDataCache);

$objectivesList = null;

if( $this->objectiveOrientedPresentationRequired() )
{
$testSequence = $this->testSequenceFactory->getSequenceByPass($testSession, $pass);
$testSequence->loadFromDb();
$testSequence->loadQuestions();

require_once 'Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php';
$objectivesAdapter = ilLOTestQuestionAdapter::getInstance($testSession);

$objectivesList = $this->buildQuestionRelatedObjectivesList(
$objectivesAdapter, $testSequence->getQuestionIds()
);
$objectivesList->loadObjectivesTitles();

$testResultHeaderLabelBuilder->setObjectiveOrientedContainerId($testSession->getObjectiveOrientedContainerId());
$testResultHeaderLabelBuilder->setUserId($testSession->getUserId());
$testResultHeaderLabelBuilder->setTestObjId($this->object->getId());
$testResultHeaderLabelBuilder->setTestRefId($this->object->getRefId());
$testResultHeaderLabelBuilder->initObjectiveOrientedMode();
}

$result_array = $this->getFilteredTestResult($active_id, $pass);

$command_solution_details = "";
Expand Down Expand Up @@ -1113,42 +1141,46 @@ function outUserPassDetails()
}
}

if( $this->isGradingMessageRequired() && $this->object->getNrOfTries() == 1 )
if( !$this->objectiveOrientedPresentationRequired() &&
$this->isGradingMessageRequired() && $this->object->getNrOfTries() == 1 )
{
$tpl->setCurrentBlock('grading_message');
$tpl->setVariable('GRADING_MESSAGE', $this->getGradingMessage($active_id));
$tpl->parseCurrentBlock();
}

$overview = $this->getPassDetailsOverview(
$result_array, $active_id, $pass, $this, "outUserPassDetails", $command_solution_details, $questionAnchorNav
$result_array, $active_id, $pass, $this, "outUserPassDetails",
$command_solution_details, $questionAnchorNav, $objectivesList
);
$tpl->setVariable("PASS_DETAILS", $overview);

if( $this->object->canShowSolutionPrintview() )
{
$list_of_answers = $this->getPassListOfAnswers(
$result_array, $active_id, $pass, $this->object->getShowSolutionListComparison(),
false, false, false, true
false, false, false, true, $objectivesList
);
$tpl->setVariable("LIST_OF_ANSWERS", $list_of_answers);
}

$tpl->setVariable("TEXT_RESULTS", $this->lng->txt("tst_results"));
$tpl->setVariable("TEXT_RESULTS", $testResultHeaderLabelBuilder->getPassDetailsHeaderLabel($pass+1));
$tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));

$uname = $this->object->userLookupFullName($user_id, TRUE);
$user_data = $this->getResultsUserdata($testSession, $active_id, TRUE);
if ($this->object->getAnonymity())
{
$tpl->setVariable("TEXT_HEADING", $this->lng->txt("tst_result_pass"));
}
else
if( !$this->objectiveOrientedPresentationRequired() )
{
$tpl->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $uname));
$tpl->setVariable("USER_DATA", $user_data);
if($this->object->getAnonymity())
{
$tpl->setVariable("TEXT_HEADING", $this->lng->txt("tst_result_pass"));
} else
{
$tpl->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name_pass"), $pass + 1, $uname));
$tpl->setVariable("USER_DATA", $user_data);
}
}

$this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
if ($this->object->getShowSolutionAnswersOnly())
{
Expand All @@ -1173,7 +1205,7 @@ function outUserPassDetails()
*/
function outUserResultsOverview()
{
global $ilUser, $ilTabs;
global $ilUser, $ilTabs, $ilObjDataCache;

$ilTabs->setBackTarget(
$this->lng->txt('tst_results_back_introduction'),
Expand Down Expand Up @@ -1218,26 +1250,44 @@ function outUserResultsOverview()
}

$template->setCurrentBlock("pass_overview");
$overview = $this->getPassOverview($active_id, "iltestevaluationgui", "outUserPassDetails", FALSE, $hide_details);
$overview = $this->getPassOverview($testSession, "iltestevaluationgui", "outUserPassDetails", FALSE, $hide_details);
$template->setVariable("PASS_OVERVIEW", $overview);
$template->setVariable("TEXT_RESULTS", $this->lng->txt("tst_results_overview"));

require_once 'Modules/Test/classes/class.ilTestResultHeaderLabelBuilder.php';
$testResultHeaderLabelBuilder = new ilTestResultHeaderLabelBuilder($this->lng, $ilObjDataCache);
if( $this->objectiveOrientedPresentationRequired() )
{
$testResultHeaderLabelBuilder->setObjectiveOrientedContainerId($testSession->getObjectiveOrientedContainerId());
$testResultHeaderLabelBuilder->setUserId($testSession->getUserId());
$testResultHeaderLabelBuilder->setTestObjId($this->object->getId());
$testResultHeaderLabelBuilder->setTestRefId($this->object->getRefId());
$testResultHeaderLabelBuilder->initObjectiveOrientedMode();
}

$template->setVariable("TEXT_RESULTS", $testResultHeaderLabelBuilder->getPassOverviewHeaderLabel());

$template->parseCurrentBlock();

$user_data = $this->getResultsUserdata($testSession, $active_id, TRUE);

if ($this->object->getAnonymity()) {
$template->setVariable("TEXT_HEADING", $this->lng->txt("tst_result"));
}
else {
$template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
$template->setVariable("USER_DATA", $user_data);
}

if( $this->isGradingMessageRequired() )
if( !$this->objectiveOrientedPresentationRequired() )
{
$template->setCurrentBlock('grading_message');
$template->setVariable('GRADING_MESSAGE', $this->getGradingMessage($active_id));
$template->parseCurrentBlock();
if ($this->object->getAnonymity())
{
$template->setVariable("TEXT_HEADING", $this->lng->txt("tst_result"));
}
else
{
$template->setVariable("TEXT_HEADING", sprintf($this->lng->txt("tst_result_user_name"), $uname));
$template->setVariable("USER_DATA", $user_data);
}

if( $this->isGradingMessageRequired() )
{
$template->setCurrentBlock('grading_message');
$template->setVariable('GRADING_MESSAGE', $this->getGradingMessage($active_id));
$template->parseCurrentBlock();
}
}

$this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
Expand Down Expand Up @@ -1296,7 +1346,7 @@ function outUserListOfAnswerPasses()
}
else
{
$overview = $this->getPassOverview($active_id, "iltestevaluationgui", "outUserListOfAnswerPasses", TRUE);
$overview = $this->getPassOverview($testSession, "iltestevaluationgui", "outUserListOfAnswerPasses", TRUE);
$template->setVariable("TEXT_RESULTS", $this->lng->txt("tst_passes"));
$template->setVariable("PASS_OVERVIEW", $overview);
}
Expand Down Expand Up @@ -1401,6 +1451,18 @@ function outCorrectSolution()
$testSequence->loadQuestions();

$questionId = (int)$_GET['evaluation'];

if( $this->objectiveOrientedPresentationRequired() )
{
require_once 'Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php';
$objectivesAdapter = ilLOTestQuestionAdapter::getInstance($testSession);
$objectivesList = $this->buildQuestionRelatedObjectivesList($objectivesAdapter, array($questionId));
$objectivesList->loadObjectivesTitles();
}
else
{
$objectivesList = null;
}

if( !$testSequence->questionExists($questionId) )
{
Expand All @@ -1426,7 +1488,7 @@ function outCorrectSolution()
$this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"), "print");
}

$solution = $this->getCorrectSolutionOutput($questionId, $activeId, $pass);
$solution = $this->getCorrectSolutionOutput($questionId, $activeId, $pass, $objectivesList);

$this->tpl->setContent($solution);
}
Expand Down
Loading

0 comments on commit a9334af

Please sign in to comment.