ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestToplistGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\Data\Factory as DataFactory;
28use ILIAS\UI\Factory as UIFactory;
29use ILIAS\UI\Renderer as UIRenderer;
30use ILIAS\HTTP\GlobalHttpState as GlobalHttpState;
31
37{
38 public function __construct(
39 protected readonly ilObjTest $test_obj,
40 protected readonly TestTopListRepository $repository,
41 protected readonly ilCtrlInterface $ctrl,
42 protected readonly ilGlobalTemplateInterface $tpl,
43 protected readonly ilLanguage $lng,
44 protected readonly ilObjUser $user,
45 protected readonly UIFactory $ui_factory,
46 protected readonly UIRenderer $ui_renderer,
47 protected readonly DataFactory $data_factory,
48 protected readonly GlobalHttpState $http_state
49 ) {
50 }
51
55 public function executeCommand(): void
56 {
57 if (!$this->test_obj->getHighscoreEnabled()) {
58 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
59 $this->ctrl->redirectByClass(ilObjTestGUI::class);
60 }
61
62 $this->ctrl->saveParameter($this, 'active_id');
63
64 $cmd = $this->ctrl->getCmd();
65
66 switch ($cmd) {
67 default:
69 }
70 }
71
72 protected function showResultsToplistsCmd(): void
73 {
74 $this->tpl->setContent($this->ui_renderer->render([
75 $this->buildMedianMarkPanel(),
76 ...$this->buildResultsToplists(TopListOrder::BY_SCORE),
77 ...$this->buildResultsToplists(TopListOrder::BY_TIME),
78 ]));
79 }
80
81 protected function buildMedianMarkPanel(): Panel
82 {
83 $title = $this->lng->txt('tst_median_mark_panel');
84
85 // BH: this really is the "mark of median" ??!
86 $activeId = $this->test_obj->getActiveIdOfUser($this->user->getId());
87 $data = $this->test_obj->getCompleteEvaluationData();
88 $median = $data->getStatistics()->median();
89 $pct = $data->getParticipant($activeId)->getMaxpoints() ? ($median / $data->getParticipant($activeId)->getMaxpoints()) * 100.0 : 0;
90 $mark = $this->test_obj->getMarkSchema()->getMatchingMark($pct);
91 $content = $mark->getShortName();
92
93 return $this->ui_factory->panel()->standard(
94 $title,
95 $this->ui_factory->legacy()->content($content)
96 );
97 }
98
102 protected function buildResultsToplists(TopListOrder $order_by): array
103 {
104 $tables = [];
105
106 if ($this->isTopTenRankingTableRequired()) {
107 $tables[] = $this->buildTable(
108 $this->lng->txt('toplist_by_' . $order_by->getLabel()),
109 TopListType::GENERAL,
110 $order_by
111 )->withId('tst_top_list' . $this->test_obj->getRefId());
112 }
113
114 if ($this->isOwnRankingTableRequired()) {
115 $tables[] = $this->buildTable(
116 count($tables) == 0 ? $this->lng->txt('toplist_by_' . $order_by->getLabel()) : '',
118 $order_by
119 )->withId('tst_own_list' . $this->test_obj->getRefId());
120 }
121
122 return $tables;
123 }
124
125 protected function buildTable(string $title, TopListType $list_type, TopListOrder $order_by): Data
126 {
127 $table = new DataRetrieval(
128 $this->test_obj,
129 $this->repository,
130 $this->lng,
131 $this->user,
132 $this->ui_factory,
133 $this->ui_renderer,
134 $this->data_factory,
135 $list_type,
136 $order_by
137 );
138 return $this->ui_factory->table()
139 ->data($table, $title, $table->getColumns())
140 ->withRequest($this->http_state->request());
141 }
142
143 protected function isTopTenRankingTableRequired(): bool
144 {
145 return $this->test_obj->getHighscoreTopTable();
146 }
147
148 protected function isOwnRankingTableRequired(): bool
149 {
150 return $this->test_obj->getHighscoreOwnTable();
151 }
152}
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)
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:31
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