parse quiz file
This commit is contained in:
parent
576fca0d32
commit
02ba404afe
@ -2,34 +2,35 @@
|
|||||||
|
|
||||||
namespace App\Form;
|
namespace App\Form;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Form\AbstractType;
|
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;
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
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
|
$quizFile = Yaml::parseFile("../config/SafetyQuiz.yaml", 2, 2, Yaml::PARSE_OBJECT_FOR_MAP);
|
||||||
->add('Question_1', ChoiceType::class, [
|
//Parse the quiz file & register each question as a multiple-choice form input
|
||||||
'choices' => [
|
foreach($quizFile['Questions'] as $key => $value)
|
||||||
'Correct' => true,
|
{
|
||||||
'False' => false,
|
//read answer choices
|
||||||
'False again' => false
|
$choiceArr = array();
|
||||||
],
|
foreach($value['Choices'] as $choice )
|
||||||
'expanded' => true
|
{
|
||||||
])
|
$choiceArr[$choice['Label']] = $choice['Value'];
|
||||||
->add('Question_2', ChoiceType::class, [
|
}
|
||||||
'choices' => [
|
|
||||||
'Correct' => true,
|
$builder->add($key, ChoiceType::class, [
|
||||||
'False' => false,
|
'choices' => $choiceArr,
|
||||||
'False again' => false
|
'expanded' => true,
|
||||||
],
|
'label' => $value['Text']
|
||||||
'expanded' => true
|
]);
|
||||||
])
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user