ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCmiXapiHighscoreReportLinkBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
35 protected function buildPipeline(): array
36 {
37 $pipeline = [];
38
39 $pipeline[] = $this->buildFilterStage();
40 $pipeline[] = $this->buildOrderStage();
41
42
43 $obj = $this->getObj();
44 $id = null;
45 $cmix = ilObject::_lookupType($this->getObjId()) == 'cmix';
46 if ($cmix && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_GENERIC) {
47 $id = '$statement.actor.mbox';
48 }
49 if ($cmix && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5 && !$obj->isMixedContentType()) {
50 $id = '$statement.actor.account.name';
51 }
52 $pipeline[] = ['$group' => [
53 '_id' => $id,
54 'mbox' => [ '$last' => '$statement.actor.mbox' ],
55 'account' => [ '$last' => '$statement.actor.account.name'],
56 'username' => [ '$last' => '$statement.actor.name' ],
57 'timestamp' => [ '$last' => '$statement.timestamp' ],
58 'duration' => [ '$push' => '$statement.result.duration' ],
59 'score' => [ '$last' => '$statement.result.score' ]
60 ]];
61 return $pipeline;
62 }
63
67 protected function buildFilterStage(): array
68 {
69 $stage = array();
70
71 $stage['statement.object.objectType'] = 'Activity';
72 $stage['statement.actor.objectType'] = 'Agent';
73
74 $stage['statement.object.id'] = $this->filter->getActivityId();
75
76 $stage['statement.result.score.scaled'] = [
77 '$exists' => 1
78 ];
79
80 $obj = $this->getObj();
81 if ((ilObject::_lookupType($this->getObjId()) == 'cmix' && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_GENERIC) || $obj->isMixedContentType()) {
82 $stage['$or'] = $this->getUsersStack();
83 }
84
85 return [
86 '$match' => $stage
87 ];
88 }
89
93 protected function buildOrderStage(): array
94 {
95 return [ '$sort' => [
96 'statement.timestamp' => 1
97 ]];
98 }
99
100 // not used in cmi5 see above
104 protected function getUsersStack(): array
105 {
106 $users = [];
107 $obj = $this->getObj();
108 if ($obj->isMixedContentType()) {
109 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
110 $users[] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
111 $users[] = ['statement.actor.account.name' => "{$cmixUser->getUsrIdent()}"];
112 }
113 } else {
114 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
115 $users[] = [
116 'statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"
117 ];
118 }
119 }
120 return $users;
121 }
122
123 public function getPipelineDebug(): string
124 {
125 return '<pre>' . json_encode($this->buildPipeline(), JSON_PRETTY_PRINT) . '</pre>';
126 }
127}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getUsersForObject(int $objId, bool $asUsrId=false)
static _lookupType(int $id, bool $reference=false)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)