Skip to content

Commit

Permalink
1.3.0 see cl
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 22, 2018
1 parent a1f226c commit 4b69379
Show file tree
Hide file tree
Showing 21 changed files with 211 additions and 94 deletions.
7 changes: 7 additions & 0 deletions 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
Expand Down
4 changes: 2 additions & 2 deletions src/Manager/QuizAnswerSolvingManager.php
Expand Up @@ -44,15 +44,15 @@ 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');
}

$templateData = $this->getNextQuestionUrl($token, $quizId);
$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);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Manager/QuizEvaluationManager.php
Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions src/Manager/QuizQuestionManager.php
Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/Manager/TokenManager.php
Expand Up @@ -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']);
Expand All @@ -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'));
Expand Down
4 changes: 3 additions & 1 deletion src/Module/ModuleQuizReader.php
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_quiz.php
Expand Up @@ -57,7 +57,7 @@
],
'copy' => [
'label' => &$GLOBALS['TL_LANG']['tl_quiz']['copy'],
'href' => 'act=copy',
'href' => 'act=paste&amp;mode=copy',
'icon' => 'copy.gif',
],
'delete' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_quiz_answer.php
Expand Up @@ -58,7 +58,7 @@
],
'copy' => [
'label' => &$GLOBALS['TL_LANG']['tl_quiz_answer']['copy'],
'href' => 'act=copy',
'href' => 'act=paste&amp;mode=copy',
'icon' => 'copy.gif',
],
'delete' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_quiz_answer_solving.php
Expand Up @@ -53,7 +53,7 @@
],
'copy' => [
'label' => &$GLOBALS['TL_LANG']['tl_quiz_answer_solving']['copy'],
'href' => 'act=copy',
'href' => 'act=paste&amp;mode=copy',
'icon' => 'copy.gif',
],
'delete' => [
Expand Down
68 changes: 42 additions & 26 deletions src/Resources/contao/dca/tl_quiz_evaluation.php
Expand Up @@ -53,14 +53,14 @@
],
'copy' => [
'label' => &$GLOBALS['TL_LANG']['tl_quiz_evaluation']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif',
'href' => 'act=paste&amp;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'],
Expand All @@ -77,64 +77,64 @@
],
'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',
'overwriteMeta' => 'alt,imageTitle,imageUrl,caption',
'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,
'inputType' => 'text',
'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,
'inputType' => 'checkbox',
'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,
Expand All @@ -148,51 +148,51 @@
'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,
'inputType' => 'text',
'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,
'inputType' => 'text',
'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',
Expand All @@ -203,31 +203,31 @@
},
'sql' => "varchar(64) NOT NULL default ''",
],
'imagemargin' => [
'imagemargin' => [
'label' => &$GLOBALS['TL_LANG']['tl_content']['imagemargin'],
'exclude' => true,
'inputType' => 'trbl',
'options' => $GLOBALS['TL_CSS_UNITS'],
'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,
'inputType' => 'text',
'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,
'inputType' => 'text',
'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,
Expand All @@ -237,21 +237,37 @@
'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,
'inputType' => 'textarea',
'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 ''",
],
],
];

Expand Down

0 comments on commit 4b69379

Please sign in to comment.