Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function executeCommand()
$tree = $DIC['tree'];
$ilias = $DIC['ilias'];
$ilUser = $DIC['ilUser'];
$randomGroup = $DIC->refinery()->random();

$cmd = $this->ctrl->getCmd("infoScreen");

Expand Down Expand Up @@ -659,7 +660,7 @@ public function executeCommand()
$this->ctrl->saveParameter($this, "q_id");

require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewGUI.php';
$gui = new ilAssQuestionPreviewGUI($this->ctrl, $this->tabs_gui, $this->tpl, $this->lng, $ilDB, $ilUser);
$gui = new ilAssQuestionPreviewGUI($this->ctrl, $this->tabs_gui, $this->tpl, $this->lng, $ilDB, $ilUser, $randomGroup);

$gui->initQuestion($this->fetchAuthoringQuestionIdParameter(), $this->object->getId());
$gui->initPreviewSettings($this->object->getRefId());
Expand Down
18 changes: 11 additions & 7 deletions Modules/Test/classes/class.ilTestPlayerAbstractGUI.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */

use ILIAS\Refinery\Transformation;
use ILIAS\Refinery\Random\Seed\RandomSeed;
use ILIAS\Refinery\Random\Seed\GivenSeed;
use ILIAS\Refinery\Random\Group as RandomGroup;

require_once './Modules/Test/classes/inc.AssessmentConstants.php';
require_once './Modules/Test/classes/class.ilTestPlayerCommands.php';
require_once './Modules/Test/classes/class.ilTestServiceGUI.php';
Expand Down Expand Up @@ -61,6 +66,8 @@ abstract class ilTestPlayerAbstractGUI extends ilTestServiceGUI
*/
protected $testSequence = null;

private RandomGroup $randomGroup;

/**
* ilTestOutputGUI constructor
*
Expand All @@ -81,6 +88,7 @@ public function __construct($a_object)
$this->processLocker = null;
$this->testSession = null;
$this->assSettings = null;
$this->randomGroup = $DIC->refinery()->random();
}

protected function checkReadAccess()
Expand Down Expand Up @@ -2534,17 +2542,13 @@ protected function initTestQuestionConfig(assQuestion $questionOBJ)

/**
* @param $questionId
* @return ilArrayElementShuffler
* @return Transformation
*/
protected function buildQuestionAnswerShuffler($questionId)
{
require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
$shuffler = new ilArrayElementShuffler();

$fixedSeed = $this->buildFixedShufflerSeed($questionId);
$shuffler->setSeed($fixedSeed);

return $shuffler;

return $this->randomGroup->shuffleArray(new GivenSeed($fixedSeed));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Modules/Test/test/ilTestBaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use ILIAS\Filesystem\Filesystems;
use ILIAS\HTTP\Services;
use ILIAS\UI\Implementation\Factory;
use ILIAS\Refinery\Factory as RefineryFactory;
use ILIAS\Refinery\Random\Group as RandomGroup;

/**
* Class ilTestBaseClass
Expand Down Expand Up @@ -216,4 +218,11 @@ protected function addGlobal_uiRenderer() : void
{
$this->setGlobalVariable("ui.renderer", $this->createMock(ILIAS\UI\Implementation\DefaultRenderer::class));
}

protected function addGlobal_refinery() : void
{
$refineryMock = $this->getMockBuilder(RefineryFactory::class)->disableOriginalConstructor()->getMock();
$refineryMock->expects(self::any())->method('random')->willReturn($this->getMockBuilder(RandomGroup::class)->getMock());
$this->setGlobalVariable("refinery", $refineryMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp() : void
$this->addGlobal_ilObjDataCache();
$this->addGlobal_rbacsystem();
$this->addGlobal_ilUser();
$this->addGlobal_refinery();

$_GET["ref_id"] = 2;

Expand Down
1 change: 1 addition & 0 deletions Modules/Test/test/ilTestPlayerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function testGetPlayerGUI() : void
$this->addGlobal_ilObjDataCache();
$_GET["ref_id"] = 2;
$this->addGlobal_rbacsystem();
$this->addGlobal_refinery();

$objTest = new ilObjTest();

Expand Down
1 change: 1 addition & 0 deletions Modules/Test/test/ilTestPlayerFixedQuestionSetGUITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function setUp() : void
$this->addGlobal_ilObjDataCache();
$this->addGlobal_rbacsystem();
$this->addGlobal_ilUser();
$this->addGlobal_refinery();

$this->testObj = new ilTestPlayerFixedQuestionSetGUI(
$this->createMock(ilObjTest::class)
Expand Down
1 change: 1 addition & 0 deletions Modules/Test/test/ilTestPlayerRandomQuestionSetGUITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function setUp() : void
$this->addGlobal_ilObjDataCache();
$this->addGlobal_rbacsystem();
$this->addGlobal_ilUser();
$this->addGlobal_refinery();

$_GET["ref_id"] = "0";

Expand Down
12 changes: 7 additions & 5 deletions Modules/TestQuestionPool/classes/class.assClozeGap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */

use ILIAS\Refinery\Transformation;

include_once "./Modules/Test/classes/inc.AssessmentConstants.php";

/**
Expand Down Expand Up @@ -85,13 +87,13 @@ public function setType($a_type = 0)
/**
* Gets the items of a cloze gap
*
* @param ilRandomArrayElementProvider $shuffler
* @param Transformation $shuffler
* @return assAnswerCloze[] The list of items
*/
public function getItems(ilRandomArrayElementProvider $shuffler)
public function getItems(Transformation $shuffler) : array
{
if ($this->getShuffle()) {
return $shuffler->shuffle($this->items);
return $shuffler->transform($this->items)->value();
}

return $this->items;
Expand Down Expand Up @@ -334,11 +336,11 @@ public function getBestSolutionIndexes()
}

/**
* @param ilRandomArrayElementProvider $shuffler
* @param Transformation $shuffler
* @param null | array $combinations
* @return string
*/
public function getBestSolutionOutput(ilRandomArrayElementProvider $shuffler, $combinations = null)
public function getBestSolutionOutput(Transformation $shuffler, $combinations = null)
{
global $DIC;
$lng = $DIC['lng'];
Expand Down
9 changes: 8 additions & 1 deletion Modules/TestQuestionPool/classes/class.assClozeTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */

use ILIAS\Refinery\Random\Group as RandomGroup;

require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
require_once './Modules/Test/classes/inc.AssessmentConstants.php';
require_once './Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
Expand Down Expand Up @@ -101,6 +103,8 @@ class assClozeTest extends assQuestion implements ilObjQuestionScoringAdjustable

protected $feedbackMode = ilAssClozeTestFeedback::FB_MODE_GAP_QUESTION;

private RandomGroup $randomGroup;

/**
* assClozeTest constructor
*
Expand All @@ -121,6 +125,8 @@ public function __construct(
$owner = -1,
$question = ""
) {
global $DIC;

parent::__construct($title, $comment, $author, $owner, $question);
$this->start_tag = "[gap]";
$this->end_tag = "[/gap]";
Expand All @@ -130,6 +136,7 @@ public function __construct(
$this->identical_scoring = 1;
$this->gap_combinations_exists = false;
$this->gap_combinations = array();
$this->randomGroup = $DIC->refinery()->random();
}

/**
Expand Down Expand Up @@ -2010,7 +2017,7 @@ public function isAddableAnswerOptionValue(int $qIndex, string $answerOptionValu
return false;
}

foreach ($gap->getItems(new ilDeterministicArrayElementProvider()) as $item) {
foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $item) {
if ($item->getAnswertext() == $answerOptionValue) {
return false;
}
Expand Down
15 changes: 12 additions & 3 deletions Modules/TestQuestionPool/classes/class.assClozeTestGUI.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */

use ILIAS\Refinery\Random\Group as RandomGroup;
use ILIAS\Refinery\Random\RandomSeed;

require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiAnswerScoringAdjustable.php';
Expand Down Expand Up @@ -29,19 +32,25 @@ class assClozeTestGUI extends assQuestionGUI implements ilGuiQuestionScoringAdju
*/
private $gapIndex;

private RandomGroup $randomGroup;

/**
* assClozeTestGUI constructor
*
* @param integer $id The database id of a image map question object
*/
public function __construct($id = -1)
{
global $DIC;

parent::__construct();
include_once "./Modules/TestQuestionPool/classes/class.assClozeTest.php";
$this->object = new assClozeTest();
if ($id >= 0) {
$this->object->loadFromDb($id);
}

$this->randomGroup = $DIC->refinery()->random();
}

public function getCommand($cmd)
Expand Down Expand Up @@ -1432,7 +1441,7 @@ public function getAggregatedAnswersView($relevant_answers)

if ($gap->type == CLOZE_TEXT) {
$present_elements = array();
foreach ($gap->getItems(new ilArrayElementShuffler()) as $item) {
foreach ($gap->getItems($this->randomGroup->shuffleArray(new RandomSeed())) as $item) {
/** @var assAnswerCloze $item */
$present_elements[] = $item->getAnswertext();
}
Expand Down Expand Up @@ -1577,7 +1586,7 @@ protected function getAnswerTextLabel($gapIndex, $answer)

case CLOZE_SELECT:

$items = $gap->getItems(new ilDeterministicArrayElementProvider());
$items = $gap->getItems($this->randomGroup->dontShuffle());
return $items[$answer]->getAnswertext();
}
}
Expand All @@ -1593,7 +1602,7 @@ protected function completeAddAnswerAction($answers, $questionIndex)
foreach ($answers as $key => $ans) {
$found = false;

foreach ($gap->getItems(new ilDeterministicArrayElementProvider()) as $item) {
foreach ($gap->getItems($this->randomGroup->dontShuffle()) as $item) {
if ($ans['answer'] !== $item->getAnswerText()) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ protected function getParticipantsAnswerKeySequence()
$choiceKeys = array_keys($this->object->getAnswers());

if ($this->object->isShuffleAnswersEnabled()) {
$choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
$choiceKeys = $this->object->getShuffler()->transform($choiceKeys)->value();
}

return $choiceKeys;
Expand Down
20 changes: 12 additions & 8 deletions Modules/TestQuestionPool/classes/class.assMatchingQuestion.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */

use ILIAS\Refinery\Random\Group as RandomGroup;
use ILIAS\Refinery\Random\Seed\RandomSeed;

require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
require_once './Modules/Test/classes/inc.AssessmentConstants.php';
require_once './Modules/TestQuestionPool/interfaces/interface.ilObjQuestionScoringAdjustable.php';
Expand Down Expand Up @@ -68,6 +71,8 @@ class assMatchingQuestion extends assQuestion implements ilObjQuestionScoringAdj

protected $matchingMode = self::MATCHING_MODE_1_ON_1;

private RandomGroup $randomGroup;

/**
* assMatchingQuestion constructor
*
Expand All @@ -90,11 +95,14 @@ public function __construct(
$question = "",
$matching_type = MT_TERMS_DEFINITIONS
) {
global $DIC;

parent::__construct($title, $comment, $author, $owner, $question);
$this->matchingpairs = array();
$this->matching_type = $matching_type;
$this->terms = array();
$this->definitions = array();
$this->randomGroup = $DIC->refinery()->random();
}

/**
Expand Down Expand Up @@ -1380,14 +1388,11 @@ public function toJSON() : string
'onenotcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), false)),
'allcorrect' => $this->formatSAQuestion($this->feedbackOBJ->getGenericFeedbackTestPresentation($this->getId(), true))
);

require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
$this->setShuffler(new ilArrayElementShuffler());
$seed = $this->getShuffler()->getSeed();

$this->setShuffler($this->randomGroup->shuffleArray(new RandomSeed()));

$terms = array();
$this->getShuffler()->setSeed($this->getShuffler()->buildSeedFromString($seed . 'terms'));
foreach ($this->getShuffler()->shuffle($this->getTerms()) as $term) {
foreach ($this->getShuffler()->transform($this->getTerms())->value() as $term) {
$terms[] = array(
"text" => $this->formatSAQuestion($term->text),
"id" => (int) $this->getId() . $term->identifier
Expand All @@ -1403,8 +1408,7 @@ public function toJSON() : string
// when the second one (the copy) is answered.

$definitions = array();
$this->getShuffler()->setSeed($this->getShuffler()->buildSeedFromString($seed . 'definitions'));
foreach ($this->getShuffler()->shuffle($this->getDefinitions()) as $def) {
foreach ($this->getShuffler()->transform($this->getDefinitions())->value() as $def) {
$definitions[] = array(
"text" => $this->formatSAQuestion((string) $def->text),
"id" => (int) $this->getId() . $def->identifier
Expand Down
24 changes: 8 additions & 16 deletions Modules/TestQuestionPool/classes/class.assMatchingQuestionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,14 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
$definitions = $this->object->getDefinitions();
switch ($this->object->getShuffle()) {
case 1:
$seed = $this->object->getShuffler()->getSeed();
$this->object->getShuffler()->setSeed($seed . '1');
$terms = $this->object->getShuffler()->shuffle($terms);
$this->object->getShuffler()->setSeed($seed . '2');
$definitions = $this->object->getShuffler()->shuffle($definitions);
$this->object->getShuffler()->setSeed($seed);
$terms = $this->object->getShuffler()->transform($terms)->value();
$definitions = $this->object->getShuffler()->transform($definitions)->value();
break;
case 2:
$terms = $this->object->getShuffler()->shuffle($terms);
$terms = $this->object->getShuffler()->transform($terms)->value();
break;
case 3:
$definitions = $this->object->getShuffler()->shuffle($definitions);
$definitions = $this->object->getShuffler()->transform($definitions)->value();
break;
}

Expand Down Expand Up @@ -828,25 +824,21 @@ public function getTestOutput($active_id, $pass, $is_postponed = false, $user_po
$definitions = $this->object->getDefinitions();
switch ($this->object->getShuffle()) {
case 1:
$seed = $this->object->getShuffler()->getSeed();
$this->object->getShuffler()->setSeed($seed . '1');
$terms = $this->object->getShuffler()->shuffle($terms);
$terms = $this->object->getShuffler()->transform($terms)->value();
if (count($solutions)) {
$definitions = $this->sortDefinitionsBySolution($solutions, $definitions);
} else {
$this->object->getShuffler()->setSeed($seed . '2');
$definitions = $this->object->getShuffler()->shuffle($definitions);
$definitions = $this->object->getShuffler()->transform($definitions)->value();
}
$this->object->getShuffler()->setSeed($seed);
break;
case 2:
$terms = $this->object->getShuffler()->shuffle($terms);
$terms = $this->object->getShuffler()->transform($terms)->value();
break;
case 3:
if (count($solutions)) {
$definitions = $this->sortDefinitionsBySolution($solutions, $definitions);
} else {
$definitions = $this->object->getShuffler()->shuffle($definitions);
$definitions = $this->object->getShuffler()->transform($definitions)->value();
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ public function getChoiceKeys()
$choiceKeys = array_keys($this->object->answers);

if ($this->object->getShuffle()) {
$choiceKeys = $this->object->getShuffler()->shuffle($choiceKeys);
$choiceKeys = $this->object->getShuffler()->transform($choiceKeys)->value();
}

return $choiceKeys;
Expand Down
Loading