ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIConsumerScoringGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
32 public const PART_FILTER_ACTIVE_ONLY = 1;
33 public const PART_FILTER_INACTIVE_ONLY = 2;
34 public const PART_FILTER_ALL_USERS = 3; // default
37 //const PART_FILTER_MANSCORING_PENDING = 6;
38
39
44
49
50 private array $tableData;
51 private string $tableHtml = '';
52 private ?int $userRank;
53 private \ilGlobalTemplateInterface $main_tpl;
54
55
57 {
58 global $DIC;
59 $this->main_tpl = $DIC->ui()->mainTemplate();
60 $this->object = $object;
61
62 $this->access = ilLTIConsumerAccess::getInstance($this->object);
63 }
64
68 public function executeCommand(): void
69 {
70 global $DIC; /* @var \ILIAS\DI\Container $DIC */
71
72 if (!$this->access->hasHighscoreAccess()) {
73 throw new ilCmiXapiException('access denied!');
74 }
75
76 switch ($DIC->ctrl()->getNextClass($this)) {
77 default:
78 $cmd = $DIC->ctrl()->getCmd('show') . 'Cmd';
79 $this->{$cmd}();
80 }
81 }
82
83 protected function showCmd(): void
84 {
85 global $DIC; /* @var \ILIAS\DI\Container $DIC */
86
87 try {
88 $this->initTableData()
89 ->initHighScoreTable()
90 ->initUserRankTable()
91 ;
92 } catch (Exception $e) {
93 $this->main_tpl->setOnScreenMessage('failure', $e->getMessage());
94 //$DIC->ui()->mainTemplate()->
95 $table = $this->buildTableGUI('fallback');
96 $table->setData(array());
97 $table->setMaxCount(0);
98 $table->resetOffset();
99 $this->tableHtml = $table->getHTML();
100 }
101
102 $DIC->ui()->mainTemplate()->setContent($this->tableHtml);
103 }
104
108 protected function initTableData(): self
109 {
110 $aggregateEndPointUrl = str_replace(
111 'data/xAPI',
112 'api/statements/aggregate',
113 $this->object->getProvider()->getXapiLaunchUrl() // should be named endpoint not launch url
114 );
115
117 $this->object->getProvider()->getXapiLaunchKey(),
118 $this->object->getProvider()->getXapiLaunchSecret()
119 );
120
121 $filter = new ilCmiXapiStatementsReportFilter();
122 $filter->setActivityId($this->object->getActivityId());
123
124 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
125 $this->object->getId(),
126 $aggregateEndPointUrl,
127 $filter
128 );
129
130 $request = new ilCmiXapiHighscoreReportRequest(
131 $basicAuth,
132 $linkBuilder
133 );
134
135 $scoringReport = $request->queryReport($this->object->getId());
136
137 if (true === $scoringReport->initTableData()) {
138 $this->tableData = $scoringReport->getTableData();
139 $this->userRank = $scoringReport->getUserRank();
140 }
141 return $this;
142 }
143
147 private function getTableDataRange(?bool $scopeUserRank = false): array
148 {
149 if (false === $scopeUserRank) {
150 return array_slice($this->tableData, 0, $this->object->getHighscoreTopNum());
151 } else {
152 $offset = $this->userRank - 2 < 0 ? 0 : $this->userRank - 2;
153 $length = 5;
154 return array_slice($this->tableData, $offset, $length);
155 }
156 return [];
157 }
158
162 protected function initHighScoreTable(): self
163 {
164 if (!$this->object->getHighscoreTopTable() || !$this->object->getHighscoreEnabled()) {
165 $this->tableHtml .= '';
166 return $this;
167 }
168 $table = $this->buildTableGUI('highscore');
169 $table->setData($this->getTableDataRange());
170 $this->tableHtml .= $table->getHTML();
171 return $this;
172 }
173
177 protected function initUserRankTable(): self
178 {
179 if (!$this->object->getHighscoreOwnTable() || !$this->object->getHighscoreEnabled()) {
180 $this->tableHtml .= '';
181 return $this;
182 }
183 $table = $this->buildTableGUI('userRank');
184 $table->setData($this->getTableDataRange(true));
185 $this->tableHtml .= $table->getHTML();
186 return $this;
187 }
188
189 protected function buildTableGUI(string $tableId): ilLTIConsumerScoringTableGUI
190 {
191 $isMultiActorReport = $this->access->hasOutcomesAccess();
193 $this,
194 'show',
195 $isMultiActorReport,
196 $tableId,
197 $this->access->hasOutcomesAccess()
198 );
199 }
200
201 public function getObject(): \ilObjLTIConsumer
202 {
203 return $this->object;
204 }
205}
static buildBasicAuth($lrsKey, $lrsSecret)
static getInstance(ilObjLTIConsumer $object)
__construct(ilObjLTIConsumer $object)
ilGlobalTemplateInterface $main_tpl
getTableDataRange(?bool $scopeUserRank=false)
global $DIC
Definition: shib_login.php:26