ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLTIConsumerXapiStatementsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 {
36 
41  private \ilGlobalTemplateInterface $main_tpl;
42  private \ILIAS\DI\Container $dic;
43 
44  public function __construct(ilObjLTIConsumer $object)
45  {
46  global $DIC;
47  $this->dic = $DIC;
48  $this->main_tpl = $DIC->ui()->mainTemplate();
49  $this->object = $object;
50 
51  $this->access = ilLTIConsumerAccess::getInstance($this->object);
52  }
53 
57  public function executeCommand(): void
58  {
59  global $DIC; /* @var \ILIAS\DI\Container $DIC */
60 
61  if (!$this->access->hasStatementsAccess()) {
62  throw new ilCmiXapiException('access denied!');
63  }
64 
65  switch ($DIC->ctrl()->getNextClass($this)) {
66  default:
67  $cmd = $DIC->ctrl()->getCmd('show') . 'Cmd';
68  $this->{$cmd}();
69  }
70  }
71 
72  protected function resetFilterCmd(): void
73  {
74  $table = $this->buildTableGUI();
75  $table->resetFilter();
76  $table->resetOffset();
77  $this->showCmd();
78  }
79 
80  protected function applyFilterCmd(): void
81  {
82  $table = $this->buildTableGUI();
83  $table->writeFilterToSession();
84  $table->resetOffset();
85  $this->showCmd();
86  }
87 
88  protected function showCmd(): void
89  {
90  global $DIC; /* @var \ILIAS\DI\Container $DIC */
91 
92  $table = $this->buildTableGUI();
93 
94  try {
95  $statementsFilter = new ilCmiXapiStatementsReportFilter();
96 
97  $statementsFilter->setActivityId($this->object->getActivityId());
98 
99  $this->initLimitingAndOrdering($statementsFilter, $table);
100  $this->initActorFilter($statementsFilter, $table);
101  $this->initVerbFilter($statementsFilter, $table);
102  $this->initPeriodFilter($statementsFilter, $table);
103  $this->initTableData($table, $statementsFilter);
104  } catch (Exception $e) {
105  $this->main_tpl->setOnScreenMessage('failure', $e->getMessage());
106  $table->setData(array());
107  $table->setMaxCount(0);
108  $table->resetOffset();
109  }
110 
111  $DIC->ui()->mainTemplate()->setContent($table->getHTML());
112  }
113 
115  {
116  $table->determineOffsetAndOrder();
117 
118  $filter->setLimit($table->getLimit());
119  $filter->setOffset($table->getOffset());
120 
121  $filter->setOrderField($table->getOrderField());
122  $filter->setOrderDirection($table->getOrderDirection());
123  }
124 
126  {
127  global $DIC; /* @var \ILIAS\DI\Container $DIC */
128 
129  if ($this->access->hasOutcomesAccess()) {
130  $actor = $table->getFilterItemByPostVar('actor')->getValue();
131 
132  if (strlen($actor)) {
133  $usrId = ilObjUser::getUserIdByLogin($actor);
134 
135  if ($usrId) {
136  $filter->setActor(new ilCmiXapiUser($this->object->getId(), $usrId, $this->object->getProvider()->getPrivacyIdent()));
137  } else {
139  "given actor ({$actor}) is not a valid actor for object ({$this->object->getId()})"
140  );
141  }
142  }
143  } else {
144  $filter->setActor(new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getProvider()->getPrivacyIdent()));
145  }
146  }
147 
149  {
150  $verb = urldecode($table->getFilterItemByPostVar('verb')->getValue());
151 
152  if (ilCmiXapiVerbList::getInstance()->isValidVerb($verb)) {
153  $filter->setVerb($verb);
154  }
155  }
156 
158  {
159  $period = $table->getFilterItemByPostVar('period');
160 
161  if ($period->getStartXapiDateTime()) {
162  $filter->setStartDate($period->getStartXapiDateTime());
163  }
164 
165  if ($period->getEndXapiDateTime()) {
166  $filter->setEndDate($period->getEndXapiDateTime());
167  }
168  }
169 
170  public function asyncUserAutocompleteCmd(): void
171  {
172  $auto = new ilCmiXapiUserAutocomplete($this->object->getId());
173  $auto->setSearchFields(array('login','firstname','lastname','email'));
174  $auto->setResultField('login');
175  $auto->enableFieldSearchableCheck(true);
176  $auto->setMoreLinkAvailable(true);
177 
178  //$auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
179  $term = '';
180  if ($this->dic->http()->wrapper()->query()->has('term')) {
181  $term = $this->dic->http()->wrapper()->query()->retrieve('term', $this->dic->refinery()->kindlyTo()->string());
182  } elseif ($this->dic->http()->wrapper()->post()->has('term')) {
183  $term = $this->dic->http()->wrapper()->post()->retrieve('term', $this->dic->refinery()->kindlyTo()->string());
184  }
185  if ($term != '') {
186  $result = json_decode($auto->getList(ilUtil::stripSlashes($term)), true);
187  echo json_encode($result);
188  }
189  exit();
190  }
191 
193  {
194  $aggregateEndPointUrl = str_replace(
195  'data/xAPI',
196  'api/statements/aggregate',
197  $this->object->getProvider()->getXapiLaunchUrl() // should be named endpoint not launch url
198  );
199 
200  $linkBuilder = new ilCmiXapiStatementsReportLinkBuilder(
201  $this->object->getId(),
202  $aggregateEndPointUrl,
203  $filter
204  );
205 
207  $this->object->getProvider()->getXapiLaunchKey(),
208  $this->object->getProvider()->getXapiLaunchSecret()
209  );
210 
211  $request = new ilCmiXapiStatementsReportRequest(
212  $basicAuth,
213  $linkBuilder
214  );
215 
216  $statementsReport = $request->queryReport($this->object->getId());
217  $table->setData($statementsReport->getTableData());
218  $table->setMaxCount($statementsReport->getMaxCount());
219  }
220 
222  {
223  $isMultiActorReport = $this->access->hasOutcomesAccess();
224 
225  $table = new ilCmiXapiStatementsTableGUI($this, 'show', $isMultiActorReport);
226  $table->setFilterCommand('applyFilter');
227  $table->setResetCommand('resetFilter');
228  return $table;
229  }
230 }
setData(array $a_data)
initTableData(ilCmiXapiStatementsTableGUI $table, ilCmiXapiStatementsReportFilter $filter)
initLimitingAndOrdering(ilCmiXapiStatementsReportFilter $filter, ilCmiXapiStatementsTableGUI $table)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
initActorFilter(ilCmiXapiStatementsReportFilter $filter, ilCmiXapiStatementsTableGUI $table)
initPeriodFilter(ilCmiXapiStatementsReportFilter $filter, ilCmiXapiStatementsTableGUI $table)
static getInstance(ilObjLTIConsumer $object)
getFilterItemByPostVar(string $a_post_var)
static getUserIdByLogin(string $a_login)
static buildBasicAuth($lrsKey, $lrsSecret)
global $DIC
Definition: shib_login.php:22
setSearchFields(array $a_fields)
Set searchable fields.
initVerbFilter(ilCmiXapiStatementsReportFilter $filter, ilCmiXapiStatementsTableGUI $table)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
determineOffsetAndOrder(bool $a_omit_offset=false)
setMaxCount(int $a_max_count)
set max.