ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Printer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Test\Questions\Properties\Repository as TestQuestionsRepository;
25use ILIAS\UI\Factory as UIFactory;
28
30{
34 public function __construct(
35 private readonly UIFactory $ui_factory,
36 private \ilGlobalTemplateInterface $tpl,
37 private TabsManager $tabs_manager,
38 private \ilToolbarGUI $toolbar,
39 private readonly Refinery $refinery,
40 private readonly Language $lng,
41 private readonly \ilCtrl $ctrl,
42 private readonly \ilObjUser $user,
43 private readonly \ilTestQuestionHeaderBlockBuilder $question_header_builder,
44 private readonly \ilObjTest $test_obj,
45 ) {
46 }
47
51 public function printSelectedQuestions(
52 array $print_view_types,
53 ?Types $selected_print_view_type,
54 array $question_ids
55 ): void {
56 $this->tabs_manager->resetTabsAndAddBacklink(
57 $this->ctrl->getLinkTargetByClass(\ilObjTestGUI::class, \ilObjTestGUI::SHOW_QUESTIONS_CMD)
58 );
59
60 $this->toolbar->addComponent(
61 $this->ui_factory->viewControl()->mode(
62 $print_view_types,
63 $this->lng->txt('show_hide_best_solution')
64 )->withActive($selected_print_view_type->getLabel($this->lng))
65 );
66
67 $this->toolbar->addSeparator();
69
70 $template = new \ilTemplate('tpl.il_as_tst_print_questions_preview.html', true, true, 'components/ILIAS/Test');
71
72 $this->tpl->addCss(\ilUtil::getStyleSheetLocation('output', 'test_print.css'), 'print');
73
74 $max_points = 0;
75 $counter = 1;
76 $this->question_header_builder->setHeaderMode($this->test_obj->getTitleOutput());
77
78 foreach ($question_ids as $question_id) {
79 $template->setCurrentBlock('question');
80 $question_gui = $this->test_obj->createQuestionGUI('', $question_id);
81 $question_gui->setRenderPurpose(\assQuestionGUI::RENDER_PURPOSE_PREVIEW);
82
83 $this->question_header_builder->setQuestionTitle($question_gui->getObject()->getTitleForHTMLOutput());
84 $this->question_header_builder->setQuestionPoints($question_gui->getObject()->getMaximumPoints());
85 $this->question_header_builder->setQuestionPosition($counter);
86 $template->setVariable('QUESTION_HEADER', $this->question_header_builder->getHTML());
87
88 if ($selected_print_view_type === Types::RESULTS_VIEW_TYPE_HIDE) {
89 $template->setVariable('SOLUTION_OUTPUT', $question_gui->getPreview(false));
90 } else {
91 $template->setVariable('TXT_QUESTION_ID', $this->lng->txt('question_id_short'));
92 $template->setVariable('QUESTION_ID', $question_gui->getObject()->getId());
93 $template->setVariable('SOLUTION_OUTPUT', $question_gui->getSolutionOutput(0, null, false, true, false, false));
94 }
95
96 $template->parseCurrentBlock('question');
97 $counter++;
98 $max_points += $question_gui->getObject()->getMaximumPoints();
99 }
100
101 $template->setVariable('PRINT_TEST', $this->lng->txt('print_view'));
102 $template->setVariable('TXT_PRINT_DATE', $this->lng->txt('date'));
103 $template->setVariable(
104 'VALUE_PRINT_DATE',
105 (new \DateTimeImmutable())
106 ->setTimezone(new \DateTimeZone($this->user->getTimeZone()))
107 ->format($this->user->getDateTimeFormat()->toString())
108 );
109 $template->setVariable(
110 'TXT_MAXIMUM_POINTS',
111 $this->lng->txt('tst_maximum_points')
112 );
113 $template->setVariable('VALUE_MAXIMUM_POINTS', $max_points);
114 $this->tpl->setVariable('PRINT_CONTENT', $template->get());
115 }
116
117 public function printAnswers(int $question_id): void
118 {
119 $this->tabs_manager->resetTabsAndAddBacklink(
120 $this->ctrl->getLinkTargetByClass(\ilObjTestGUI::class, \ilObjTestGUI::SHOW_QUESTIONS_CMD)
121 );
122
123 $this->addPrintButtonToToolbar();
124
125 $template = new \ilTemplate('tpl.il_as_tst_print_questions_answers.html', true, true, 'components/ILIAS/Test');
126 $this->tpl->addCss(\ilUtil::getStyleSheetLocation('output', 'test_print.css'), 'print');
127
128 $question_gui = $this->test_obj->createQuestionGUI('', $question_id);
129 $question_gui->setRenderPurpose(\assQuestionGUI::RENDER_PURPOSE_PREVIEW);
130 $template->setVariable('TITLE', $question_gui->getObject()->getTitleForHTMLOutput());
131 $template->setVariable('TXT_PRINT_DATE', $this->lng->txt('date'));
132 $template->setVariable(
133 'VALUE_PRINT_DATE',
134 (new \DateTimeImmutable())
135 ->setTimezone(new \DateTimeZone($this->user->getTimeZone()))
136 ->format($this->user->getDateTimeFormat()->toString())
137 );
138
139 $this->tpl->setVariable(
140 'PRINT_CONTENT',
141 $this->addQuestionResultForTestUsersToTemplate(
142 $template,
143 $question_gui,
144 $this->test_obj->getTestId()
145 )->get()
146 );
147 }
148
150 \ilTemplate $template,
151 \assQuestionGUI $question_gui,
152 int $test_id
153 ): \ilTemplate {
154 $this->test_obj->setAccessFilteredParticipantList(
155 $this->test_obj->buildStatisticsAccessFilteredParticipantList()
156 );
157
158 $foundusers = $this->test_obj->getParticipantsForTestAndQuestion(
159 $test_id,
160 $question_gui->getObject()->getId()
161 );
162
163 foreach ($foundusers as $active_id => $passes) {
164 if (($resultpass = \ilObjTest::_getResultPass($active_id)) === null) {
165 continue;
166 }
167
168 for ($i = 0; $i < count($passes); $i++) {
169 if ($passes[$i]['pass'] !== $resultpass) {
170 continue;
171 }
172
173 $template->setCurrentBlock('question');
174 $template = $this->addResultUserInfoToTemplate(
175 $template,
176 $active_id,
177 $resultpass + 1
178 );
179 $template->setVariable(
180 'SOLUTION_OUTPUT',
181 $question_gui->getSolutionOutput(
182 $active_id,
183 $resultpass,
184 false,
185 false,
186 false,
187 false
188 )
189 );
190 $template->parseCurrentBlock('question');
191 }
192 }
193 return $template;
194 }
195
197 \ilTemplate $template,
198 int $active_id,
199 int $pass
200 ): \ilTemplate {
201 $user_id = $this->test_obj->_getUserIdFromActiveId($active_id);
202 if (\ilObjUser::_lookupLogin($user_id) !== '') {
203 $user = new \ilObjUser($user_id);
204 } else {
205 $user = new \ilObjUser();
206 $user->setLastname($this->lng->txt('deleted_user'));
207 }
208 if ($user->getMatriculation() !== ''
209 && $this->test_obj->getAnonymity() === false) {
210 $template->setCurrentBlock('matriculation');
211 $template->setVariable('TXT_USR_MATRIC', $this->lng->txt('matriculation'));
212 $template->setVariable('VALUE_USR_MATRIC', $user->getMatriculation());
213 $template->parseCurrentBlock();
214 }
215
216 $template->setVariable('TXT_USR_NAME', $this->lng->txt('name'));
217 $uname = $this->test_obj->userLookupFullName($user_id, false);
218 $template->setVariable('VALUE_USR_NAME', $uname);
219 $template->setVariable('TXT_PASS', $this->lng->txt('scored_pass'));
220 $template->setVariable('VALUE_PASS', $pass);
221 return $template;
222 }
223
224 private function addPrintButtonToToolbar(): void
225 {
226 $this->toolbar->addComponent(
227 $this->ui_factory->button()->standard($this->lng->txt('print'), '')
228 ->withOnLoadCode(fn($id) => "$('#$id').on('click', ()=>{window.print();})")
229 );
230 }
231}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
__construct(private readonly UIFactory $ui_factory, private \ilGlobalTemplateInterface $tpl, private TabsManager $tabs_manager, private \ilToolbarGUI $toolbar, private readonly Refinery $refinery, private readonly Language $lng, private readonly \ilCtrl $ctrl, private readonly \ilObjUser $user, private readonly \ilTestQuestionHeaderBlockBuilder $question_header_builder, private readonly \ilObjTest $test_obj,)
Definition: Printer.php:34
printSelectedQuestions(array $print_view_types, ?Types $selected_print_view_type, array $question_ids)
Definition: Printer.php:51
addResultUserInfoToTemplate(\ilTemplate $template, int $active_id, int $pass)
Definition: Printer.php:196
addQuestionResultForTestUsersToTemplate(\ilTemplate $template, \assQuestionGUI $question_gui, int $test_id)
Definition: Printer.php:149
getSolutionOutput(int $active_id, ?int $pass=null, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_inline_feedback=true)
Class ilCtrl provides processing control methods.
Class ilObjTestGUI.
static _getResultPass($active_id)
Retrieves the pass number that should be counted for a given user.
User class.
static _lookupLogin(int $a_user_id)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
global $lng
Definition: privfeed.php:31
$counter