ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestToplistGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
30  public function __construct(
31  private ilObjTest $test_obj,
32  private ilTestTopList $toplist,
33  private ilCtrl $ctrl,
34  private ilGlobalTemplateInterface $tpl,
35  private ilLanguage $lng,
36  private ilObjUser $user,
37  private UIFactory $ui_factory,
38  private UIRenderer $ui_renderer
39  ) {
40  }
41 
45  public function executeCommand(): void
46  {
47  if (!$this->test_obj->getHighscoreEnabled()) {
48  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
49  $this->ctrl->redirectByClass(ilObjTestGUI::class);
50  }
51 
52  $this->ctrl->saveParameter($this, 'active_id');
53 
54  $cmd = $this->ctrl->getCmd();
55 
56  switch ($cmd) {
57  default:
58  $this->showResultsToplistsCmd();
59  }
60  }
61 
62  protected function showResultsToplistsCmd(): void
63  {
64  $this->tpl->setContent(implode('', [
65  $this->renderMedianMarkPanel(),
68  ]));
69  }
70 
74  protected function renderMedianMarkPanel(): string
75  {
76  $title = $this->lng->txt('tst_median_mark_panel');
77 
78  // BH: this really is the "mark of median" ??!
79  $activeId = $this->test_obj->getActiveIdOfUser($this->user->getId());
80  $data = $this->test_obj->getCompleteEvaluationData();
81  $median = $data->getStatistics()->getStatistics()->median();
82  $pct = $data->getParticipant($activeId)->getMaxpoints() ? ($median / $data->getParticipant($activeId)->getMaxpoints()) * 100.0 : 0;
83  $mark = $this->test_obj->getMarkSchema()->getMatchingMark($pct);
84  $content = $mark->getShortName();
85 
86  $panel = $this->ui_factory->panel()->standard(
87  $title,
88  $this->ui_factory->legacy($content)
89  );
90 
91  return $this->ui_renderer->render($panel);
92  }
93 
97  protected function renderResultsToplistByScore(): string
98  {
99  $title = $this->lng->txt('toplist_by_score');
100  $html = '';
101 
102  if ($this->isTopTenRankingTableRequired()) {
103  $topData = $this->toplist->getGeneralToplistByPercentage(
104  $this->test_obj->getRefId(),
105  (int) $this->user->getId()
106  );
107 
108  $table = $this->buildTableGUI();
109  $table->setData($topData);
110  $table->setTitle($title);
111 
112  $html .= $table->getHTML();
113  }
114 
115  if ($this->isOwnRankingTableRequired()) {
116  $ownData = $this->toplist->getUserToplistByPercentage(
117  $this->test_obj->getRefId(),
118  (int) $this->user->getId()
119  );
120 
121  $table = $this->buildTableGUI();
122  $table->setData($ownData);
123  if (!$this->isTopTenRankingTableRequired()) {
124  $table->setTitle($title);
125  }
126 
127  $html .= $table->getHTML();
128  }
129 
130  return $html;
131  }
132 
136  protected function renderResultsToplistByTime(): string
137  {
138  $title = $this->lng->txt('toplist_by_time');
139  $html = '';
140 
141  if ($this->isTopTenRankingTableRequired()) {
142  $topData = $this->toplist->getGeneralToplistByWorkingtime(
143  $this->test_obj->getRefId(),
144  $this->user->getId()
145  );
146 
147  $table = $this->buildTableGUI();
148  $table->setData($topData);
149  $table->setTitle($title);
150 
151  $html .= $table->getHTML();
152  }
153 
154  if ($this->isOwnRankingTableRequired()) {
155  $ownData = $this->toplist->getUserToplistByWorkingtime(
156  $this->test_obj->getRefId(),
157  (int) $this->user->getId()
158  );
159 
160  $table = $this->buildTableGUI();
161  $table->setData($ownData);
162 
163  if (!$this->isTopTenRankingTableRequired()) {
164  $table->setTitle($title);
165  }
166 
167  $html .= $table->getHTML();
168  }
169 
170  return $html;
171  }
172 
176  protected function buildTableGUI(): ilTestTopListTableGUI
177  {
178  $table = new ilTestTopListTableGUI($this, $this->test_obj);
179 
180  return $table;
181  }
182 
186  protected function isTopTenRankingTableRequired(): bool
187  {
188  return $this->test_obj->getHighscoreTopTable();
189  }
190 
194  protected function isOwnRankingTableRequired(): bool
195  {
196  return $this->test_obj->getHighscoreOwnTable();
197  }
198 }
__construct(private ilObjTest $test_obj, private ilTestTopList $toplist, private ilCtrl $ctrl, private ilGlobalTemplateInterface $tpl, private ilLanguage $lng, private ilObjUser $user, private UIFactory $ui_factory, private UIRenderer $ui_renderer)
$lng
Class ilTestTopListTableGUI.