ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCmiXapiScoringGUI.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 public $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 = ilCmiXapiAccess::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 resetFilterCmd()
69// {
70// $table = $this->buildTableGUI("");
71// $table->resetFilter();
72// $table->resetOffset();
73// $this->showCmd();
74// }
75//
76// protected function applyFilterCmd()
77// {
78// $table = $this->buildTableGUI("");
79// $table->writeFilterToSession();
80// $table->resetOffset();
81// $this->showCmd();
82// }
83
84 protected function showCmd()
85 {
86 global $DIC; /* @var \ILIAS\DI\Container $DIC */
87
88 try {
89 $this->initTableData()
90 ->initHighScoreTable()
91 ->initUserRankTable()
92 ;
93 //$table->setData($this->tableData);
94 } catch (Exception $e) {
95 ilUtil::sendFailure($e->getMessage());
96 $table = $this->buildTableGUI('fallback');
97 $table->setData(array());
98 $table->setMaxCount(0);
99 $table->resetOffset();
100 $this->tableHtml = $table->getHTML();
101 }
102
103 $DIC->ui()->mainTemplate()->setContent($this->tableHtml);
104 }
105
109 protected function initTableData()
110 {
111 $filter = new ilCmiXapiStatementsReportFilter();
112 $filter->setActivityId($this->object->getActivityId());
113
114 $linkBuilder = new ilCmiXapiHighscoreReportLinkBuilder(
115 $this->object,
116 $this->object->getLrsType()->getLrsEndpointStatementsAggregationLink(),
117 $filter
118 );
119
120 $request = new ilCmiXapiHighscoreReportRequest(
121 $this->object->getLrsType()->getBasicAuth(),
122 $linkBuilder
123 );
124
125 $scoringReport = $request->queryReport($this->object);
126 if (true === $scoringReport->initTableData()) {
127 $this->tableData = $scoringReport->getTableData();
128 $this->userRank = $scoringReport->getUserRank();
129 }
130 return $this;
131 }
132
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 }
143
147 protected function initHighScoreTable()
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
162 protected function initUserRankTable()
163 {
164 if (!$this->object->getHighscoreOwnTable() || !$this->object->getHighscoreEnabled()) {
165 $this->tableHtml .= '';
166 return $this;
167 }
168 $table = $this->buildTableGUI('userRank');
169 $table->setData($this->getTableDataRange(true));
170 $this->tableHtml .= $table->getHTML();
171 return $this;
172 }
173
178 protected function buildTableGUI($tableId) : ilCmiXapiScoringTableGUI
179 {
180 $isMultiActorReport = $this->access->hasOutcomesAccess();
181 $table = new ilCmiXapiScoringTableGUI(
182 $this,
183 'show',
184 $isMultiActorReport,
185 $tableId,
186 $this->access->hasOutcomesAccess()
187 );
188 return $table;
189 }
190}
An exception for terminatinating execution or to throw for unit testing.
static getInstance(ilObjCmiXapi $object)
getTableDataRange($scopeUserRank=false)
__construct(ilObjCmiXapi $object)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24