ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once 'Modules/Test/classes/inc.AssessmentConstants.php';
5 require_once 'Modules/Test/classes/class.ilTestTopList.php';
6 require_once 'Services/Table/classes/class.ilTable2GUI.php';
7 
15 {
19  protected $ctrl;
20 
24  protected $tabs;
25 
29  protected $tpl;
30 
34  protected $lng;
35 
39  protected $user;
40 
42  protected $object;
43 
47  protected $toplist;
48 
52  public function __construct(ilObjTest $testOBJ)
53  {
54  global $DIC; /* @var ILIAS\DI\Container $DIC */
55  $this->ctrl = $DIC['ilCtrl'];
56  $this->tpl = $DIC['tpl'];
57  $this->lng = $DIC['lng'];
58  $this->user = $DIC['ilUser'];
59 
60  $this->object = $testOBJ;
61  $this->toplist = new ilTestTopList($testOBJ);
62  }
63 
64  public function executeCommand()
65  {
66  if (!$this->object->getHighscoreEnabled()) {
67  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
68  $this->ctrl->redirectByClass('ilObjTestGUI');
69  }
70 
71  $this->ctrl->saveParameter($this, 'active_id');
72 
73  $cmd = $this->ctrl->getCmd();
74 
75  switch ($cmd) {
76  default:
77  $this->showResultsToplistsCmd();
78  }
79  }
80 
81  protected function showResultsToplistsCmd()
82  {
83  $html = $this->renderMedianMarkPanel();
86 
87  $this->tpl->setVariable("ADM_CONTENT", $html);
88  }
89 
90  protected function renderMedianMarkPanel()
91  {
92  global $DIC; /* @var ILIAS\DI\Container $DIC */
93 
94  $title = $DIC->language()->txt('tst_median_mark_panel');
95 
96  // BH: this really is the "mark of median" ??!
97  $activeId = $this->object->getActiveIdOfUser($DIC->user()->getId());
98  $data = $this->object->getCompleteEvaluationData();
99  $median = $data->getStatistics()->getStatistics()->median();
100  $pct = $data->getParticipant($activeId)->getMaxpoints() ? ($median / $data->getParticipant($activeId)->getMaxpoints()) * 100.0 : 0;
101  $mark = $this->object->mark_schema->getMatchingMark($pct);
102  $content = $mark->getShortName();
103 
104  $panel = $DIC->ui()->factory()->panel()->standard(
105  $title,
106  $DIC->ui()->factory()->legacy($content)
107  );
108 
109  return $DIC->ui()->renderer()->render($panel);
110  }
111 
112  protected function renderResultsToplistByScore()
113  {
114  $title = $this->lng->txt('toplist_by_score');
115  $html = '';
116 
117  if ($this->isTopTenRankingTableRequired()) {
118  $data = $this->toplist->getGeneralToplistByPercentage($_GET['ref_id'], $this->user->getId());
119 
120  $table_gui = $this->buildTableGUI();
121 
122  $table_gui->setData($data);
123  $table_gui->setTitle($title);
124 
125  $html .= $table_gui->getHTML();
126  }
127 
128  if ($this->isOwnRankingTableRequired()) {
129  $table_gui = $this->buildTableGUI();
130 
131  $table_gui->setData(
132  $this->toplist->getUserToplistByPercentage($_GET['ref_id'], $this->user->getID())
133  );
134 
135  if (!$this->isTopTenRankingTableRequired()) {
136  $table_gui->setTitle($title);
137  }
138 
139  $html .= $table_gui->getHTML();
140  }
141 
142  return $html;
143  }
144 
145  protected function renderResultsToplistByTime()
146  {
147  $title = $this->lng->txt('toplist_by_time');
148  $html = '';
149 
150  if ($this->isTopTenRankingTableRequired()) {
151  $topData = $this->toplist->getGeneralToplistByWorkingtime($_GET['ref_id'], $this->user->getId());
152 
153  $table_gui = $this->buildTableGUI();
154  $table_gui->setData($topData);
155  $table_gui->setTitle($title);
156 
157  $html .= $table_gui->getHTML();
158  }
159 
160  if ($this->isOwnRankingTableRequired()) {
161  $ownData = $this->toplist->getUserToplistByWorkingtime($_GET['ref_id'], $this->user->getID());
162 
163  $table_gui = $this->buildTableGUI();
164 
165  $table_gui->setData($ownData);
166 
167  if (!$this->isTopTenRankingTableRequired()) {
168  $table_gui->setTitle($title);
169  }
170 
171  $html .= $table_gui->getHTML();
172  }
173 
174  return $html;
175  }
176 
180  private function prepareTable(ilTable2GUI $table_gui)
181  {
182  $table_gui->addColumn($this->lng->txt('toplist_col_rank'));
183  $table_gui->addColumn($this->lng->txt('toplist_col_participant'));
184  if ($this->object->getHighscoreAchievedTS()) {
185  $table_gui->addColumn($this->lng->txt('toplist_col_achieved'));
186  }
187 
188  if ($this->object->getHighscoreScore()) {
189  $table_gui->addColumn($this->lng->txt('toplist_col_score'));
190  }
191 
192  if ($this->object->getHighscorePercentage()) {
193  $table_gui->addColumn($this->lng->txt('toplist_col_percentage'));
194  }
195 
196  if ($this->object->getHighscoreHints()) {
197  $table_gui->addColumn($this->lng->txt('toplist_col_hints'));
198  }
199 
200  if ($this->object->getHighscoreWTime()) {
201  $table_gui->addColumn($this->lng->txt('toplist_col_wtime'));
202  }
203  $table_gui->setEnableNumInfo(false);
204  $table_gui->setLimit(10);
205  }
206 
210  protected function buildTableGUI()
211  {
212  $table_gui = new ilTable2GUI($this);
213  $this->prepareTable($table_gui);
214  $table_gui->setRowTemplate('tpl.toplist_tbl_rows.html', 'Modules/Test');
215  return $table_gui;
216  }
217 
221  protected function isTopTenRankingTableRequired()
222  {
223  if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_TOP_TABLE) {
224  return true;
225  }
226 
227  if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_ALL_TABLES) {
228  return true;
229  }
230 
231  return false;
232  }
233 
237  protected function isOwnRankingTableRequired()
238  {
239  if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_OWN_TABLE) {
240  return true;
241  }
242 
243  if ($this->object->getHighscoreMode() == ilObjTest::HIGHSCORE_SHOW_ALL_TABLES) {
244  return true;
245  }
246 
247  return false;
248  }
249 }
Scoring class for tests.
Class ilTestTopList.
global $DIC
Definition: saml.php:7
__construct(ilObjTest $testOBJ)
$_GET["client_id"]
setEnableNumInfo($a_val)
Set enable num info.
user()
Definition: user.php:4
prepareTable(ilTable2GUI $table_gui)
Class ilTable2GUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const HIGHSCORE_SHOW_TOP_TABLE
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
const HIGHSCORE_SHOW_OWN_TABLE
const HIGHSCORE_SHOW_ALL_TABLES
$html
Definition: example_001.php:87
setLimit($a_limit=0, $a_default_limit=0)
$data
Definition: bench.php:6