Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request ILIAS/Plugins/DhbwTraining!23
  • Loading branch information
mstuder committed Mar 29, 2021
2 parents a73d012 + 85e5075 commit c5d0c7e
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 32 deletions.
116 changes: 116 additions & 0 deletions classes/Feedback/Feedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/**
* Class Feedback
*
*
* @author Sebastian Wankerl <[email protected]>
*/
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 "<strong>Ihre Antwort ist korrekt!</strong>";
}
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 = "<ul> <li>" . implode("</li><li>", $answers) . "</li> </ul>";
}
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 = "<ul> <li>" . implode("</li><li>", $answers) . "</li> </ul>";
}

return "<strong><em>Ihre Antwort ist nicht korrekt.<br>Lösung:</em></strong><br>$correct_answer";
}
}
10 changes: 9 additions & 1 deletion classes/Question/class.xdhtQuestionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 22 additions & 1 deletion classes/QuestionAnswer/QuestionAnswer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class QuestionAnswer
*/
//Todo separate Class er Question!
protected $cloze_type;
/**
* @var float
*/
protected $points;


/**
Expand Down Expand Up @@ -100,7 +104,7 @@ public function getAnswertext() : string
*/
public function setAnswertext(string $answertext)
{
$this->answertext = $answertext;
$this->answertext = str_replace(array(' ', ','), array('', '.'), $answertext);
}


Expand All @@ -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;
}
}
3 changes: 3 additions & 0 deletions classes/QuestionAnswer/QuestionAnswers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
18 changes: 13 additions & 5 deletions classes/Recommender/RecommenderCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions classes/Recommender/RecommenderResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class RecommenderResponse
*/
protected $send_failure = [];

/**
* @var bool
*/
protected $correct;



/**
* @return string
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit c5d0c7e

Please sign in to comment.