ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Test\Questions\Presentation\Printer Class Reference
+ Collaboration diagram for ILIAS\Test\Questions\Presentation\Printer:

Public Member Functions

 __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,)
 
 printSelectedQuestions (array $print_view_types, ?Types $selected_print_view_type, array $question_ids)
 
 printAnswers (int $question_id)
 

Private Member Functions

 addQuestionResultForTestUsersToTemplate (\ilTemplate $template, \assQuestionGUI $question_gui, int $test_id)
 
 addResultUserInfoToTemplate (\ilTemplate $template, int $active_id, int $pass)
 
 addPrintButtonToToolbar ()
 

Detailed Description

Definition at line 29 of file Printer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Questions\Presentation\Printer::__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 
)
Parameters
array$data<string, mixed>

Definition at line 34 of file Printer.php.

45 {
46 }

Member Function Documentation

◆ addPrintButtonToToolbar()

ILIAS\Test\Questions\Presentation\Printer::addPrintButtonToToolbar ( )
private

Definition at line 224 of file Printer.php.

224 : 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 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

◆ addQuestionResultForTestUsersToTemplate()

ILIAS\Test\Questions\Presentation\Printer::addQuestionResultForTestUsersToTemplate ( \ilTemplate  $template,
\assQuestionGUI  $question_gui,
int  $test_id 
)
private

Definition at line 149 of file Printer.php.

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 }
addResultUserInfoToTemplate(\ilTemplate $template, int $active_id, int $pass)
Definition: Printer.php:196
static _getResultPass($active_id)
Retrieves the pass number that should be counted for a given user.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)

References ilObjTest\_getResultPass(), assQuestionGUI\getSolutionOutput(), ilTemplate\parseCurrentBlock(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

+ Here is the call graph for this function:

◆ addResultUserInfoToTemplate()

ILIAS\Test\Questions\Presentation\Printer::addResultUserInfoToTemplate ( \ilTemplate  $template,
int  $active_id,
int  $pass 
)
private

Definition at line 196 of file Printer.php.

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 }
static _lookupLogin(int $a_user_id)

References $user_id.

◆ printAnswers()

ILIAS\Test\Questions\Presentation\Printer::printAnswers ( int  $question_id)

Definition at line 117 of file Printer.php.

117 : void
118 {
119 $this->tabs_manager->resetTabsAndAddBacklink(
120 $this->ctrl->getLinkTargetByClass(\ilObjTestGUI::class, \ilObjTestGUI::SHOW_QUESTIONS_CMD)
121 );
122
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',
142 $template,
143 $question_gui,
144 $this->test_obj->getTestId()
145 )->get()
146 );
147 }
addQuestionResultForTestUsersToTemplate(\ilTemplate $template, \assQuestionGUI $question_gui, int $test_id)
Definition: Printer.php:149
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user

References ILIAS\Repository\ctrl(), ilUtil\getStyleSheetLocation(), ILIAS\Repository\lng(), assQuestionGUI\RENDER_PURPOSE_PREVIEW, ilObjTestGUI\SHOW_QUESTIONS_CMD, and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ printSelectedQuestions()

ILIAS\Test\Questions\Presentation\Printer::printSelectedQuestions ( array  $print_view_types,
?Types  $selected_print_view_type,
array  $question_ids 
)
Parameters
array<int>$question_ids

Definition at line 51 of file Printer.php.

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 }
$counter

The documentation for this class was generated from the following file: