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/BusinessClass/CheckBoxQuestion.php

67 lines
1.7 KiB

<?php
namespace BusinessClass;
/**
* Définit une question à choix multiples.
*/
class CheckBoxQuestion extends BoxQuestion
{
public function __construct()
{
$ctp = func_num_args();
$args = func_get_args();
switch($ctp)
{
case 4:
parent::__construct($args[0], $args[1], $args[2], $args[3]);
break;
case 2:
parent::__construct($args[0], $args[1]);
break;
default:
break;
}
}
/**
* Permet de définir la manière donc la réponse doit être traitée
*
* @return void
*/
public function responseStrategy(): void
{
echo "Implement responseStrategy() method.";
}
/**
* Permet de définir la manière dont la question doit s'afficher en HTML.
*
* @return string
*/
public function printStrategy(): string
{
$id = $this->getId();
$content = $this->getContent();
$possibleResponses = $this->getPossibleResponses();
$categories = $this->getCategories();
$html = "\t\t\t<div class='question'>
<label>$content</label>\n";
for ($i = 0; $i < count($possibleResponses); $i++) {
$categoriesSplit = $id."#".$possibleResponses[$i]."||";
foreach ($categories[$i] as $category) {
$categoriesSplit.= $category."_";
}
$html.= "\t\t\t\t<input type='checkbox' name='answers[]' value='$categoriesSplit' />
<label>$possibleResponses[$i]</label>\n";
}
$html.= "\t\t\t</div>\n";
return $html;
}
}