ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCmiXapiHighscoreReport Class Reference
+ Collaboration diagram for ilCmiXapiHighscoreReport:

Public Member Functions

 __construct (string $responseBody, int $objId)
 ilCmiXapiHighscoreReport constructor. More...
 
 initTableData ()
 
 getTableData ()
 
 getUserRank ()
 
 getResponseDebug ()
 

Protected Member Functions

 fetchTotalDuration (array $allDurations)
 

Protected Attributes

array $response = []
 
int $objId
 
array $cmixUsersByIdent = []
 

Private Member Functions

 identUser (int $userIdent)
 
 formatRawTimestamp (string $rawTimestamp)
 

Private Attributes

array $tableData = []
 
int $userRank = null
 

Detailed Description

Definition at line 30 of file class.ilCmiXapiHighscoreReport.php.

Constructor & Destructor Documentation

◆ __construct()

ilCmiXapiHighscoreReport::__construct ( string  $responseBody,
int  $objId 
)

ilCmiXapiHighscoreReport constructor.

Definition at line 44 of file class.ilCmiXapiHighscoreReport.php.

45 {
46 $this->objId = $objId;
47 $responseBody = json_decode($responseBody, true);
48
49 if (is_array($responseBody) && count($responseBody)) {
50 $this->response = $responseBody;
51 } else {
52 $this->response = array();
53 }
54
55 foreach (ilCmiXapiUser::getUsersForObject($objId) as $cmixUser) {
56 $this->cmixUsersByIdent[$cmixUser->getUsrIdent()] = $cmixUser;
57 }
58 }
static getUsersForObject(int $objId, bool $asUsrId=false)

References $objId, and ilCmiXapiUser\getUsersForObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ fetchTotalDuration()

ilCmiXapiHighscoreReport::fetchTotalDuration ( array  $allDurations)
protected
Parameters
array$allDurations
Returns
string

Definition at line 163 of file class.ilCmiXapiHighscoreReport.php.

163 : string
164 {
165 $totalDuration = 0;
166
167 foreach ($allDurations as $duration) {
169 }
170
171 $hours = (string) floor($totalDuration / 3600);
172 $hours = strlen($hours) < 2 ? "0" . $hours : $hours;
173
174 return $hours . ":" . date('i:s', (int) round($totalDuration));
175 }
$duration
static _ISODurationToCentisec(string $str)
convert ISO 8601 Timeperiods to centiseconds

References $duration, and ilObjSCORM2004LearningModule\_ISODurationToCentisec().

Referenced by initTableData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatRawTimestamp()

ilCmiXapiHighscoreReport::formatRawTimestamp ( string  $rawTimestamp)
private

Definition at line 177 of file class.ilCmiXapiHighscoreReport.php.

177 : string
178 {
179 $dateTime = ilCmiXapiDateTime::fromXapiTimestamp($rawTimestamp);
180 return ilDatePresentation::formatDate($dateTime);
181 }
static fromXapiTimestamp(string $xapiTimestamp)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)

References ilDatePresentation\formatDate(), and ilCmiXapiDateTime\fromXapiTimestamp().

Referenced by initTableData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getResponseDebug()

ilCmiXapiHighscoreReport::getResponseDebug ( )

Definition at line 196 of file class.ilCmiXapiHighscoreReport.php.

196 : string
197 {
198 // foreach($this->response as $key => $item)
199 // {
200 // $user = ilCmiXapiUser::getUserFromIdent(
201 // ilObjectFactory::getInstanceByRefId($_GET['ref_id']),
202 // $tableRowData['mbox']
203 // );
204 //
205 // $this->response[$key]['realname'] = $user->getFullname();
206 // }
207 return '<pre>' . json_encode($this->response, JSON_PRETTY_PRINT) . '</pre>';
208 }

◆ getTableData()

ilCmiXapiHighscoreReport::getTableData ( )
Returns
mixed[]

Definition at line 186 of file class.ilCmiXapiHighscoreReport.php.

186 : array
187 {
188 return $this->tableData;
189 }

References $tableData.

◆ getUserRank()

ilCmiXapiHighscoreReport::getUserRank ( )

Definition at line 191 of file class.ilCmiXapiHighscoreReport.php.

191 : ?int
192 {
193 return $this->userRank;
194 }

References $userRank.

◆ identUser()

ilCmiXapiHighscoreReport::identUser ( int  $userIdent)
private

Definition at line 147 of file class.ilCmiXapiHighscoreReport.php.

147 : bool
148 {
149 global $DIC; /* @var \ILIAS\DI\Container $DIC */
150
151 $cmixUser = $this->cmixUsersByIdent[$userIdent];
152
153 if ($cmixUser->getUsrId() == $DIC->user()->getId()) {
154 return true;
155 }
156 return false;
157 }
global $DIC
Definition: shib_login.php:26

References $DIC.

◆ initTableData()

ilCmiXapiHighscoreReport::initTableData ( )

Definition at line 60 of file class.ilCmiXapiHighscoreReport.php.

60 : bool
61 {
62 global $DIC;
63
64 $rows = [];
65 if (ilObject::_lookupType($this->objId) == 'cmix') {
66 $obj = ilObjCmiXapi::getInstance($this->objId, false);
67 } else {
68 $obj = ilObjLTIConsumer::getInstance($this->objId, false);
69 }
70
71 if ($obj->isMixedContentType()) {
72 foreach ($this->response as $item) {
73 $userIdent = str_replace('mailto:', '', $item['mbox']);
74 if (empty($userIdent)) {
75 $userIdent = $item['account'];
76 }
77 $cmixUser = $this->cmixUsersByIdent[$userIdent];
78 $rows[] = [
79 'user_ident' => $userIdent,
80 'user' => '',
81 'date' => $this->formatRawTimestamp($item['timestamp']),
82 'duration' => $this->fetchTotalDuration($item['duration']),
83 'score' => $item['score']['scaled'],
84 'ilias_user_id' => $cmixUser->getUsrId()
85 ];
86 }
87 } elseif ($obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
88 foreach ($this->response as $item) {
89 $userIdent = $item['account'];
90 $cmixUser = $this->cmixUsersByIdent[$userIdent];
91 $rows[] = [
92 'user_ident' => $userIdent,
93 'user' => '',
94 'date' => $this->formatRawTimestamp($item['timestamp']),
95 'duration' => $this->fetchTotalDuration($item['duration']),
96 'score' => $item['score']['scaled'],
97 'ilias_user_id' => $cmixUser->getUsrId()
98 ];
99 }
100 } else {
101 foreach ($this->response as $item) {
102 $userIdent = str_replace('mailto:', '', $item['mbox']);
103 $cmixUser = $this->cmixUsersByIdent[$userIdent];
104 $rows[] = [
105 'user_ident' => $userIdent,
106 'user' => '',
107 'date' => $this->formatRawTimestamp($item['timestamp']),
108 'duration' => $this->fetchTotalDuration($item['duration']),
109 'score' => $item['score']['scaled'],
110 'ilias_user_id' => $cmixUser->getUsrId()
111 ];
112 }
113 }
114 usort($rows, fn($a, $b): int => $a['score'] != $b['score'] ? $a['score'] > $b['score'] ? -1 : 1 : 0);
115
116 $i = 0;
117 $prevScore = null;
118 //$userRank = null;
119 $retArr = [];
120 foreach ($rows as $key => $item) {
121 if ($prevScore !== $item['score']) {
122 $i++;
123 }
124 $rows[$key]['rank'] = $i;
125 $prevScore = $rows[$key]['score'];
126 /* instantiate userObj until loginUserRank is unknown */
127 if (null === $this->userRank) {
128 /* just boolean */
129 $userIdent = str_replace('mailto:', '', $rows[$key]['user_ident']);
130 $cmixUser = $this->cmixUsersByIdent[$userIdent];
131 if ($cmixUser->getUsrId() == $DIC->user()->getId()) {
132 $this->userRank = $key; //$rows[$key]['rank'];
133 $userObj = ilObjectFactory::getInstanceByObjId($cmixUser->getUsrId());
134 $rows[$key]['user'] = $userObj->getFullname();
135 }
136 $retArr[$key] = $rows[$key];
137 } else {
138 /* same same */
139 $rows[$key]['user_ident'] = false;
140 $retArr[$key] = $rows[$key];
141 } // EOF if( null === $this->userRank )
142 } // EOF foreach ($rows as $key => $item)
143 $this->tableData = $retArr;
144 return true;
145 }
static getInstance(int $a_id=0, bool $a_reference=true)
static getInstance(int $a_id=0, bool $a_reference=true)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, $DIC, ilObject\_lookupType(), ilObjCmiXapi\CONT_TYPE_CMI5, fetchTotalDuration(), formatRawTimestamp(), ilObjCmiXapi\getInstance(), ilObjLTIConsumer\getInstance(), and ilObjectFactory\getInstanceByObjId().

+ Here is the call graph for this function:

Field Documentation

◆ $cmixUsersByIdent

array ilCmiXapiHighscoreReport::$cmixUsersByIdent = []
protected

Definition at line 39 of file class.ilCmiXapiHighscoreReport.php.

◆ $objId

int ilCmiXapiHighscoreReport::$objId
protected

Definition at line 35 of file class.ilCmiXapiHighscoreReport.php.

Referenced by __construct().

◆ $response

array ilCmiXapiHighscoreReport::$response = []
protected

Definition at line 32 of file class.ilCmiXapiHighscoreReport.php.

◆ $tableData

array ilCmiXapiHighscoreReport::$tableData = []
private

Definition at line 33 of file class.ilCmiXapiHighscoreReport.php.

Referenced by getTableData().

◆ $userRank

int ilCmiXapiHighscoreReport::$userRank = null
private

Definition at line 34 of file class.ilCmiXapiHighscoreReport.php.

Referenced by getUserRank().


The documentation for this class was generated from the following file: