From 4b6937977efae2ff2c63fdf11c6232ec63756bb1 Mon Sep 17 00:00:00 2001 From: Konstantin Wagner Date: Thu, 22 Feb 2018 14:55:01 +0100 Subject: [PATCH] 1.3.0 see cl --- CHANGELOG.md | 7 ++ src/Manager/QuizAnswerSolvingManager.php | 4 +- src/Manager/QuizEvaluationManager.php | 6 +- src/Manager/QuizQuestionManager.php | 38 +++++++++++ src/Manager/TokenManager.php | 6 +- src/Module/ModuleQuizReader.php | 4 +- src/Resources/contao/dca/tl_quiz.php | 2 +- src/Resources/contao/dca/tl_quiz_answer.php | 2 +- .../contao/dca/tl_quiz_answer_solving.php | 2 +- .../contao/dca/tl_quiz_evaluation.php | 68 ++++++++++++------- src/Resources/contao/dca/tl_quiz_question.php | 57 +++++++++------- .../languages/de/tl_quiz_evaluation.php | 7 +- .../contao/languages/de/tl_quiz_question.php | 5 +- src/Resources/contao/languages/en/tl_quiz.php | 10 +-- .../languages/en/tl_quiz_evaluation.php | 15 ++-- .../contao/languages/en/tl_quiz_question.php | 11 +-- src/Resources/translations/messages.de.yml | 6 +- tests/Frontend/InsertTagsTest.php | 2 +- .../Manager/QuizAnswerSolvingManagerTest.php | 5 +- tests/Manager/QuizQuestionManagerTest.php | 36 ++++++++++ tests/Manager/TokenManagerTest.php | 12 ++-- 21 files changed, 211 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d0a92..c85a3b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## [1.3.0] - 2018-02-22 + +### Added +- Added point system +- Added custom evaluation per reached points +- Added points per question, set points per question from 1 to 100 + ## [1.2.0] - 2018-02-09 ### Changed diff --git a/src/Manager/QuizAnswerSolvingManager.php b/src/Manager/QuizAnswerSolvingManager.php index a51f2f8..bcbfd9f 100644 --- a/src/Manager/QuizAnswerSolvingManager.php +++ b/src/Manager/QuizAnswerSolvingManager.php @@ -44,7 +44,8 @@ public function parseAnswerSolving($pid, $quizId, $token) $token = System::getContainer()->get('huh.quiz.token.manager')->addDataToJwtToken($token, $answer->id, $answer->pid); if ($answer->isSolution) { - $token = System::getContainer()->get('huh.quiz.token.manager')->increaseScore($token); + $pointsPerQuestion = System::getContainer()->get('huh.quiz.question.manager')->getPointsPerQuestion($answer->pid); + $token = System::getContainer()->get('huh.quiz.token.manager')->increaseScore($token, $pointsPerQuestion); $solving = System::getContainer()->get('translator')->trans('huh.quiz.answer.solving.correct'); } @@ -52,7 +53,6 @@ public function parseAnswerSolving($pid, $quizId, $token) $answerSolving = $this->findPublishedByPid($pid); if (null !== $answerSolving) { - $solving = ''; foreach ($answerSolving as $item) { $solving .= System::getContainer()->get('huh.quiz.model.manager')->parseModel($item, $item->solving, QuizAnswerSolvingModel::getTable(), $item->cssClass, $item->imgSize); } diff --git a/src/Manager/QuizEvaluationManager.php b/src/Manager/QuizEvaluationManager.php index 375231b..316b089 100644 --- a/src/Manager/QuizEvaluationManager.php +++ b/src/Manager/QuizEvaluationManager.php @@ -48,7 +48,11 @@ public function parseQuizEvaluation($quizId, $count, $token) } $templateData['evaluation'] = ''; foreach ($quizEvaluationModel as $item) { - $templateData['evaluation'] .= System::getContainer()->get('huh.quiz.model.manager')->parseModel($item, $item->evaluationText, QuizEvaluationModel::getTable(), $item->cssClass, $item->imgSize); + if ($item->evaluationPerPointsMin <= $score && $score <= $item->evaluationPerPointsMax) { + $templateData['evaluation'] .= System::getContainer()->get('huh.quiz.model.manager')->parseModel($item, $item->evaluationText, QuizEvaluationModel::getTable(), $item->cssClass, $item->imgSize); + } elseif ('' === $item->evaluationPerPointsMin && '' === $item->evaluationPerPointsMax) { + $templateData['evaluation'] .= System::getContainer()->get('huh.quiz.model.manager')->parseModel($item, $item->evaluationText, QuizEvaluationModel::getTable(), $item->cssClass, $item->imgSize); + } } return $twig->render('@HeimrichHannotContaoQuiz/quiz/quiz_evaluation.html.twig', $templateData); diff --git a/src/Manager/QuizQuestionManager.php b/src/Manager/QuizQuestionManager.php index df4b0ee..48d9219 100644 --- a/src/Manager/QuizQuestionManager.php +++ b/src/Manager/QuizQuestionManager.php @@ -94,4 +94,42 @@ public function prepareQuestion($question, $quiz, $count, $imgSize) return $twig->render('@HeimrichHannotContaoQuiz/quiz/quiz_question.html.twig', $templateData); } + + /** + * @param $id + * + * @return int + */ + public function getPointsPerQuestion($id) + { + $question = $this->findBy('id', $id); + + if (null === $question) { + return 0; + } + + return $question->pointsPerQuestion; + } + + /** + * @param $quizId + * + * @return int + */ + public function getMaxReachablePointsPerQuiz($quizId) + { + $questions = $this->findByPid($quizId); + + if (null === $questions) { + return 0; + } + + $points = 0; + + foreach ($questions as $question) { + $points = $points + $question->pointsPerQuestion; + } + + return $points; + } } diff --git a/src/Manager/TokenManager.php b/src/Manager/TokenManager.php index ead457b..2f2b247 100644 --- a/src/Manager/TokenManager.php +++ b/src/Manager/TokenManager.php @@ -87,7 +87,7 @@ public function getDataFromJwtToken($token) /** * increase the score +1. */ - public function increaseScore($token) + public function increaseScore($token, $pointsPerQuestion) { try { $decoded = JWT::decode($token, System::getContainer()->getParameter('secret'), ['HS256']); @@ -106,10 +106,10 @@ public function increaseScore($token) } if (!isset($decoded->score)) { - $decoded->score = 1; + $decoded->score = $pointsPerQuestion; } else { $score = $decoded->score; - $decoded->score = $score + 1; + $decoded->score = $score + $pointsPerQuestion; } return JWT::encode($decoded, System::getContainer()->getParameter('secret')); diff --git a/src/Module/ModuleQuizReader.php b/src/Module/ModuleQuizReader.php index 73e0eb7..626f3cb 100644 --- a/src/Module/ModuleQuizReader.php +++ b/src/Module/ModuleQuizReader.php @@ -109,7 +109,9 @@ protected function compile() } if (Request::hasGet('finished')) { - return $this->Template->quiz = System::getContainer()->get('huh.quiz.evaluation.manager')->parseQuizEvaluation($this->quiz, $this->count, $this->token); + $reachablePoints = System::getContainer()->get('huh.quiz.question.manager')->getMaxReachablePointsPerQuiz($this->quiz); + + return $this->Template->quiz = System::getContainer()->get('huh.quiz.evaluation.manager')->parseQuizEvaluation($this->quiz, $reachablePoints, $this->token); } if (Request::hasGet('question')) { diff --git a/src/Resources/contao/dca/tl_quiz.php b/src/Resources/contao/dca/tl_quiz.php index dddcacc..733bb25 100644 --- a/src/Resources/contao/dca/tl_quiz.php +++ b/src/Resources/contao/dca/tl_quiz.php @@ -57,7 +57,7 @@ ], 'copy' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz']['copy'], - 'href' => 'act=copy', + 'href' => 'act=paste&mode=copy', 'icon' => 'copy.gif', ], 'delete' => [ diff --git a/src/Resources/contao/dca/tl_quiz_answer.php b/src/Resources/contao/dca/tl_quiz_answer.php index f1ee8a8..04b9b49 100644 --- a/src/Resources/contao/dca/tl_quiz_answer.php +++ b/src/Resources/contao/dca/tl_quiz_answer.php @@ -58,7 +58,7 @@ ], 'copy' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_answer']['copy'], - 'href' => 'act=copy', + 'href' => 'act=paste&mode=copy', 'icon' => 'copy.gif', ], 'delete' => [ diff --git a/src/Resources/contao/dca/tl_quiz_answer_solving.php b/src/Resources/contao/dca/tl_quiz_answer_solving.php index 9213ff8..757b186 100644 --- a/src/Resources/contao/dca/tl_quiz_answer_solving.php +++ b/src/Resources/contao/dca/tl_quiz_answer_solving.php @@ -53,7 +53,7 @@ ], 'copy' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_answer_solving']['copy'], - 'href' => 'act=copy', + 'href' => 'act=paste&mode=copy', 'icon' => 'copy.gif', ], 'delete' => [ diff --git a/src/Resources/contao/dca/tl_quiz_evaluation.php b/src/Resources/contao/dca/tl_quiz_evaluation.php index 918f770..b7069be 100644 --- a/src/Resources/contao/dca/tl_quiz_evaluation.php +++ b/src/Resources/contao/dca/tl_quiz_evaluation.php @@ -53,14 +53,14 @@ ], 'copy' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['copy'], - 'href' => 'act=copy', - 'icon' => 'copy.gif', + 'href' => 'act=paste&mode=copy', + 'icon' => 'copy.svg', ], 'delete' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['delete'], 'href' => 'act=delete', 'icon' => 'delete.gif', - 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"', + 'attributes' => 'onclick="if(!confirm(' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '))return false;Backend.getScrollOffset()"', ], 'toggle' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['toggle'], @@ -77,7 +77,7 @@ ], 'palettes' => [ '__selector__' => ['addImage', 'overwriteMeta', 'published'], - 'default' => '{general_legend},title,author;{evaluation_legend},evaluationText;{image_legend},addImage;{expert_legend:hide},cssClass;{publish_legend},published', + 'default' => '{general_legend},title,author;{evaluation_legend},evaluationPerPointsMin,evaluationPerPointsMax,evaluationText;{image_legend},addImage;{expert_legend:hide},cssClass;{publish_legend},published', ], 'subpalettes' => [ 'addImage' => 'singleSRC,size,floating,imagemargin,fullsize,overwriteMeta', @@ -85,26 +85,26 @@ 'published' => 'start,stop', ], 'fields' => [ - 'id' => [ + 'id' => [ 'sql' => "int(10) unsigned NOT NULL auto_increment", ], - 'pid' => [ + 'pid' => [ 'foreignKey' => 'tl_quiz_question.id', 'sql' => "int(10) unsigned NOT NULL default '0'", 'relation' => ['type' => 'belongsTo', 'load' => 'eager'], ], - 'tstamp' => [ + 'tstamp' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_answer']['tstamp'], 'sql' => "int(10) unsigned NOT NULL default '0'", ], - 'dateAdded' => [ + 'dateAdded' => [ 'label' => &$GLOBALS['TL_LANG']['MSC']['dateAdded'], 'sorting' => true, 'flag' => 6, 'eval' => ['rgxp' => 'datim', 'doNotCopy' => true], 'sql' => "int(10) unsigned NOT NULL default '0'", ], - 'title' => [ + 'title' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['title'], 'exclude' => true, 'search' => true, @@ -112,7 +112,7 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], 'sql' => "varchar(255) NOT NULL default ''", ], - 'published' => [ + 'published' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['published'], 'exclude' => true, 'filter' => true, @@ -120,21 +120,21 @@ 'eval' => ['doNotCopy' => true, 'submitOnChange' => true], 'sql' => "char(1) NOT NULL default ''", ], - 'start' => [ + 'start' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['start'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(10) NOT NULL default ''", ], - 'stop' => [ + 'stop' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['stop'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(10) NOT NULL default ''", ], - 'author' => [ + 'author' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['author'], 'default' => BackendUser::getInstance()->id, 'exclude' => true, @@ -148,35 +148,35 @@ 'sql' => "int(10) unsigned NOT NULL default '0'", 'relation' => ['type' => 'hasOne', 'load' => 'eager'], ], - 'cssClass' => [ + 'cssClass' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['cssClass'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'addImage' => [ + 'addImage' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['addImage'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['submitOnChange' => true], 'sql' => "char(1) NOT NULL default ''", ], - 'overwriteMeta' => [ + 'overwriteMeta' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['overwriteMeta'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], 'sql' => "char(1) NOT NULL default ''", ], - 'singleSRC' => [ + 'singleSRC' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['singleSRC'], 'exclude' => true, 'inputType' => 'fileTree', 'eval' => ['fieldType' => 'radio', 'filesOnly' => true, 'extensions' => Config::get('validImageTypes'), 'mandatory' => true], 'sql' => "binary(16) NULL", ], - 'alt' => [ + 'alt' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['alt'], 'exclude' => true, 'search' => true, @@ -184,7 +184,7 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'imageTitle' => [ + 'imageTitle' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imageTitle'], 'exclude' => true, 'search' => true, @@ -192,7 +192,7 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'size' => [ + 'size' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['size'], 'exclude' => true, 'inputType' => 'imageSize', @@ -203,7 +203,7 @@ }, 'sql' => "varchar(64) NOT NULL default ''", ], - 'imagemargin' => [ + 'imagemargin' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imagemargin'], 'exclude' => true, 'inputType' => 'trbl', @@ -211,7 +211,7 @@ 'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'], 'sql' => "varchar(128) NOT NULL default ''", ], - 'imageUrl' => [ + 'imageUrl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imageUrl'], 'exclude' => true, 'search' => true, @@ -219,7 +219,7 @@ 'eval' => ['rgxp' => 'url', 'decodeEntities' => true, 'maxlength' => 255, 'dcaPicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'caption' => [ + 'caption' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['caption'], 'exclude' => true, 'search' => true, @@ -227,7 +227,7 @@ 'eval' => ['maxlength' => 255, 'allowHtml' => true, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'floating' => [ + 'floating' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['floating'], 'default' => 'above', 'exclude' => true, @@ -237,14 +237,14 @@ 'reference' => &$GLOBALS['TL_LANG']['MSC'], 'sql' => "varchar(12) NOT NULL default ''", ], - 'fullsize' => [ + 'fullsize' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['fullsize'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50 m12'], 'sql' => "char(1) NOT NULL default ''", ], - 'evaluationText' => [ + 'evaluationText' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['evaluationText'], 'exclude' => true, 'search' => true, @@ -252,6 +252,22 @@ 'eval' => ['rte' => 'tinyMCE', 'tl_class' => 'clr'], 'sql' => "text NULL", ], + 'evaluationPerPointsMin' => [ + 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['evaluationPerPointsMin'], + 'exclude' => true, + 'search' => true, + 'inputType' => 'text', + 'eval' => ['maxlength' => 4, 'tl_class' => 'w50'], + 'sql' => "varchar(4) NOT NULL default ''", + ], + 'evaluationPerPointsMax' => [ + 'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['evaluationPerPointsMax'], + 'exclude' => true, + 'search' => true, + 'inputType' => 'text', + 'eval' => ['maxlength' => 4, 'tl_class' => 'w50'], + 'sql' => "varchar(4) NOT NULL default ''", + ], ], ]; diff --git a/src/Resources/contao/dca/tl_quiz_question.php b/src/Resources/contao/dca/tl_quiz_question.php index cc78a83..85d9545 100644 --- a/src/Resources/contao/dca/tl_quiz_question.php +++ b/src/Resources/contao/dca/tl_quiz_question.php @@ -58,7 +58,7 @@ ], 'copy' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['copy'], - 'href' => 'act=copy', + 'href' => 'act=paste&mode=copy', 'icon' => 'copy.gif', ], 'delete' => [ @@ -82,7 +82,7 @@ ], 'palettes' => [ '__selector__' => ['addImage', 'overwriteMeta'], - 'default' => '{general_legend},title,author;{question_legend},question;{image_legend},addImage;{expert_legend:hide},cssClass;{publish_legend},published,start,stop', + 'default' => '{general_legend},title,author;{question_legend},pointsPerQuestion,question;{image_legend},addImage;{expert_legend:hide},cssClass;{publish_legend},published,start,stop', ], 'subpalettes' => [ @@ -90,26 +90,26 @@ 'overwriteMeta' => 'alt,imageTitle,imageUrl,caption', ], 'fields' => [ - 'id' => [ + 'id' => [ 'sql' => "int(10) unsigned NOT NULL auto_increment", ], - 'pid' => [ + 'pid' => [ 'foreignKey' => 'tl_quiz.id', 'sql' => "int(10) unsigned NOT NULL default '0'", 'relation' => ['type' => 'belongsTo', 'load' => 'eager'], ], - 'tstamp' => [ + 'tstamp' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['tstamp'], 'sql' => "int(10) unsigned NOT NULL default '0'", ], - 'dateAdded' => [ + 'dateAdded' => [ 'label' => &$GLOBALS['TL_LANG']['MSC']['dateAdded'], 'sorting' => true, 'flag' => 6, 'eval' => ['rgxp' => 'datim', 'doNotCopy' => true], 'sql' => "int(10) unsigned NOT NULL default '0'", ], - 'title' => [ + 'title' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['title'], 'exclude' => true, 'search' => true, @@ -117,28 +117,28 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], 'sql' => "varchar(255) NOT NULL default ''", ], - 'published' => [ + 'published' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['published'], 'exclude' => true, 'filter' => true, 'inputType' => 'checkbox', 'sql' => "char(1) NOT NULL default ''", ], - 'start' => [ + 'start' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['start'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(10) NOT NULL default ''", ], - 'stop' => [ + 'stop' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['stop'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(10) NOT NULL default ''", ], - 'author' => [ + 'author' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['author'], 'default' => BackendUser::getInstance()->id, 'exclude' => true, @@ -152,35 +152,35 @@ 'sql' => "int(10) unsigned NOT NULL default '0'", 'relation' => ['type' => 'hasOne', 'load' => 'eager'], ], - 'cssClass' => [ + 'cssClass' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['cssClass'], 'exclude' => true, 'inputType' => 'text', 'eval' => ['tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'addImage' => [ + 'addImage' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['addImage'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['submitOnChange' => true], 'sql' => "char(1) NOT NULL default ''", ], - 'overwriteMeta' => [ + 'overwriteMeta' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['overwriteMeta'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], 'sql' => "char(1) NOT NULL default ''", ], - 'singleSRC' => [ + 'singleSRC' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['singleSRC'], 'exclude' => true, 'inputType' => 'fileTree', 'eval' => ['fieldType' => 'radio', 'filesOnly' => true, 'extensions' => Config::get('validImageTypes'), 'mandatory' => true], 'sql' => "binary(16) NULL", ], - 'alt' => [ + 'alt' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['alt'], 'exclude' => true, 'search' => true, @@ -188,7 +188,7 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'imageTitle' => [ + 'imageTitle' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imageTitle'], 'exclude' => true, 'search' => true, @@ -196,7 +196,7 @@ 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'size' => [ + 'size' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['size'], 'exclude' => true, 'inputType' => 'imageSize', @@ -207,7 +207,7 @@ }, 'sql' => "varchar(64) NOT NULL default ''", ], - 'imagemargin' => [ + 'imagemargin' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imagemargin'], 'exclude' => true, 'inputType' => 'trbl', @@ -215,7 +215,7 @@ 'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'], 'sql' => "varchar(128) NOT NULL default ''", ], - 'imageUrl' => [ + 'imageUrl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['imageUrl'], 'exclude' => true, 'search' => true, @@ -223,7 +223,7 @@ 'eval' => ['rgxp' => 'url', 'decodeEntities' => true, 'maxlength' => 255, 'dcaPicker' => true, 'tl_class' => 'w50 wizard'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'caption' => [ + 'caption' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['caption'], 'exclude' => true, 'search' => true, @@ -231,7 +231,7 @@ 'eval' => ['maxlength' => 255, 'allowHtml' => true, 'tl_class' => 'w50'], 'sql' => "varchar(255) NOT NULL default ''", ], - 'floating' => [ + 'floating' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['floating'], 'default' => 'above', 'exclude' => true, @@ -241,14 +241,14 @@ 'reference' => &$GLOBALS['TL_LANG']['MSC'], 'sql' => "varchar(12) NOT NULL default ''", ], - 'fullsize' => [ + 'fullsize' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['fullsize'], 'exclude' => true, 'inputType' => 'checkbox', 'eval' => ['tl_class' => 'w50 m12'], 'sql' => "char(1) NOT NULL default ''", ], - 'question' => [ + 'question' => [ 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['question'], 'exclude' => true, 'search' => true, @@ -256,6 +256,15 @@ 'eval' => ['rte' => 'tinyMCE', 'tl_class' => 'clr'], 'sql' => "text NULL", ], + 'pointsPerQuestion' => [ + 'label' => &$GLOBALS['TL_LANG']['tl_quiz_question']['pointsPerQuestion'], + 'exclude' => true, + 'search' => true, + 'inputType' => 'select', + 'options' => range(1, 100), + 'eval' => ['maxlength' => 3, 'tl_class' => 'w50'], + 'sql' => "varchar(3) NOT NULL default '1'", + ], ], ]; diff --git a/src/Resources/contao/languages/de/tl_quiz_evaluation.php b/src/Resources/contao/languages/de/tl_quiz_evaluation.php index c50ecd2..d7cd6e8 100644 --- a/src/Resources/contao/languages/de/tl_quiz_evaluation.php +++ b/src/Resources/contao/languages/de/tl_quiz_evaluation.php @@ -29,9 +29,10 @@ $lang['start'][0] = 'Anzeigen ab'; $lang['start'][1] = 'Die Auswertung erst ab diesem Tag auf der Webseite anzeigen.'; -$lang['stop'][0] = 'Anzeigen bis'; -$lang['stop'][1] = 'Die Auswertung nur bis diesem Tag auf der Webseite anzeigen.'; - +$lang['stop'][0] = 'Anzeigen bis'; +$lang['stop'][1] = 'Die Auswertung nur bis diesem Tag auf der Webseite anzeigen.'; +$lang['evaluationPerPointsMin'] = ['Punkteminimum', 'Geben Sie hier das Punkteminimum ein, für die diese Auswertung angezeigt werden soll.']; +$lang['evaluationPerPointsMax'] = ['Punktemaximum', 'Geben Sie hier das Punktemaximum ein, für die diese Auswertung angezeigt werden soll.']; // general $lang['title'][0] = 'Titel'; diff --git a/src/Resources/contao/languages/de/tl_quiz_question.php b/src/Resources/contao/languages/de/tl_quiz_question.php index 25a64f6..dc85130 100644 --- a/src/Resources/contao/languages/de/tl_quiz_question.php +++ b/src/Resources/contao/languages/de/tl_quiz_question.php @@ -37,8 +37,9 @@ $lang['title'][1] = 'Geben Sie hier bitte den Titel ein.'; // question -$lang['question'][0] = 'Frage Eintragen'; -$lang['question'][1] = 'Geben Sie hier bitte eine Frage ein.'; +$lang['question'][0] = 'Frage Eintragen'; +$lang['question'][1] = 'Geben Sie hier bitte eine Frage ein.'; +$lang['pointsPerQuestion'] = ['Punkte pro Frage', 'Wählen Sie aus wie viele Punkte für die richtige Beantwortung dieser Frage vergeben werden sollen.']; /** * Legends diff --git a/src/Resources/contao/languages/en/tl_quiz.php b/src/Resources/contao/languages/en/tl_quiz.php index 850e4a5..a8670da 100644 --- a/src/Resources/contao/languages/en/tl_quiz.php +++ b/src/Resources/contao/languages/en/tl_quiz.php @@ -5,11 +5,11 @@ /** * Fields */ -$lang['title'] = ['Title', 'Please enter a title.']; -$lang['published'] = ['Publish Quiz', 'Make the Quiz publicly visible on the website.']; -$lang['start'] = ['Show from', 'Do not publish the Quiz on the website before this date.']; -$lang['stop'] = ['Show until', 'Unpublish the Quiz on the website after this date.']; -$lang['tstamp'] = ['Revision date', '']; +$lang['title'] = ['Title', 'Please enter a title.']; +$lang['published'] = ['Publish Quiz', 'Make the Quiz publicly visible on the website.']; +$lang['start'] = ['Show from', 'Do not publish the Quiz on the website before this date.']; +$lang['stop'] = ['Show until', 'Unpublish the Quiz on the website after this date.']; +$lang['tstamp'] = ['Revision date', '']; /** * Legends diff --git a/src/Resources/contao/languages/en/tl_quiz_evaluation.php b/src/Resources/contao/languages/en/tl_quiz_evaluation.php index f25cedd..452dcaa 100644 --- a/src/Resources/contao/languages/en/tl_quiz_evaluation.php +++ b/src/Resources/contao/languages/en/tl_quiz_evaluation.php @@ -19,13 +19,14 @@ $lang['cssClass'][0] = 'CSS-Class'; $lang['cssClass'][1] = 'Enter one or more classes.'; -$lang['title'] = ['Title', 'Please enter a title.']; -$lang['published'] = ['Publish Frage', 'Make the Frage publicly visible on the website.']; -$lang['start'] = ['Show from', 'Do not publish the Frage on the website before this date.']; -$lang['stop'] = ['Show until', 'Unpublish the Frage on the website after this date.']; -$lang['tstamp'] = ['Revision date', '']; -$lang['evaluationText'] = ['Add evaluation', '']; - +$lang['title'] = ['Title', 'Please enter a title.']; +$lang['published'] = ['Publish Frage', 'Make the Frage publicly visible on the website.']; +$lang['start'] = ['Show from', 'Do not publish the Frage on the website before this date.']; +$lang['stop'] = ['Show until', 'Unpublish the Frage on the website after this date.']; +$lang['tstamp'] = ['Revision date', '']; +$lang['evaluationText'] = ['Add evaluation', '']; +$lang['evaluationPerPointsMin'] = ['Evaluation per points minimum', 'Insert the minimum points for the evaluation']; +$lang['evaluationPerPointsMax'] = ['Evaluation per points maximum', 'Insert the maximum points for the evaluation']; /** * Legends diff --git a/src/Resources/contao/languages/en/tl_quiz_question.php b/src/Resources/contao/languages/en/tl_quiz_question.php index cc97806..8d0bea8 100644 --- a/src/Resources/contao/languages/en/tl_quiz_question.php +++ b/src/Resources/contao/languages/en/tl_quiz_question.php @@ -19,11 +19,12 @@ $lang['cssClass'][0] = 'CSS-Class'; $lang['cssClass'][1] = 'Enter one or more classes.'; -$lang['title'] = ['Title', 'Please enter a title.']; -$lang['published'] = ['Publish Frage', 'Make the Frage publicly visible on the website.']; -$lang['start'] = ['Show from', 'Do not publish the Frage on the website before this date.']; -$lang['stop'] = ['Show until', 'Unpublish the Frage on the website after this date.']; -$lang['tstamp'] = ['Revision date', '']; +$lang['title'] = ['Title', 'Please enter a title.']; +$lang['published'] = ['Publish Frage', 'Make the Frage publicly visible on the website.']; +$lang['start'] = ['Show from', 'Do not publish the Frage on the website before this date.']; +$lang['stop'] = ['Show until', 'Unpublish the Frage on the website after this date.']; +$lang['tstamp'] = ['Revision date', '']; +$lang['pointsPerQuestion'] = ['Points per question', 'Select how much Points will be given for the correct answer of the question.']; $lang['question'][0] = 'Enter question'; $lang['question'][1] = 'Please enter a question.'; diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml index c26c3a6..90e7520 100644 --- a/src/Resources/translations/messages.de.yml +++ b/src/Resources/translations/messages.de.yml @@ -2,12 +2,12 @@ huh.quiz.count.text.default: '{0} Keine Fragen gefunden|{1} 1 von 1 Frage|]1,Inf[ Frage %current% von %count%' # default solving answer -huh.quiz.answer.solving.correct: 'Richtig' -huh.quiz.answer.solving.wrong: 'Falsch' +huh.quiz.answer.solving.correct: '
Richtig
' +huh.quiz.answer.solving.wrong: '
Falsch
' huh.quiz.answer.solving.next: 'Nächste Frage' huh.quiz.answer.solving.score: 'Zur Auswertung' -huh.quiz.answer.score: '{0} Sie haben leider keine Frage richtig beantwortet.|{1} Sie haben eine von %possibleScore% Fragen richtig beantwortet.|]1,Inf[ Sie haben %score% von %possibleScore% Fragen richtig beantwortet.' +huh.quiz.answer.score: '{0} Sie haben leider 0 Punkte.|{1} Sie haben einen von %possibleScore% Punkten.|]1,Inf[ Sie haben %score% von %possibleScore% Punkten.' # error message huh.quiz.error: 'Es ist ein Fehler aufgetreten.' diff --git a/tests/Frontend/InsertTagsTest.php b/tests/Frontend/InsertTagsTest.php index e282f51..36aee1b 100644 --- a/tests/Frontend/InsertTagsTest.php +++ b/tests/Frontend/InsertTagsTest.php @@ -74,7 +74,7 @@ public function testQuizInsertTags() $framework = $this->mockContaoFramework($this->createMockAdapter()); $tokenManager = new TokenManager($framework); $encode = JWT::encode(['session' => ''], System::getContainer()->getParameter('secret')); - $token = $tokenManager->increaseScore($encode); + $token = $tokenManager->increaseScore($encode, 1); Request::setGet('token', $token); $resultCurrentScore = $insertTag->quizInsertTags(InsertTags::CURRENT_SCORE); diff --git a/tests/Manager/QuizAnswerSolvingManagerTest.php b/tests/Manager/QuizAnswerSolvingManagerTest.php index b3a40c2..83c9d8e 100644 --- a/tests/Manager/QuizAnswerSolvingManagerTest.php +++ b/tests/Manager/QuizAnswerSolvingManagerTest.php @@ -49,11 +49,12 @@ public function setUp(): void // quiz question manager $quizQuestionModel = $this->mockClassWithProperties(QuizQuestionModel::class, ['id' => 1]); - $quizQuestionAdapter = $this->mockAdapter(['findOnePublishedByPidNotInQuestions', 'getTable', 'findOneBy']); + $quizQuestionAdapter = $this->mockAdapter(['findOnePublishedByPidNotInQuestions', 'getTable', 'findOneBy', 'findBy']); $quizQuestionAdapter->method('findOnePublishedByPidNotInQuestions')->willReturn($quizQuestionModel); $quizQuestionAdapter->method('getTable')->willReturn('tl_quiz_question'); $quizQuestionAdapter->method('findOneBy')->willReturn($quizQuestionModel); + $quizQuestionAdapter->method('findBy')->willReturn($this->mockClassWithProperties(QuizQuestionModel::class, ['pointsPerQuestion' => 1])); $framework = $this->mockContaoFramework([QuizQuestionModel::class => $quizQuestionAdapter]); $manager = new QuizQuestionManager($framework); @@ -178,7 +179,7 @@ public function testParseAnswerSolving() $template = $manager->parseAnswerSolving('1', '1', $token); $html = '
-
+ huh.quiz.answer.solving.correct
correct
diff --git a/tests/Manager/QuizQuestionManagerTest.php b/tests/Manager/QuizQuestionManagerTest.php index a852b6f..ab49f2b 100644 --- a/tests/Manager/QuizQuestionManagerTest.php +++ b/tests/Manager/QuizQuestionManagerTest.php @@ -211,4 +211,40 @@ public function testPrepareQuestion() '; $this->assertSame($html, $template); } + + public function testGetPointsPerQuestion() + { + $adapter = $this->mockAdapter(['findBy']); + $adapter->method('findBy')->willReturn($this->mockClassWithProperties(QuizQuestionModel::class, ['pointsPerQuestion' => 1])); + + $manager = new QuizQuestionManager($this->mockContaoFramework([QuizQuestionModel::class => $adapter])); + $points = $manager->getPointsPerQuestion(1); + $this->assertSame(1, $points); + + $adapter = $this->mockAdapter(['findBy']); + $adapter->method('findBy')->willReturn(null); + + $manager = new QuizQuestionManager($this->mockContaoFramework([QuizQuestionModel::class => $adapter])); + $points = $manager->getPointsPerQuestion(0); + $this->assertSame(0, $points); + } + + public function testGetMaxReachablePointsPerQuiz() + { + $adapter = $this->mockAdapter(['findBy', 'getTable']); + $adapter->method('findBy')->willReturn([$this->mockClassWithProperties(QuizQuestionModel::class, ['pointsPerQuestion' => 1])]); + $adapter->method('getTable')->willReturn('tl_quiz_question'); + + $manager = new QuizQuestionManager($this->mockContaoFramework([QuizQuestionModel::class => $adapter])); + $points = $manager->getMaxReachablePointsPerQuiz(1); + $this->assertSame(1, $points); + + $adapter = $this->mockAdapter(['findBy', 'getTable']); + $adapter->method('findBy')->willReturn(null); + $adapter->method('getTable')->willReturn('tl_quiz_question'); + + $manager = new QuizQuestionManager($this->mockContaoFramework([QuizQuestionModel::class => $adapter])); + $points = $manager->getMaxReachablePointsPerQuiz(0); + $this->assertSame(0, $points); + } } diff --git a/tests/Manager/TokenManagerTest.php b/tests/Manager/TokenManagerTest.php index 0e81f02..18d3590 100644 --- a/tests/Manager/TokenManagerTest.php +++ b/tests/Manager/TokenManagerTest.php @@ -106,10 +106,10 @@ public function testGetCurrentScore() $framework = $this->mockContaoFramework($this->createMockAdapter()); $tokenManager = new TokenManager($framework); $encode = JWT::encode(['session' => ''], System::getContainer()->getParameter('secret')); - $token = $tokenManager->increaseScore($encode); + $token = $tokenManager->increaseScore($encode, 1); $score = $tokenManager->getCurrentScore($token); $this->assertSame(1, $score); - $token = $tokenManager->increaseScore($token); + $token = $tokenManager->increaseScore($token, 1); $score = $tokenManager->getCurrentScore($token); $this->assertSame(2, $score); } @@ -119,17 +119,17 @@ public function testIncreaseScore() $framework = $this->mockContaoFramework($this->createMockAdapter()); $tokenManager = new TokenManager($framework); $encode = JWT::encode(['session' => ''], System::getContainer()->getParameter('secret')); - $token = $tokenManager->increaseScore($encode); + $token = $tokenManager->increaseScore($encode, 1); $decoded = JWT::decode($token, System::getContainer()->getParameter('secret'), ['HS256']); $this->assertSame(1, $decoded->score); - $token = $tokenManager->increaseScore($token); + $token = $tokenManager->increaseScore($token, 1); $decoded = JWT::decode($token, System::getContainer()->getParameter('secret'), ['HS256']); $this->assertSame(2, $decoded->score); $tokenManager = new TokenManager($framework); try { - $token = $tokenManager->increaseScore(''); + $token = $tokenManager->increaseScore('', 1); } catch (\Exception $exception) { $this->assertInstanceOf(RedirectResponseException::class, $exception); $this->assertSame('https://www.anwaltauskunft.dav.hhdev/app_dev.php/rechtsquiz/arbeitsrecht/8?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uIjoic2pja3IwZGxvNGJqZm1wZmRpb2hubGZwcWkiLCIxMSI6IjIyIn0.8O6LzSHEk3A-TQ3PRsBuW4TkQasFpzDeM08YO2FKEpE&answer=21', $exception->getResponse()->getTargetUrl()); @@ -138,7 +138,7 @@ public function testIncreaseScore() $encode = JWT::encode(['session' => '123456789'], System::getContainer()->getParameter('secret')); $tokenManager = new TokenManager($framework); try { - $token = $tokenManager->increaseScore($encode); + $token = $tokenManager->increaseScore($encode, 1); } catch (\Exception $exception) { $this->assertInstanceOf(RedirectResponseException::class, $exception); $this->assertSame('https://www.anwaltauskunft.dav.hhdev/app_dev.php/rechtsquiz/arbeitsrecht/8?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzZXNzaW9uIjoic2pja3IwZGxvNGJqZm1wZmRpb2hubGZwcWkiLCIxMSI6IjIyIn0.8O6LzSHEk3A-TQ3PRsBuW4TkQasFpzDeM08YO2FKEpE&answer=21', $exception->getResponse()->getTargetUrl());