ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTestToplistGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6use Psr\Http\Message\ServerRequestInterface;
7
13{
15 protected $ctrl;
17 protected $tabs;
19 protected $tpl;
21 protected $lng;
23 protected $user;
25 protected $object;
27 protected $toplist;
29 private $uiFactory;
31 private $uiRenderer;
32
36 public function __construct(ilObjTest $testOBJ)
37 {
38 global $DIC;
39 /* @var ILIAS\DI\Container $DIC */
40
41 $this->ctrl = $DIC['ilCtrl'];
42 $this->tpl = $DIC['tpl'];
43 $this->lng = $DIC['lng'];
44 $this->user = $DIC['ilUser'];
45 $this->uiFactory = $DIC->ui()->factory();
46 $this->uiRenderer = $DIC->ui()->renderer();
47
48 $this->object = $testOBJ;
49 $this->toplist = new ilTestTopList($testOBJ);
50 }
51
55 public function executeCommand() : void
56 {
57 if (!$this->object->getHighscoreEnabled()) {
58 ilUtil::sendFailure($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(implode('', [
75 $this->renderMedianMarkPanel(),
78 ]));
79 }
80
84 protected function renderMedianMarkPanel() : string
85 {
86 $title = $this->lng->txt('tst_median_mark_panel');
87
88 // BH: this really is the "mark of median" ??!
89 $activeId = $this->object->getActiveIdOfUser($this->user->getId());
90 $data = $this->object->getCompleteEvaluationData();
91 $median = $data->getStatistics()->getStatistics()->median();
92 $pct = $data->getParticipant($activeId)->getMaxpoints() ? ($median / $data->getParticipant($activeId)->getMaxpoints()) * 100.0 : 0;
93 $mark = $this->object->mark_schema->getMatchingMark($pct);
94 $content = $mark->getShortName();
95
96 $panel = $this->uiFactory->panel()->standard(
97 $title,
98 $this->uiFactory->legacy($content)
99 );
100
101 return $this->uiRenderer->render($panel);
102 }
103
107 protected function renderResultsToplistByScore() : string
108 {
109 $title = $this->lng->txt('toplist_by_score');
110 $html = '';
111
112 if ($this->isTopTenRankingTableRequired()) {
113 $topData = $this->toplist->getGeneralToplistByPercentage(
114 (int) $this->object->getRefId(),
115 (int) $this->user->getId()
116 );
117
118 $table = $this->buildTableGUI();
119 $table->setData($topData);
120 $table->setTitle($title);
121
122 $html .= $table->getHTML();
123 }
124
125 if ($this->isOwnRankingTableRequired()) {
126 $ownData = $this->toplist->getUserToplistByPercentage(
127 (int) $this->object->getRefId(),
128 (int) $this->user->getId()
129 );
130
131 $table = $this->buildTableGUI();
132 $table->setData($ownData);
133 if (!$this->isTopTenRankingTableRequired()) {
134 $table->setTitle($title);
135 }
136
137 $html .= $table->getHTML();
138 }
139
140 return $html;
141 }
142
146 protected function renderResultsToplistByTime() : string
147 {
148 $title = $this->lng->txt('toplist_by_time');
149 $html = '';
150
151 if ($this->isTopTenRankingTableRequired()) {
152 $topData = $this->toplist->getGeneralToplistByWorkingtime(
153 $this->object->getRefId(),
154 $this->user->getId()
155 );
156
157 $table = $this->buildTableGUI();
158 $table->setData($topData);
159 $table->setTitle($title);
160
161 $html .= $table->getHTML();
162 }
163
164 if ($this->isOwnRankingTableRequired()) {
165 $ownData = $this->toplist->getUserToplistByWorkingtime(
166 (int) $this->object->getRefId(),
167 (int) $this->user->getId()
168 );
169
170 $table = $this->buildTableGUI();
171 $table->setData($ownData);
172
173 if (!$this->isTopTenRankingTableRequired()) {
174 $table->setTitle($title);
175 }
176
177 $html .= $table->getHTML();
178 }
179
180 return $html;
181 }
182
187 {
188 $table = new ilTestTopListTableGUI($this, $this->object);
189
190 return $table;
191 }
192
196 protected function isTopTenRankingTableRequired() : bool
197 {
198 if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_TOP_TABLE) {
199 return true;
200 }
201
202 if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_ALL_TABLES) {
203 return true;
204 }
205
206 return false;
207 }
208
212 protected function isOwnRankingTableRequired() : bool
213 {
214 if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_OWN_TABLE) {
215 return true;
216 }
217
218 if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_ALL_TABLES) {
219 return true;
220 }
221
222 return false;
223 }
224}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const HIGHSCORE_SHOW_ALL_TABLES
const HIGHSCORE_SHOW_OWN_TABLE
const HIGHSCORE_SHOW_TOP_TABLE
Class ilTestTopListTableGUI.
Class ilTestTopList.
__construct(ilObjTest $testOBJ)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46