ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 }
169 else {
170 $actor['$or'] = [];
171 foreach (ilCmiXapiUser::getUsersForObject($this->getObjId()) as $cmixUser) {
172 $actor['$or'][] = ['statement.actor.mbox' => "mailto:{$cmixUser->getUsrIdent()}"];
173 }
174 }
175 }
176 $stage['$and'] = [];
177 $stage['$and'][] = $activityId;
178 if (count($actor) > 0) {
179 $stage['$and'][] = $actor;
180 }
181 return array('$match' => $stage);
182 }
static getUserIdents(int $objId, int $usrId)
static getUsersForObject(int $objId, bool $asUsrId=false)
filter(string $filter_id, $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 187 of file class.ilCmiXapiStatementsReportLinkBuilder.php.

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