ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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  {
122  $this->tpl->setVariable('STMT_ACTOR', 'user_not_found');
123  }
124  else
125  {
126  $this->tpl->setVariable('STMT_ACTOR', $this->getUsername($data['actor']));
127  }
128  }
129 
130  $this->tpl->setVariable('STMT_VERB', ilCmiXapiVerbList::getVerbTranslation(
131  $DIC->language(),
132  $data['verb_id']
133  ));
134 
135  $this->tpl->setVariable('STMT_OBJECT', $data['object']);
136  $this->tpl->setVariable('STMT_OBJECT_INFO', $data['object_info']);
137  $this->tpl->setVariable('ACTIONS', $r->render($actionsList));
138  $this->tpl->setVariable('RAW_DATA_MODAL', $r->render($rawDataModal));
139  }
140 
141  protected function getActionsList(RoundTrip $rawDataModal, $data)
142  {
143  global $DIC; /* @var \ILIAS\DI\Container $DIC */
144  $f = $DIC->ui()->factory();
145 
146  $actions = $f->dropdown()->standard([
147  $f->button()->shy(
148  $DIC->language()->txt('tbl_action_raw_data'),
149  '#'
150  )->withOnClick($rawDataModal->getShowSignal())
151  ])->withLabel($DIC->language()->txt('actions'));
152 
153  return $actions;
154  }
155 
156  protected function getRawDataModal($data)
157  {
158  global $DIC; /* @var \ILIAS\DI\Container $DIC */
159  $f = $DIC->ui()->factory();
160 
161  $modal = $f->modal()->roundtrip(
162  'Raw Statement',
163  $f->legacy('<pre>' . $data['statement'] . '</pre>')
164  )->withCancelButtonLabel('close');
165 
166  return $modal;
167  }
168 
169  protected function getUsername(ilCmiXapiUser $cmixUser)
170  {
171  global $DIC; /* @var \ILIAS\DI\Container $DIC */
172  $ret = 'not found';
173  try
174  {
175  $userObj = ilObjectFactory::getInstanceByObjId($cmixUser->getUsrId());
176  $ret = $userObj->getFullname();
177  }
178  catch (Exception $e)
179  {
180  $ret = $DIC->language()->txt('deleted_user');
181  }
182  return $ret;
183  }
184 }
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)
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
$DIC
Definition: xapitoken.php:46
static fromXapiTimestamp($xapiTimestamp)