Add FactoryQuestion
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
b59fc21b42
commit
9b0a096bd6
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
use BusinessClass\Question;
|
||||
|
||||
abstract class Factory
|
||||
{
|
||||
public abstract function create(array $results): array;
|
||||
|
||||
public static function getBuiltObjects(array $results, string $type): array
|
||||
{
|
||||
$type = "\\Model\\Factory".$type;
|
||||
return (new $type())->create($results);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
use BusinessClass\Question;
|
||||
use BusinessClass\TextQuestion;
|
||||
|
||||
class FactoryQuestion extends Factory
|
||||
{
|
||||
public function create(array $results): array
|
||||
{
|
||||
$questions = [];
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue