private function ChoiceProcessor::generateTable in Opigno module 8
Same name and namespace in other branches
- 3.x ActivityTypes/opigno_h5p/src/TypeProcessors/ChoiceProcessor.php \Drupal\opigno_h5p\TypeProcessors\ChoiceProcessor::generateTable()
Generate HTML table of choices.
1 call to ChoiceProcessor::generateTable()
- ChoiceProcessor::generateHTML in ActivityTypes/
opigno_h5p/ src/ TypeProcessors/ ChoiceProcessor.php - Determines options for interaction, generates a human readable HTML report.
File
- ActivityTypes/
opigno_h5p/ src/ TypeProcessors/ ChoiceProcessor.php, line 72
Class
- ChoiceProcessor
- Class FillInProcessor.
Namespace
Drupal\opigno_h5p\TypeProcessorsCode
private function generateTable($extras, $correctAnswers, $responses) {
$choices = $extras->choices;
$tableHeader = '<tr class="h5p-choices-table-heading">' . '<td class="h5p-choices-choice">' . t('Answers') . '</td>' . '<td class="h5p-choices-user-answer">' . t('Your Answer') . '</td>' . '<td class="h5p-choices-crp-answer">' . t('Correct') . '</td></tr>';
$rows = '';
foreach ($choices as $choice) {
$choiceID = $choice->id;
$isCRP = in_array($choiceID, $correctAnswers);
$isAnswered = in_array($choiceID, $responses);
$userClasses = 'h5p-choices-user';
$crpClasses = 'h5p-choices-crp';
if ($isAnswered) {
$userClasses .= ' h5p-choices-answered';
}
if ($isCRP) {
$userClasses .= ' h5p-choices-user-correct';
$crpClasses .= ' h5p-choices-crp-correct';
}
$row = '<td class="h5p-choices-alternative">' . $choice->description->{'en-US'} . '</td><td class="h5p-choices-icon-cell"><span class="' . $userClasses . '"></span></td>' . '<td class="h5p-choices-icon-cell"><span class="' . $crpClasses . '"></span></td>';
$rows .= '<tr>' . $row . '</tr>';
}
$tableContent = '<tbody>' . $tableHeader . $rows . '</tbody>';
return '<table class="h5p-choices-table">' . $tableContent . '</table>';
}