diff --git a/classes/Feedback/Feedback.php b/classes/Feedback/Feedback.php
new file mode 100644
index 0000000..741f072
--- /dev/null
+++ b/classes/Feedback/Feedback.php
@@ -0,0 +1,116 @@
+
+ */
+class Feedback
+{
+ /**
+ * @var string
+ */
+ protected $feedback;
+
+ /**
+ * @var string
+ */
+ protected $recomander_id;
+
+ /**
+ * @var bool
+ */
+ protected $correct;
+
+ /**
+ * @var xdhtObjectFacadeInterface
+ */
+ protected $facade;
+
+ /**
+ * Feedback constructor.
+ * @param string $feedback
+ * @param string $recomander_id
+ * @param bool $correct
+ * @param xdhtObjectFacadeInterface $facade
+ */
+ public function __construct($feedback, $recomander_id, $correct, $facade)
+ {
+ $this->feedback = $feedback;
+ $this->recomander_id = $recomander_id;
+ $this->correct = $correct;
+ $this->facade = $facade;
+ }
+
+ public function getFeedback()
+ {
+ global $ilDB;
+ $question_data = $this->facade->xdhtQuestionFactory()->getQuestionByRecomanderId($this->recomander_id);
+ $question_id = $question_data['question_id'];
+ $question_type = $question_data['question_type_fi'];
+ if (is_numeric($this->feedback)) {
+ $sql = "SELECT feedback FROM qpl_fb_specific WHERE question_fi = $question_id AND answer = $this->feedback";
+ $set = $ilDB->query($sql);
+
+ $row = $ilDB->fetchAssoc($set);
+ $feedback = $row["feedback"];
+ if (!empty($feedback)) {
+ return $feedback;
+ }
+
+ $cdb = (int)$this->correct;
+ $sql = "SELECT feedback FROM qpl_fb_generic WHERE question_fi = $question_id AND correctness = $cdb";
+ $set = $ilDB->query($sql);
+
+ $row = $ilDB->fetchAssoc($set);
+ $feedback = $row["feedback"];
+ if (!empty($feedback)) {
+ return $feedback;
+ }
+ }
+
+ if (!empty($this->feedback) and !is_numeric($this->feedback)) {
+ return $this->feedback;
+ }
+ elseif ($this->correct) {
+ return "Ihre Antwort ist korrekt!";
+ }
+ else {
+ return $this->getCorrectAnswer($question_id, $question_type);
+ }
+ }
+
+ public function getFeedbackType()
+ {
+ if ($this->correct) {
+ return ilGlobalTemplate::MESSAGE_TYPE_SUCCESS;
+ }
+ else {
+ return ilGlobalTemplate::MESSAGE_TYPE_FAILURE;
+ }
+ }
+
+ private function getCorrectAnswer($question, $question_type) {
+ global $ilDB;
+ if ($question_type == 1) {
+ $sql = "select answertext from qpl_a_sc where question_fi = $question and points > 0";
+ $set = $ilDB->query($sql);
+ $correct_answer = $ilDB->fetchAssoc($set)["answertext"];
+ }
+ elseif ($question_type == 2) {
+ $sql = "select answertext from qpl_a_mc where question_fi = $question and points > 0";
+ $set = $ilDB->query($sql);
+ $answers = array_column($ilDB->fetchAll($set),"answertext");
+ $correct_answer = "
- " . implode("
- ", $answers) . "
";
+ }
+ elseif ($question_type == 3) {
+ $sql = "select answertext from qpl_a_cloze where question_fi = $question order by gap_id";
+ $set = $ilDB->query($sql);
+ $answers = array_column($ilDB->fetchAll($set), "answertext");
+ $correct_answer = " - " . implode("
- ", $answers) . "
";
+ }
+
+ return "Ihre Antwort ist nicht korrekt.
Lösung:
$correct_answer";
+ }
+}
\ No newline at end of file
diff --git a/classes/Question/class.xdhtQuestionFactory.php b/classes/Question/class.xdhtQuestionFactory.php
index 9f87a7b..655b285 100644
--- a/classes/Question/class.xdhtQuestionFactory.php
+++ b/classes/Question/class.xdhtQuestionFactory.php
@@ -45,13 +45,21 @@ public function getQuestionByRecomanderId($recomander_id)
{
global $ilDB;
$sql = "SELECT * FROM qpl_questions
-inner join qpl_qst_type on qpl_qst_type.question_type_id = qpl_questions.question_type_fi where qpl_questions.description LIKE " . $ilDB->quote("%[[" . $recomander_id . "]]", 'text');
+inner join qpl_qst_type on qpl_qst_type.question_type_id = qpl_questions.question_type_fi where qpl_questions.description LIKE " . $ilDB->quote("%[[" . $recomander_id . "]]", 'text') . "order by qpl_questions.question_id desc limit 1";
$set = $ilDB->query($sql);
$row = $ilDB->fetchAssoc($set);
$row['recomander_id'] = $recomander_id;
+ $row['skills'] = array();
+
+ $question_id = $row["question_id"];
+ $sql = "SELECT skill_tref_fi FROM qpl_qst_skl_assigns where question_fi = $question_id";
+ $set = $ilDB->query($sql);
+ while ($sk = $ilDB->fetchAssoc($set)) {
+ array_push($row['skills'], $sk['skill_tref_fi']);
+ }
return $row;
}
diff --git a/classes/QuestionAnswer/QuestionAnswer.php b/classes/QuestionAnswer/QuestionAnswer.php
index da7e455..00ba5dc 100644
--- a/classes/QuestionAnswer/QuestionAnswer.php
+++ b/classes/QuestionAnswer/QuestionAnswer.php
@@ -30,6 +30,10 @@ class QuestionAnswer
*/
//Todo separate Class er Question!
protected $cloze_type;
+ /**
+ * @var float
+ */
+ protected $points;
/**
@@ -100,7 +104,7 @@ public function getAnswertext() : string
*/
public function setAnswertext(string $answertext)
{
- $this->answertext = $answertext;
+ $this->answertext = str_replace(array(' ', ','), array('', '.'), $answertext);
}
@@ -120,4 +124,21 @@ public function setClozeType(int $cloze_type)
{
$this->cloze_type = $cloze_type;
}
+
+ /**
+ * @return int
+ */
+ public function getPoints() : float
+ {
+ return $this->points;
+ }
+
+
+ /**
+ * @param float $points
+ */
+ public function setPoints(float $points)
+ {
+ $this->points = $points;
+ }
}
\ No newline at end of file
diff --git a/classes/QuestionAnswer/QuestionAnswers.php b/classes/QuestionAnswer/QuestionAnswers.php
index 3ff2292..f5c59e4 100644
--- a/classes/QuestionAnswer/QuestionAnswers.php
+++ b/classes/QuestionAnswer/QuestionAnswers.php
@@ -52,6 +52,7 @@ private function read()
$question_answer->setAnswerId($row['answer_id']);
$question_answer->setAnswertext($row['answertext']);
$question_answer->setAOrder($row['aorder']);
+ $question_answer->setPoints($row['points']);
$arr_question_answers[$row['aorder']] = $question_answer;
}
$this->setAnswers($arr_question_answers);
@@ -69,6 +70,7 @@ private function read()
$question_answer->setAnswerId($row['answer_id']);
$question_answer->setAnswertext($row['answertext']);
$question_answer->setAOrder($row['aorder']);
+ $question_answer->setPoints($row['points']);
$arr_question_answers[$row['aorder']] = $question_answer;
}
$this->setAnswers($arr_question_answers);
@@ -88,6 +90,7 @@ private function read()
$question_answer->setAnswertext($row['answertext']);
$question_answer->setAOrder($row['aorder']);
$question_answer->setClozeType($row['cloze_type']);
+ $question_answer->setPoints($row['points']);
$arr_question_answers[$row['gap_id']]['cloze_type'] = $row['cloze_type'];
$arr_question_answers[$row['gap_id']][$row['aorder']] = $question_answer;
}
diff --git a/classes/Recommender/RecommenderCurl.php b/classes/Recommender/RecommenderCurl.php
index f0f25fc..aa791ef 100644
--- a/classes/Recommender/RecommenderCurl.php
+++ b/classes/Recommender/RecommenderCurl.php
@@ -153,7 +153,7 @@ protected function doRequest(string $rest_url, array $headers, array $post_data
$this->response->setResponseType(intval($result['response_type']));
}
- if (!empty($result['answer_response'])) {
+ if (isset($result['answer_response'])) {
$this->response->setAnswerResponse(strval($result['answer_response']));
}
@@ -216,6 +216,10 @@ protected function doRequest(string $rest_url, array $headers, array $post_data
}
}
+ if (isset($result['correct'])) {
+ $this->response->setCorrect($result['correct']);
+ }
+
} catch (Exception $ex) {
if ($this->facade->settings()->getLog()) {
@@ -279,10 +283,12 @@ protected function initCurlConnection(string $rest_url, array $headers) : ilCurl
/**
* @param string $recomander_id
- * @param int $question_type
- * @param mixed $answer
+ * @param int $question_type
+ * @param int $question_max_points
+ * @param array $skill
+ * @param mixed $answer
*/
- public function answer(string $recomander_id, int $question_type, $answer)/*:void*/
+ public function answer(string $recomander_id, int $question_type, int $question_max_points, array $skill, $answer)/*:void*/
{
global $DIC;
@@ -300,7 +306,9 @@ public function answer(string $recomander_id, int $question_type, $answer)/*:voi
"question_pool_obj_id" => $this->facade->settings()->getQuestionPoolId(),
"recomander_id" => $recomander_id,
"question_type" => $question_type,
- "answer" => $answer
+ "question_max_points" => $question_max_points,
+ "answer" => $answer,
+ "skills" => $skill
];
$this->doRequest("/v1/answer", $headers, $data);
diff --git a/classes/Recommender/RecommenderResponse.php b/classes/Recommender/RecommenderResponse.php
index 9e2f403..5aeaf49 100644
--- a/classes/Recommender/RecommenderResponse.php
+++ b/classes/Recommender/RecommenderResponse.php
@@ -106,6 +106,12 @@ class RecommenderResponse
*/
protected $send_failure = [];
+ /**
+ * @var bool
+ */
+ protected $correct;
+
+
/**
* @return string
@@ -598,4 +604,21 @@ public function renderProgressBar() : string
return self::output()->getHTML($progress_bar);
}
+
+ /**
+ * @return bool
+ */
+ public function getCorrect() : bool
+ {
+ return $this->correct;
+ }
+
+
+ /**
+ * @param bool $correct
+ */
+ public function setCorrect(bool $correct)
+ {
+ $this->correct = $correct;
+ }
}
\ No newline at end of file
diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php
index 63df774..d70542c 100644
--- a/classes/Start/class.xdhtStartGUI.php
+++ b/classes/Start/class.xdhtStartGUI.php
@@ -121,10 +121,15 @@ public function proceedWithReturnOfRecommender()
}
if (!empty($this->response->getCompetences())) {
+ global $ilDB;
foreach ($this->response->getCompetences() as $competence_id => $level_id) {
+ $sql = "select id from skl_level as sl join qpl_qst_skl_assigns as ql on ql.skill_base_fi = sl.skill_id where ql.skill_tref_fi = $competence_id and sl.nr = $level_id limit 1";
+ $set = $ilDB->query($sql);
+ $row = $ilDB->fetchAssoc($set);
+
ilPersonalSkill::addPersonalSkill(self::dic()->user()->getId(), $competence_id);
ilBasicSkill::writeUserSkillLevelStatus(
- $level_id,
+ $row['id'],
self::dic()->user()->getId(),
$this->facade->refId(),
$competence_id,
@@ -136,16 +141,18 @@ public function proceedWithReturnOfRecommender()
switch ($this->response->getStatus()) {
case RecommenderResponse::STATUS_SUCCESS:
- if ($this->response->getAnswerResponse()) {
+ if ($this->response->getAnswerResponse() != "") {
$formatter = new ilAssSelfAssessmentQuestionFormatter();
- $this->response->addSendMessage($formatter->format($this->response->getAnswerResponse()), $this->response->getAnswerResponseType());
+ $feedback = new Feedback($this->response->getAnswerResponse(), $this->response->getRecomanderId(), $this->response->getCorrect(), $this->facade);
+
+ $this->response->addSendMessage($formatter->format($feedback->getFeedback()), $feedback->getFeedbackType());
}
if ($this->response->getMessage()) {
$this->response->addSendMessage($this->response->getMessage(), $this->response->getMessageType());
}
- if ($this->response->getAnswerResponse()) {
+ if ($this->response->getAnswerResponse() != "") {
$question = $this->facade->xdhtQuestionFactory()->getQuestionByRecomanderId($_POST['recomander_id']);
$output = $this->initAnsweredQuestionForm($question);
@@ -168,7 +175,6 @@ public function proceedWithReturnOfRecommender()
self::dic()->ctrl()->redirect($this, self::CMD_STANDARD);
return;
- break;
default:
$output = $this->initSeparatorForm();
break;
@@ -242,7 +248,7 @@ protected function initAnsweredQuestionForm($question) : ilTemplate
$tpl->setVariable('QUESTION_ID', $question['question_id']);
$tpl->setVariable('RECOMANDER_ID', $question['recomander_id']);
- $previewSession->setParticipantsSolution(999999);
+ $previewSession->setParticipantsSolution(null);
return $tpl;
}
@@ -336,9 +342,9 @@ public function answer()
*/
$question_answer = $question_answers->getAnswers()[$_POST['multiple_choice_result' . $_POST['question_id'] . 'ID']];
if (is_object($question_answer)) {
- $answertext = ["answertext" => base64_encode($question_answer->getAnswertext())];
+ $answertext = ["answertext" => base64_encode("Choice " . $question_answer->getAOrder()), "points" => $question_answer->getPoints()];
} else {
- $answertext = ["answertext" => ""];
+ $answertext = ["answertext" => "", "points" => 0];
}
break;
case 'assMultipleChoice':
@@ -346,9 +352,9 @@ public function answer()
if (strpos($key, 'multiple_choice_result') !== false) {
$question_answer = $question_answers->getAnswers()[$value];
if (is_object($question_answer)) {
- $answertext[] = ["aorder" => base64_encode($question_answer->getAnswertext())];
+ $answertext[] = ["answertext" => base64_encode("Choice " . $question_answer->getAOrder()), "points" => $question_answer->getPoints()];
} else {
- $answertext = ["answertext" => ""];
+ $answertext = ["answertext" => "", "points" => 0];
}
}
}
@@ -357,26 +363,26 @@ public function answer()
foreach ($_POST as $key => $value) {
if (strpos($key, 'gap_') !== false) {
+ $value = str_replace(array(' ', ','), array('', '.'), $value);
$arr_splitted_gap = explode('gap_', $key);
$question_answer = $question_answers->getAnswers();
- if (in_array($question_answer[$arr_splitted_gap[1]]['cloze_type'], [
- xdhtQuestionFactory::CLOZE_TYPE_TEXT,
- xdhtQuestionFactory::CLOZE_TYPE_NUMERIC
- ])
- ) {
- $answertext[] = ["gap_id" => $arr_splitted_gap[1], 'cloze_type' => 2, 'answertext' => base64_encode($value)];
+ if (in_array($question_answer[$arr_splitted_gap[1]]['cloze_type'], [xdhtQuestionFactory::CLOZE_TYPE_TEXT, xdhtQuestionFactory::CLOZE_TYPE_NUMERIC])) {
+ $answertext[] = ["gap_id" => $arr_splitted_gap[1], 'cloze_type' => 2, 'answertext' => base64_encode($value),
+ 'points' => ($question_answer[$arr_splitted_gap[1]][0]->getAnswertext() == $value) * $question_answer[$arr_splitted_gap[1]][0]->getPoints()];
} else {
if (is_object($question_answer[$arr_splitted_gap[1]][$value])) {
$answertext[] = [
"gap_id" => $arr_splitted_gap[1],
'cloze_type' => $question_answer[$arr_splitted_gap[1]]['cloze_type'],
- 'answertext' => base64_encode($question_answer[$arr_splitted_gap[1]][$value]->getAnswertext())
+ 'answertext' => base64_encode($question_answer[$arr_splitted_gap[1]][$value]->getAnswertext()),
+ 'points' => $question_answer[$arr_splitted_gap[1]][$value]->getPoints()
];
} else {
$answertext[] = [
"gap_id" => $arr_splitted_gap[1],
'cloze_type' => $question_answer[$arr_splitted_gap[1]]['cloze_type'],
- 'answertext' => ""
+ 'answertext' => "",
+ 'points' => 0
];
}
}
@@ -386,7 +392,7 @@ public function answer()
}
$recommender = new RecommenderCurl($this->facade, $this->response);
- $recommender->answer($_POST['recomander_id'], $question['question_type_fi'], $answertext);
+ $recommender->answer($_POST['recomander_id'], $question['question_type_fi'], $question['points'], $question['skills'], $answertext);
$this->proceedWithReturnOfRecommender();
}
diff --git a/plugin.php b/plugin.php
index fc261ab..9ec6cd3 100644
--- a/plugin.php
+++ b/plugin.php
@@ -3,7 +3,7 @@
require_once __DIR__ . "/vendor/srag/dic/src/PHPVersionChecker.php";
$id = "xdht";
-$version = "0.0.10";
+$version = "0.0.11";
$ilias_min_version = "5.4.0";
$ilias_max_version = "6.999";
$responsible = "Martin Studer";
diff --git a/templates/default/tpl.questions_answered_form.html b/templates/default/tpl.questions_answered_form.html
index 8493945..1dddb2f 100644
--- a/templates/default/tpl.questions_answered_form.html
+++ b/templates/default/tpl.questions_answered_form.html
@@ -2,10 +2,12 @@
+
-
\ No newline at end of file
diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php
index 8dc9477..aea95b3 100644
--- a/vendor/composer/autoload_classmap.php
+++ b/vendor/composer/autoload_classmap.php
@@ -11,6 +11,7 @@
'ProgressMeter' => $baseDir . '/classes/ProgressMeter/ProgressMeter.php',
'QuestionAnswer' => $baseDir . '/classes/QuestionAnswer/QuestionAnswer.php',
'QuestionAnswers' => $baseDir . '/classes/QuestionAnswer/QuestionAnswers.php',
+ 'Feedback' => $baseDir . '/classes/Feedback/Feedback.php',
'Ramsey\\Uuid\\BinaryUtils' => $vendorDir . '/ramsey/uuid/src/BinaryUtils.php',
'Ramsey\\Uuid\\Builder\\DefaultUuidBuilder' => $vendorDir . '/ramsey/uuid/src/Builder/DefaultUuidBuilder.php',
'Ramsey\\Uuid\\Builder\\DegradedUuidBuilder' => $vendorDir . '/ramsey/uuid/src/Builder/DegradedUuidBuilder.php',
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
index ee257d0..3d391eb 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -77,6 +77,7 @@ class ComposerStaticInit268597d9500c41eaba80b604ac39cdcf
'ProgressMeter' => __DIR__ . '/../..' . '/classes/ProgressMeter/ProgressMeter.php',
'QuestionAnswer' => __DIR__ . '/../..' . '/classes/QuestionAnswer/QuestionAnswer.php',
'QuestionAnswers' => __DIR__ . '/../..' . '/classes/QuestionAnswer/QuestionAnswers.php',
+ 'Feedback' => __DIR__ . '/../..' . '/classes/Feedback/Feedback.php',
'Ramsey\\Uuid\\BinaryUtils' => __DIR__ . '/..' . '/ramsey/uuid/src/BinaryUtils.php',
'Ramsey\\Uuid\\Builder\\DefaultUuidBuilder' => __DIR__ . '/..' . '/ramsey/uuid/src/Builder/DefaultUuidBuilder.php',
'Ramsey\\Uuid\\Builder\\DegradedUuidBuilder' => __DIR__ . '/..' . '/ramsey/uuid/src/Builder/DegradedUuidBuilder.php',