ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLTIConsumerScoringGUI.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
16{
19 const PART_FILTER_ALL_USERS = 3; // default
22 //const PART_FILTER_MANSCORING_PENDING = 6;
23
24
28 protected $object;
29
33 protected $access;
34
35 private $tableData;
36 private $tableHtml = '';
37 private $userRank;
38
39
44 {
45 $this->object = $object;
46
47 $this->access = ilLTIConsumerAccess::getInstance($this->object);
48 }
49
53 public function executeCommand()
54 {
55 global $DIC; /* @var \ILIAS\DI\Container $DIC */
56
57 if (!$this->access->hasHighscoreAccess()) {
58 throw new ilCmiXapiException('access denied!');
59 }
60
61 switch ($DIC->ctrl()->getNextClass($this)) {
62 default:
63 $cmd = $DIC->ctrl()->getCmd('show') . 'Cmd';
64 $this->{$cmd}();
65 }
66 }
67
68 protected function showCmd()
69 {
70 global $DIC; /* @var \ILIAS\DI\Container $DIC */
71
72 try {
73 $this->initTableData()
74 ->initHighScoreTable()
75 ->initUserRankTable()
76 ;
77 } catch (Exception $e) {
78 ilUtil::sendFailure($e->getMessage());
79 //$DIC->ui()->mainTemplate()->
80 $table = $this->buildTableGUI('fallback');
81 $table->setData(array());
82 $table->setMaxCount(0);
83 $table->resetOffset();
84 $this->tableHtml = $table->getHTML();
85 }
86
87 $DIC->ui()->mainTemplate()->setContent($this->tableHtml);
88 }
89
93 protected function initTableData()
94 {
95 $aggregateEndPointUrl = str_replace(
96 'data/xAPI',
97 'api/statements/aggregate',
98 $this->object->getProvider()->getXapiLaunchUrl() // should be named endpoint not launch url
99 );
100
102 $this->object->getProvider()->getXapiLaunchKey(),
103 $this->object->getProvider()->getXapiLaunchSecret()
104 );
105
106 $filter = new ilCmiXapiStatementsReportFilter();
107 $filter->setActivityId($this->object->getActivityId());
108
109 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
110 $this->object,
111 $aggregateEndPointUrl,
112 $filter
113 );
114
115 $request = new ilCmiXapiHighscoreReportRequest(
116 $basicAuth,
117 $linkBuilder
118 );
119
120 $scoringReport = $request->queryReport($this->object);
121
122 if (true === $scoringReport->initTableData()) {
123 $this->tableData = $scoringReport->getTableData();
124 $this->userRank = $scoringReport->getUserRank();
125 }
126 return $this;
127 }
128
133 private function getTableDataRange($scopeUserRank = false)
134 {
135 if (false === $scopeUserRank) {
136 return array_slice($this->tableData, 0, (int) $this->object->getHighscoreTopNum());
137 } else {
138 $offset = $this->userRank - 2 < 0 ? 0 : $this->userRank - 2;
139 $length = 5;
140 return array_slice($this->tableData, $offset, $length);
141 }
142 return [];
143 }
144
148 protected function initHighScoreTable()
149 {
150 if (!$this->object->getHighscoreTopTable() || !$this->object->getHighscoreEnabled()) {
151 $this->tableHtml .= '';
152 return $this;
153 }
154 $table = $this->buildTableGUI('highscore');
155 $table->setData($this->getTableDataRange());
156 $this->tableHtml .= $table->getHTML();
157 return $this;
158 }
159
163 protected function initUserRankTable()
164 {
165 if (!$this->object->getHighscoreOwnTable() || !$this->object->getHighscoreEnabled()) {
166 $this->tableHtml .= '';
167 return $this;
168 }
169 $table = $this->buildTableGUI('userRank');
170 $table->setData($this->getTableDataRange(true));
171 $this->tableHtml .= $table->getHTML();
172 return $this;
173 }
174
179 protected function buildTableGUI($tableId) : ilLTIConsumerScoringTableGUI
180 {
181 $isMultiActorReport = $this->access->hasOutcomesAccess();
182 $table = new ilLTIConsumerScoringTableGUI(
183 $this,
184 'show',
185 $isMultiActorReport,
186 $tableId,
187 $this->access->hasOutcomesAccess()
188 );
189 return $table;
190 }
191
195 public function getObject()
196 {
197 return $this->object;
198 }
199}
An exception for terminatinating execution or to throw for unit testing.
static buildBasicAuth($lrsKey, $lrsSecret)
static getInstance(ilObjLTIConsumer $object)
__construct(ilObjLTIConsumer $object)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$DIC
Definition: xapitoken.php:46