Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
smeyer-ilias committed Aug 21, 2015
1 parent 10a82d1 commit f36bf27
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 35 deletions.
19 changes: 19 additions & 0 deletions Modules/Course/classes/Objectives/class.ilLOTestAssignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ public function getTestByObjective($a_objective_id, $a_type)
return 0;
}

public function isSeparateTest($a_test_ref_id)
{
if(!$this->getSettings()->hasSeparateInitialTests())
{
if($this->getSettings()->getInitialTest() == $a_test_ref_id)
{
return FALSE;
}
}
if($this->getSettings()->hasSeparateQualifiedTests())
{
if($this->getSettings()->getQualifiedTest() == $a_test_ref_id)
{
return FALSE;
}
}
return TRUE;
}

/**
* Get test type by test id
* @param type $a_test_ref_id
Expand Down
74 changes: 51 additions & 23 deletions Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */

include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';

/**
* Test question filter
Expand All @@ -12,6 +13,7 @@
class ilLOTestQuestionAdapter
{
protected $settings = NULL;
protected $assignments = null;

protected $user_id = 0;
protected $container_id = 0;
Expand All @@ -29,6 +31,7 @@ public function __construct($a_user_id, $a_course_id)
$this->container_id = $a_course_id;

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

/**
Expand Down Expand Up @@ -158,11 +161,11 @@ public function prepareTestPass(ilTestSession $a_test_session, ilTestSequence $a

if($this->getSettings()->getPassedObjectiveMode() == ilLOSettings::MARK_PASSED_OBJECTIVE_QST)
{
$this->setQuestionsOptional($a_test_sequence);
#$this->setQuestionsOptional($a_test_sequence);
}
elseif($this->getSettings()->getPassedObjectiveMode() == ilLOSettings::HIDE_PASSED_OBJECTIVE_QST)
{
$this->hideQuestions($a_test_sequence);
#$this->hideQuestions($a_test_sequence);
}

$this->storeTestRun();
Expand Down Expand Up @@ -231,6 +234,15 @@ protected function getSettings()
return $this->settings;
}

/**
*
* @return ilLOTestAssignments
*/
protected function getAssignments()
{
return $this->assignments;
}

/**
* init user result
*/
Expand All @@ -253,19 +265,15 @@ protected function initUserResult(ilTestSession $session)
$this->container_id,
$this->user_id,
$run->getObjectiveId(),
($this->getSettings()->getQualifiedTest() == $session->getRefId()) ?
ilLOUserResults::TYPE_QUALIFIED :
ilLOUserResults::TYPE_INITIAL
$this->getAssignments()->getTypeByTest($session->getRefId())
);

include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';

$limit = ilLOUtils::lookupObjectiveRequiredPercentage(
$this->container_id,
$run->getObjectiveId(),
($this->getSettings()->getQualifiedTest() == $session->getRefId()) ?
ilLOSettings::TYPE_TEST_QUALIFIED :
ilLOSettings::TYPE_TEST_INITIAL,
$session->getRefId(),
$run->getMaxPoints()
);

Expand All @@ -285,10 +293,8 @@ protected function initUserResult(ilTestSession $session)

$ur = new ilLOUserResults($this->container_id,$this->user_id);
$ur->saveObjectiveResult(
$run->getObjectiveId(),
($this->getSettings()->getQualifiedTest() == $session->getRefId()) ?
ilLOUserResults::TYPE_QUALIFIED :
ilLOUserResults::TYPE_INITIAL,
$run->getObjectiveId(),
$this->getAssignments()->getTypeByTest($session->getRefId()),
$old_result['status'],
$old_result['result_perc'],
$limit,
Expand All @@ -305,11 +311,12 @@ protected function initUserResult(ilTestSession $session)
*/
protected function isQualifiedStartRun(ilTestSession $session)
{
if($session->getRefId() == $this->getSettings()->getInitialTest())
if($this->getAssignments()->getTypeByTest($session->getRefId()) == ilLOSettings::TYPE_TEST_INITIAL)
{
$GLOBALS['ilLog']->write(__METHOD__.': is intial');
$GLOBALS['ilLog']->write(__METHOD__.': is initial');
return false;
}

if($session->getRefId() != $this->getSettings()->getQualifiedTest())
{
$GLOBALS['ilLog']->write(__METHOD__.': is not qualified');
Expand Down Expand Up @@ -367,17 +374,13 @@ public function updateQuestionResult(ilTestSession $session, assQuestion $qst)
$this->container_id,
$this->user_id,
$run->getObjectiveId(),
($this->getSettings()->getQualifiedTest() == $session->getRefId()) ?
ilLOUserResults::TYPE_QUALIFIED :
ilLOUserResults::TYPE_INITIAL
$this->getAssignments()->getTypeByTest($session->getRefId())
);

$ur = new ilLOUserResults($this->container_id,$this->user_id);
$ur->saveObjectiveResult(
$run->getObjectiveId(),
($this->getSettings()->getQualifiedTest() == $session->getRefId()) ?
ilLOUserResults::TYPE_QUALIFIED :
ilLOUserResults::TYPE_INITIAL,
$this->getAssignments()->getTypeByTest($session->getRefId()),
ilLOUtils::isCompleted(
$this->container_id,
$session->getRefId(),
Expand Down Expand Up @@ -457,17 +460,43 @@ protected function storeTestRun()

protected function updateQuestions(ilTestSession $session, ilTestSequence $seq)
{
if($this->getAssignments()->isSeparateTest($session->getRefId()))
{
return $this->updateSeparateTestQuestions($session, $seq);
}
if($seq instanceof ilTestSequenceFixedQuestionSet)
{
$this->updateFixedQuestions($session, $seq);
return $this->updateFixedQuestions($session, $seq);
}
if($seq instanceof ilTestSequenceRandomQuestionSet)
{
$this->updateRandomQuestions($session, $seq);
return $this->updateRandomQuestions($session, $seq);
}

}

/**
* Update questions for separate tests
* @param ilTestSession $session
* @param ilTestSequence $seq
*/
protected function updateSeparateTestQuestions(ilTestSession $session, ilTestSequence $seq)
{
foreach($this->run as $tst_run)
{
$tst_run->clearQuestions();
$points = 0;
foreach($seq->getQuestionIds() as $idx => $qst_id)
{
$tst_run->addQuestion($qst_id);
include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
$points += ilCourseObjectiveQuestion::_lookupMaximumPointsOfQuestion($qst_id);
}
$tst_run->setMaxPoints($points);
}
}


protected function updateFixedQuestions(ilTestSession $session, ilTestSequence $seq)
{
foreach ($this->run as $tst_run)
Expand All @@ -478,7 +507,6 @@ protected function updateFixedQuestions(ilTestSession $session, ilTestSequence $
ilObject::_lookupObjId($session->getRefId()),
$tst_run->getObjectiveId()
);
#$GLOBALS['ilLog']->write(__METHOD__.': '.print_r($qst,true));
$points = 0;
foreach($qst as $id)
{
Expand Down
17 changes: 17 additions & 0 deletions Modules/Course/classes/Objectives/class.ilLOTestRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public static function lookupRunExistsForObjective($a_test_id, $a_objective_id,
}
return false;
}

/**
* Delete runs
* @global type $ilDB
* @param type $a_container_id
* @param type $a_user_id
*/
public static function deleteRuns($a_container_id, $a_user_id)
{
global $ilDB;

$query = 'DELETE FROM loc_tst_run '.
'WHERE container_id = ' . $ilDB->quote($a_container_id,'integer').' '.
'AND user_id = '.$ilDB->quote($a_user_id,'integer').' ';
$ilDB->manipulate($query);

}

public static function deleteRun($a_container_id, $a_user_id, $a_test_id)
{
Expand Down
31 changes: 24 additions & 7 deletions Modules/Course/classes/Objectives/class.ilLOUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,36 @@ public static function isCompleted($a_cont_oid, $a_test_rid, $a_objective_id, $m
* @param type $a_objective_id
* @param type $a_test_type
*/
public static function lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_type, $a_max_points)
public static function lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_ref_id, $a_max_points)
{
include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
$settings = ilLOSettings::getInstanceByObjId($a_container_id);

if($a_test_type == ilLOSettings::TYPE_TEST_QUALIFIED)
{
$tst_ref_id = $settings->getQualifiedTest();
}
else
include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
$assignments = ilLOTestAssignments::getInstance($a_container_id);
$a_test_type = $assignments->getTypeByTest($a_test_ref_id);

if($assignments->isSeparateTest($a_test_ref_id))
{
$tst_ref_id = $settings->getInitialTest();
include_once './Services/Object/classes/class.ilObjectFactory.php';
$factory = new ilObjectFactory();
$tst = $factory->getInstanceByRefId($a_test_ref_id, FALSE);
if($tst instanceof ilObjTest)
{
$schema = $tst->getMarkSchema();
foreach($schema->getMarkSteps() as $mark)
{
if($mark->getPassed())
{
return (int) $mark->getMinimumLevel();
}
}
}
}



$tst_ref_id = $a_test_ref_id;
if(self::lookupRandomTest(ilObject::_lookupObjId($tst_ref_id)))
{
include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
Expand Down
18 changes: 17 additions & 1 deletion Modules/Course/classes/class.ilCourseObjectiveResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,24 @@ function reset($a_course_id)

include_once './Services/Object/classes/class.ilObjectFactory.php';
$factory = new ilObjectFactory();


include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
$assignments = ilLOTestAssignments::getInstance($a_course_id);
foreach(array_merge
(
$assignments->getAssignmentsByType(ilLOSettings::TYPE_TEST_INITIAL),
$assignments->getAssignmentsByType(ilLOSettings::TYPE_TEST_QUALIFIED)
)
as $assignment)
{
$tst = $factory->getInstanceByRefId($assignment->getTestRefId(),FALSE);
if($tst instanceof ilObjTest)
{
$tst->removeTestResultsForUser($this->getUserId());
}
}

$initial = ilLOSettings::getInstanceByObjId($a_course_id)->getInitialTest();
$initial_tst = $factory->getInstanceByRefId($initial, FALSE);
if($initial_tst instanceof ilObjTest)
Expand Down
5 changes: 2 additions & 3 deletions Modules/Course/classes/class.ilObjCourseGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -5220,10 +5220,9 @@ function resetObject()

include_once './Modules/Course/classes/Objectives/class.ilLOTestRun.php';
include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
ilLOTestRun::deleteRun(
ilLOTestRun::deleteRuns(
$this->object->getId(),
$GLOBALS['ilUser']->getId(),
ilObject::_lookupObjId(ilLOSettings::getInstanceByObjId($this->object->getId())->getQualifiedTest())
$GLOBALS['ilUser']->getId()
);

include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php';
Expand Down
2 changes: 1 addition & 1 deletion Modules/Test/classes/class.ilTestOutputGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ protected function outWorkingForm($sequence = "", $test_id, $postpone_allowed, $
{
require_once 'Modules/Course/classes/Objectives/class.ilLOTestQuestionAdapter.php';
$objectivesAdapter = ilLOTestQuestionAdapter::getInstance($this->testSession);
$objectivesAdapter->buildQuestionRelatedObjectiveList($this->questionRelatedObjectivesList);
$objectivesAdapter->buildQuestionRelatedObjectiveList($this->testSequence,$this->questionRelatedObjectivesList);
$this->questionRelatedObjectivesList->loadObjectivesTitles();

$objectivesString = $this->questionRelatedObjectivesList->getQuestionRelatedObjectiveTitle($questionId);
Expand Down

0 comments on commit f36bf27

Please sign in to comment.