ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCmiXapiHighscoreReportLinkBuilder.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
20 protected function buildPipeline() : array
21 {
22 $pipeline = [];
23
24 $pipeline[] = $this->buildFilterStage();
25 $pipeline[] = $this->buildOrderStage();
26
27
28 $obj = $this->getObj();
29 $id = null;
30 if ($obj instanceof ilObjLTIConsumer || $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_GENERIC) {
31 $id = '$statement.actor.mbox';
32 }
33 if ($obj instanceof ilObjCmiXapi && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5 && !$obj->isMixedContentType()) {
34 $id = '$statement.actor.account.name';
35 }
36 $pipeline[] = ['$group' => [
37 '_id' => $id,
38 'mbox' => [ '$last' => '$statement.actor.mbox' ],
39 'account' => [ '$last' => '$statement.actor.account.name'],
40 'username' => [ '$last' => '$statement.actor.name' ],
41 'timestamp' => [ '$last' => '$statement.timestamp' ],
42 'duration' => [ '$push' => '$statement.result.duration' ],
43 'score' => [ '$last' => '$statement.result.score' ]
44 ]];
45 return $pipeline;
46 }
47
48 protected function buildFilterStage()
49 {
50 $stage = array();
51
52 $stage['statement.object.objectType'] = 'Activity';
53 $stage['statement.actor.objectType'] = 'Agent';
54
55 $stage['statement.object.id'] = $this->filter->getActivityId();
56
57 $stage['statement.result.score.scaled'] = [
58 '$exists' => 1
59 ];
60
61 $obj = $this->getObj();
62 if ($obj instanceof ilObjLTIConsumer || ($obj->getContentType() == ilObjCmiXapi::CONT_TYPE_GENERIC) || $obj->isMixedContentType()) {
63 $stage['$or'] = $this->getUsersStack();
64 }
65
66 return [
67 '$match' => $stage
68 ];
69 }
70
71 protected function buildOrderStage()
72 {
73 return [ '$sort' => [
74 'statement.timestamp' => 1
75 ]];
76 }
77
78 // not used in cmi5 see above
79 protected function getUsersStack()
80 {
81 $users = [];
82 $obj = $this->getObj();
83 if ($obj instanceof ilObjCmiXapi && $obj->isMixedContentType()) {
84 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
85 $users[] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
86 $users[] = ['statement.actor.account.name' => "{$cmixUser->getUsrIdent()}"];
87 }
88 } else {
89 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
90 $users[] = [
91 'statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"
92 ];
93 }
94 }
95 return $users;
96 }
97
98 public function getPipelineDebug()
99 {
100 return '<pre>' . json_encode($this->buildPipeline(), JSON_PRETTY_PRINT) . '</pre>';
101 }
102}
An exception for terminatinating execution or to throw for unit testing.
static getUsersForObject($objId, $asUsrId=false)
filter()
Definition: filter.php:2