ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
TitlesBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
29 {
30  private const LO_TEST_TYPE_INITIAL = 'loTestInitial';
31  private const LO_TEST_TYPE_QUALIFYING = 'loTestQualifying';
32 
34  private ?int $test_obj_id = null;
35  private ?int $test_ref_id = null;
36  private ?int $user_id = null;
37  private ?string $attempt_last_access_date = null;
38  private ?string $crs_title = null;
39  private ?string $test_type = null;
40  private array $objectives = [];
41 
42  public function __construct(
43  protected Language $lng,
44  protected \ilObjectDataCache $obj_cache
45  ) {
46  }
47 
48  public function initObjectiveOrientedMode(): void
49  {
50  $this->initTestType();
51  $this->initObjectives();
52  $this->initCourseTitle();
53  }
54 
55  public function setObjectiveOrientedContainerId(int $container_id): void
56  {
57  $this->objective_oriented_container_id = $container_id;
58  }
59 
60  public function setTestObjId(int $testObjId): void
61  {
62  $this->test_obj_id = $testObjId;
63  }
64 
65  public function setTestRefId(int $testRefId): void
66  {
67  $this->test_ref_id = $testRefId;
68  }
69 
70  public function setUserId(int $userId): void
71  {
72  $this->user_id = $userId;
73  }
74 
75  public function setAttemptLastAccessDate(string $formatted_date): void
76  {
77  $this->attempt_last_access_date = $formatted_date;
78  }
79 
80  public function getPassOverviewHeaderLabel(): string
81  {
82  if (!$this->objective_oriented_container_id) {
83  return $this->lng->txt('tst_results_overview');
84  }
85 
86  if ($this->isInitialTestForAllObjectives()) {
87  return sprintf(
88  $this->lng->txt('tst_pass_overview_header_lo_initial_all_objectives'),
90  );
91  }
92 
93  if ($this->isInitialTestPerObjective()) {
94  return sprintf(
95  $this->lng->txt('tst_pass_overview_header_lo_initial_per_objective'),
96  $this->getObjectivesString(),
98  );
99  }
100 
101  if ($this->isQualifyingTestForAllObjectives()) {
102  return sprintf(
103  $this->lng->txt('tst_pass_overview_header_lo_qualifying_all_objectives'),
105  );
106  }
107 
108  if ($this->isQualifyingTestPerObjective()) {
109  return sprintf(
110  $this->lng->txt('tst_pass_overview_header_lo_qualifying_per_objective'),
111  $this->getObjectivesString(),
113  );
114  }
115 
116  return '';
117  }
118 
119  public function getPassDetailsHeaderLabel(int $attempt): string
120  {
121  if (!$this->objective_oriented_container_id) {
122  return sprintf(
123  $this->lng->txt('tst_pass_details_overview_table_title'),
124  $attempt
125  );
126  }
127 
128  if ($this->isInitialTest()) {
129  return sprintf(
130  $this->lng->txt('tst_pass_details_header_lo_initial'),
131  $this->getObjectivesString(),
132  $this->getAttemptLabel($attempt)
133  );
134  }
135 
136  if ($this->isQualifyingTest()) {
137  return sprintf(
138  $this->lng->txt('tst_pass_details_header_lo_qualifying'),
139  $this->getObjectivesString(),
140  $this->getAttemptLabel($attempt)
141  );
142  }
143 
144  return '';
145  }
146 
147  public function getListOfAnswersHeaderLabel(int $attempt): string
148  {
149  $langVar = 'tst_eval_results_by_pass';
150 
151  if ($this->objective_oriented_container_id) {
152  $langVar = 'tst_eval_results_by_pass_lo';
153  }
154 
155  $title = sprintf($this->lng->txt($langVar), $attempt);
156 
157  if ($this->attempt_last_access_date === null) {
158  return $title;
159  }
160 
161  return "{$title} - {$this->attempt_last_access_date}";
162  }
163 
164  public function getVirtualListOfAnswersHeaderLabel(): string
165  {
166  return $this->lng->txt('tst_eval_results_lo');
167  }
168 
169  public function getVirtualPassDetailsHeaderLabel($objectiveTitle): string
170  {
171  if ($this->isInitialTest()) {
172  return sprintf(
173  $this->lng->txt('tst_virtual_pass_header_lo_initial'),
174  $objectiveTitle
175  );
176  } elseif ($this->isQualifyingTest()) {
177  return sprintf(
178  $this->lng->txt('tst_virtual_pass_header_lo_qualifying'),
179  $objectiveTitle
180  );
181  }
182 
183  return '';
184  }
185 
186  private function initTestType()
187  {
188  $loSettings = \ilLOSettings::getInstanceByObjId($this->objective_oriented_container_id);
189 
190  if ($loSettings->getInitialTest() == $this->test_ref_id) {
191  $this->test_type = self::LO_TEST_TYPE_INITIAL;
192  } elseif ($loSettings->getQualifiedTest() == $this->test_ref_id) {
193  $this->test_type = self::LO_TEST_TYPE_QUALIFYING;
194  }
195  }
196 
197  private function initObjectives()
198  {
199  $lo_attempts = \ilLOTestRun::getRun($this->objective_oriented_container_id, $this->user_id, $this->test_obj_id);
200 
201  $this->objectives = [];
202 
203  foreach ($lo_attempts as $lo_attempt) {
204  $this->objectives[$lo_attempt->getObjectiveId()] = $this->getObjectiveTitle($lo_attempt);
205  }
206  }
207 
208  private function initCourseTitle()
209  {
210  $this->crs_title = $this->obj_cache->lookupTitle($this->objective_oriented_container_id);
211  }
212 
213  private function isInitialTest(): bool
214  {
215  return $this->test_type === self::LO_TEST_TYPE_INITIAL;
216  }
217 
218  private function isQualifyingTest(): bool
219  {
220  return $this->test_type === self::LO_TEST_TYPE_QUALIFYING;
221  }
222 
223  private function isInitialTestForAllObjectives(): bool
224  {
225  if ($this->test_type !== self::LO_TEST_TYPE_INITIAL) {
226  return false;
227  }
228 
229  if (count($this->objectives) <= 1) {
230  return false;
231  }
232 
233  return true;
234  }
235 
236  private function isInitialTestPerObjective(): bool
237  {
238  if ($this->test_type !== self::LO_TEST_TYPE_INITIAL) {
239  return false;
240  }
241 
242  if (count($this->objectives) > 1) {
243  return false;
244  }
245 
246  return true;
247  }
248 
249  private function isQualifyingTestForAllObjectives(): bool
250  {
251  if ($this->test_type !== self::LO_TEST_TYPE_QUALIFYING) {
252  return false;
253  }
254 
255  if (count($this->objectives) <= 1) {
256  return false;
257  }
258 
259  return true;
260  }
261 
262  private function isQualifyingTestPerObjective(): bool
263  {
264  if ($this->test_type !== self::LO_TEST_TYPE_QUALIFYING) {
265  return false;
266  }
267 
268  if (count($this->objectives) > 1) {
269  return false;
270  }
271 
272  return true;
273  }
274 
275  private function getObjectiveTitle(\ilLOTestRun $loRun)
276  {
277  return \ilCourseObjective::lookupObjectiveTitle($loRun->getObjectiveId());
278  }
279 
280  private function getObjectivesString(): string
281  {
282  return implode(', ', $this->objectives);
283  }
284 
285  private function getAttemptLabel(int $attempt): string
286  {
287  return sprintf($this->lng->txt('tst_res_lo_try_n'), $attempt);
288  }
289 }
setAttemptLastAccessDate(string $formatted_date)
__construct(protected Language $lng, protected \ilObjectDataCache $obj_cache)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getInstanceByObjId(int $a_obj_id)
static getRun(int $a_container_id, int $a_user_id, int $a_test_id)
global $lng
Definition: privfeed.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...