ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestResultsFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
33  public function __construct(
34  protected ilTestShuffler $shuffler,
35  protected UIFactory $ui_factory,
36  protected UIRenderer $ui_renderer
37  ) {
38  }
39  public function getPassResultsFor(
40  ilObjTest $test_obj,
41  int $active_id,
42  int $pass_id,
43  bool $is_user_output = true
44  ): ilTestPassResult {
45  $settings = $this->getPassResultsSettings($test_obj, $is_user_output);
46  return $this->buildPassResults(
47  $settings,
48  $test_obj,
49  $active_id,
50  $pass_id,
51  $is_user_output
52  );
53  }
54 
55  protected function buildPassResults(
57  ilObjTest $test_obj,
58  int $active_id,
59  int $pass_id,
60  bool $is_user_output
61  ): ilTestPassResult {
62  $question_results = [];
63 
64  $results = $test_obj->getTestResult(
65  $active_id,
66  $pass_id,
67  false, //$ordered_sequence
68  $settings->getShowHiddenQuestions(),
69  $settings->getShowOptionalQuestions()
70  );
71 
72  // params of getSolutionOutput
73  $graphical_output = false;
74  $result_output = false;
75  $show_question_only = $settings->getQuestionTextOnly();
76  $show_feedback = false; //general
77  $show_correct_solution = false;
78  $show_manual_scoring = false;
79  $show_question_text = true;
80  $show_inline_feedback = true;
81 
82  foreach ($results as $idx => $qresult) {
83  if (!is_numeric($idx)) {
84  continue;
85  }
86 
87  $qid = $qresult['qid'];
88  $type = $qresult['type'];
89  $title = $qresult['title'];
90  $question_score = $qresult['max'];
91  $usr_score = $qresult['reached'];
92  $workedthrough = (bool) $qresult['workedthrough'];
93  $answered = (bool) $qresult['answered'];
94  $requested_hints = (int) $qresult['requested_hints'];
95 
96 
97  $question_gui = $test_obj->createQuestionGUI("", $qid);
98  $shuffle_trafo = $this->shuffler->getAnswerShuffleFor($qid, $active_id, $pass_id);
99  $question_gui->object->setShuffler($shuffle_trafo);
100 
101  $graphical_output = true;
102  $show_correct_solution = false;
103  $show_feedback = $settings->getShowFeedback();
104  $usr_solution = $question_gui->getSolutionOutput(
105  $active_id,
106  $pass_id,
107  $graphical_output,
108  $result_output,
109  $show_question_only,
110  $show_feedback,
111  $show_correct_solution,
112  $show_manual_scoring,
113  $show_question_text,
114  $show_inline_feedback
115  );
116 
117  $autosave_output = null;
118  $show_autosave_title = false;
119  if ($test_obj->getAutosave()) {
120  $autosave_output = $question_gui->getAutoSavedSolutionOutput(
121  $active_id,
122  $pass_id,
123  $graphical_output,
124  $result_output,
125  $show_question_only,
126  $show_feedback,
127  $show_correct_solution,
128  $show_manual_scoring,
129  $show_question_text,
130  $show_autosave_title,
131  $show_inline_feedback
132  );
133  }
134 
135  $graphical_output = false;
136  $show_correct_solution = true;
137  $show_feedback = false;
138  $show_inline_feedback = false;
139  $best_solution = $question_gui->getSolutionOutput(
140  $active_id,
141  $pass_id,
142  $graphical_output,
143  $result_output,
144  $show_question_only,
145  $show_feedback,
146  $show_correct_solution,
147  $show_manual_scoring,
148  $show_question_text,
149  $show_inline_feedback
150  );
151 
152  if ($show_question_only) {
153  $usr_solution = $this->ui_renderer->render($this->ui_factory->legacy('<div class="ilc_question_Standard">' . $usr_solution . '</div>'));
154  $best_solution = $this->ui_renderer->render($this->ui_factory->legacy('<div class="ilc_question_Standard">' . $best_solution . '</div>'));
155  }
156 
157  $feedback = $question_gui->getGenericFeedbackOutput($active_id, $pass_id);
158 
159  $recapitulation = null;
160  if ($is_user_output && $settings->getShowRecapitulation()) {
161  $recapitulation = $question_gui->object->getSuggestedSolutionOutput();
162  }
163 
164  $question_results[] = new ilQuestionResult(
165  $qid,
166  $type,
167  $title,
168  $question_score,
169  $usr_score,
170  $usr_solution,
171  $best_solution,
172  $feedback,
173  $workedthrough,
174  $answered,
175  $requested_hints,
176  $recapitulation,
177  $autosave_output,
178  $idx
179  );
180  }
181 
182  return new ilTestPassResult(
183  $settings,
184  $active_id,
185  $pass_id,
186  $question_results
187  );
188  }
189 
190  protected function getPassResultsSettings(
191  ilObjTest $test_obj,
192  bool $is_user_output
194  $settings = $test_obj->getScoreSettings();
195  $settings_summary = $settings->getResultSummarySettings();
196  $settings_result = $settings->getResultDetailsSettings();
197 
198  $show_hidden_questions = false;
199  $show_optional_questions = true;
200  $show_best_solution = $is_user_output ?
201  $settings_result->getShowSolutionListComparison() :
202  (bool) ilSession::get('tst_results_show_best_solutions');
203  $show_feedback = $settings_result->getShowSolutionFeedback();
204  $show_question_text_only = $settings_result->getShowSolutionAnswersOnly();
205  $show_content_for_recapitulation = $settings_result->getShowSolutionSuggested();
206 
207  return new ilTestPassResultsSettings(
208  $show_hidden_questions,
209  $show_optional_questions,
210  $show_best_solution,
211  $show_feedback,
212  $show_question_text_only,
213  $show_content_for_recapitulation
214  );
215  }
216 }
static get(string $a_var)
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
& getTestResult(int $active_id, ?int $pass=null, bool $ordered_sequence=false, bool $considerHiddenQuestions=true, bool $considerOptionalQuestions=true)
Calculates the results of a test for a given user and returns an array with all test results...
createQuestionGUI($question_type, $question_id=-1)
Creates a question GUI instance of a given question type.
getPassResultsFor(ilObjTest $test_obj, int $active_id, int $pass_id, bool $is_user_output=true)
__construct(protected ilTestShuffler $shuffler, protected UIFactory $ui_factory, protected UIRenderer $ui_renderer)
$results
buildPassResults(ilTestPassResultsSettings $settings, ilObjTest $test_obj, int $active_id, int $pass_id, bool $is_user_output)
getPassResultsSettings(ilObjTest $test_obj, bool $is_user_output)