From bd3a28c428f5722db7fca654549c9456b07a4ccb Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Thu, 30 Jul 2020 15:37:12 +0200 Subject: [PATCH 01/12] fixed url --- classes/Recommender/RecommenderCurl.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/Recommender/RecommenderCurl.php b/classes/Recommender/RecommenderCurl.php index 45fe033..f0f25fc 100644 --- a/classes/Recommender/RecommenderCurl.php +++ b/classes/Recommender/RecommenderCurl.php @@ -64,7 +64,7 @@ public function start()/*:void*/ "question_pool_obj_id" => $this->facade->settings()->getQuestionPoolId() ]; - $this->doRequest("api/v1/start", $headers, $data); + $this->doRequest("/v1/start", $headers, $data); } @@ -303,7 +303,7 @@ public function answer(string $recomander_id, int $question_type, $answer)/*:voi "answer" => $answer ]; - $this->doRequest("api/v1/answer", $headers, $data); + $this->doRequest("/v1/answer", $headers, $data); } @@ -331,6 +331,6 @@ public function sendRating(string $recomander_id, int $rating)/*:void*/ "rating" => $rating ]; - $this->doRequest("api/v1/rating", $headers, $data); + $this->doRequest("/v1/rating", $headers, $data); } } From 554402a5949913e8d90545d9d4af6de29f4cb14f Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Fri, 31 Jul 2020 21:09:13 +0200 Subject: [PATCH 02/12] layout fixes --- templates/default/tpl.questions_answered_form.html | 10 ++++++---- templates/default/tpl.questions_form.html | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) 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 @@

{TITLE}

-
- {QUESTION} - -
+
+
+ {QUESTION} + +
+
{DIFFICULTY}
diff --git a/templates/default/tpl.questions_form.html b/templates/default/tpl.questions_form.html index 7ec71a0..473fc50 100644 --- a/templates/default/tpl.questions_form.html +++ b/templates/default/tpl.questions_form.html @@ -6,8 +6,8 @@

{TITLE}

{QUESTION}
+ - \ No newline at end of file From 2ce1a74397de521846f8a353c95c0e0787e18e6c Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Fri, 31 Jul 2020 21:13:10 +0200 Subject: [PATCH 03/12] send aorder instead of answer string --- classes/Start/class.xdhtStartGUI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index 63df774..6598a1b 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -336,9 +336,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 = ["aorder" => $question_answer->getAOrder()]; } else { - $answertext = ["answertext" => ""]; + $answertext = ["aorder" => "-1"]; } break; case 'assMultipleChoice': @@ -346,9 +346,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[] = ["aorder" => $question_answer->getAOrder()]; } else { - $answertext = ["answertext" => ""]; + $answertext = ["aorder" => "-1"]; } } } From 6f47a6a0e02f2430aac5fe3be2e9a0ba262cea85 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Mon, 3 Aug 2020 20:18:46 +0200 Subject: [PATCH 04/12] send points along with answer and max_points of question --- classes/QuestionAnswer/QuestionAnswer.php | 21 +++++++++++++++++++++ classes/QuestionAnswer/QuestionAnswers.php | 3 +++ classes/Recommender/RecommenderCurl.php | 3 ++- classes/Start/class.xdhtStartGUI.php | 19 +++++++++++-------- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/classes/QuestionAnswer/QuestionAnswer.php b/classes/QuestionAnswer/QuestionAnswer.php index da7e455..a24385e 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 int + */ + protected $points; /** @@ -120,4 +124,21 @@ public function setClozeType(int $cloze_type) { $this->cloze_type = $cloze_type; } + + /** + * @return int + */ + public function getPoints() : int + { + return $this->points; + } + + + /** + * @param int $points + */ + public function setPoints(int $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..65fbc57 100644 --- a/classes/Recommender/RecommenderCurl.php +++ b/classes/Recommender/RecommenderCurl.php @@ -282,7 +282,7 @@ protected function initCurlConnection(string $rest_url, array $headers) : ilCurl * @param int $question_type * @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, $answer)/*:void*/ { global $DIC; @@ -300,6 +300,7 @@ 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, + "question_max_points" => $question_max_points, "answer" => $answer ]; diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index 6598a1b..0402b7c 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -336,9 +336,9 @@ public function answer() */ $question_answer = $question_answers->getAnswers()[$_POST['multiple_choice_result' . $_POST['question_id'] . 'ID']]; if (is_object($question_answer)) { - $answertext = ["aorder" => $question_answer->getAOrder()]; + $answertext = ["answertext" => base64_encode("Choice " . $question_answer->getAOrder()), "points" => $question_answer->getPoints()]; } else { - $answertext = ["aorder" => "-1"]; + $answertext = ["answertext" => "", "points" => 0]; } break; case 'assMultipleChoice': @@ -346,9 +346,9 @@ public function answer() if (strpos($key, 'multiple_choice_result') !== false) { $question_answer = $question_answers->getAnswers()[$value]; if (is_object($question_answer)) { - $answertext[] = ["aorder" => $question_answer->getAOrder()]; + $answertext[] = ["answertext" => base64_encode("Choice " . $question_answer->getAOrder()), "points" => $question_answer->getPoints()]; } else { - $answertext = ["aorder" => "-1"]; + $answertext = ["answertext" => "", "points" => 0]; } } } @@ -364,19 +364,22 @@ public function answer() xdhtQuestionFactory::CLOZE_TYPE_NUMERIC ]) ) { - $answertext[] = ["gap_id" => $arr_splitted_gap[1], 'cloze_type' => 2, 'answertext' => base64_encode($value)]; + $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]][0]->getAnswertext() == $value) * $question_answer[$arr_splitted_gap[1]][0]->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 +389,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'], $answertext); $this->proceedWithReturnOfRecommender(); } From 299a6e7ede22c360a9eea40eb111e1c21a0b42b6 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Wed, 5 Aug 2020 17:23:53 +0200 Subject: [PATCH 05/12] remove whitespace and , in cloze questions --- classes/QuestionAnswer/QuestionAnswer.php | 2 +- classes/Start/class.xdhtStartGUI.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/QuestionAnswer/QuestionAnswer.php b/classes/QuestionAnswer/QuestionAnswer.php index a24385e..f945e1a 100644 --- a/classes/QuestionAnswer/QuestionAnswer.php +++ b/classes/QuestionAnswer/QuestionAnswer.php @@ -104,7 +104,7 @@ public function getAnswertext() : string */ public function setAnswertext(string $answertext) { - $this->answertext = $answertext; + $this->answertext = str_replace(array(' ', ','), array('', '.'), $answertext); } diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index 0402b7c..370ea68 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -357,6 +357,7 @@ 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'], [ From 50e36cf3aacc59094ce7fa561f7dacff3d348193 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Wed, 5 Aug 2020 19:33:07 +0200 Subject: [PATCH 06/12] load feedback from ilias db --- classes/Feedback/Feedback.php | 116 ++++++++++++++++++ .../Question/class.xdhtQuestionFactory.php | 2 +- classes/Recommender/RecommenderCurl.php | 6 +- classes/Recommender/RecommenderResponse.php | 23 ++++ classes/Start/class.xdhtStartGUI.php | 9 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 7 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 classes/Feedback/Feedback.php diff --git a/classes/Feedback/Feedback.php b/classes/Feedback/Feedback.php new file mode 100644 index 0000000..157aac5 --- /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 ilTemplate::MESSAGE_TYPE_SUCCESS; + } + else { + return ilTemplate::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..406f580 100644 --- a/classes/Question/class.xdhtQuestionFactory.php +++ b/classes/Question/class.xdhtQuestionFactory.php @@ -45,7 +45,7 @@ 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); diff --git a/classes/Recommender/RecommenderCurl.php b/classes/Recommender/RecommenderCurl.php index 65fbc57..b663882 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()) { diff --git a/classes/Recommender/RecommenderResponse.php b/classes/Recommender/RecommenderResponse.php index ff4b166..aa06d57 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 370ea68..fb92e7b 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -136,16 +136,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 +170,6 @@ public function proceedWithReturnOfRecommender() self::dic()->ctrl()->redirect($this, self::CMD_STANDARD); return; - break; default: $output = $this->initSeparatorForm(); break; diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index c54ace2..c411541 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -12,6 +12,7 @@ 'ProgressMeterList' => $baseDir . '/classes/ProgressMeter/ProgressMeterList.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 e52dbbb..495dae3 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -73,6 +73,7 @@ class ComposerStaticInit268597d9500c41eaba80b604ac39cdcf 'ProgressMeterList' => __DIR__ . '/../..' . '/classes/ProgressMeter/ProgressMeterList.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', From 8eb7c3475ac7155b02028807b73aabe7bc131e1f Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Wed, 5 Aug 2020 19:33:17 +0200 Subject: [PATCH 07/12] new plugin version --- plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index 575a502..d9e79aa 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.0"; $responsible = "Martin Studer"; From a335b4de0f23128368bc6986cb2b1fd32ef71c32 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Mon, 7 Sep 2020 18:31:13 +0200 Subject: [PATCH 08/12] allow points < 1 --- classes/QuestionAnswer/QuestionAnswer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/QuestionAnswer/QuestionAnswer.php b/classes/QuestionAnswer/QuestionAnswer.php index f945e1a..00ba5dc 100644 --- a/classes/QuestionAnswer/QuestionAnswer.php +++ b/classes/QuestionAnswer/QuestionAnswer.php @@ -31,7 +31,7 @@ class QuestionAnswer //Todo separate Class er Question! protected $cloze_type; /** - * @var int + * @var float */ protected $points; @@ -128,16 +128,16 @@ public function setClozeType(int $cloze_type) /** * @return int */ - public function getPoints() : int + public function getPoints() : float { return $this->points; } /** - * @param int $points + * @param float $points */ - public function setPoints(int $points) + public function setPoints(float $points) { $this->points = $points; } From ff87e81174336b24e2eaf49a27d49b5e4fbe7bbb Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Mon, 7 Sep 2020 18:32:04 +0200 Subject: [PATCH 09/12] reset preview --- classes/Start/class.xdhtStartGUI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index fb92e7b..e4e56ba 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -243,7 +243,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; } From 6fadb5be1ff93c190acaa38e77d98d8448a5330c Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Tue, 8 Sep 2020 17:22:31 +0200 Subject: [PATCH 10/12] fixed cloze selection --- classes/Start/class.xdhtStartGUI.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index e4e56ba..1e94148 100644 --- a/classes/Start/class.xdhtStartGUI.php +++ b/classes/Start/class.xdhtStartGUI.php @@ -361,11 +361,7 @@ public function answer() $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 - ]) - ) { + 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 { @@ -374,7 +370,7 @@ public function answer() "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()), - 'points' => ($question_answer[$arr_splitted_gap[1]][0]->getAnswertext() == $value) * $question_answer[$arr_splitted_gap[1]][0]->getPoints() + 'points' => $question_answer[$arr_splitted_gap[1]][$value]->getPoints() ]; } else { $answertext[] = [ From 8bf874228d9db86b9063052bc3098ebb642e32c7 Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Fri, 29 Jan 2021 16:02:20 +0100 Subject: [PATCH 11/12] Support questions with skill annotations --- classes/Question/class.xdhtQuestionFactory.php | 8 ++++++++ classes/Recommender/RecommenderCurl.php | 11 +++++++---- classes/Start/class.xdhtStartGUI.php | 9 +++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/classes/Question/class.xdhtQuestionFactory.php b/classes/Question/class.xdhtQuestionFactory.php index 406f580..655b285 100644 --- a/classes/Question/class.xdhtQuestionFactory.php +++ b/classes/Question/class.xdhtQuestionFactory.php @@ -52,6 +52,14 @@ public function getQuestionByRecomanderId($recomander_id) $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/Recommender/RecommenderCurl.php b/classes/Recommender/RecommenderCurl.php index b663882..aa791ef 100644 --- a/classes/Recommender/RecommenderCurl.php +++ b/classes/Recommender/RecommenderCurl.php @@ -283,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, int $question_max_points, $answer)/*:void*/ + public function answer(string $recomander_id, int $question_type, int $question_max_points, array $skill, $answer)/*:void*/ { global $DIC; @@ -305,7 +307,8 @@ public function answer(string $recomander_id, int $question_type, int $question_ "recomander_id" => $recomander_id, "question_type" => $question_type, "question_max_points" => $question_max_points, - "answer" => $answer + "answer" => $answer, + "skills" => $skill ]; $this->doRequest("/v1/answer", $headers, $data); diff --git a/classes/Start/class.xdhtStartGUI.php b/classes/Start/class.xdhtStartGUI.php index 1e94148..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, @@ -387,7 +392,7 @@ public function answer() } $recommender = new RecommenderCurl($this->facade, $this->response); - $recommender->answer($_POST['recomander_id'], $question['question_type_fi'], $question['points'], $answertext); + $recommender->answer($_POST['recomander_id'], $question['question_type_fi'], $question['points'], $question['skills'], $answertext); $this->proceedWithReturnOfRecommender(); } From 85e507544659889053dabc83f34978f61e53664e Mon Sep 17 00:00:00 2001 From: Sebastian Wankerl Date: Tue, 9 Feb 2021 10:56:17 +0100 Subject: [PATCH 12/12] Feedback.php ilias 6 fix --- classes/Feedback/Feedback.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Feedback/Feedback.php b/classes/Feedback/Feedback.php index 157aac5..741f072 100644 --- a/classes/Feedback/Feedback.php +++ b/classes/Feedback/Feedback.php @@ -84,10 +84,10 @@ public function getFeedback() public function getFeedbackType() { if ($this->correct) { - return ilTemplate::MESSAGE_TYPE_SUCCESS; + return ilGlobalTemplate::MESSAGE_TYPE_SUCCESS; } else { - return ilTemplate::MESSAGE_TYPE_FAILURE; + return ilGlobalTemplate::MESSAGE_TYPE_FAILURE; } }