You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SAE4.01_FORMULAIRE/Source/Model/FactoryQuestion.php

30 lines
928 B

<?php
namespace Model;
use BusinessClass\Question;
use BusinessClass\TextQuestion;
class FactoryQuestion extends Factory
{
public function create(array $results): array
{
$questions = [];
if ($results[0] != null) {
for ($i = 0; $i < count($results[0]); $i++) {
if (strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) {
$questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']);
} else {
$possiblesResponses = $results[1][$i];
$content = $results[0][$i]['content'];
$categories = $results[2][$i];
$id = $results[0][$i]['id'];
$questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id);
}
}
}
return $questions;
}
}