ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilCmiXapiStatementsReportLinkBuilder Class Reference
+ Inheritance diagram for ilCmiXapiStatementsReportLinkBuilder:
+ Collaboration diagram for ilCmiXapiStatementsReportLinkBuilder:

Protected Member Functions

 buildPipeline ()
 
 buildLimitStage ()
 
 buildFilterStage ()
 
 buildOrderingStage ()
 
- Protected Member Functions inherited from ilCmiXapiAbstractReportLinkBuilder
 appendRequestParameters (string $url)
 
 buildPipelineParameter ()
 
 buildPipeline ()
 

Additional Inherited Members

- Public Member Functions inherited from ilCmiXapiAbstractReportLinkBuilder
 __construct (int $objId, string $aggregateEndPoint, ilCmiXapiStatementsReportFilter $filter)
 ilCmiXapiAbstractReportLinkBuilder constructor. More...
 
 getUrl ()
 
 getObjId ()
 
 getAggregateEndPoint ()
 
 getObj ()
 
- Protected Attributes inherited from ilCmiXapiAbstractReportLinkBuilder
int $objId
 
string $aggregateEndPoint
 
ilCmiXapiStatementsReportFilter $filter
 

Detailed Description

Member Function Documentation

◆ buildFilterStage()

ilCmiXapiStatementsReportLinkBuilder::buildFilterStage ( )
protected
Returns
mixed[][]

i don't think this will work with user >~ 100 this will blow up the GET request GET Queries are sometimes limited to an amount of characters

Definition at line 84 of file class.ilCmiXapiStatementsReportLinkBuilder.php.

84 : array
85 {
86 $cmi5_extensions_query = false;
87
88 $stage = array();
89 $stage['statement.object.objectType'] = 'Activity';
90 $stage['statement.actor.objectType'] = 'Agent';
91 if ($this->filter->getVerb()) {
92 $stage['statement.verb.id'] = $this->filter->getVerb();
93 }
94
95 if ($this->filter->getStartDate() || $this->filter->getEndDate()) {
96 $stage['statement.timestamp'] = array();
97
98 if ($this->filter->getStartDate() !== null) {
99 $stage['statement.timestamp']['$gt'] = $this->filter->getStartDate()->toXapiTimestamp();
100 }
101
102 if ($this->filter->getEndDate() !== null) {
103 $stage['statement.timestamp']['$lt'] = $this->filter->getEndDate()->toXapiTimestamp();
104 }
105 }
106
107 $obj = $this->getObj();
108 $activityId = array();
109
110 if ($cmi5_extensions_query == true && $obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5 && !$obj->isMixedContentType()) {
111 // https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#963-extensions
112 $activityId['statement.context.extensions.https://ilias&46;de/cmi5/activityid'] = $obj->getActivityId();
113 } else {
114 // for case-insensive: '$regex' => '(?i)^' . preg_quote($this->filter->getActivityId()) . ''
115 $activityQuery = [
116 '$regex' => '^' . preg_quote($this->filter->getActivityId()) . ''
117 ];
118 $activityId['$or'] = [];
119 // ToDo : restriction to exact activityId?
120 // query existing activityId in grouping? we have not enough control over acticityId in xapi statements
121 // another way put the obj_id into a generated registration, but we are not sure that content will put this into statement context
122 // $activityId['$or'][] = ['statement.object.id' => "{$this->filter->getActivityId()}"];
123 $activityId['$or'][] = ['statement.object.id' => $activityQuery];
124 $activityId['$or'][] = ['statement.context.contextActivities.parent.id' => $activityQuery];
125 }
126
127 $actor = array();
128
129 // mixed
130 if ($obj->isMixedContentType()) {
131 if ($this->filter->getActor()) {
132 // could be registration query but so what...
133 foreach (ilCmiXapiUser::getUserIdents($this->getObjId(), $this->filter->getActor()->getUsrId()) as $usrIdent) {
134 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$usrIdent}"]; // older statements
135 $actor['$or'][] = ['statement.actor.account.name' => "{$usrIdent}"];
136 }
137 // not launched yet?
138 if (count($actor) == 0) {
139 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$this->filter->getActor()->getUsrIdent()}"]; // older statements
140 $actor['$or'][] = ['statement.actor.account.name' => "{$this->filter->getActor()->getUsrIdent()}"];
141 }
142 } else {
143 $actor['$or'] = [];
144 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
145 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
146 $actor['$or'][] = ['statement.actor.account.name' => "{$cmixUser->getUsrIdent()}"];
147 }
148 }
149 } elseif ($obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) { // new
150 if ($this->filter->getActor()) {
151 $cmixUser = $this->filter->getActor();
152 $actor['statement.context.registration'] = $cmixUser->getRegistration();
153 }
154 } else {
155 if ($this->filter->getActor()) {
156 foreach (ilCmiXapiUser::getUserIdents($this->getObjId(), $this->filter->getActor()->getUsrId()) as $usrIdent) {
157 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$usrIdent}"];
158 }
159 // not launched yet?
160 if (count($actor) == 0) {
161 $actor['statement.actor.mbox'] = $this->filter->getActor()->getUsrIdent();
162 }
163 } else {
169 $actor['$or'] = [];
170 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
171 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
172 }
173 }
174 }
175 $stage['$and'] = [];
176 $stage['$and'][] = $activityId;
177 if (count($actor) > 0) {
178 $stage['$and'][] = $actor;
179 }
180 return array('$match' => $stage);
181 }
static getUserIdents(int $objId, int $usrId)
static getUsersForObject(int $objId, bool $asUsrId=false)
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)

References ilObjCmiXapi\CONT_TYPE_CMI5, ILIAS\Repository\filter(), ilCmiXapiAbstractReportLinkBuilder\getObj(), ilCmiXapiAbstractReportLinkBuilder\getObjId(), ilCmiXapiUser\getUserIdents(), and ilCmiXapiUser\getUsersForObject().

Referenced by buildPipeline().

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

◆ buildLimitStage()

ilCmiXapiStatementsReportLinkBuilder::buildLimitStage ( )
protected
Returns
array<int, mixed[]>

Definition at line 69 of file class.ilCmiXapiStatementsReportLinkBuilder.php.

69 : array
70 {
71 $stage = array(
72 array('$skip' => (int) $this->filter->getOffset())
73 );
74
75 if ($this->filter->getLimit() !== 0) {
76 $stage[] = array('$limit' => (int) $this->filter->getLimit());
77 }
78 return $stage;
79 }

References ILIAS\Repository\filter().

Referenced by buildPipeline().

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

◆ buildOrderingStage()

ilCmiXapiStatementsReportLinkBuilder::buildOrderingStage ( )
protected
Returns
array<string, int[]>

Definition at line 186 of file class.ilCmiXapiStatementsReportLinkBuilder.php.

186 : array
187 {
188 $obj = $this->getObj();
189 $actor = '';
190 $privacyName = ilObjCmiXapi::PRIVACY_NAME_NONE;
191 if (ilObject::_lookupType($this->objId) == 'lti') {
192 $privacyName = $obj->getProvider()->getPrivacyName();
193 } else {
194 $privacyName = $obj->getPrivacyName();
195 }
196
197 if ($privacyName != ilObjCmiXapi::PRIVACY_NAME_NONE) {
198 $actor = 'statement.actor.name';
199 } else {
200 if ($obj->getContentType() == ilObjCmiXapi::CONT_TYPE_CMI5) {
201 if ($obj->getPublisherId() == '') { // old
202 $actor = 'statement.actor.mbox';
203 } else {
204 $actor = 'statement.actor.account.name';
205 }
206 } else {
207 $actor = 'statement.actor.mbox';
208 }
209 }
210 switch ($this->filter->getOrderField()) {
211 case 'object': // definition/description are displayed in the Table if not empty => sorting not alphabetical on displayed fields
212 $field = 'statement.object.id';
213 break;
214
215 case 'verb':
216 $field = 'statement.verb.id';
217 break;
218
219 case 'actor':
220 $field = $actor;
221 break;
222
223 case 'date':
224 default:
225 $field = 'statement.timestamp';
226 break;
227 }
228
229 $orderingFields = array(
230 $field => $this->filter->getOrderDirection() == 'desc' ? -1 : 1
231 );
232
233 return ['$sort' => $orderingFields];
234 }
static _lookupType(int $id, bool $reference=false)

References ilObject\_lookupType(), ilObjCmiXapi\CONT_TYPE_CMI5, ILIAS\Repository\filter(), ilCmiXapiAbstractReportLinkBuilder\getObj(), and ilObjCmiXapi\PRIVACY_NAME_NONE.

Referenced by buildPipeline().

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

◆ buildPipeline()

ilCmiXapiStatementsReportLinkBuilder::buildPipeline ( )
protected
Returns
array<int, array<string|mixed[]>>

Reimplemented from ilCmiXapiAbstractReportLinkBuilder.

Definition at line 35 of file class.ilCmiXapiStatementsReportLinkBuilder.php.

35 : array
36 {
37 $pipeline = [];
38
39 $pipeline[] = $this->buildFilterStage();
40
41 $pipeline[] = $this->buildOrderingStage();
42
43 $pipeline[] = ['$facet' => [
44 'stage1' => [
45 ['$group' => ['_id' => null, 'count' => ['$sum' => 1]]]
46 ],
47 'stage2' => $this->buildLimitStage()
48 ]
49 ];
50
51 $pipeline[] = ['$unwind' => '$stage1'];
52
53 $pipeline[] = [
54 '$project' => [
55 'maxcount' => '$stage1.count',
56 'statements' => '$stage2.statement'
57 ]
58 ];
59
61 //$log->debug("aggregation pipeline:\n" . json_encode($pipeline, JSON_PRETTY_PRINT));
62
63 return $pipeline;
64 }
static getLogger(string $a_component_id)
Get component logger.
$log
Definition: ltiresult.php:34

References $log, buildFilterStage(), buildLimitStage(), buildOrderingStage(), and ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

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