ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCmiXapiScoringGUI.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
40
42
43 private array $tableData;
44 private string $tableHtml = '';
45 private ?int $userRank = null;
46 private \ilGlobalTemplateInterface $main_tpl;
47
48 private \ILIAS\DI\Container $dic;
49
51 {
52 global $DIC;
53 $this->dic = $DIC;
54 $this->main_tpl = $DIC->ui()->mainTemplate();
55 $this->object = $object;
56
57 $this->access = ilCmiXapiAccess::getInstance($this->object);
58 }
59
63 public function executeCommand(): void
64 {
65 if (!$this->access->hasHighscoreAccess()) {
66 throw new ilCmiXapiException('access denied!');
67 }
68
69 switch ($this->dic->ctrl()->getNextClass($this)) {
70 default:
71 $cmd = $this->dic->ctrl()->getCmd('show') . 'Cmd';
72 $this->{$cmd}();
73 }
74 }
75
76 protected function resetFilterCmd(): void
77 {
78 $table = $this->buildTableGUI("");
79 $table->resetFilter();
80 $table->resetOffset();
81 $this->showCmd();
82 }
83
84 protected function applyFilterCmd(): void
85 {
86 $table = $this->buildTableGUI("");
87 $table->writeFilterToSession();
88 $table->resetOffset();
89 $this->showCmd();
90 }
91
92 protected function showCmd(): void
93 {
94 try {
95 $this->initTableData()
96 ->initHighScoreTable()
97 ->initUserRankTable()
98 ;
99 //$table->setData($this->tableData);
100 } catch (Exception $e) {
101 $this->main_tpl->setOnScreenMessage('failure', $e->getMessage());
102 $table = $this->buildTableGUI('fallback');
103 $table->setData(array());
104 $table->setMaxCount(0);
105 $table->resetOffset();
106 $this->tableHtml = $table->getHTML();
107 }
108
109 $this->dic->ui()->mainTemplate()->setContent($this->tableHtml);
110 }
111
112 protected function initTableData(): self
113 {
114 $filter = new ilCmiXapiStatementsReportFilter();
115 $filter->setActivityId($this->object->getActivityId());
116
117 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
118 $this->object->getId(),
119 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
120 $filter
121 );
122
123 $request = new ilCmiXapiHighscoreReportRequest(
124 $this->object->getLrsType()->getBasicAuth(),
125 $linkBuilder
126 );
127
128 $scoringReport = $request->queryReport($this->object->getId());
129 if (true === $scoringReport->initTableData()) {
130 $this->tableData = $scoringReport->getTableData();
131 $this->userRank = $scoringReport->getUserRank();
132 }
133 return $this;
134 }
135
136 private function getTableDataRange(bool $scopeUserRank = false): array
137 {
138 if (false === $scopeUserRank) {
139 return array_slice($this->tableData, 0, $this->object->getHighscoreTopNum());
140 } else {
141 $offset = $this->userRank - 2 < 0 ? 0 : $this->userRank - 2;
142 $length = 5;
143 return array_slice($this->tableData, $offset, $length);
144 }
145 }
146
147 protected function initHighScoreTable(): self
148 {
149 if (!$this->object->getHighscoreTopTable() || !$this->object->getHighscoreEnabled()) {
150 $this->tableHtml .= '';
151 return $this;
152 }
153 $table = $this->buildTableGUI('highscore');
154 $table->setData($this->getTableDataRange());
155 $this->tableHtml .= $table->getHTML();
156 return $this;
157 }
158
159 protected function initUserRankTable(): self
160 {
161 if (!$this->object->getHighscoreOwnTable() || !$this->object->getHighscoreEnabled()) {
162 $this->tableHtml .= '';
163 return $this;
164 }
165 $table = $this->buildTableGUI('userRank');
166 $table->setData($this->getTableDataRange(true));
167 $this->tableHtml .= $table->getHTML();
168 return $this;
169 }
170
171 protected function buildTableGUI(string $tableId): ilCmiXapiScoringTableGUI
172 {
173 $isMultiActorReport = $this->access->hasOutcomesAccess();
174 return new ilCmiXapiScoringTableGUI(
175 $this,
176 'show',
177 $isMultiActorReport,
178 $tableId,
179 $this->access->hasOutcomesAccess()
180 );
181 }
182}
static getInstance(ilObjCmiXapi $object)
getTableDataRange(bool $scopeUserRank=false)
ilGlobalTemplateInterface $main_tpl
__construct(ilObjCmiXapi $object)
global $DIC
Definition: shib_login.php:26