ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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  {
32  $id = '$statement.actor.mbox';
33  }
34  if ($obj instanceof ilObjCmiXapi && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5 && !$obj->isMixedContentType())
35  {
36  $id = '$statement.actor.account.name';
37  }
38  $pipeline[] = ['$group' => [
39  '_id' => $id,
40  'mbox' => [ '$last' => '$statement.actor.mbox' ],
41  'account' => [ '$last' => '$statement.actor.account.name'],
42  'username' => [ '$last' => '$statement.actor.name' ],
43  'timestamp' => [ '$last' => '$statement.timestamp' ],
44  'duration' => [ '$push' => '$statement.result.duration' ],
45  'score' => [ '$last' => '$statement.result.score' ]
46  ]];
47  return $pipeline;
48  }
49 
50  protected function buildFilterStage()
51  {
52  $stage = array();
53 
54  $stage['statement.object.objectType'] = 'Activity';
55  $stage['statement.actor.objectType'] = 'Agent';
56 
57  $stage['statement.object.id'] = $this->filter->getActivityId();
58 
59  $stage['statement.result.score.scaled'] = [
60  '$exists' => 1
61  ];
62 
63  $obj = $this->getObj();
64  if ($obj instanceof ilObjLTIConsumer || ($obj->getContentType() == ilObjCmiXapi::CONT_TYPE_GENERIC) || $obj->isMixedContentType())
65  {
66  $stage['$or'] = $this->getUsersStack();
67  }
68 
69  return [
70  '$match' => $stage
71  ];
72  }
73 
74  protected function buildOrderStage()
75  {
76  return [ '$sort' => [
77  'statement.timestamp' => 1
78  ]];
79  }
80 
81  // not used in cmi5 see above
82  protected function getUsersStack()
83  {
84  $users = [];
85  $obj = $this->getObj();
86  if ($obj instanceof ilObjCmiXapi && $obj->isMixedContentType())
87  {
88  foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser)
89  {
90  $users[] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
91  $users[] = ['statement.actor.account.name' => "{$cmixUser->getUsrIdent()}"];
92  }
93  }
94  else
95  {
96  foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser)
97  {
98  $users[] = [
99  'statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"
100  ];
101  }
102  }
103  return $users;
104  }
105 
106  public function getPipelineDebug()
107  {
108  return '<pre>' . json_encode($this->buildPipeline(), JSON_PRETTY_PRINT) . '</pre>';
109  }
110 }
static getUsersForObject($objId, $asUsrId=false)