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

Public Member Functions

 __construct (string $responseBody, int $objId)
 
 getMaxCount ()
 
 getStatements ()
 
 hasStatements ()
 
 getTableData ()
 

Static Public Member Functions

static getLanguageEntry (array $obj, string $userLanguage)
 with multiple language keys like [de-DE] [en-US] More...
 

Protected Member Functions

 fetchDate (array $statement)
 
 fetchActor (array $statement)
 
 fetchVerbId (array $statement)
 
 fetchVerbDisplay (array $statement)
 
 fetchObjectName (array $statement)
 
 fetchObjectInfo (array $statement)
 

Protected Attributes

array $response
 
array $statements
 
int $maxCount
 
array $cmixUsersByIdent
 
string $userLanguage
 
string $contentType
 
bool $isMixedContentType
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 51 of file class.ilCmiXapiStatementsReport.php.

52 {
53 global $DIC;
54 $this->userLanguage = $DIC->user()->getLanguage();
55
56 $responseBody = json_decode($responseBody, true);
57
58 if (ilObject::_lookupType($objId) == 'lti') {
59 $this->contentType = ilObjCmiXapi::CONT_TYPE_GENERIC;
60 $this->isMixedContentType = ilObjLTIConsumer::getInstance($objId, false)->isMixedContentType();
61 } else {
62 $this->contentType = ilObjCmiXapi::getInstance($objId, false)->getContentType();
63 $this->isMixedContentType = ilObjCmiXapi::getInstance($objId, false)->isMixedContentType();
64 }
65
66 if (is_array($responseBody) && count($responseBody) > 0) {
67 $this->response = current($responseBody);
68 $this->statements = $this->response['statements'];
69 $this->maxCount = $this->response['maxcount'];
70 } else {
71 $this->response = array();
72 $this->statements = array();
73 $this->maxCount = 0;
74 }
75
76 foreach (ilCmiXapiUser::getUsersForObject($objId) as $cmixUser) {
77 $this->cmixUsersByIdent[$cmixUser->getUsrIdent()] = $cmixUser;
78 }
79 }
static getUsersForObject(int $objId, bool $asUsrId=false)
static getInstance(int $a_id=0, bool $a_reference=true)
static getInstance(int $a_id=0, bool $a_reference=true)
static _lookupType(int $id, bool $reference=false)
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57

References $DIC, $objId, ilObject\_lookupType(), ilObjCmiXapi\CONT_TYPE_GENERIC, ilObjCmiXapi\getInstance(), ilObjLTIConsumer\getInstance(), and ilCmiXapiUser\getUsersForObject().

+ Here is the call graph for this function:

Member Function Documentation

◆ fetchActor()

ilCmiXapiStatementsReport::fetchActor ( array  $statement)
protected

Definition at line 129 of file class.ilCmiXapiStatementsReport.php.

130 {
131 if ($this->isMixedContentType) {
132 $ident = str_replace('mailto:', '', $statement['actor']['mbox']);
133 if (empty($ident)) {
134 $ident = $statement['actor']['account']['name'];
135 }
136 } elseif ($this->contentType == ilObjCmiXapi::CONT_TYPE_CMI5) {
137 $ident = $statement['actor']['account']['name'];
138 } else {
139 $ident = str_replace('mailto:', '', $statement['actor']['mbox']);
140 }
141 return $this->cmixUsersByIdent[$ident];
142 }

References ilObjCmiXapi\CONT_TYPE_CMI5.

Referenced by getTableData().

+ Here is the caller graph for this function:

◆ fetchDate()

ilCmiXapiStatementsReport::fetchDate ( array  $statement)
protected
Returns
mixed

Definition at line 124 of file class.ilCmiXapiStatementsReport.php.

124 : string
125 {
126 return $statement['timestamp'];
127 }

Referenced by getTableData().

+ Here is the caller graph for this function:

◆ fetchObjectInfo()

ilCmiXapiStatementsReport::fetchObjectInfo ( array  $statement)
protected

Definition at line 180 of file class.ilCmiXapiStatementsReport.php.

180 : ?string
181 {
182 try {
183 return $statement['object']['definition']['description']['en-US'];
184 } catch (Exception $e) {
185 ilObjCmiXapi::log()->debug('debug:' . $e->getMessage());
186 return "";
187 }
188 }

References Vendor\Package\$e, and ilObjCmiXapi\log().

Referenced by getTableData().

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

◆ fetchObjectName()

ilCmiXapiStatementsReport::fetchObjectName ( array  $statement)
protected

Definition at line 158 of file class.ilCmiXapiStatementsReport.php.

158 : string
159 {
160 try {
161 $ret = urldecode($statement['object']['id']);
162 if (array_key_exists('definition', $statement['object'])) {
163 if (array_key_exists('name', $statement['object']['definition'])) {
164 $lang = self::getLanguageEntry($statement['object']['definition']['name'], $this->userLanguage);
165 if (array_key_exists('languageEntry', $lang)) {
166 $langEntry = $lang['languageEntry'];
167 if ($langEntry != '') {
168 $ret = $langEntry;
169 }
170 }
171 }
172 }
173 return $ret;
174 } catch (Exception $e) {
175 ilObjCmiXapi::log()->error('error:' . $e->getMessage());
176 return "";
177 }
178 }
static getLanguageEntry(array $obj, string $userLanguage)
with multiple language keys like [de-DE] [en-US]
$lang
Definition: xapiexit.php:25

References Vendor\Package\$e, $lang, getLanguageEntry(), and ilObjCmiXapi\log().

Referenced by getTableData().

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

◆ fetchVerbDisplay()

ilCmiXapiStatementsReport::fetchVerbDisplay ( array  $statement)
protected

Definition at line 149 of file class.ilCmiXapiStatementsReport.php.

149 : string
150 {
151 try {
152 return $statement['verb']['display']['en-US'];
153 } catch (Exception $e) {
154 return $statement['verb']['id'];
155 }
156 }

References Vendor\Package\$e.

Referenced by getTableData().

+ Here is the caller graph for this function:

◆ fetchVerbId()

ilCmiXapiStatementsReport::fetchVerbId ( array  $statement)
protected

Definition at line 144 of file class.ilCmiXapiStatementsReport.php.

144 : string
145 {
146 return $statement['verb']['id'];
147 }

Referenced by getTableData().

+ Here is the caller graph for this function:

◆ getLanguageEntry()

static ilCmiXapiStatementsReport::getLanguageEntry ( array  $obj,
string  $userLanguage 
)
static

with multiple language keys like [de-DE] [en-US]

Returns
array<string, mixed>

Definition at line 194 of file class.ilCmiXapiStatementsReport.php.

194 : array
195 {
196 $defaultLanguage = 'en-US';
197 $defaultLanguageEntry = '';
198 $defaultLanguageExists = false;
199 $firstLanguage = '';
200 $firstLanguageEntry = '';
201 $firstLanguageExists = false;
202 $userLanguage = '';
203 $userLanguageEntry = '';
204 $userLanguageExists = false;
205 $language = '';
206 $languageEntry = '';
207 try {
208 foreach ($obj as $k => $v) {
209 // save $firstLanguage
210 if ($firstLanguage == '') {
211 $f = '/^[a-z]+-?.*/';
212 if (preg_match($f, $k)) {
213 $firstLanguageExists = true;
214 $firstLanguage = $k;
215 $firstLanguageEntry = $v;
216 }
217 }
218 // check defaultLanguage
219 if ($k == $defaultLanguage) {
220 $defaultLanguageExists = true;
221 $defaultLanguageEntry = $v;
222 }
223 // check userLanguage
224 $p = '/^' . $userLanguage . '-?./';
225 preg_match($p, $k);
226 if (preg_match($p, $k)) {
227 $userLanguageExists = true;
228 $userLanguage = $k;
229 $userLanguageEntry = $v;
230 }
231 }
232 } catch (Exception $e) {
233 };
234
235 if ($userLanguageExists) {
236 $language = $userLanguage;
237 $languageEntry = $userLanguageEntry;
238 } elseif ($defaultLanguageExists) {
239 $language = $userLanguage;
240 $languageEntry = $userLanguageEntry;
241 } elseif ($firstLanguageExists) {
242 $language = $firstLanguage;
243 $languageEntry = $firstLanguageEntry;
244 }
245 return ['language' => $language, 'languageEntry' => $languageEntry];
246 }
$defaultLanguage
Definition: xapiexit.php:23

References $defaultLanguage, Vendor\Package\$e, Vendor\Package\$f, and $userLanguage.

Referenced by fetchObjectName().

+ Here is the caller graph for this function:

◆ getMaxCount()

ilCmiXapiStatementsReport::getMaxCount ( )

Definition at line 81 of file class.ilCmiXapiStatementsReport.php.

References $maxCount.

◆ getStatements()

ilCmiXapiStatementsReport::getStatements ( )
Returns
mixed[]

Definition at line 89 of file class.ilCmiXapiStatementsReport.php.

89 : array
90 {
91 return $this->statements;
92 }

References $statements.

Referenced by ilXapiStatementEvaluation\evaluateReport().

+ Here is the caller graph for this function:

◆ getTableData()

ilCmiXapiStatementsReport::getTableData ( )
Returns
array<int, array<string, mixed>>

Definition at line 102 of file class.ilCmiXapiStatementsReport.php.

102 : array
103 {
104 $data = [];
105
106 foreach ($this->statements as $statement) {
107 $data[] = [
108 'date' => $this->fetchDate($statement),
109 'actor' => $this->fetchActor($statement),
110 'verb_id' => $this->fetchVerbId($statement),
111 'verb_display' => $this->fetchVerbDisplay($statement),
112 'object' => $this->fetchObjectName($statement),
113 'object_info' => $this->fetchObjectInfo($statement),
114 'statement' => json_encode($statement, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
115 ];
116 }
117
118 return $data;
119 }

References $data, fetchActor(), fetchDate(), fetchObjectInfo(), fetchObjectName(), fetchVerbDisplay(), and fetchVerbId().

+ Here is the call graph for this function:

◆ hasStatements()

ilCmiXapiStatementsReport::hasStatements ( )

Definition at line 94 of file class.ilCmiXapiStatementsReport.php.

94 : bool
95 {
96 return (bool) count($this->statements);
97 }

Field Documentation

◆ $cmixUsersByIdent

array ilCmiXapiStatementsReport::$cmixUsersByIdent
protected

Definition at line 41 of file class.ilCmiXapiStatementsReport.php.

◆ $contentType

string ilCmiXapiStatementsReport::$contentType
protected

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

◆ $isMixedContentType

bool ilCmiXapiStatementsReport::$isMixedContentType
protected

Definition at line 49 of file class.ilCmiXapiStatementsReport.php.

◆ $maxCount

int ilCmiXapiStatementsReport::$maxCount
protected

Definition at line 36 of file class.ilCmiXapiStatementsReport.php.

Referenced by getMaxCount().

◆ $response

array ilCmiXapiStatementsReport::$response
protected

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

◆ $statements

array ilCmiXapiStatementsReport::$statements
protected

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

Referenced by getStatements().

◆ $userLanguage

string ilCmiXapiStatementsReport::$userLanguage
protected

Definition at line 43 of file class.ilCmiXapiStatementsReport.php.

Referenced by getLanguageEntry().


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