Calculate points.
This function calculates the points for a given answer. Better would be to re-use from T&A here in the future. When this code has been written this has not been possible yet.
{
switch ($a_type)
{
case "assSingleChoice":
include_once("./Modules/TestQuestionPool/classes/class.assSingleChoice.php");
$q->loadFromDb($a_id);
$points = 0;
foreach ($q->getAnswers() as $key => $answer)
{
if (isset($a_choice[0]) && $key == $a_choice[0])
{
$points += $answer->getPoints();
}
}
break;
case "assMultipleChoice":
include_once("./Modules/TestQuestionPool/classes/class.assMultipleChoice.php");
$q->loadFromDb($a_id);
$points = 0;
foreach ($q->getAnswers() as $key => $answer)
{
if (is_array($a_choice) && in_array($key, $a_choice))
{
$points += $answer->getPoints();
}
else
{
$points += $answer->getPointsUnchecked();
}
}
break;
case "assClozeTest":
include_once("./Modules/TestQuestionPool/classes/class.assClozeTest.php");
$q->loadFromDb($a_id);
$points = 0;
foreach ($q->getGaps() as $id => $gap)
{
$choice = $a_choice[$id];
switch ($gap->getType())
{
$gappoints = 0;
for ($order = 0; $order < $gap->getItemCount(); $order++)
{
$answer = $gap->getItem($order);
$gotpoints = $q->getTextgapPoints($answer->getAnswertext(),
$choice, $answer->getPoints());
if ($gotpoints > $gappoints) $gappoints = $gotpoints;
}
$points += $gappoints;
break;
$gappoints = 0;
for ($order = 0; $order < $gap->getItemCount(); $order++)
{
$answer = $gap->getItem($order);
$gotpoints = $q->getNumericgapPoints($answer->getAnswertext(),
$choice, $answer->getPoints(),
$answer->getLowerBound(), $answer->getUpperBound());
if ($gotpoints > $gappoints) $gappoints = $gotpoints;
}
$points += $gappoints;
break;
for ($order = 0; $order < $gap->getItemCount(); $order++)
{
$answer = $gap->getItem($order);
if ($choice == $answer->getOrder())
{
$answerpoints = $answer->getPoints();
$points += $answerpoints;
}
}
break;
}
}
break;
case "assMatchingQuestion":
include_once("./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php");
$q->loadFromDb($a_id);
$points = 0;
for ($i = 0; $i < $q->getMatchingPairCount(); $i++)
{
$pair = $q->getMatchingPair($i);
if (is_array($a_choice) && in_array($pair->definition->identifier."-".$pair->term->identifier, $a_choice))
{
$points += $pair->points;
}
}
break;
case "assOrderingQuestion":
include_once("./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php");
$q->loadFromDb($a_id);
$points = 0;
$cnt = 1;
$right = true;
foreach ($q->getAnswers() as $answer)
{
if ($a_choice[$cnt - 1] != $cnt)
{
$right = false;
}
$cnt++;
}
if ($right)
{
$points = $q->getPoints();
}
break;
case "assImagemapQuestion":
include_once("./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php");
$q->loadFromDb($a_id);
$points = 0;
foreach ($q->getAnswers() as $key => $answer)
{
if (is_array($a_choice) && in_array($key, $a_choice))
{
$points += $answer->getPoints();
}
}
break;
}
if ($points < 0)
{
$points = 0;
}
return (int) $points;
}