ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSCORM2004TrackingItemsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
30 
32 
33  private int $obj_id = 0;
34  private int $user_id = 0;
35  private bool $bySCO = false;
36  private array $scosSelected = array();
37  private array $userSelected = array();
38  private bool $allowExportPrivacy = false;
39  private string $lmTitle = "";
40  private string $report = "";
41 
46  public function __construct(int $a_obj_id, ?object $a_parent_obj, string $a_parent_cmd, array $a_userSelected, array $a_scosSelected, string $a_report)
47  {
48  global $DIC;
49 
50  $this->ctrl = $DIC->ctrl();
51  $lng = $DIC->language();
52  $lng->loadLanguageModule("scormtrac");
53  $this->lng = $lng;
54  $this->access = $DIC->access();
55  $this->rbacsystem = $DIC->rbac()->system();
56 
57  $this->obj_id = $a_obj_id;
58  $this->report = $a_report;
59  $this->scosSelected = $a_scosSelected;
60  $this->userSelected = $a_userSelected;
61  if ($a_parent_cmd === "showTrackingItemsBySco") {
62  $this->bySCO = true;
63  }
64  if ($a_parent_obj !== null) {
65  $this->lmTitle = $a_parent_obj->getObject()->getTitle();
66  $this->setId('2004' . $this->report);
67  parent::__construct($a_parent_obj, $a_parent_cmd);
68  }
69  $privacy = ilPrivacySettings::getInstance();
70  $this->allowExportPrivacy = $privacy->enabledExportSCORM();
71 
72  // if($a_print_view)
73  // {
74  // $this->setPrintMode(true);
75  // }
76 
77  foreach ($this->getSelectedColumns() as $c) {
78  $l = $c;
79  if (in_array($l, array("status", "time", "score"))) {
80  $l = "cont_" . $l;
81  // } else {
82  // $l =
83  }
84  $s = $this->lng->txt($l);
85  if (substr($l, 0, 14) === "interaction_id") {
86  $s = $this->lng->txt(substr($l, 0, 14)) . ' ' . substr($l, 14);
87  }
88  if (substr($l, 0, 17) === "interaction_value") {
89  $s = sprintf($this->lng->txt(substr($l, 0, 17)), substr($l, 17, (strpos($l, ' ') - 17))) . substr($l, strpos($l, ' '));
90  }
91  if (substr($l, 0, 23) === "interaction_description") {
92  $s = $this->lng->txt(substr($l, 0, 23)) . ' ' . substr($l, 23);
93  }
94  $this->addColumn($s, $c);
95  }
96 
97  $this->setRowTemplate('tpl.scorm2004_tracking_items.html', 'Modules/Scorm2004');
98  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
99 
100  $this->setExternalSorting(true);
101  // $this->setExternalSegmentation(true);
102  $this->setEnableHeader(true);
103  $this->setEnableTitle(true);
104  // $this->setDefaultOrderField("cp_node_id, user_id");
105  $this->setDefaultOrderField("");
106  $this->setDefaultOrderDirection("asc");
107  $this->setShowTemplates(true);
108 
109  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
110  // $this->initFilter();
111  $this->getItems();
112  }
113 
117  public function getSelectableColumns(): array
118  {
119  // default fields
120  $cols = array();
121 
122  switch ($this->report) {
123  case "exportSelectedCore":
124  $cols = ilSCORM2004TrackingItems::exportSelectedCoreColumns($this->bySCO, $this->allowExportPrivacy);
125  break;
126  case "exportSelectedInteractions":
128  break;
129  case "exportSelectedObjectives":
131  break;
132  case "exportObjGlobalToSystem":
134  break;
135  case "tracInteractionItem":
136  $cols = ilSCORM2004TrackingItems::tracInteractionItemColumns($this->bySCO, $this->allowExportPrivacy);
137  break;
138  case "tracInteractionUser":
139  $cols = ilSCORM2004TrackingItems::tracInteractionUserColumns($this->bySCO, $this->allowExportPrivacy);
140  break;
141  case "tracInteractionUserAnswers":
142  $cols = ilSCORM2004TrackingItems::tracInteractionUserAnswersColumns((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy);
143  break;
144  case "exportSelectedSuccess":
146  break;
147  }
148 
149  return $cols;
150  }
151 
152  public function getObjId(): int
153  {
154  return $this->obj_id;
155  }
156 
157  public function getItems(): void
158  {
159  $this->determineOffsetAndOrder(true);
160  $this->determineLimit();
161 
162  $ilSCORM2004TrackingItems = new ilSCORM2004TrackingItems();
163  switch ($this->report) {
164  case "exportSelectedCore":
165  $tr_data = $ilSCORM2004TrackingItems->exportSelectedCore((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
166  break;
167  case "exportSelectedInteractions":
168  $tr_data = $ilSCORM2004TrackingItems->exportSelectedInteractions((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
169  break;
170  case "exportSelectedObjectives":
171  $tr_data = $ilSCORM2004TrackingItems->exportSelectedObjectives((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
172  break;
173  case "exportObjGlobalToSystem":
174  $tr_data = $ilSCORM2004TrackingItems->exportObjGlobalToSystem((array) $this->userSelected, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
175  break;
176  case "tracInteractionItem":
177  $tr_data = $ilSCORM2004TrackingItems->tracInteractionItem((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
178  break;
179  case "tracInteractionUser":
180  $tr_data = $ilSCORM2004TrackingItems->tracInteractionUser((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
181  break;
182  case "tracInteractionUserAnswers":
183  $tr_data = $ilSCORM2004TrackingItems->tracInteractionUserAnswers((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
184  break;
185  case "exportSelectedSuccess":
186  $tr_data = $ilSCORM2004TrackingItems->exportSelectedSuccess((array) $this->userSelected, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
187  break;
188  }
189  // $this->setMaxCount($tr_data["cnt"]);
190  if (ilUtil::stripSlashes($this->getOrderField()) != "") {
191  $tr_data = ilArrayUtil::stableSortArray(
192  $tr_data,
195  );
196  }
197 
198  $this->setData($tr_data);
199  }
200 
205  protected function parseValue(string $id, $value, string $type)
206  {
207  if ($id === "status") {
209  $path = $icons->getImagePathForStatus((int) $value);
210  $text = ilLearningProgressBaseGUI::_getStatusText((int) $value);
211  $value = ilUtil::img($path, $text);
212  }
213  //BLUM round
214  elseif ($id === "launch_data" || $id === "suspend_data") {
215  return $value;
216  }
217  if (is_numeric($value)) {
218  return round((float) $value, 2);
219  }
220  return $value;
221  }
222 
227  protected function fillRow(array $a_set): void
228  {
229  foreach ($this->getSelectedColumns() as $c) {
230  $this->tpl->setCurrentBlock("user_field");
231  $val = $this->parseValue($c, $a_set[$c], "scormtrac");
232  $this->tpl->setVariable("VAL_UF", $val);
233  $this->tpl->parseCurrentBlock();
234  }
235  }
236 
237  protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
238  {
239  $labels = $this->getSelectableColumns();
240  $cnt = 0;
241  foreach ($this->getSelectedColumns() as $c) {
242  $a_excel->setCell($a_row, $cnt, $labels[$c]["txt"]);
243  $cnt++;
244  }
245  }
246 
247  protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
248  {
249 // $lng = $this->lng;
250 // $lng->loadLanguageModule("trac");
251  $cnt = 0;
252  foreach ($this->getSelectedColumns() as $c) {
253  if ($c !== 'status') {
254  $val = $this->parseValue($c, $a_set[$c], "user");
255  } else {
256  $val = ilLearningProgressBaseGUI::_getStatusText((int) $a_set[$c]);
257  }
258  $a_excel->setCell($a_row, $cnt, $val);
259  $cnt++;
260  }
261  }
262 
263  protected function fillHeaderCSV(ilCSVWriter $a_csv): void
264  {
265  $labels = $this->getSelectableColumns();
266  foreach ($this->getSelectedColumns() as $c) {
267  $a_csv->addColumn($labels[$c]["txt"]);
268  }
269 
270  $a_csv->addRow();
271  }
272 
273  protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
274  {
275 // $lng = $this->lng;
276 // $lng->loadLanguageModule("trac");
277  foreach ($this->getSelectedColumns() as $c) {
278  if ($c !== 'status') {
279  $val = $this->parseValue($c, $a_set[$c], "user");
280  } else {
281  $val = ilLearningProgressBaseGUI::_getStatusText((int) $a_set[$c]);
282  }
283  $a_csv->addColumn($val);
284  }
285 
286  $a_csv->addRow();
287  }
288 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setData(array $a_data)
addColumn(string $a_col)
setExportFormats(array $formats)
Set available export formats.
$c
Definition: cli.php:38
setFormAction(string $a_form_action, bool $a_multipart=false)
$type
setEnableTitle(bool $a_enabletitle)
static exportSelectedCoreColumns(bool $b_orderBySCO, bool $b_allowExportPrivacy)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setShowTemplates(bool $a_value)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
loadLanguageModule(string $a_module)
Load language module.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
ilLanguage $lng
setId(string $a_val)
static tracInteractionItemColumns(bool $b_orderBySCO, bool $b_allowExportPrivacy)
$path
Definition: ltiservices.php:32
__construct(int $a_obj_id, ?object $a_parent_obj, string $a_parent_cmd, array $a_userSelected, array $a_scosSelected, string $a_report)
global $DIC
Definition: feed.php:28
setExternalSorting(bool $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
static _getStatusText(int $a_status, ?ilLanguage $a_lng=null)
Get status alt text.
static tracInteractionUserAnswersColumns(array $a_user, array $a_sco, bool $b_orderBySCO, bool $b_allowExportPrivacy)
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
__construct(Container $dic, ilPlugin $plugin)
static tracInteractionUserColumns(bool $b_orderBySCO, bool $b_allowExportPrivacy)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
$cols
Definition: xhr_table.php:11
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)