ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilTestArchiveService.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Test\Results\Presentation\TitlesBuilder as ResultsTitlesBuilder;
22use ILIAS\UI\Factory as UIFactory;
23use ILIAS\UI\Renderer as UIRenderer;
24use Psr\Http\Message\ServerRequestInterface;
26
34{
36
37 public function __construct(
38 private readonly ilObjTest $test_obj,
39 private readonly ilLanguage $lng,
40 private readonly ilDBInterface $db,
41 private readonly ilObjUser $user,
42 private readonly UIFactory $ui_factory,
43 private readonly UIRenderer $ui_renderer,
44 private readonly IRSS $irss,
45 private readonly ServerRequestInterface $request,
46 private readonly ilObjectDataCache $obj_cache,
47 private readonly ilTestParticipantAccessFilterFactory $participant_access_filter_factory,
48 private readonly ilTestHTMLGenerator $html_generator
49 ) {
50 $this->participantData = null;
51 }
52
54 {
56 }
57
59 {
60 $this->participantData = $participantData;
61 }
62
63 public function archivePassesByActives($passesByActives): void
64 {
65 foreach ($passesByActives as $activeId => $passes) {
66 foreach ($passes as $pass) {
67 $this->archiveActivesPass($activeId, $pass);
68 }
69 }
70 }
71
72 public function archiveActivesPass(int $active_id, int $pass): void
73 {
74 $participant_data = $this->getParticipantData();
75 $user = $participant_data->getUserDataByActiveId($active_id);
76
77 $tpl = new ilTemplate(
78 'tpl.il_as_tst_archive_page.html',
79 true,
80 true,
81 'components/ILIAS/Test'
82 );
83
84 $tpl->setVariable(
85 'NAME',
86 sprintf(
87 $this->lng->txt('tst_result_user_name'),
88 $this->test_obj->buildName(
89 $user['user_id'],
90 $user['firstname'],
91 $user['lastname']
92 )
93 )
94 );
95
96 if (!empty($user['matriculation']) && $this->test_obj->getAnonymity() === false) {
97 $tpl->setCurrentBlock('matriculation');
98 $tpl->setVariable(
99 'MATRICULATION_LABEL',
100 $this->lng->txt('matriculation')
101 );
102 $tpl->setVariable(
103 'MATRICULATION',
104 $user['matriculation']
105 );
106 $tpl->parseCurrentBlock();
107 }
108
109 $tpl->setVariable(
110 'PASS_FINISH_DATE_LABEL',
111 $this->lng->txt('tst_pass_finished_on')
112 );
113
114 $finish_date = ilObjTest::lookupLastTestPassAccess($active_id, $pass);
115 $tpl->setVariable(
116 'PASS_FINISH_DATE',
117 $finish_date === null
118 ? ''
119 : (new DateTimeImmutable(
120 "@{$finish_date}",
121 new DateTimeZone($this->user->getTimeZone())
122 ))->format(
123 $this->user->getDateTimeFormat()->toString()
124 )
125 );
126
127 $tpl->setVariable(
128 'OVERVIEW',
129 $this->renderOverviewContent($active_id, $pass)
130 );
131
132 $filename = $this->buildOverviewFilename($active_id, $pass);
133 $this->html_generator->generateHTML($tpl->get(), $filename);
134 $archiver = new ilTestArchiver(
135 $this->lng,
136 $this->db,
137 $this->user,
138 $this->ui_factory,
139 $this->ui_renderer,
140 $this->irss,
141 $this->request,
142 $this->obj_cache,
143 $this->participant_access_filter_factory,
144 $this->test_obj->getTestLogViewer(),
145 $this->test_obj->getId()
146 );
147 $archiver->setParticipantData($this->getParticipantData());
148 $archiver->handInTestResult($active_id, $pass, $filename);
149 $archiver->handInParticipantUploadedResults($active_id, $pass, $this->test_obj);
150 unlink($filename);
151 }
152
158 private function renderOverviewContent($activeId, $pass): string
159 {
160 $results = $this->test_obj->getTestResult(
161 $activeId,
162 $pass,
163 false
164 );
165
166 $gui = new ilTestServiceGUI($this->test_obj);
167 $testResultHeaderLabelBuilder = new ResultsTitlesBuilder($this->lng, $this->obj_cache);
168
169 return $gui->getPassListOfAnswers(
170 $results,
171 $activeId,
172 $pass,
173 true,
174 false,
175 false,
176 true,
177 false,
178 null,
179 $testResultHeaderLabelBuilder
180 );
181 }
182
188 private function buildOverviewFilename($activeId, $pass): string
189 {
190 $tmpFileName = ilFileUtils::ilTempnam();
191 return dirname($tmpFileName) . '/scores-' . $this->test_obj->getId() . '-' . $activeId . '-' . $pass . '.html';
192 }
193}
$filename
Definition: buildRTE.php:78
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
language handling
User class.
class ilObjectDataCache
special template class to simplify handling of ITX/PEAR
archiveActivesPass(int $active_id, int $pass)
archivePassesByActives($passesByActives)
renderOverviewContent($activeId, $pass)
ilTestParticipantData $participantData
buildOverviewFilename($activeId, $pass)
__construct(private readonly ilObjTest $test_obj, private readonly ilLanguage $lng, private readonly ilDBInterface $db, private readonly ilObjUser $user, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly IRSS $irss, private readonly ServerRequestInterface $request, private readonly ilObjectDataCache $obj_cache, private readonly ilTestParticipantAccessFilterFactory $participant_access_filter_factory, private readonly ilTestHTMLGenerator $html_generator)
setParticipantData(ilTestParticipantData $participantData)
Class that handles PDF generation for test and assessment.
Service GUI class for tests.
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31
$results