You are here

private function ScormReport::generateTable in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_scorm_activity/src/ScormReport.php \Drupal\opigno_scorm_activity\ScormReport::generateTable()

Generate HTML table of choices.

1 call to ScormReport::generateTable()
ScormReport::generateHtml in ActivityTypes/opigno_scorm_activity/src/ScormReport.php
Determines options for interaction, generates a human readable HTML report.

File

ActivityTypes/opigno_scorm_activity/src/ScormReport.php, line 49

Class

ScormReport
Class H5PReport.

Namespace

Drupal\opigno_scorm_activity

Code

private function generateTable($answer_data, $full_table) {
  if ($full_table) {
    $tableHeader = '<tr class="h5p-choices-table-heading">' . '<td class="h5p-choices-number">#</td><td class="h5p-choices-choice">' . t('Question') . '</td>' . '<td class="h5p-choices-user-answer">' . t('Result') . '</td>' . '<td class="h5p-choices-crp-answer">' . t('Type') . '</td>' . '<td class="h5p-choices-crp-answer">' . t('Date') . '</td></tr>';
  }
  else {
    $tableHeader = '<tr class="h5p-choices-table-heading">' . '<td class="h5p-choices-number">#</td><td class="h5p-choices-choice">' . t('Question') . '</td>' . '<td class="h5p-choices-user-answer">' . t('Result') . '</td>' . '<td class="h5p-choices-crp-answer">' . t('Type') . '</td></tr>';
  }
  $rows = '';
  foreach ($answer_data as $key => $choice) {
    if ($choice->response == '') {
      $userClasses = 'h5p-true-false-correct-responses-pattern';
      $choice->result = t('not answered');
    }
    else {
      $isAnswered = $choice->result == 'correct' ? TRUE : FALSE;
      $userClasses = $isAnswered ? 'h5p-true-false-user-response-correct' : 'h5p-true-false-user-response-wrong';
    }
    if ($full_table) {
      $row = '<td class="h5p-choices-icon-cell">' . ($key + 1) . '</td>' . '<td class="h5p-choices-alternative">' . $choice->description . '</td>' . '<td class="h5p-choices-icon-cell"><span class="' . $userClasses . '">' . ucfirst($choice->result) . '</span></td>' . '<td class="h5p-choices-icon-cell">' . ucfirst($choice->interaction_type) . '</td>' . '<td class="h5p-choices-icon-cell">' . date('d/m/Y H:i', $choice->timestamp) . '</td>';
    }
    else {
      $row = '<td class="h5p-choices-icon-cell">' . ($key + 1) . '</td>' . '<td class="h5p-choices-alternative">' . $choice->description . '</td>' . '<td class="h5p-choices-icon-cell"><span class="' . $userClasses . '">' . ucfirst($choice->result) . '</span></td>' . '<td class="h5p-choices-icon-cell">' . ucfirst($choice->interaction_type) . '</td>';
    }
    $rows .= '<tr>' . $row . '</tr>';
  }
  $tableContent = '<tbody>' . $tableHeader . $rows . '</tbody>';
  return '<table class="h5p-choices-table">' . $tableContent . '</table>';
}