ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilPageQuestionProcessor Class Reference

Page question processor. More...

+ Collaboration diagram for ilPageQuestionProcessor:

Public Member Functions

 __construct ()
 constructor
 saveQuestionAnswer ($a_type, $a_id, $a_answer)
 Save question answer.
 calculatePoints ($a_type, $a_id, $a_choice)
 Calculate points.

Static Public Member Functions

static getQuestionStatistics ($a_q_id)
 Get statistics for question.

Detailed Description

Page question processor.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 11 of file class.ilPageQuestionProcessor.php.

Constructor & Destructor Documentation

ilPageQuestionProcessor::__construct ( )

constructor

Parameters
@return

Definition at line 19 of file class.ilPageQuestionProcessor.php.

{
}

Member Function Documentation

ilPageQuestionProcessor::calculatePoints (   $a_type,
  $a_id,
  $a_choice 
)

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.

Parameters
@return

Definition at line 142 of file class.ilPageQuestionProcessor.php.

References $ilLog, CLOZE_NUMERIC, CLOZE_SELECT, and CLOZE_TEXT.

Referenced by saveQuestionAnswer().

{
global $ilLog;
switch ($a_type)
{
case "assSingleChoice":
include_once("./Modules/TestQuestionPool/classes/class.assSingleChoice.php");
$q = new assSingleChoice();
$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 = new assMultipleChoice();
$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 = new assClozeTest();
$q->loadFromDb($a_id);
$points = 0;
foreach ($q->getGaps() as $id => $gap)
{
$choice = $a_choice[$id];
switch ($gap->getType())
{
case CLOZE_TEXT:
$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;
//$ilLog->write("ct: ".$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;
//$ilLog->write("cn: ".$gappoints);
break;
for ($order = 0; $order < $gap->getItemCount(); $order++)
{
$answer = $gap->getItem($order);
if ($choice == $answer->getOrder())
{
$answerpoints = $answer->getPoints();
$points += $answerpoints;
//$ilLog->write("cs: ".$answerpoints);
}
}
break;
}
}
break;
case "assMatchingQuestion":
include_once("./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php");
$q = new assMatchingQuestion();
$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 = new assOrderingQuestion();
$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 = new assImagemapQuestion();
$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;
}

+ Here is the caller graph for this function:

static ilPageQuestionProcessor::getQuestionStatistics (   $a_q_id)
static

Get statistics for question.

Parameters
intquestion id
Returns
array

Definition at line 88 of file class.ilPageQuestionProcessor.php.

Referenced by ilLMQuestionListTableGUI\fillRow().

{
global $ilDB;
$set = $ilDB->query("SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
" qst_id = ".$ilDB->quote($a_q_id, "integer")
);
$rec = $ilDB->fetchAssoc($set);
$all = $rec["usr_cnt"];
$first = false;
$second = false;
$third_or_more = false;
if ($all > 0)
{
$set = $ilDB->query("SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
" qst_id = ".$ilDB->quote($a_q_id, "integer")." AND ".
" passed = ".$ilDB->quote(1, "integer")." AND ".
" try = ".$ilDB->quote(1, "integer")
);
$rec = $ilDB->fetchAssoc($set);
$first = $rec["usr_cnt"];
$set = $ilDB->query("SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
" qst_id = ".$ilDB->quote($a_q_id, "integer")." AND ".
" passed = ".$ilDB->quote(1, "integer")." AND ".
" try = ".$ilDB->quote(2, "integer")
);
$rec = $ilDB->fetchAssoc($set);
$second = $rec["usr_cnt"];
$set = $ilDB->query($q = "SELECT count(user_id) usr_cnt FROM page_qst_answer WHERE ".
" qst_id = ".$ilDB->quote($a_q_id, "integer")." AND ".
" passed = ".$ilDB->quote(1, "integer")." AND ".
" try >= ".$ilDB->quote(3, "integer")
);
$rec = $ilDB->fetchAssoc($set);
$third_or_more = $rec["usr_cnt"];
}
return array("all" => $all, "first" => $first, "second" => $second, "third_or_more" => $third_or_more);
}

+ Here is the caller graph for this function:

ilPageQuestionProcessor::saveQuestionAnswer (   $a_type,
  $a_id,
  $a_answer 
)

Save question answer.

Parameters
@return

Definition at line 31 of file class.ilPageQuestionProcessor.php.

References $ilLog, $ilUser, calculatePoints(), ilJsonUtil\decode(), and exit.

Referenced by ilPageObjectGUI\processAnswer().

{
global $ilUser, $ilLog, $ilDB;
//$a_type = "assOrderingQuestion";
//$a_id = 74;
//$a_answer = '{"tries":1,"wrong":2,"passed":false,"answer":[true,true,false,true,false],"interactionId":null,"choice":["1","2","5","4","3"]}';
$ilLog->write($a_type);
$ilLog->write($a_id);
$ilLog->write($a_answer);
include_once("./Services/JSON/classes/class.ilJsonUtil.php");
$answer = ilJsonUtil::decode($a_answer);
$tries = $answer->tries;
$passed = $answer->passed;
$choice = $answer->choice;
$points = ilPageQuestionProcessor::calculatePoints($a_type, $a_id, $choice);
$ilLog->write("Points: ".$points);
$set = $ilDB->query("SELECT * FROM page_qst_answer WHERE ".
" qst_id = ".$ilDB->quote($a_id, "integer")." AND ".
" user_id = ".$ilDB->quote($ilUser->getId(), "integer")
);
if ($rec = $ilDB->fetchAssoc($set))
{
$ilDB->manipulate("UPDATE page_qst_answer SET ".
" try = try + 1,".
" passed = ".$ilDB->quote($passed, "integer").",".
" points = ".$ilDB->quote($points, "float").
" WHERE qst_id = ".$ilDB->quote($a_id, "integer").
" AND user_id = ".
$ilDB->quote($ilUser->getId(), "integer")
);
}
else
{
$ilDB->manipulate("INSERT INTO page_qst_answer ".
"(qst_id, user_id, try, passed, points) VALUES (".
$ilDB->quote($a_id, "integer").",".
$ilDB->quote($ilUser->getId(), "integer").",".
$ilDB->quote(1, "integer").",".
$ilDB->quote($passed, "integer").",".
$ilDB->quote($points, "float").
")");
}
//$ilLog->write("tries: ".$tries);
//$ilLog->write("passed: ".$passed);
//$ilLog->write("points: ".$points);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: