Skip to content

Commit

Permalink
refactor: ilTestTopList by using the DataTable component instead of i…
Browse files Browse the repository at this point in the history
…lTable2GUI inheritance
  • Loading branch information
lukas-heinrich authored and kergomard committed Oct 24, 2024
1 parent 0d649ea commit c70732f
Show file tree
Hide file tree
Showing 11 changed files with 463 additions and 462 deletions.
104 changes: 0 additions & 104 deletions components/ILIAS/Test/classes/Tables/class.ilTestTopListTableGUI.php

This file was deleted.

11 changes: 7 additions & 4 deletions components/ILIAS/Test/classes/class.ilTestResultsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use ILIAS\Test\Logging\TestLogger;
use ILIAS\Test\Settings\ScoreReporting\SettingsResultSummary;
use ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository;

use ILIAS\Test\Results\Toplist\TestTopListRepository;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;
use ILIAS\Refinery\Factory as Refinery;
Expand Down Expand Up @@ -74,7 +74,8 @@ public function __construct(
private readonly SkillService $skills_service,
private readonly GeneralQuestionPropertiesRepository $questionrepository,
private readonly RequestDataCollector $testrequest,
private readonly GlobalHttpState $http
private readonly GlobalHttpState $http,
private readonly DataFactory $data_factory = new DataFactory()
) {
}

Expand Down Expand Up @@ -242,13 +243,15 @@ public function executeCommand(): void

$gui = new ilTestToplistGUI(
$this->getTestObj(),
new ilTestTopList($this->getTestObj(), $this->db),
new TestTopListRepository($this->getTestObj(), $this->db),
$this->ctrl,
$this->main_tpl,
$this->lng,
$this->user,
$this->ui_factory,
$this->ui_renderer
$this->ui_renderer,
$this->data_factory,
$this->http
);
$this->ctrl->forwardCommand($gui);
break;
Expand Down
152 changes: 53 additions & 99 deletions components/ILIAS/Test/classes/class.ilTestToplistGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

declare(strict_types=1);

use ILIAS\Test\Results\Toplist\TestTopListRepository;
use ILIAS\Test\Results\Toplist\DataRetrieval;
use ILIAS\Test\Results\Toplist\TopListOrder;
use ILIAS\Test\Results\Toplist\TopListType;
use ILIAS\Data\Factory as DataFactory;
use ILIAS\UI\Component\Panel\Panel;
use ILIAS\UI\Component\Table\Data;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;
use ILIAS\HTTP\GlobalHttpState as GlobalHttpState;

/**
* @author Maximilian Becker <[email protected]>
Expand All @@ -28,14 +36,16 @@
class ilTestToplistGUI
{
public function __construct(
private ilObjTest $test_obj,
private ilTestTopList $toplist,
private ilCtrlInterface $ctrl,
private ilGlobalTemplateInterface $tpl,
private ilLanguage $lng,
private ilObjUser $user,
private UIFactory $ui_factory,
private UIRenderer $ui_renderer
protected readonly ilObjTest $test_obj,
protected readonly TestTopListRepository $repository,
protected readonly ilCtrlInterface $ctrl,
protected readonly ilGlobalTemplateInterface $tpl,
protected readonly ilLanguage $lng,
protected readonly ilObjUser $user,
protected readonly UIFactory $ui_factory,
protected readonly UIRenderer $ui_renderer,
protected readonly DataFactory $data_factory,
protected readonly GlobalHttpState $http_state
) {
}

Expand All @@ -61,17 +71,14 @@ public function executeCommand(): void

protected function showResultsToplistsCmd(): void
{
$this->tpl->setContent(implode('', [
$this->renderMedianMarkPanel(),
$this->renderResultsToplistByScore(),
$this->renderResultsToplistByTime(),
$this->tpl->setContent($this->ui_renderer->render([
$this->buildMedianMarkPanel(),
...$this->buildResultsToplists(TopListOrder::BY_SCORE),
...$this->buildResultsToplists(TopListOrder::BY_TIME),
]));
}

/**
* @return string
*/
protected function renderMedianMarkPanel(): string
protected function buildMedianMarkPanel(): Panel
{
$title = $this->lng->txt('tst_median_mark_panel');

Expand All @@ -83,114 +90,61 @@ protected function renderMedianMarkPanel(): string
$mark = $this->test_obj->getMarkSchema()->getMatchingMark($pct);
$content = $mark->getShortName();

$panel = $this->ui_factory->panel()->standard(
return $this->ui_factory->panel()->standard(
$title,
$this->ui_factory->legacy($content)
);

return $this->ui_renderer->render($panel);
}

/**
* @return string
*/
protected function renderResultsToplistByScore(): string
{
$title = $this->lng->txt('toplist_by_score');
$html = '';

if ($this->isTopTenRankingTableRequired()) {
$topData = $this->toplist->getGeneralToplistByPercentage(
$this->test_obj->getRefId(),
(int) $this->user->getId()
);

$table = $this->buildTableGUI();
$table->setData($topData);
$table->setTitle($title);

$html .= $table->getHTML();
}

if ($this->isOwnRankingTableRequired()) {
$ownData = $this->toplist->getUserToplistByPercentage(
$this->test_obj->getRefId(),
(int) $this->user->getId()
);

$table = $this->buildTableGUI();
$table->setData($ownData);
if (!$this->isTopTenRankingTableRequired()) {
$table->setTitle($title);
}

$html .= $table->getHTML();
}

return $html;
}

/**
* @return string
* @return array<Data>
*/
protected function renderResultsToplistByTime(): string
protected function buildResultsToplists(TopListOrder $order_by): array
{
$title = $this->lng->txt('toplist_by_time');
$html = '';
$tables = [];

if ($this->isTopTenRankingTableRequired()) {
$topData = $this->toplist->getGeneralToplistByWorkingtime(
$this->test_obj->getRefId(),
$this->user->getId()
);

$table = $this->buildTableGUI();
$table->setData($topData);
$table->setTitle($title);

$html .= $table->getHTML();
$tables[] = $this->buildTable(
$this->lng->txt('toplist_by_' . $order_by->getLabel()),
TopListType::GENERAL,
$order_by
)->withId('tst_top_list' . $this->test_obj->getRefId());
}

if ($this->isOwnRankingTableRequired()) {
$ownData = $this->toplist->getUserToplistByWorkingtime(
$this->test_obj->getRefId(),
(int) $this->user->getId()
);

$table = $this->buildTableGUI();
$table->setData($ownData);

if (!$this->isTopTenRankingTableRequired()) {
$table->setTitle($title);
}

$html .= $table->getHTML();
$tables[] = $this->buildTable(
count($tables) == 0 ? $this->lng->txt('toplist_by_score' . $order_by->getLabel()) : '',
TopListType::USER,
$order_by
)->withId('tst_own_list' . $this->test_obj->getRefId());
}

return $html;
return $tables;
}

/**
* @return ilTestTopListTableGUI
*/
protected function buildTableGUI(): ilTestTopListTableGUI
protected function buildTable(string $title, TopListType $list_type, TopListOrder $order_by): Data
{
$table = new ilTestTopListTableGUI($this, $this->test_obj);

return $table;
$table = new DataRetrieval(
$this->test_obj,
$this->repository,
$this->lng,
$this->user,
$this->ui_factory,
$this->ui_renderer,
$this->data_factory,
$list_type,
$order_by
);
return $this->ui_factory->table()
->data($title, $table->getColumns(), $table)
->withRequest($this->http_state->request());
}

/**
* @return bool
*/
protected function isTopTenRankingTableRequired(): bool
{
return $this->test_obj->getHighscoreTopTable();
}

/**
* @return bool
*/
protected function isOwnRankingTableRequired(): bool
{
return $this->test_obj->getHighscoreOwnTable();
Expand Down
Loading

0 comments on commit c70732f

Please sign in to comment.