basic safety quiz implementation

This commit is contained in:
Audrey Jensen 2023-06-28 21:34:34 +00:00
parent 2caa43345c
commit f2dfb84e1a
4 changed files with 49 additions and 4 deletions

View File

@ -1,10 +1,14 @@
<?php <?php
namespace App\Controller; namespace App\Controller;
use App\Form\SafetyQuizType;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Symfony\Component\HttpFoundation\Request;
use jv\intranet\Types\NavbarItem; use jv\intranet\Types\NavbarItem;
class SafetyController extends AbstractController class SafetyController extends AbstractController
{ {
#[Route('/training/safety')] #[Route('/training/safety')]
@ -15,8 +19,16 @@ class SafetyController extends AbstractController
return $this->render('Training/Safety/safetyHome.html.twig',['header' => $headerFile, 'content' => $contentFile]); return $this->render('Training/Safety/safetyHome.html.twig',['header' => $headerFile, 'content' => $contentFile]);
} }
#[Route('/training/safety/quiz')] #[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]);
} }
} }

View File

@ -6,18 +6,28 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\RadioType; use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class SafetyQuizType extends AbstractType class SafetyQuizType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('q1', ChoiceType::class, [ ->add('Question_1', ChoiceType::class, [
'choices' => [ 'choices' => [
'Correct' => true, 'Correct' => true,
'False' => false, 'False' => false,
'False again' => false 'False again' => false
] ],
'expanded' => true
])
->add('Question_2', ChoiceType::class, [
'choices' => [
'Correct' => true,
'False' => false,
'False again' => false
],
'expanded' => true
]) ])
; ;
} }

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
{{ include('_header.html.twig') }}
<body>
<!-- Navigation -->
<div class="siteNavbar">
<ul class="list-group list-group-horizontal-md">
{% for item in header.Navbar %}
<h3 class="navitem"><a class=" list-group-item list-group-item-action text-decoration-none h-100 text-white border-0" href="{{item.url}}">{{item.title}}</a></h3>
{% endfor %}
</ul>
</div>
<div class="container">
<h4>Complete the Safety Quiz below</h4>
<p>When you're finished, click 'Submit' at the bottom and print your results.
<br>You may retake this quiz as many times as you need.
<br>To pass this quiz you must answer NaN% of questions correctly.</p> {#TODO: figure out what the correct number is #}
{% form_theme quiz 'bootstrap_5_layout.html.twig' %}
{{ form(quiz )}}
</div>
</body>

View File

@ -22,7 +22,7 @@
</p> </p>
</div> </div>
</div> </div>
<a class="col-12 btn btn-danger my-2 disabled" href=""> <a class="col-12 btn btn-danger my-2" href="/training/safety/quiz">
<h4>Take the Workplace Safety Quiz</h4> <h4>Take the Workplace Safety Quiz</h4>
</a> </a>
{# Cards #} {# Cards #}