ILIAS  release_7 Revision v7.30-3-g800a261c036
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 163 of file class.ilCmiXapiHighscoreReport.php.

164 {
165 $totalDuration = 0;
166
167 foreach ($allDurations as $duration) {
168 $totalDuration += ilObjSCORM2004LearningModule::_ISODurationToCentisec($duration) / 100;
169 }
170
171 $hours = floor($totalDuration / 3600);
172 $hours = strlen($hours) < 2 ? "0" . $hours : $hours;
173 $totalDuration = $hours . ":" . date('i:s', $totalDuration);
174
175 return $totalDuration;
176 }
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 178 of file class.ilCmiXapiHighscoreReport.php.

179 {
180 $dateTime = ilCmiXapiDateTime::fromXapiTimestamp($rawTimestamp);
181 return ilDatePresentation::formatDate($dateTime);
182 }
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 194 of file class.ilCmiXapiHighscoreReport.php.

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

◆ getTableData()

ilCmiXapiHighscoreReport::getTableData ( )

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

References $tableData.

◆ getUserRank()

ilCmiXapiHighscoreReport::getUserRank ( )

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

References $userRank.

◆ identUser()

ilCmiXapiHighscoreReport::identUser (   $userIdent)
private

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

152 {
153 global $DIC; /* @var \ILIAS\DI\Container $DIC */
154
155 $cmixUser = $this->cmixUsersByIdent[$userIdent];
156
157 if ($cmixUser->getUsrId() == $DIC->user()->getId()) {
158 return true;
159 }
160 return false;
161 }
global $DIC
Definition: goto.php:24

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 foreach ($this->response as $item) {
75 $userIdent = str_replace('mailto:', '', $item['mbox']);
76 if (empty($userIdent)) {
77 $userIdent = $item['account'];
78 }
79 $cmixUser = $this->cmixUsersByIdent[$userIdent];
80 $rows[] = [
81 'user_ident' => $userIdent,
82 'user' => '',
83 'date' => $this->formatRawTimestamp($item['timestamp']),
84 'duration' => $this->fetchTotalDuration($item['duration']),
85 'score' => $item['score']['scaled'],
86 'ilias_user_id' => $cmixUser->getUsrId()
87 ];
88 }
89 } elseif ($this->obj instanceof ilObjCmiXapi && $this->obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
90 foreach ($this->response as $item) {
91 $userIdent = $item['account'];
92 $cmixUser = $this->cmixUsersByIdent[$userIdent];
93 $rows[] = [
94 'user_ident' => $userIdent,
95 'user' => '',
96 'date' => $this->formatRawTimestamp($item['timestamp']),
97 'duration' => $this->fetchTotalDuration($item['duration']),
98 'score' => $item['score']['scaled'],
99 'ilias_user_id' => $cmixUser->getUsrId()
100 ];
101 }
102 } else {
103 foreach ($this->response as $item) {
104 $userIdent = str_replace('mailto:', '', $item['mbox']);
105 $cmixUser = $this->cmixUsersByIdent[$userIdent];
106 $rows[] = [
107 'user_ident' => $userIdent,
108 'user' => '',
109 'date' => $this->formatRawTimestamp($item['timestamp']),
110 'duration' => $this->fetchTotalDuration($item['duration']),
111 'score' => $item['score']['scaled'],
112 'ilias_user_id' => $cmixUser->getUsrId()
113 ];
114 }
115 }
116 usort($rows, function ($a, $b) {
117 return $a['score'] != $b['score'] ? $a['score'] > $b['score'] ? -1 : 1 : 0;
118 });
119
120 $i = 0;
121 $prevScore = null;
122 //$userRank = null;
123 $retArr = [];
124 foreach ($rows as $key => $item) {
125 if ($prevScore !== $item['score']) {
126 $i++;
127 }
128 $rows[$key]['rank'] = $i;
129 $prevScore = $rows[$key]['score'];
130 /* instantiate userObj until loginUserRank is unknown */
131 if (null === $this->userRank) {
132 /* just boolean */
133 $userIdent = str_replace('mailto:', '', $rows[$key]['user_ident']);
134 $cmixUser = $this->cmixUsersByIdent[$userIdent];
135 if ($cmixUser->getUsrId() == $DIC->user()->getId()) {
136 $this->userRank = $key; //$rows[$key]['rank'];
137 $userObj = ilObjectFactory::getInstanceByObjId($cmixUser->getUsrId());
138 $rows[$key]['user'] = $userObj->getFullname();
139 }
140 $retArr[$key] = $rows[$key];
141 } else {
142 /* same same */
143 $rows[$key]['user_ident'] = false;
144 $retArr[$key] = $rows[$key];
145 } // EOF if( null === $this->userRank )
146 } // EOF foreach ($rows as $key => $item)
147 $this->tableData = $retArr;
148 return true;
149 }
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: