Skip to content

Commit

Permalink
TA: PresentationTable for results, separate Result-/PresentationFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Oct 18, 2023
1 parent 953532c commit 67fa414
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@
* @package Modules/Test
* Results for one user and pass
*/
class ilTestResult
class ilTestPassResult
{
/**
* @param ilQuestionResult[] $question_results
*/
public function __construct(
protected ilTestPassResultsSettings $settings,
protected int $active_id,
protected int $pass_id,
protected array $question_results
) {
}

public function getSettings(): ilTestPassResultsSettings
{
return $this->settings;
}

public function getActiveId(): int
{
return $this->active_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @package Modules/Test
* Environment/settings to control result presentation
*/
class ilTestResultsSettings
class ilTestPassResultsSettings
{
protected bool $show_hidden_questions = false;
protected bool $show_optional_questions = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

/**
* @package Modules/Test
* Results Overview Table
* Table Presentation of Pass Results
*/
class ilTestResultsOverviewTable
class ilTestPassResultsTable
{
private const ENV = 'e';
private const LNG = 'l';
Expand All @@ -47,14 +47,11 @@ public function __construct(
protected ILIAS\HTTP\Services $http,
ILIAS\Data\Factory $data_factory,
ilLanguage $lng,
string $title,
ilTestResult $test_results,
ilTestResultsSettings $environment
ilTestPassResult $test_results,
string $title
) {
list($mode, $sortation) = $this->getViewControlsParameter();

$results = $this->applyControls($mode, $sortation, $test_results->getQuestionResults());

$target = new URLBuilder($data_factory->uri($http->request()->getUri()->__toString()));

$this->table = $ui_factory->table()->presentation(
Expand All @@ -63,7 +60,7 @@ public function __construct(
$this->getMapping()
)
->withEnvironment([
self::ENV => $environment,
self::ENV => $test_results->getSettings(),
self::LNG => $lng
])
->withData($results);
Expand Down
102 changes: 43 additions & 59 deletions Modules/Test/classes/Results/class.ilTestResultsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,47 @@

/**
* @package Modules/Test
* Results for one user and pass
* Results (currently, for one user and pass)
*/
class ilTestResultsFactory
{
protected ilObjTest $test_obj;
protected int $active_id;
protected int $pass_id;
protected bool $is_user_output = true;

/**
* @param ilQuestionResult[] $question_results
*/
public function __construct(
protected ilTestShuffler $shuffler,
protected ILIAS\UI\Factory $ui_factory,
protected ILIAS\UI\Renderer $ui_renderer,
protected ILIAS\Refinery\Factory $refinery,
protected ILIAS\Data\Factory $data_factory,
protected ILIAS\HTTP\Services $http,
protected ilLanguage $lng
protected ILIAS\UI\Renderer $ui_renderer
) {
}
public function for(
public function getPassResultsFor(
ilObjTest $test_obj,
int $active_id,
int $pass_id,
bool $is_user_output = true
): self {
$clone = clone $this;
$clone->test_obj = $test_obj;
$clone->active_id = $active_id;
$clone->pass_id = $pass_id;
$clone->is_user_output = $is_user_output;
return $clone;
): ilTestPassResult {
$settings = $this->getPassResultsSettings($test_obj, $is_user_output);
return $this->buildPassResults(
$settings,
$test_obj,
$active_id,
$pass_id,
$is_user_output
);
}

protected function getResults(): ilTestResult
{
$settings = $this->getResultsSettings();
protected function buildPassResults(
ilTestPassResultsSettings $settings,
ilObjTest $test_obj,
int $active_id,
int $pass_id,
bool $is_user_output
): ilTestPassResult {
$question_results = [];

$results = $this->test_obj->getTestResult(
$this->active_id,
$this->pass_id,
$results = $test_obj->getTestResult(
$active_id,
$pass_id,
false, //$ordered_sequence
$settings->getShowHiddenQuestions(),
$settings->getShowOptionalQuestions()
Expand All @@ -80,7 +77,7 @@ protected function getResults(): ilTestResult
$show_inline_feedback = true;

foreach ($results as $idx => $qresult) {
if (! is_numeric($idx)) {
if (!is_numeric($idx)) {
continue;
}

Expand All @@ -92,16 +89,16 @@ protected function getResults(): ilTestResult
$workedthrough = (bool)$qresult['workedthrough'];
$answered = (bool)$qresult['answered'];

$question_gui = $this->test_obj->createQuestionGUI("", $qid);
$shuffle_trafo = $this->shuffler->getAnswerShuffleFor($qid, $this->active_id, $this->pass_id);
$question_gui = $test_obj->createQuestionGUI("", $qid);
$shuffle_trafo = $this->shuffler->getAnswerShuffleFor($qid, $active_id, $pass_id);
$question_gui->object->setShuffler($shuffle_trafo);

$graphical_output = true;
$show_correct_solution = false;
$show_inline_feedback = $settings->getShowFeedback();
$usr_solution = $question_gui->getSolutionOutput(
$this->active_id,
$this->pass_id,
$active_id,
$pass_id,
$graphical_output,
$result_output,
$show_question_only,
Expand All @@ -116,8 +113,8 @@ protected function getResults(): ilTestResult
$show_correct_solution = true;
$show_inline_feedback = false;
$best_solution = $question_gui->getSolutionOutput(
$this->active_id,
$this->pass_id,
$active_id,
$pass_id,
$graphical_output,
$result_output,
$show_question_only,
Expand All @@ -133,10 +130,10 @@ protected function getResults(): ilTestResult
$best_solution = $this->ui_renderer->render($this->ui_factory->legacy('<div class="ilc_question_Standard">' . $best_solution . '</div>'));
}

$feedback = $question_gui->getGenericFeedbackOutput($this->active_id, $this->pass_id);
$feedback = $question_gui->getGenericFeedbackOutput($active_id, $pass_id);

$recapitulation = null;
if ($this->is_user_output && $settings->getShowRecapitulation()) {
if ($is_user_output && $settings->getShowRecapitulation()) {
$recapitulation = $question_gui->object->getSuggestedSolutionOutput();
}

Expand All @@ -155,46 +152,33 @@ protected function getResults(): ilTestResult
);
}

return new ilTestResult(
$this->active_id,
$this->pass_id,
return new ilTestPassResult(
$settings,
$active_id,
$pass_id,
$question_results
);
}

protected function getResultsSettings(): ilTestResultsSettings
{
$settings = $this->test_obj->getScoreSettings();
protected function getPassResultsSettings(
ilObjTest $test_obj,
bool $is_user_output
): ilTestPassResultsSettings {
$settings = $test_obj->getScoreSettings();
$settings_summary = $settings->getResultSummarySettings();
$settings_result = $settings->getResultDetailsSettings();
$show_best_solution = $this->is_user_output ?
$show_best_solution = $is_user_output ?
$settings_result->getShowSolutionListComparison() :
(bool)ilSession::get('tst_results_show_best_solutions');

$environment = (new ilTestResultsSettings())
$pass_result_settings = (new ilTestPassResultsSettings())
->withShowHiddenQuestions(false)
->withShowOptionalQuestions(true)
->withShowBestSolution($show_best_solution)
->withShowFeedback($settings_result->getShowSolutionFeedback())
->withQuestionTextOnly($settings_result->getShowSolutionAnswersOnly())
->withShowRecapitulation($settings_result->getShowSolutionSuggested())
;

return $environment;
}

public function getTable(string $title = ''): ilTestResultsOverviewTable
{
return new ilTestResultsOverviewTable(
$this->ui_factory,
$this->ui_renderer,
$this->refinery,
$this->http,
$this->data_factory,
$this->lng,
$title,
$this->getResults(),
$this->getResultsSettings()
);
return $pass_result_settings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

/**
* @package Modules/Test
* Results for one user and pass in a Presentation Table
*/
class ilTestResultsPresentationFactory
{
public function __construct(
protected ILIAS\UI\Factory $ui_factory,
protected ILIAS\UI\Renderer $ui_renderer,
protected ILIAS\Refinery\Factory $refinery,
protected ILIAS\Data\Factory $data_factory,
protected ILIAS\HTTP\Services $http,
protected ilLanguage $lng
) {
}

public function getPassResultsPresentationTable(
ilTestPassResult $pass_results,
string $title = ''
): ilTestPassResultsTable {
return new ilTestPassResultsTable(
$this->ui_factory,
$this->ui_renderer,
$this->refinery,
$this->http,
$this->data_factory,
$this->lng,
$pass_results,
$title
);
}
}
19 changes: 14 additions & 5 deletions Modules/Test/classes/class.ilTestDIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,26 @@ protected static function buildDIC(): Container
new ilTestResultsFactory(
$c['shuffler'],
$dic['ui.factory'],
$dic['ui.renderer'],
$dic['refinery'],
new ILIAS\Data\Factory(),
$dic['http'],
$dic['lng']
$dic['ui.renderer']
);

$dic['factory.results_presentation'] = static fn($c): ilTestResultsPresentationFactory =>
new ilTestResultsPresentationFactory(
$dic['ui.factory'],
$dic['ui.renderer'],
$dic['refinery'],
new ILIAS\Data\Factory(),
$dic['http'],
$dic['lng']
);


$dic['participantAccessFilterFactory'] = static fn($c): ilTestParticipantAccessFilterFactory =>
new ilTestParticipantAccessFilterFactory($dic['ilAccess']);

$dic['manScoringDoneHelper'] = static fn($c): TestManScoringDoneHelper =>
new TestManScoringDoneHelper();

$dic['request.internal'] = static fn($c): InternalRequestService =>
new InternalRequestService($dic['http'], $dic['refinery']);

Expand Down
26 changes: 22 additions & 4 deletions Modules/Test/classes/class.ilTestEvaluationGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,17 @@ public function outParticipantsPassDetails()
ilObjUser::_lookupFullname($this->object->_getUserIdFromActiveId($active_id))
);

$results = $this->results_factory->for($this->object, $active_id, $pass, false);
$pass_results = $this->results_factory->getPassResultsFor(
$this->object,
$active_id,
$pass,
false
);

$table = $results->getTable($title);
$table = $this->results_presentation_factory->getPassResultsPresentationTable(
$pass_results,
$title
);

$this->tpl->addCss(ilObjStyleSheet::getContentStylePath(0));

Expand Down Expand Up @@ -1168,8 +1176,18 @@ public function outUserPassDetails(): void
$pass + 1,
ilObjUser::_lookupFullname($this->object->_getUserIdFromActiveId($active_id))
);
$results = $this->results_factory->for($this->object, $active_id, $pass, true);
$table = $results->getTable($title);

$pass_results = $this->results_factory->getPassResultsFor(
$this->object,
$active_id,
$pass,
true
);

$table = $this->results_presentation_factory->getPassResultsPresentationTable(
$pass_results,
$title
);

$tpl->setVariable("LIST_OF_ANSWERS", $table->render());

Expand Down
1 change: 1 addition & 0 deletions Modules/Test/classes/class.ilTestServiceGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public function __construct(
$this->participant_access_filter = $local_dic['participantAccessFilterFactory'];
$this->shuffler = $local_dic['shuffler'];
$this->results_factory = $local_dic['factory.results'];
$this->results_presentation_factory = $local_dic['factory.results_presentation'];
}

public function setParticipantData(ilTestParticipantData $participantData): void
Expand Down
Loading

0 comments on commit 67fa414

Please sign in to comment.