ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilTestToplistGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\Data\Factory as DataFactory;
29use ILIAS\UI\Factory as UIFactory;
30use ILIAS\UI\Renderer as UIRenderer;
31use ILIAS\HTTP\GlobalHttpState as GlobalHttpState;
32
38{
39 public function __construct(
40 protected readonly ilObjTest $test_obj,
41 protected readonly TestTopListRepository $repository,
42 protected readonly ilCtrlInterface $ctrl,
43 protected readonly ilGlobalTemplateInterface $tpl,
44 protected readonly ilLanguage $lng,
45 protected readonly ilObjUser $user,
46 protected readonly UIFactory $ui_factory,
47 protected readonly UIRenderer $ui_renderer,
48 protected readonly DataFactory $data_factory,
49 protected readonly GlobalHttpState $http_state,
50 protected readonly ParticipantRepository $participant_repository
51 ) {
52 }
53
57 public function executeCommand(): void
58 {
59 if (!$this->test_obj->getHighscoreEnabled()) {
60 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
61 $this->ctrl->redirectByClass(ilObjTestGUI::class);
62 }
63
64 $this->ctrl->saveParameter($this, 'active_id');
65
66 $cmd = $this->ctrl->getCmd();
67
68 switch ($cmd) {
69 default:
71 }
72 }
73
74 protected function showResultsToplistsCmd(): void
75 {
76 $this->tpl->setContent($this->ui_renderer->render([
77 $this->buildMedianMarkPanel(),
78 ...$this->buildResultsToplists(TopListOrder::BY_SCORE),
79 ...$this->buildResultsToplists(TopListOrder::BY_TIME),
80 ]));
81 }
82
83 protected function buildMedianMarkPanel(): Panel
84 {
85 $title = $this->lng->txt('tst_median_mark_panel');
86
87 // BH: this really is the "mark of median" ??!
88 $activeId = $this->test_obj->getActiveIdOfUser($this->user->getId());
89 $data = $this->test_obj->getCompleteEvaluationData();
90 $median = $data->getStatistics()->median();
91 $pct = $data->getParticipant($activeId)->getMaxpoints() ? ($median / $data->getParticipant($activeId)->getMaxpoints()) * 100.0 : 0;
92 $mark = $this->test_obj->getMarkSchema()->getMatchingMark($pct);
93 $content = $mark->getShortName();
94
95 return $this->ui_factory->panel()->standard(
96 $title,
97 $this->ui_factory->legacy()->content($content)
98 );
99 }
100
104 protected function buildResultsToplists(TopListOrder $order_by): array
105 {
106 $tables = [];
107
108 if ($this->isTopTenRankingTableRequired()) {
109 $tables[] = $this->buildTable(
110 $this->lng->txt('toplist_by_' . $order_by->getLabel()),
111 TopListType::GENERAL,
112 $order_by
113 )->withId('tst_top_list' . $this->test_obj->getRefId());
114 }
115
116 if ($this->isOwnRankingTableRequired()) {
117 $tables[] = $this->buildTable(
118 count($tables) == 0 ? $this->lng->txt('toplist_by_' . $order_by->getLabel()) : '',
120 $order_by
121 )->withId('tst_own_list' . $this->test_obj->getRefId());
122 }
123
124 return $tables;
125 }
126
127 protected function buildTable(string $title, TopListType $list_type, TopListOrder $order_by): Data
128 {
129 $table = new DataRetrieval(
130 $this->test_obj,
131 $this->repository,
132 $this->lng,
133 $this->user,
134 $this->ui_factory,
135 $this->ui_renderer,
136 $this->data_factory,
137 $list_type,
138 $order_by,
139 $this->participant_repository
140 );
141 return $this->ui_factory->table()
142 ->data($table, $title, $table->getColumns())
143 ->withRequest($this->http_state->request());
144 }
145
146 protected function isTopTenRankingTableRequired(): bool
147 {
148 return $this->test_obj->getHighscoreTopTable();
149 }
150
151 protected function isOwnRankingTableRequired(): bool
152 {
153 return $this->test_obj->getHighscoreOwnTable();
154 }
155}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
language handling
User class.
buildResultsToplists(TopListOrder $order_by)
buildTable(string $title, TopListType $list_type, TopListOrder $order_by)
__construct(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, protected readonly ParticipantRepository $participant_repository)
Interface GlobalHttpState.
This describes how a panel could be modified during construction of UI.
Definition: Panel.php:31
This describes a Data Table.
Definition: Data.php:33
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31