ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilCmiXapiHighscoreReport Class Reference
+ Collaboration diagram for ilCmiXapiHighscoreReport:

Public Member Functions

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

Protected Member Functions

 fetchTotalDuration ($allDurations)
 

Protected Attributes

 $response
 
 $cmixUsersByIdent
 
 $objId
 
 $obj
 

Private Member Functions

 identUser ($userIdent)
 
 formatRawTimestamp ($rawTimestamp)
 

Private Attributes

 $tableData = []
 
 $userRank = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilCmiXapiHighscoreReport::__construct ( string  $responseBody,
  $obj 
)

ilCmiXapiHighscoreReport constructor.

Parameters
string$responseBody

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

48 {
49 $this->obj = $obj;
50 $this->objId = $obj->getId();
51 $responseBody = json_decode($responseBody, true);
52
53 if (count($responseBody)) {
54 $this->response = $responseBody;
55 } else {
56 $this->response = array();
57 }
58
59 foreach (ilCmiXapiUser::getUsersForObject($this->objId) as $cmixUser) {
60 $this->cmixUsersByIdent[$cmixUser->getUsrIdent()] = $cmixUser;
61 }
62 }
static getUsersForObject($objId, $asUsrId=false)

References $obj, and ilCmiXapiUser\getUsersForObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ fetchTotalDuration()

ilCmiXapiHighscoreReport::fetchTotalDuration (   $allDurations)
protected

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

170 {
171 $totalDuration = 0;
172
173 foreach ($allDurations as $duration) {
174 $totalDuration += ilObjSCORM2004LearningModule::_ISODurationToCentisec($duration) / 100;
175 }
176
177 $hours = floor($totalDuration / 3600);
178 $hours = strlen($hours) < 2 ? "0" . $hours : $hours;
179 $totalDuration = $hours . ":" . date('i:s', $totalDuration);
180
181 return $totalDuration;
182 }
static _ISODurationToCentisec($str)
convert ISO 8601 Timeperiods to centiseconds ta

References ilObjSCORM2004LearningModule\_ISODurationToCentisec().

Referenced by initTableData().

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

◆ formatRawTimestamp()

ilCmiXapiHighscoreReport::formatRawTimestamp (   $rawTimestamp)
private

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

185 {
186 $dateTime = ilCmiXapiDateTime::fromXapiTimestamp($rawTimestamp);
187 return ilDatePresentation::formatDate($dateTime);
188 }
static fromXapiTimestamp($xapiTimestamp)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.

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 200 of file class.ilCmiXapiHighscoreReport.php.

201 {
202 /*
203 foreach($this->response as $key => $item)
204 {
205 $user = ilCmiXapiUser::getUserFromIdent(
206 ilObjectFactory::getInstanceByRefId($_GET['ref_id']),
207 $tableRowData['mbox']
208 );
209
210 $this->response[$key]['realname'] = $user->getFullname();
211 }
212 */
213 return '<pre>' . json_encode($this->response, JSON_PRETTY_PRINT) . '</pre>';
214 }

◆ getTableData()

ilCmiXapiHighscoreReport::getTableData ( )

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

References $tableData.

◆ getUserRank()

ilCmiXapiHighscoreReport::getUserRank ( )

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

References $userRank.

◆ identUser()

ilCmiXapiHighscoreReport::identUser (   $userIdent)
private

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

158 {
159 global $DIC; /* @var \ILIAS\DI\Container $DIC */
160
161 $cmixUser = $this->cmixUsersByIdent[$userIdent];
162
163 if ($cmixUser->getUsrId() == $DIC->user()->getId()) {
164 return true;
165 }
166 return false;
167 }
$DIC
Definition: xapitoken.php:46

References $DIC.

◆ initTableData()

ilCmiXapiHighscoreReport::initTableData ( )
Returns
bool

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

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

References Vendor\Package\$a, Vendor\Package\$b, $DIC, $i, $rows, ilObjCmiXapi\CONT_TYPE_CMI5, fetchTotalDuration(), formatRawTimestamp(), ilObjCmiXapi\getContentType(), ilObjectFactory\getInstanceByObjId(), and ilObjCmiXapi\isMixedContentType().

+ Here is the call graph for this function:

Field Documentation

◆ $cmixUsersByIdent

ilCmiXapiHighscoreReport::$cmixUsersByIdent
protected

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

◆ $obj

ilCmiXapiHighscoreReport::$obj
protected

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

Referenced by __construct().

◆ $objId

ilCmiXapiHighscoreReport::$objId
protected

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

◆ $response

ilCmiXapiHighscoreReport::$response
protected

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

◆ $tableData

ilCmiXapiHighscoreReport::$tableData = []
private

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

Referenced by getTableData().

◆ $userRank

ilCmiXapiHighscoreReport::$userRank = null
private

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

Referenced by getUserRank().


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