19 declare(strict_types=1);
63 ?
string $scope = self::DELETE_SCOPE_FILTERED,
66 $this->objId = $obj_id;
68 $this->activityId = $activity_id;
69 $this->usrId = $usr_id;
73 $this->endpointDefault = $this->lrsType->getLrsEndpoint();
76 'X-Experience-API-Version' =>
'1.0.3' 79 $this->defaultHeaders[
'Authorization'] = $this->lrsType->getBasicAuth();
87 public function delete():
bool 91 $resStatements = $allResponses[
'statements'];
92 $resStates = $allResponses[
'states'];
93 $defaultRejected = isset($resStatements[
'default']) && isset($resStatements[
'default'][
'state']) && $resStatements[
'default'][
'state'] ===
'rejected';
96 if (isset($resStatements[
'default']) && isset($resStatements[
'default'][
'value'])) {
97 $res = $resStatements[
'default'][
'value'];
98 $resBody = json_decode((
string)
$res->getBody(),
true);
99 $resArr[] = $resBody[
'_id'];
101 if (count($resArr) == 0) {
102 $this->log->debug(
"No data deleted");
103 return !$defaultRejected;
109 while ($t < $maxtime) {
115 $resBody = json_decode((
string)
$res->getBody(),
true);
116 if ($resBody && $resBody[
'edges'] && count($resBody[
'edges']) == 1) {
117 $doneDefault = $resBody[
'edges'][0][
'node'][
'done'];
118 $this->log->debug(
"doneDefault: " . $doneDefault);
140 if ($this->scope === self::DELETE_SCOPE_FILTERED) {
144 if ($this->scope === self::DELETE_SCOPE_ALL) {
147 if ($this->scope === self::DELETE_SCOPE_OWN) {
151 $this->log->debug(
'error: could not build filter');
154 $cf = array(
'filter' =>
$f);
155 $body = json_encode($cf);
156 $this->defaultHeaders[
'Content-Type'] =
'application/json; charset=utf-8';
157 $defaultUrl = $this->lrsType->getLrsEndpointDeleteLink();
159 $promisesStatements = [
160 'default' => $this->client->sendAsync($defaultRequest)
162 $promisesStates = array();
165 foreach ($urls as $i => $v) {
167 $promisesStates[
'default' . $i] = $this->client->sendAsync(
$r);
175 $response[
'statements'] = GuzzleHttp\Promise\Utils::settle($promisesStatements)->wait();
176 if ($deleteState && count($promisesStates) > 0) {
177 $response[
'states'] = GuzzleHttp\Promise\Utils::settle($promisesStates)->wait();
180 $this->log->debug(
'error:' . $e->getMessage());
189 if (is_null($scope)) {
192 if ($scope === self::DELETE_SCOPE_OWN) {
194 if (count(
$f) == 0) {
198 if ($scope === self::DELETE_SCOPE_FILTERED) {
201 if ($scope === self::DELETE_SCOPE_ALL) {
204 $pipeline[] = array(
'$match' =>
$f);
205 $pipeline[] = array(
'$count' =>
'count');
206 $pquery = urlencode(json_encode($pipeline));
207 $query =
"pipeline={$pquery}";
208 $purl = $this->lrsType->getLrsEndpointStatementsAggregationLink();
212 $response = $this->client->sendAsync($request)->wait();
213 $cnt = json_decode(
$response->getBody());
214 return (
int) $cnt[0]->count;
216 throw new Exception(
"LRS Connection Problems");
228 $defaultUrl = $this->
getBatchUrl($this->lrsType->getLrsEndpointBatchLink(), $batchId[0]);
231 'default' => $this->client->sendAsync($defaultRequest)
235 $response = GuzzleHttp\Promise\Utils::settle($promises)->wait();
237 $this->log->debug(
'error:' . $e->getMessage());
248 $f = urlencode(json_encode(
$f));
257 foreach($states as $i => $v) {
268 $f[
'statement.object.objectType'] =
'Activity';
269 $f[
'statement.object.id'] = [
270 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 273 $f[
'statement.actor.objectType'] =
'Agent';
279 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
281 if (count(
$f[
'$or']) == 0) {
294 $f[
'statement.object.objectType'] =
'Activity';
295 $f[
'statement.object.id'] = [
296 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 299 $f[
'statement.actor.objectType'] =
'Agent';
301 if ($this->
filter->getActor()) {
303 if ($cmixUser->getUsrId() == $this->
filter->getActor()->getUsrId()) {
304 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
309 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
313 if ($this->
filter->getVerb()) {
314 $f[
'statement.verb.id'] = $this->
filter->getVerb();
317 if ($this->
filter->getStartDate() || $this->
filter->getEndDate()) {
318 $f[
'statement.timestamp'] = array();
320 if ($this->
filter->getStartDate()) {
321 $f[
'statement.timestamp'][
'$gt'] = $this->
filter->getStartDate()->toXapiTimestamp();
324 if ($this->
filter->getEndDate()) {
325 $f[
'statement.timestamp'][
'$lt'] = $this->
filter->getEndDate()->toXapiTimestamp();
329 if (count(
$f[
'$or']) == 0) {
341 $f[
'statement.object.objectType'] =
'Activity';
342 $f[
'statement.object.id'] = [
343 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 345 $f[
'statement.actor.objectType'] =
'Agent';
347 $usrId = ($this->usrId !== null) ? $this->usrId : $DIC->user()->getId();
350 foreach ($cmixUsers as $cmixUser) {
351 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
353 if (count(
$f[
'$or']) == 0) {
365 if ($this->scope === self::DELETE_SCOPE_FILTERED && $this->
filter->getActor()) {
367 if ($cmixUser->getUsrId() == $this->
filter->getActor()->getUsrId()) {
368 $user = $cmixUser->getUsrIdent();
369 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
374 if ($this->scope === self::DELETE_SCOPE_OWN) {
375 $usrId = ($this->usrId !== null) ? $this->usrId : $DIC->user()->getId();
377 if ((
int) $cmixUser->getUsrId() ===
$usrId) {
378 $user = $cmixUser->getUsrIdent();
379 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
384 if ($this->scope === self::DELETE_SCOPE_ALL) {
387 $user = $cmixUser->getUsrIdent();
388 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
397 if ($this->scope === self::DELETE_SCOPE_ALL || $this->scope === self::DELETE_SCOPE_OWN) {
400 if ($this->
filter->getActor()) {
401 if ($this->
filter->getVerb() || $this->
filter->getStartDate() || $this->
filter->getEndDate()) {
413 if ($this->scope === self::DELETE_SCOPE_ALL) {
418 if ($this->scope === self::DELETE_SCOPE_OWN) {
419 $usrId = ($this->usrId !== null) ? [$this->usrId] : [$DIC->user()->getId()];
422 if ($this->scope === self::DELETE_SCOPE_FILTERED) {
424 $usrId = [$this->
filter->getActor()->getUsrId()];
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
getBatchUrl(string $url, string $batchId)
static getLogger(string $a_component_id)
Get component logger.
Class ilCmiXapiStatementsDeleteRequest.
ilCmiXapiLrsType $lrsType
queryBatch(array $batchId)
checkDeleteUsersForObject()
static deleteUsersForObject(int $objId, ?array $users=[])
__construct(int $obj_id, int $type_id, string $activity_id, int $usr_id=null, ?string $scope=self::DELETE_SCOPE_FILTERED, ?ilCmiXapiStatementsReportFilter $filter=null)
const DELETE_SCOPE_FILTERED
GuzzleHttp Client $client
static getInstancesByObjectIdAndUsrId(int $objId, int $usrId)
ilCmiXapiStatementsReportFilter $filter
_lookUpDataCount($scope=null)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static getUsersForObject(int $objId, bool $asUsrId=false)