ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSCORM2004TrackingItemsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
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', 'components/ILIAS/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 
108  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
109  // $this->initFilter();
110  $this->getItems();
111  }
112 
116  public function getSelectableColumns(): array
117  {
118  // default fields
119  $cols = array();
120 
121  switch ($this->report) {
122  case "exportSelectedCore":
123  $cols = ilSCORM2004TrackingItems::exportSelectedCoreColumns($this->bySCO, $this->allowExportPrivacy);
124  break;
125  case "exportSelectedInteractions":
127  break;
128  case "exportSelectedObjectives":
130  break;
131  case "exportObjGlobalToSystem":
133  break;
134  case "tracInteractionItem":
135  $cols = ilSCORM2004TrackingItems::tracInteractionItemColumns($this->bySCO, $this->allowExportPrivacy);
136  break;
137  case "tracInteractionUser":
138  $cols = ilSCORM2004TrackingItems::tracInteractionUserColumns($this->bySCO, $this->allowExportPrivacy);
139  break;
140  case "tracInteractionUserAnswers":
141  $cols = ilSCORM2004TrackingItems::tracInteractionUserAnswersColumns((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy);
142  break;
143  case "exportSelectedSuccess":
145  break;
146  }
147 
148  return $cols;
149  }
150 
151  public function getObjId(): int
152  {
153  return $this->obj_id;
154  }
155 
156  public function getItems(): void
157  {
158  $this->determineOffsetAndOrder(true);
159  $this->determineLimit();
160 
161  $ilSCORM2004TrackingItems = new ilSCORM2004TrackingItems();
162  switch ($this->report) {
163  case "exportSelectedCore":
164  $tr_data = $ilSCORM2004TrackingItems->exportSelectedCore((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
165  break;
166  case "exportSelectedInteractions":
167  $tr_data = $ilSCORM2004TrackingItems->exportSelectedInteractions((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
168  break;
169  case "exportSelectedObjectives":
170  $tr_data = $ilSCORM2004TrackingItems->exportSelectedObjectives((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
171  break;
172  case "exportObjGlobalToSystem":
173  $tr_data = $ilSCORM2004TrackingItems->exportObjGlobalToSystem((array) $this->userSelected, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
174  break;
175  case "tracInteractionItem":
176  $tr_data = $ilSCORM2004TrackingItems->tracInteractionItem((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
177  break;
178  case "tracInteractionUser":
179  $tr_data = $ilSCORM2004TrackingItems->tracInteractionUser((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
180  break;
181  case "tracInteractionUserAnswers":
182  $tr_data = $ilSCORM2004TrackingItems->tracInteractionUserAnswers((array) $this->userSelected, (array) $this->scosSelected, $this->bySCO, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
183  break;
184  case "exportSelectedSuccess":
185  $tr_data = $ilSCORM2004TrackingItems->exportSelectedSuccess((array) $this->userSelected, $this->allowExportPrivacy, $this->getObjId(), $this->lmTitle);
186  break;
187  }
188  // $this->setMaxCount($tr_data["cnt"]);
189  if (ilUtil::stripSlashes($this->getOrderField()) != "") {
190  $tr_data = ilArrayUtil::stableSortArray(
191  $tr_data,
194  );
195  }
196 
197  $this->setData($tr_data);
198  }
199 
207  protected function parseValue(string $id, float|int|string|null $value, string $type): float|int|string|null
208  {
209  if ($id === "status") {
211  $path = $icons->getImagePathForStatus((int) $value);
212  $text = ilLearningProgressBaseGUI::_getStatusText((int) $value);
213  $value = ilUtil::img($path, $text);
214  }
215  //BLUM round
216  elseif ($id === "launch_data" || $id === "suspend_data") {
217  return $value;
218  }
219  if (is_numeric($value)) {
220  return round((float) $value, 2);
221  }
222  return $value;
223  }
224 
229  protected function fillRow(array $a_set): void
230  {
231  foreach ($this->getSelectedColumns() as $c) {
232  $this->tpl->setCurrentBlock("user_field");
233  $val = $this->parseValue($c, $a_set[$c], "scormtrac");
234  $this->tpl->setVariable("VAL_UF", $val);
235  $this->tpl->parseCurrentBlock();
236  }
237  }
238 
239  protected function fillHeaderExcel(ilExcel $a_excel, int &$a_row): void
240  {
241  $labels = $this->getSelectableColumns();
242  $cnt = 0;
243  foreach ($this->getSelectedColumns() as $c) {
244  $a_excel->setCell($a_row, $cnt, $labels[$c]["txt"]);
245  $cnt++;
246  }
247  }
248 
249  protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
250  {
251  // $lng = $this->lng;
252  // $lng->loadLanguageModule("trac");
253  $cnt = 0;
254  foreach ($this->getSelectedColumns() as $c) {
255  if ($c !== 'status') {
256  $val = $this->parseValue($c, $a_set[$c], "user");
257  } else {
258  $val = ilLearningProgressBaseGUI::_getStatusText((int) $a_set[$c]);
259  }
260  $a_excel->setCell($a_row, $cnt, $val);
261  $cnt++;
262  }
263  }
264 
265  protected function fillHeaderCSV(ilCSVWriter $a_csv): void
266  {
267  $labels = $this->getSelectableColumns();
268  foreach ($this->getSelectedColumns() as $c) {
269  $a_csv->addColumn($labels[$c]["txt"]);
270  }
271 
272  $a_csv->addRow();
273  }
274 
275  protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
276  {
277  // $lng = $this->lng;
278  // $lng->loadLanguageModule("trac");
279  foreach ($this->getSelectedColumns() as $c) {
280  if ($c !== 'status') {
281  $val = $this->parseValue($c, $a_set[$c], "user");
282  } else {
283  $val = ilLearningProgressBaseGUI::_getStatusText((int) $a_set[$c]);
284  }
285  $a_csv->addColumn($val);
286  }
287 
288  $a_csv->addRow();
289  }
290 }
Class ilSCORM2004TrackingItems.
setData(array $a_data)
addColumn(string $a_col)
setExportFormats(array $formats)
Set available export formats.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
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="")
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.
$c
Definition: deliver.php:25
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:29
__construct(int $a_obj_id, ?object $a_parent_obj, string $a_parent_cmd, array $a_userSelected, array $a_scosSelected, string $a_report)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setExternalSorting(bool $a_val)
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
Class ilSCORM2004TrackingItemsTableGUI.
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:22
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...
parseValue(string $id, float|int|string|null $value, string $type)
__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)
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)