ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCmiXapiStatementsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 use \ILIAS\UI\Component\Modal\RoundTrip;
6 
17 {
18  const TABLE_ID = 'cmix_statements_table';
19 
24 
25  public function __construct($a_parent_obj, $a_parent_cmd, $isMultiActorReport)
26  {
27  global $DIC; /* @var \ILIAS\DI\Container $DIC */
28 
29  $DIC->language()->loadLanguageModule('cmix');
30 
31  $this->isMultiActorReport = $isMultiActorReport;
32 
33  $this->setId(self::TABLE_ID);
34  parent::__construct($a_parent_obj, $a_parent_cmd);
35 
36  $DIC->language()->loadLanguageModule('form');
37 
38  $this->setFormAction($DIC->ctrl()->getFormAction($a_parent_obj, $a_parent_cmd));
39  $this->setRowTemplate('tpl.cmix_statements_table_row.html', 'Modules/CmiXapi');
40 
41  #$this->setTitle($DIC->language()->txt('tbl_statements_header'));
42  #$this->setDescription($DIC->language()->txt('tbl_statements_header_info'));
43 
44  $this->initColumns();
45  $this->initFilter();
46 
47  $this->setExternalSegmentation(true);
48  $this->setExternalSorting(true);
49 
50  $this->setDefaultOrderField('date');
51  $this->setDefaultOrderDirection('desc');
52  }
53 
54  protected function initColumns()
55  {
56  global $DIC; /* @var \ILIAS\DI\Container $DIC */
57 
58  $this->addColumn($DIC->language()->txt('tbl_statements_date'), 'date');
59 
60  if ($this->isMultiActorReport) {
61  $this->addColumn($DIC->language()->txt('tbl_statements_actor'), 'actor');
62  }
63 
64  $this->addColumn($DIC->language()->txt('tbl_statements_verb'), 'verb');
65  $this->addColumn($DIC->language()->txt('tbl_statements_object'), 'object');
66 
67  $this->addColumn('', '', '1%');
68  }
69 
70  public function initFilter()
71  {
72  global $DIC; /* @var \ILIAS\DI\Container $DIC */
73 
74  if ($this->isMultiActorReport) {
75  $ti = new ilTextInputGUI('User', "actor");
76  $ti->setDataSource($DIC->ctrl()->getLinkTarget($this->parent_obj, 'asyncUserAutocomplete', '', true));
77  $ti->setMaxLength(64);
78  $ti->setSize(20);
79  $this->addFilterItem($ti);
80  $ti->readFromSession();
81  $this->filter["actor"] = $ti->getValue();
82  }
83 
84  $si = new ilSelectInputGUI('Used Verb', "verb");
85  if (strtolower($this->ctrl->getCmdClass()) == "illticonsumerxapistatementsgui") {
86  $si->setOptions(ilCmiXapiVerbList::getInstance()->getSelectOptions());
87  } else { //xapi
88  $verbs = $this->parent_obj->getVerbs(); // ToDo: Caching
89  $si->setOptions(ilCmiXapiVerbList::getInstance()->getDynamicSelectOptions($verbs));
90  }
91  $this->addFilterItem($si);
92  $si->readFromSession();
93  $this->filter["verb"] = $si->getValue();
94  $dp = new ilCmiXapiDateDurationInputGUI('Period', 'period');
95  $dp->setShowTime(true);
96  $this->addFilterItem($dp);
97  $dp->readFromSession();
98  $this->filter["period"] = $dp->getValue();
99  }
100 
101  public function fillRow($data)
102  {
103  global $DIC; /* @var \ILIAS\DI\Container $DIC */
104 
105  $r = $DIC->ui()->renderer();
106 
107  $data['rowkey'] = md5(serialize($data));
108 
109  $rawDataModal = $this->getRawDataModal($data);
110  $actionsList = $this->getActionsList($rawDataModal, $data);
111 
114  );
115 
116  $this->tpl->setVariable('STMT_DATE', $date);
117 
118  if ($this->isMultiActorReport) {
119  $actor = $data['actor'];
120  if (empty($actor)) {
121  $this->tpl->setVariable('STMT_ACTOR', 'user_not_found');
122  } else {
123  $this->tpl->setVariable('STMT_ACTOR', $this->getUsername($data['actor']));
124  }
125  }
126 
127  $this->tpl->setVariable('STMT_VERB', ilCmiXapiVerbList::getVerbTranslation(
128  $DIC->language(),
129  $data['verb_id']
130  ));
131 
132  $this->tpl->setVariable('STMT_OBJECT', $data['object']);
133  $this->tpl->setVariable('STMT_OBJECT_INFO', $data['object_info']);
134  $this->tpl->setVariable('ACTIONS', $r->render($actionsList));
135  $this->tpl->setVariable('RAW_DATA_MODAL', $r->render($rawDataModal));
136  }
137 
138  protected function getActionsList(RoundTrip $rawDataModal, $data)
139  {
140  global $DIC; /* @var \ILIAS\DI\Container $DIC */
141  $f = $DIC->ui()->factory();
142 
143  $actions = $f->dropdown()->standard([
144  $f->button()->shy(
145  $DIC->language()->txt('tbl_action_raw_data'),
146  '#'
147  )->withOnClick($rawDataModal->getShowSignal())
148  ])->withLabel($DIC->language()->txt('actions'));
149 
150  return $actions;
151  }
152 
153  protected function getRawDataModal($data)
154  {
155  global $DIC; /* @var \ILIAS\DI\Container $DIC */
156  $f = $DIC->ui()->factory();
157 
158  $modal = $f->modal()->roundtrip(
159  'Raw Statement',
160  $f->legacy('<pre>' . $data['statement'] . '</pre>')
161  )->withCancelButtonLabel('close');
162 
163  return $modal;
164  }
165 
166  protected function getUsername(ilCmiXapiUser $cmixUser)
167  {
168  global $DIC; /* @var \ILIAS\DI\Container $DIC */
169  $ret = 'not found';
170  try {
171  $userObj = ilObjectFactory::getInstanceByObjId($cmixUser->getUsrId());
172  $ret = $userObj->getFullname();
173  } catch (Exception $e) {
174  $ret = $DIC->language()->txt('deleted_user');
175  }
176  return $ret;
177  }
178 }
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
getShowSignal()
Get the signal to show this modal in the frontend.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
getActionsList(RoundTrip $rawDataModal, $data)
__construct($a_parent_obj, $a_parent_cmd, $isMultiActorReport)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static getVerbTranslation(ilLanguage $lng, $verb)
global $DIC
Definition: goto.php:24
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
__construct(Container $dic, ilPlugin $plugin)
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.
$ret
Definition: parser.php:6
filter()
Definition: filter.php:2
static fromXapiTimestamp($xapiTimestamp)