19 declare(strict_types=1);
31 string $filtertext =
'',
32 bool $passedonly =
false,
33 bool $scoredonly =
true,
36 $this->scoredonly = $scoredonly;
43 $this->worksheet->addSheet($this->
lng->txt(
'tst_results'));
47 foreach ($header_row as $col => $value) {
48 $this->worksheet->setFormattedExcelTitle($this->worksheet->getColumnCoord($col) . $row, $value);
50 $this->worksheet->setBold(
'A' . $row .
':' . $this->worksheet->getColumnCoord(count($header_row) + 1) . $row);
53 foreach ($datarows as $row =>
$data) {
54 if ($this->test_obj->isRandomTest()) {
56 foreach (
$data as $col => $value) {
57 if ($value !==
"" && $col >= count($header_row)) {
58 $this->worksheet->setFormattedExcelTitle(
59 $this->worksheet->getColumnCoord($col) . $row + 1,
63 $this->worksheet->setCellByCoordinates($this->worksheet->getColumnCoord($col) . $row + 1, $value);
66 } elseif ($row % 2 === 1) {
68 for ($col = 0, $colMax = count($header_row); $col < $colMax - 1; $col++) {
72 foreach (
$data as $col => $value) {
73 $this->worksheet->setCellByCoordinates($this->worksheet->getColumnCoord($col) . $row + 1, $value);
77 foreach (
$data as $col => $value) {
78 $this->worksheet->setCellByCoordinates($this->worksheet->getColumnCoord($col) . $row + 1, $value);
95 $allusersheet =
false;
98 $participantcount = count($this->complete_data->getParticipants());
99 foreach ($this->complete_data->getParticipants() as $active_id => $userdata) {
100 $username = (!is_null($userdata) && $userdata->getName()) ? $userdata->getName() :
"ID $active_id";
101 $username = mb_substr($username, 0, 26);
102 $username_to_lower = strtolower($username);
103 if (array_key_exists($username_to_lower, $usernames)) {
104 $usernames[$username_to_lower]++;
105 $username .=
" (" . $usernames[$username_to_lower] .
")";
107 $usernames[$username_to_lower] = 0;
110 if ($participantcount > 250) {
111 if (!$allusersheet || ($pages - 1) < floor($row / 64000)) {
112 $this->worksheet->addSheet(
113 $this->
lng->txt(
"eval_all_users") . (($pages > 0) ?
" (" . ($pages + 1) .
")" :
"")
115 $allusersheet =
true;
120 $resultsheet = $this->worksheet->addSheet($username);
122 if ($this->scoredonly) {
123 $passes = [$userdata->getScoredPassObject()];
125 $passes = $userdata->getPasses();
128 foreach ($passes as $pass) {
129 $passCount = $pass->getPass();
130 $row = ($allusersheet) ? $row : 1;
132 $this->
lng->txt(
"tst_result_user_name_pass"),
136 (!$this->scoredonly && $userdata->getScoredPass() === $passCount ?
" " .
137 $this->
lng->txt(
"exp_scored_test_run") .
138 " (" . ($this->test_obj->getPassScoring() ? $this->
lng->txt(
139 'tst_pass_scoring_best' 140 ) : $this->
lng->txt(
'tst_pass_scoring_last')) .
")" :
"");
141 $this->worksheet->setCell(
146 $this->worksheet->setBold($this->worksheet->getColumnCoord($col) . $row);
148 if (is_object($userdata) && is_array($userdata->getQuestions($passCount))) {
149 $questions = $userdata->getQuestions($passCount);
150 usort($questions,
static function (
$a,
$b) {
151 return $a[
'sequence'] -
$b[
'sequence'];
153 foreach ($questions as $question) {
155 if (is_object($question)) {
156 $row = $question->setExportDetailsXLSX($this->worksheet, $row, $col, $active_id, $passCount);
169 $this->worksheet->addSheet($this->
lng->txt(
'tst_results_aggregated'));
173 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'result'));
174 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'value'));
176 $this->worksheet->setBold(
'A' . $row .
':' . $this->worksheet->getColumnCoord($col - 1) . $row);
179 foreach ($this->aggregated_data[
'overview'] as
$key => $value) {
181 $this->worksheet->setCell($row, $col++,
$key);
182 $this->worksheet->setCell($row, $col++, $value);
189 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'question_id'));
190 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'question_title'));
191 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'average_reached_points'));
192 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'points'));
193 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'percentage'));
194 $this->worksheet->setCell($row, $col++, $this->
lng->txt(
'number_of_answers'));
196 $this->worksheet->setBold(
'A' . $row .
':' . $this->worksheet->getColumnCoord($col - 1) . $row);
199 foreach ($this->aggregated_data[
'questions'] as
$key => $value) {
201 $this->worksheet->setCell($row, $col++,
$key);
202 $this->worksheet->setCell($row, $col++, $value[0]);
203 $this->worksheet->setCell($row, $col++, $value[4]);
204 $this->worksheet->setCell($row, $col++, $value[5]);
205 $this->worksheet->setCell($row, $col++, $value[6]);
206 $this->worksheet->setCell($row, $col++, $value[3]);
219 $this->worksheet->sendToClient($testname);
getDatarows(ilObjTest $test_obj)
withAggregatedResultsPage()
ilAssExcelFormatHelper $worksheet
static getASCIIFilename(string $a_filename)
getHeaderRow(ilLanguage $lng, ilObjTest $test_obj)
static instantiateQuestion(int $question_id)
__construct(ilObjTest $test_obj, string $filter_key_participants=ilTestEvaluationData::FILTER_BY_NONE, string $filtertext='', bool $passedonly=false, bool $scoredonly=true, ilLanguage $lng=null)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples