diff --git a/components/ILIAS/Test/classes/class.ilObjTest.php b/components/ILIAS/Test/classes/class.ilObjTest.php index 3141f31e9f7a..ba8895db7a70 100755 --- a/components/ILIAS/Test/classes/class.ilObjTest.php +++ b/components/ILIAS/Test/classes/class.ilObjTest.php @@ -4273,7 +4273,7 @@ public function getTestParticipants(): array LEFT JOIN usr_data ON tst_active.user_fi = usr_data.usr_id WHERE tst_active.test_fi = %s - ORDER BY usr_data.lastname + ORDER BY usr_data.lastname, usr_data.firstname, tst_active.active_id "; $result = $this->db->queryF( $query, @@ -4297,7 +4297,7 @@ public function getTestParticipants(): array LEFT JOIN usr_data ON tst_active.user_fi = usr_data.usr_id WHERE tst_active.test_fi = %s - ORDER BY usr_data.lastname + ORDER BY usr_data.lastname, usr_data.firstname, tst_active.active_id "; $result = $this->db->queryF( $query, diff --git a/components/ILIAS/Test/src/GUIFactory.php b/components/ILIAS/Test/src/GUIFactory.php index 49fc2e305a33..eda48733b5ae 100644 --- a/components/ILIAS/Test/src/GUIFactory.php +++ b/components/ILIAS/Test/src/GUIFactory.php @@ -84,7 +84,8 @@ public function __construct( $this->internal['manscoring.positionsfactory'] = fn(\ilObjTest $test_obj): PositionsFactory => new PositionsFactory( $test_obj, - $this->test_dic['question.general_properties.repository'] + $this->test_dic['question.general_properties.repository'], + $this->global_dic['ilAccess'] ); $this->internal['manscoring.testscoring'] = fn(\ilObjTest $test_obj): TestScoring => diff --git a/components/ILIAS/Test/src/Scoring/Manual/PositionsFactory.php b/components/ILIAS/Test/src/Scoring/Manual/PositionsFactory.php index 54d3ebb75774..dec6b3ee7c61 100644 --- a/components/ILIAS/Test/src/Scoring/Manual/PositionsFactory.php +++ b/components/ILIAS/Test/src/Scoring/Manual/PositionsFactory.php @@ -26,7 +26,8 @@ class PositionsFactory { public function __construct( private readonly \ilObjTest $test_obj, - private readonly GeneralQuestionPropertiesRepository $question_repo + private readonly GeneralQuestionPropertiesRepository $question_repo, + private readonly \ilAccess $access ) { } @@ -35,7 +36,10 @@ public function get(): Positions $user_questions = []; $user_attempts = []; $question_properties = []; - foreach (array_keys($this->test_obj->getTestParticipants()) as $usr_active_id) { + + $test_participants = $this->filterParticipantsIfOrgUnitsEnabled($this->test_obj->getTestParticipants()); + + foreach (array_keys($test_participants) as $usr_active_id) { $attempt = \ilObjTest::_getResultPass($usr_active_id); $user_attempts[$usr_active_id] = $attempt; $user_questions[$usr_active_id] = $this->test_obj->isRandomTest() @@ -73,4 +77,22 @@ public function get(): Positions $question_properties ); } + + private function filterParticipantsIfOrgUnitsEnabled(array $test_participants): array + { + if (!\ilOrgUnitGlobalSettings::getInstance()->isPositionAccessActiveForObject($this->test_obj->getId())) { + return $test_participants; + } + + $allowed_participants = $this->access->filterUserIdsByPositionOfCurrentUser( + \ilOrgUnitOperation::OP_SCORE_PARTICIPANTS, + $this->test_obj->getRefId(), + array_column($test_participants, 'usr_id') + ); + + return array_filter( + $test_participants, + static fn(array $participant): bool => in_array($participant['usr_id'], $allowed_participants, true) + ); + } }