ILIAS  release_8 Revision v8.24
Result.php
Go to the documentation of this file.
1<?php
2
20
23
32{
36 public static string $SCOPE = 'https://purl.imsglobal.org/spec/lti-ags/scope/result.readonly';
37
41 public static int $defaultLimit = 500;
42
50 private ?int $limit;
51
59 private bool $pagingMode;
60
68 public function __construct(\ILIAS\LTI\ToolProvider\Platform $platform, string $endpoint, int $limit = null, bool $pagingMode = false)
69 {
71 $this->limit = $limit;
72 $this->pagingMode = $pagingMode;
73 $this->scope = self::$SCOPE;
74 $this->mediaType = 'application/vnd.ims.lis.v2.resultcontainer+json';
75 }
76
82 public function getAll(int $limit = null)
83 {
84 $params = array();
85 if (is_null($limit)) {
87 }
88 if (is_null($limit)) {
90 }
91 if (!empty($limit)) {
92 $params['limit'] = $limit;
93 }
94 $outcomes = array();
96 do {
97 $http = $this->send('GET', $params);
98 $url = '';
99 if ($http->ok) {
100 if (!empty($http->responseJson)) {
101 foreach ($http->responseJson as $outcome) {
102 $outcomes[] = self::getOutcome($outcome);
103 }
104 }
105 if (!$this->pagingMode && $http->hasRelativeLink('next')) {
106 $url = $http->getRelativeLink('next');
107 $this->endpoint = $url;
108 $params = array();
109 }
110 } else {
111 $outcomes = false;
112 }
113 } while ($url);
114 $this->endpoint = $endpoint;
115
116 return $outcomes;
117 }
118
124 public function get(User $user)
125 {
126 $params = array('user_id' => $user->ltiUserId);
127 $http = $this->send('GET', $params);
128 if ($http->ok) {
129 if (!empty($http->responseJson)) {
130 $outcome = self::getOutcome(reset($http->responseJson));
131 } else {
132 $outcome = null;
133 }
134 return $outcome;
135 } else {
136 return false;
137 }
138 }
139
140 ###
141 ### PRIVATE METHOD
142 ###
143
144 private static function getOutcome(object $json): Outcome
145 {
146 $outcome = new Outcome();
147 $outcome->ltiUserId = $json->userId;
148 if (isset($json->resultScore)) {
149 $outcome->setValue($json->resultScore);
150 }
151 if (isset($json->resultMaximum)) {
152 $outcome->setPointsPossible($json->resultMaximum);
153 }
154 if (isset($json->comment)) {
155 $outcome->comment = $json->comment;
156 }
157
158 return $outcome;
159 }
160}
Class to represent an outcome.
Definition: Outcome.php:29
Class to represent a platform.
Definition: Platform.php:36
Class to implement the Assignment and Grade services.
Class to implement the Result service.
Definition: Result.php:32
bool $pagingMode
Whether requests should be made one page at a time when a limit is set.
Definition: Result.php:59
static getOutcome(object $json)
Definition: Result.php:144
static string $SCOPE
Access scope.
Definition: Result.php:36
static int $defaultLimit
Default limit on size of container to be returned from requests.
Definition: Result.php:41
int $limit
Limit on size of container to be returned from requests.
Definition: Result.php:50
getAll(int $limit=null)
Retrieve all outcomes for a line item.
Definition: Result.php:82
__construct(\ILIAS\LTI\ToolProvider\Platform $platform, string $endpoint, int $limit=null, bool $pagingMode=false)
Class constructor.
Definition: Result.php:68
string $endpoint
Service endpoint.
Definition: Service.php:47
HTTPMessage $http
HttpMessage object for last service request.
Definition: Service.php:75
send(string $method, array $parameters=array(), string $body=null)
Send a service request.
Definition: Service.php:130
Platform $platform
Platform for this service request.
Definition: Service.php:68
Class to represent a platform user.
Definition: User.php:31
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url