ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestToplistGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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:
68  $this->showResultsToplistsCmd();
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_score' . $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 }
This describes how a panel could be modified during construction of UI.
Definition: Panel.php:30
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
__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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildResultsToplists(TopListOrder $order_by)
global $lng
Definition: privfeed.php:31
buildTable(string $title, TopListType $list_type, TopListOrder $order_by)