From f2dfb84e1aa37fb25abad4203e630f9ae33159ac Mon Sep 17 00:00:00 2001
From: Audrey Jensen
Date: Wed, 28 Jun 2023 21:34:34 +0000
Subject: [PATCH] basic safety quiz implementation
---
src/Controller/SafetyController.php | 14 ++++++++++-
src/Form/SafetyQuizType.php | 14 +++++++++--
.../Training/Safety/SafetyQuiz.html.twig | 23 +++++++++++++++++++
.../Training/Safety/safetyHome.html.twig | 2 +-
4 files changed, 49 insertions(+), 4 deletions(-)
create mode 100644 templates/Training/Safety/SafetyQuiz.html.twig
diff --git a/src/Controller/SafetyController.php b/src/Controller/SafetyController.php
index 8cd6cfe..9818f40 100644
--- a/src/Controller/SafetyController.php
+++ b/src/Controller/SafetyController.php
@@ -1,10 +1,14 @@
render('Training/Safety/safetyHome.html.twig',['header' => $headerFile, 'content' => $contentFile]);
}
#[Route('/training/safety/quiz')]
- public function Quiz()
+ public function Quiz(Request $request)
{
+ $headerFile = Yaml::parseFile('../config/portalLinks.yaml', 2, 2, Yaml::PARSE_OBJECT_FOR_MAP);
+ $form = $this->createForm(SafetyQuizType::class);
+ $form->handleRequest($request);
+ if($form->isSubmitted())
+ {
+ //TODO: Process quiz submissions. Calculate score & return a printable results page
+ }
+ return $this->render('Training/Safety/SafetyQuiz.html.twig',['header' => $headerFile, 'quiz'=>$form]);
}
}
\ No newline at end of file
diff --git a/src/Form/SafetyQuizType.php b/src/Form/SafetyQuizType.php
index 2e4b3e2..af66223 100644
--- a/src/Form/SafetyQuizType.php
+++ b/src/Form/SafetyQuizType.php
@@ -6,18 +6,28 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class SafetyQuizType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
- ->add('q1', ChoiceType::class, [
+ ->add('Question_1', ChoiceType::class, [
'choices' => [
'Correct' => true,
'False' => false,
'False again' => false
- ]
+ ],
+ 'expanded' => true
+ ])
+ ->add('Question_2', ChoiceType::class, [
+ 'choices' => [
+ 'Correct' => true,
+ 'False' => false,
+ 'False again' => false
+ ],
+ 'expanded' => true
])
;
}
diff --git a/templates/Training/Safety/SafetyQuiz.html.twig b/templates/Training/Safety/SafetyQuiz.html.twig
new file mode 100644
index 0000000..9d55434
--- /dev/null
+++ b/templates/Training/Safety/SafetyQuiz.html.twig
@@ -0,0 +1,23 @@
+
+
+
+{{ include('_header.html.twig') }}
+
+
+
+
+
+ {% for item in header.Navbar %}
+
+ {% endfor %}
+
+
+
+
Complete the Safety Quiz below
+
When you're finished, click 'Submit' at the bottom and print your results.
+
You may retake this quiz as many times as you need.
+
To pass this quiz you must answer NaN% of questions correctly.
{#TODO: figure out what the correct number is #}
+ {% form_theme quiz 'bootstrap_5_layout.html.twig' %}
+ {{ form(quiz )}}
+
+
\ No newline at end of file
diff --git a/templates/Training/Safety/safetyHome.html.twig b/templates/Training/Safety/safetyHome.html.twig
index 4c475d8..75cdd3f 100644
--- a/templates/Training/Safety/safetyHome.html.twig
+++ b/templates/Training/Safety/safetyHome.html.twig
@@ -22,7 +22,7 @@
-
+
Take the Workplace Safety Quiz
{# Cards #}