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