ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
Result.php
Go to the documentation of this file.
1 <?php
2 
20 
23 
31 class Result extends AssignmentGrade
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  {
70  parent::__construct($platform, $endpoint, '/results');
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)) {
86  $limit = $this->limit;
87  }
88  if (is_null($limit)) {
89  $limit = self::$defaultLimit;
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 implement the Assignment and Grade services.
Class to represent a platform.
Definition: Platform.php:35
bool $pagingMode
Whether requests should be made one page at a time when a limit is set.
Definition: Result.php:59
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
Class to represent a platform user.
Definition: User.php:30
Class ChatMainBarProvider .
string $endpoint
Service endpoint.
Definition: Service.php:47
send(string $method, array $parameters=array(), string $body=null)
Send a service request.
Definition: Service.php:130
Class to implement the Result service.
Definition: Result.php:31
HTTPMessage $http
HttpMessage object for last service request.
Definition: Service.php:75
static getOutcome(object $json)
Definition: Result.php:144
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
static string $SCOPE
Access scope.
Definition: Result.php:36
getAll(int $limit=null)
Retrieve all outcomes for a line item.
Definition: Result.php:82
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url
Class to represent an outcome.
Definition: Outcome.php:28
Platform $platform
Platform for this service request.
Definition: Service.php:68
__construct(\ILIAS\LTI\ToolProvider\Platform $platform, string $endpoint, int $limit=null, bool $pagingMode=false)
Class constructor.
Definition: Result.php:68