ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilParticipantsTestResultsTableGUI.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 
5 include_once('./Services/Table/classes/class.ilTable2GUI.php');
6 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
7 
17 {
18  protected $accessResultsCommandsEnabled = false;
19  protected $manageResultsCommandsEnabled = false;
20 
21  protected $anonymity;
22 
23  public function __construct($a_parent_obj, $a_parent_cmd)
24  {
25  $this->setId('tst_participants_' . $a_parent_obj->getTestObj()->getRefId());
26  parent::__construct($a_parent_obj, $a_parent_cmd);
27 
28  global $DIC;
29  $this->lng = $DIC->language();
30  $this->ctrl = $DIC->ctrl();
31 
32  $this->setStyle('table', 'fullwidth');
33 
34  $this->setFormName('partResultsForm');
35  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
36 
37  $this->setRowTemplate("tpl.il_as_tst_scorings_row.html", "Modules/Test");
38 
39  $this->enable('header');
40  $this->enable('sort');
41 
42  $this->setSelectAllCheckbox('chbUser');
43 
44  $this->setDefaultOrderField('name');
45  $this->setDefaultOrderDirection('asc');
46  }
47 
52  {
54  }
55 
60  {
61  $this->accessResultsCommandsEnabled = $accessResultsCommandsEnabled;
62  }
63 
68  {
70  }
71 
76  {
77  $this->manageResultsCommandsEnabled = $manageResultsCommandsEnabled;
78  }
79 
83  public function getAnonymity()
84  {
85  return $this->anonymity;
86  }
87 
91  public function setAnonymity($anonymity)
92  {
93  $this->anonymity = $anonymity;
94  }
95 
100  public function numericOrdering($field)
101  {
102  return in_array($field, array(
103  'scored_pass', 'answered_questions', 'reached_points', 'percent_result'
104  ));
105  }
106 
107  public function init()
108  {
109  if ($this->isMultiRowSelectionRequired()) {
110  $this->setShowRowsSelector(true);
111  }
112 
113  $this->initColumns();
114  $this->initCommands();
115  $this->initFilter();
116  }
117 
118  public function initColumns()
119  {
120  if ($this->isMultiRowSelectionRequired()) {
121  $this->addColumn('', '', '1%');
122  }
123 
124  $this->addColumn($this->lng->txt("name"), 'name');
125  $this->addColumn($this->lng->txt("login"), 'login');
126 
127  $this->addColumn($this->lng->txt("tst_tbl_col_scored_pass"), 'scored_pass');
128  $this->addColumn($this->lng->txt("tst_tbl_col_pass_finished"), 'pass_finished');
129 
130  $this->addColumn($this->lng->txt("tst_tbl_col_answered_questions"), 'answered_questions');
131  $this->addColumn($this->lng->txt("tst_tbl_col_reached_points"), 'reached_points');
132  $this->addColumn($this->lng->txt("tst_tbl_col_percent_result"), 'percent_result');
133 
134  $this->addColumn($this->lng->txt("tst_tbl_col_passed_status"), 'passed_status');
135  $this->addColumn($this->lng->txt("tst_tbl_col_final_mark"), 'final_mark');
136 
137  if ($this->isActionsColumnRequired()) {
138  $this->addColumn('', '', '');
139  }
140  }
141 
142  public function initCommands()
143  {
144  if ($this->isAccessResultsCommandsEnabled() && !$this->getAnonymity()) {
145  $this->addMultiCommand('showPassOverview', $this->lng->txt('show_pass_overview'));
146  $this->addMultiCommand('showUserAnswers', $this->lng->txt('show_user_answers'));
147  $this->addMultiCommand('showDetailedResults', $this->lng->txt('show_detailed_results'));
148  }
149 
150  if ($this->isManageResultsCommandsEnabled()) {
151  $this->addMultiCommand('deleteSingleUserResults', $this->lng->txt('delete_user_data'));
152  }
153  }
154 
155  public function initFilter()
156  {
157  global $DIC;
158 
159  // no filter at all
160  }
161 
165  public function fillRow($data)
166  {
167  if ($this->isMultiRowSelectionRequired()) {
168  $this->tpl->setCurrentBlock('checkbox_column');
169  $this->tpl->setVariable("CHB_ROW_KEY", $data['active_id']);
170  $this->tpl->parseCurrentBlock();
171  }
172 
173  if ($this->isActionsColumnRequired()) {
174  $this->tpl->setCurrentBlock('actions_column');
175  $this->tpl->setVariable('ACTIONS', $this->buildActionsMenu($data)->getHTML());
176  $this->tpl->parseCurrentBlock();
177  }
178 
179  $this->tpl->setVariable("ROW_KEY", $data['active_id']);
180  $this->tpl->setVariable("LOGIN", $data['login']);
181  $this->tpl->setVariable("FULLNAME", $data['name']);
182 
183  $this->tpl->setVariable("SCORED_PASS", $this->buildScoredPassString($data));
184  $this->tpl->setVariable("PASS_FINISHED", $this->buildPassFinishedString($data));
185 
186  $this->tpl->setVariable("ANSWERED_QUESTIONS", $this->buildAnsweredQuestionsString($data));
187  $this->tpl->setVariable("REACHED_POINTS", $this->buildReachedPointsString($data));
188  $this->tpl->setVariable("PERCENT_RESULT", $this->buildPercentResultString($data));
189 
190  $this->tpl->setVariable("PASSED_STATUS", $this->buildPassedStatusString($data));
191  $this->tpl->setVariable("FINAL_MARK", $data['final_mark']);
192  }
193 
198  protected function buildActionsMenu($data)
199  {
200  $asl = new ilAdvancedSelectionListGUI();
201 
202  $this->ctrl->setParameterByClass('iltestevaluationgui', 'active_id', $data['active_id']);
203 
204  if ($this->isAccessResultsCommandsEnabled()) {
205  $resultsHref = $this->ctrl->getLinkTargetByClass('ilTestEvaluationGUI', 'outParticipantsResultsOverview');
206  $asl->addItem($this->lng->txt('tst_show_results'), $resultsHref, $resultsHref);
207  }
208 
209  return $asl;
210  }
211 
215  protected function isActionsColumnRequired()
216  {
217  if ($this->isAccessResultsCommandsEnabled()) {
218  return true;
219  }
220 
221  return false;
222  }
223 
224  protected function isMultiRowSelectionRequired()
225  {
226  if ($this->isAccessResultsCommandsEnabled() && !$this->getAnonymity()) {
227  return true;
228  }
229 
230  if ($this->isManageResultsCommandsEnabled()) {
231  return true;
232  }
233 
234  return false;
235  }
236 
241  protected function buildPassedStatusString($data)
242  {
243  if ($data['passed_status']) {
244  return $this->buildPassedIcon() . ' ' . $this->lng->txt('tst_passed');
245  }
246 
247  return $this->buildFailedIcon() . ' ' . $this->lng->txt('tst_failed');
248  }
249 
253  protected function buildPassedIcon()
254  {
255  return $this->buildImageIcon(ilUtil::getImagePath("icon_ok.svg"), $this->lng->txt("passed"));
256  }
257 
261  protected function buildFailedIcon()
262  {
263  return $this->buildImageIcon(ilUtil::getImagePath("icon_not_ok.svg"), $this->lng->txt("failed"));
264  }
265 
271  protected function buildImageIcon($src, $alt)
272  {
273  return "<img border=\"0\" align=\"middle\" src=\"" . $src . "\" alt=\"" . $alt . "\" />";
274  }
275 
280  protected function buildFormattedAccessDate($data)
281  {
283  }
284 
289  protected function buildScoredPassString($data)
290  {
291  return $this->lng->txt('pass') . ' ' . ($data['scored_pass'] + 1);
292  }
293 
298  protected function buildPassFinishedString($data)
299  {
300  return ilDatePresentation::formatDate(new ilDateTime($data['pass_finished'], IL_CAL_UNIX));
301  }
302 
308  {
309  return sprintf(
310  $this->lng->txt('tst_answered_questions_of_total'),
311  $data['answered_questions'],
312  $data['total_questions']
313  );
314  }
315 
320  protected function buildReachedPointsString($data)
321  {
322  return sprintf(
323  $this->lng->txt('tst_reached_points_of_max'),
324  $data['reached_points'],
325  $data['max_points']
326  );
327  }
328 
333  protected function buildPercentResultString($data)
334  {
335  return sprintf('%0.2f %%', $data['percent_result'] * 100);
336  }
337 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
const IL_CAL_DATETIME
setStyle($a_element, $a_style)
global $DIC
Definition: saml.php:7
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
setId($a_val)
Set id.
setAccessResultsCommandsEnabled($accessResultsCommandsEnabled)
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
getHTML()
Get HTML.
setManageResultsCommandsEnabled($manageResultsCommandsEnabled)
Class ilTable2GUI.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
Date and time handling
setRowTemplate($a_template, $a_template_dir="")
Set row template.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFormName($a_formname="")
Set Form name.
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.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.