19 declare(strict_types=1);
63 ?
string $scope = self::DELETE_SCOPE_FILTERED,
67 require_once __DIR__ .
'/../XapiProxy/vendor/autoload.php';
69 $this->objId = $obj_id;
71 $this->activityId = $activity_id;
72 $this->usrId = $usr_id;
76 $this->endpointDefault = $this->lrsType->getLrsEndpoint();
79 'X-Experience-API-Version' =>
'1.0.3' 82 $this->defaultHeaders[
'Authorization'] = $this->lrsType->getBasicAuth();
90 public function delete():
bool 94 $resStatements = $allResponses[
'statements'];
95 $resStates = $allResponses[
'states'];
96 $defaultRejected = isset($resStatements[
'default']) && isset($resStatements[
'default'][
'state']) && $resStatements[
'default'][
'state'] ===
'rejected';
99 if (isset($resStatements[
'default']) && isset($resStatements[
'default'][
'value'])) {
100 $res = $resStatements[
'default'][
'value'];
101 $resBody = json_decode((
string)
$res->getBody(),
true);
102 $resArr[] = $resBody[
'_id'];
104 if (count($resArr) == 0) {
105 $this->log->debug(
"No data deleted");
106 return !$defaultRejected;
112 while ($t < $maxtime) {
118 $resBody = json_decode((
string)
$res->getBody(),
true);
119 if ($resBody && $resBody[
'edges'] && count($resBody[
'edges']) == 1) {
120 $doneDefault = $resBody[
'edges'][0][
'node'][
'done'];
121 $this->log->debug(
"doneDefault: " . $doneDefault);
143 if ($this->scope === self::DELETE_SCOPE_FILTERED) {
147 if ($this->scope === self::DELETE_SCOPE_ALL) {
150 if ($this->scope === self::DELETE_SCOPE_OWN) {
154 $this->log->debug(
'error: could not build filter');
157 $cf = array(
'filter' =>
$f);
158 $body = json_encode($cf);
159 $this->defaultHeaders[
'Content-Type'] =
'application/json; charset=utf-8';
160 $defaultUrl = $this->lrsType->getLrsEndpointDeleteLink();
162 $promisesStatements = [
163 'default' => $this->
client->sendAsync($defaultRequest)
165 $promisesStates = array();
168 foreach ($urls as $i => $v) {
170 $promisesStates[
'default' . $i] = $this->
client->sendAsync(
$r);
178 $response[
'statements'] = GuzzleHttp\Promise\Utils::settle($promisesStatements)->wait();
179 if ($deleteState && count($promisesStates) > 0) {
180 $response[
'states'] = GuzzleHttp\Promise\Utils::settle($promisesStates)->wait();
183 $this->log->debug(
'error:' . $e->getMessage());
192 if (is_null($scope)) {
195 if ($scope === self::DELETE_SCOPE_OWN) {
197 if (count(
$f) == 0) {
201 if ($scope === self::DELETE_SCOPE_FILTERED) {
204 if ($scope === self::DELETE_SCOPE_ALL) {
207 $pipeline[] = array(
'$match' =>
$f);
208 $pipeline[] = array(
'$count' =>
'count');
209 $pquery = urlencode(json_encode($pipeline));
210 $query =
"pipeline={$pquery}";
211 $purl = $this->lrsType->getLrsEndpointStatementsAggregationLink();
216 $cnt = json_decode(
$response->getBody());
217 return (
int) $cnt[0]->count;
219 throw new Exception(
"LRS Connection Problems");
231 $defaultUrl = $this->
getBatchUrl($this->lrsType->getLrsEndpointBatchLink(), $batchId[0]);
234 'default' => $this->
client->sendAsync($defaultRequest)
238 $response = GuzzleHttp\Promise\Utils::settle($promises)->wait();
240 $this->log->debug(
'error:' . $e->getMessage());
251 $f = urlencode(json_encode(
$f));
260 foreach($states as $i => $v) {
271 $f[
'statement.object.objectType'] =
'Activity';
272 $f[
'statement.object.id'] = [
273 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 276 $f[
'statement.actor.objectType'] =
'Agent';
282 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
284 if (count(
$f[
'$or']) == 0) {
297 $f[
'statement.object.objectType'] =
'Activity';
298 $f[
'statement.object.id'] = [
299 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 302 $f[
'statement.actor.objectType'] =
'Agent';
304 if ($this->
filter->getActor()) {
306 if ($cmixUser->getUsrId() == $this->
filter->getActor()->getUsrId()) {
307 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
312 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
316 if ($this->
filter->getVerb()) {
317 $f[
'statement.verb.id'] = $this->
filter->getVerb();
320 if ($this->
filter->getStartDate() || $this->
filter->getEndDate()) {
321 $f[
'statement.timestamp'] = array();
323 if ($this->
filter->getStartDate()) {
324 $f[
'statement.timestamp'][
'$gt'] = $this->
filter->getStartDate()->toXapiTimestamp();
327 if ($this->
filter->getEndDate()) {
328 $f[
'statement.timestamp'][
'$lt'] = $this->
filter->getEndDate()->toXapiTimestamp();
332 if (count(
$f[
'$or']) == 0) {
344 $f[
'statement.object.objectType'] =
'Activity';
345 $f[
'statement.object.id'] = [
346 '$regex' =>
'^' . preg_quote($this->activityId) .
'' 348 $f[
'statement.actor.objectType'] =
'Agent';
350 $usrId = ($this->usrId !==
null) ? $this->usrId : $DIC->user()->getId();
353 foreach ($cmixUsers as $cmixUser) {
354 $f[
'$or'][] = [
'statement.actor.mbox' =>
"mailto:{$cmixUser->getUsrIdent()}"];
356 if (count(
$f[
'$or']) == 0) {
368 if ($this->scope === self::DELETE_SCOPE_FILTERED && $this->
filter->getActor()) {
370 if ($cmixUser->getUsrId() == $this->
filter->getActor()->getUsrId()) {
371 $user = $cmixUser->getUsrIdent();
372 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
377 if ($this->scope === self::DELETE_SCOPE_OWN) {
378 $usrId = ($this->usrId !==
null) ? $this->usrId : $DIC->user()->getId();
380 if ((
int) $cmixUser->getUsrId() ===
$usrId) {
381 $user = $cmixUser->getUsrIdent();
382 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
387 if ($this->scope === self::DELETE_SCOPE_ALL) {
390 $user = $cmixUser->getUsrIdent();
391 $ret[] =
'activityId=' . urlencode($this->activityId) .
'&agent=' . urlencode(
'{"mbox":"mailto:' . $user .
'"}');
400 if ($this->scope === self::DELETE_SCOPE_ALL || $this->scope === self::DELETE_SCOPE_OWN) {
403 if ($this->
filter->getActor()) {
404 if ($this->
filter->getVerb() || $this->
filter->getStartDate() || $this->
filter->getEndDate()) {
416 if ($this->scope === self::DELETE_SCOPE_ALL) {
421 if ($this->scope === self::DELETE_SCOPE_OWN) {
422 $usrId = ($this->usrId !==
null) ? [$this->usrId] : [$DIC->user()->getId()];
425 if ($this->scope === self::DELETE_SCOPE_FILTERED) {
427 $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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const ILIAS_VERSION_NUMERIC
checkDeleteUsersForObject()
static deleteUsersForObject(int $objId, ?array $users=[])
const DELETE_SCOPE_FILTERED
GuzzleHttp Client $client
static getInstancesByObjectIdAndUsrId(int $objId, int $usrId)
ilCmiXapiStatementsReportFilter $filter
client()
description: > This example shows how a Progress Bar can be rendered and used on the client...
__construct(int $obj_id, int $type_id, string $activity_id, ?int $usr_id=null, ?string $scope=self::DELETE_SCOPE_FILTERED, ?ilCmiXapiStatementsReportFilter $filter=null)
_lookUpDataCount($scope=null)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static getUsersForObject(int $objId, bool $asUsrId=false)