38 lines
836 B
PHP
38 lines
836 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
readonly class Frage implements Stringable
|
|
{
|
|
public function __construct(
|
|
private string $frage,
|
|
private string $richtigeAntwort,
|
|
private array $antworten,
|
|
private string $frageNr,
|
|
) {
|
|
}
|
|
|
|
public function getFrageNr(): string
|
|
{
|
|
return $this->frageNr;
|
|
}
|
|
|
|
public function istRichtig(string $antwort): bool
|
|
{
|
|
return $antwort === $this->richtigeAntwort;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
$fragen = '';
|
|
|
|
foreach ($this->antworten as $antwort) {
|
|
$fragen .= '<br>';
|
|
$fragen .= sprintf('<input type="radio" name="%s" value="%s">%s</input>', $this->frageNr, $antwort, $antwort);
|
|
}
|
|
|
|
$fragen .= '<hr>';
|
|
|
|
return $this->frage . '<br>' . $fragen;
|
|
}
|
|
}
|