ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
PositionsFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 public function __construct(
28 private readonly \ilObjTest $test_obj,
29 private readonly GeneralQuestionPropertiesRepository $question_repo
30 ) {
31 }
32
33 public function get(): Positions
34 {
35 $user_questions = [];
36 $user_attempts = [];
37 $question_properties = [];
38 foreach (array_keys($this->test_obj->getTestParticipants()) as $usr_active_id) {
39 $attempt = \ilObjTest::_getResultPass($usr_active_id);
40 $user_attempts[$usr_active_id] = $attempt;
41 $user_questions[$usr_active_id] = $this->test_obj->isRandomTest()
42 ? array_map(
43 fn($q) => $q['question_fi'],
44 $this->test_obj->getQuestionsOfPass($usr_active_id, $attempt)
45 )
46 : $this->test_obj->getQuestions();
47 }
48
49 $question_ids = array_unique(array_merge(...array_values($user_questions)));
50 foreach ($question_ids as $qid) {
51 $question_properties[$qid] = $this->question_repo->getForQuestionId($qid);
52 }
53
54 $qtypes = $this->test_obj->getGlobalSettings()->getDisabledQuestionTypes();
55
56 $question_properties = array_filter(
57 $question_properties,
58 fn($qprops, $id) => !in_array($qprops->getTypeId(), $qtypes),
59 ARRAY_FILTER_USE_BOTH
60 );
61
62 $user_questions = array_map(
63 fn($question_ids) => array_filter(
64 $question_ids,
65 fn($qid) => array_key_exists($qid, $question_properties)
66 ),
67 $user_questions
68 );
69
70 return new Positions(
71 $user_questions,
72 $user_attempts,
73 $question_properties
74 );
75 }
76}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(private readonly \ilObjTest $test_obj, private readonly GeneralQuestionPropertiesRepository $question_repo)
static _getResultPass($active_id)
Retrieves the pass number that should be counted for a given user.
$q
Definition: shib_logout.php:23