ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCmiXapiStatementsTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
33{
34 public const TABLE_ID = 'cmix_statements_table';
35
36 protected bool $isMultiActorReport;
37 protected array $filter = [];
38 private \ILIAS\DI\Container $dic;
40
47 public function __construct(?object $a_parent_obj, string $a_parent_cmd, bool $isMultiActorReport)
48 {
49 global $DIC; /* @var \ILIAS\DI\Container $DIC */
50 $this->dic = $DIC;
51 $DIC->language()->loadLanguageModule('cmix');
52 $this->language = $DIC->language();
53
54 $this->isMultiActorReport = $isMultiActorReport;
55
56 $this->setId(self::TABLE_ID);
57 parent::__construct($a_parent_obj, $a_parent_cmd);
58
59 $DIC->language()->loadLanguageModule('form');
60
61 $this->setFormAction($DIC->ctrl()->getFormAction($a_parent_obj, $a_parent_cmd));
62 $this->setRowTemplate('tpl.cmix_statements_table_row.html', 'components/ILIAS/CmiXapi');
63
64 #$this->setTitle($DIC->language()->txt('tbl_statements_header'));
65 #$this->setDescription($DIC->language()->txt('tbl_statements_header_info'));
66
67 $this->initColumns();
68 $this->initFilter();
69
70 $this->setExternalSegmentation(true);
71 $this->setExternalSorting(true);
72
73 $this->setDefaultOrderField('date');
74 $this->setDefaultOrderDirection('desc');
75 }
76
77 protected function initColumns(): void
78 {
79 $this->addColumn($this->language->txt('tbl_statements_date'), 'date');
80
81 if ($this->isMultiActorReport) {
82 $this->addColumn($this->language->txt('tbl_statements_actor'), 'actor');
83 }
84
85 $this->addColumn($this->language->txt('tbl_statements_verb'), 'verb');
86 $this->addColumn($this->language->txt('tbl_statements_object'), 'object');
87
88 $this->addColumn('', '', '');
89 }
90
91 public function initFilter(): void
92 {
93 if ($this->isMultiActorReport) {
94 $ti = new ilTextInputGUI('User', "actor");
95 $ti->setDataSource($this->dic->ctrl()->getLinkTarget($this->parent_obj, 'asyncUserAutocomplete', '', true));
96 $ti->setMaxLength(64);
97 $ti->setSize(20);
98 $this->addFilterItem($ti);
99 $ti->readFromSession();
100 $this->filter["actor"] = $ti->getValue();
101 }
102
103 $si = new ilSelectInputGUI('Used Verb', "verb");
104 if (strtolower($this->ctrl->getCmdClass()) == "illticonsumerxapistatementsgui") {
105 $si->setOptions(ilCmiXapiVerbList::getInstance()->getSelectOptions());
106 } else { //xapi
107 $verbs = $this->parent_obj->getVerbs(); // ToDo: Caching
108 $si->setOptions(ilCmiXapiVerbList::getInstance()->getDynamicSelectOptions($verbs));
109 }
110 $this->addFilterItem($si);
111 $si->readFromSession();
112 $this->filter["verb"] = $si->getValue();
113
114 $dp = new ilCmiXapiDateDurationInputGUI('Period', 'period');
115 $dp->setShowTime(true);
116 $this->addFilterItem($dp);
117 $dp->readFromSession();
118 $this->filter["period"] = $dp->getValue();
119 }
120
121 protected function fillRow(array $a_set): void
122 {
123 $r = $this->dic->ui()->renderer();
124 $a_set['rowkey'] = md5(serialize($a_set['statement']));
125 $rawDataModal = $this->getRawDataModal($a_set);
126 $actionsList = $this->getActionsList($rawDataModal, $a_set);
127
130 );
131
132 $this->tpl->setVariable('STMT_DATE', $date);
133
134 if ($this->isMultiActorReport) {
135 $actor = $a_set['actor'];
136 if (empty($actor)) {
137 $this->tpl->setVariable('STMT_ACTOR', 'user_not_found');
138 } else {
139 $this->tpl->setVariable('STMT_ACTOR', $this->getUsername($a_set['actor']));
140 }
141 }
142
143 $this->tpl->setVariable('STMT_VERB', ilCmiXapiVerbList::getVerbTranslation(
144 $this->language,
145 $a_set['verb_id']
146 ));
147
148 $this->tpl->setVariable('STMT_OBJECT', $a_set['object']);
149 $this->tpl->setVariable('STMT_OBJECT_INFO', $a_set['object_info']);
150 $this->tpl->setVariable('ACTIONS', $r->render($actionsList));
151 $this->tpl->setVariable('RAW_DATA_MODAL', $r->render($rawDataModal));
152 }
153
154 protected function getActionsList(RoundTrip $rawDataModal, array $data): \ILIAS\UI\Component\Dropdown\Dropdown
155 {
156 $f = $this->dic->ui()->factory();
157
158 return $f->dropdown()->standard([
159 $f->button()->shy(
160 $this->language->txt('tbl_action_raw_data'),
161 '#'
162 )->withOnClick($rawDataModal->getShowSignal())
163 ])->withLabel($this->language->txt('actions'));
164 }
165
166 protected function getRawDataModal(array $data): RoundTrip
167 {
168 $f = $this->dic->ui()->factory();
169
170 return $f->modal()->roundtrip(
171 'Raw Statement',
172 $f->legacy()->content('<pre>' . $data['statement'] . '</pre>')
173 )->withCancelButtonLabel($this->language->txt('close'));
174 }
175
176 protected function getUsername(ilCmiXapiUser $cmixUser): string
177 {
178 $ret = 'not found';
179 try {
180 $userObj = ilObjectFactory::getInstanceByObjId($cmixUser->getUsrId());
181 $ret = $userObj->getFullname();
182 } catch (Exception $e) {
183 $ret = $this->language->txt('deleted_user');
184 }
185 return $ret;
186 }
187}
static fromXapiTimestamp(string $xapiTimestamp)
getActionsList(RoundTrip $rawDataModal, array $data)
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(?object $a_parent_obj, string $a_parent_cmd, bool $isMultiActorReport)
static getVerbTranslation(ilLanguage $lng, string $verb)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
language handling
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setExternalSegmentation(bool $a_val)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
setDefaultOrderField(string $a_defaultorderfield)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
This class represents a text property in a property form.
getShowSignal()
Get the signal to show this modal in the frontend.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26