-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from IMSGlobal/groups_and_sub_review
Add support for the groups service and submission review
- Loading branch information
Showing
7 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class LTI_Course_Groups_Service { | ||
|
||
private $service_connector; | ||
private $service_data; | ||
|
||
public function __construct(LTI_Service_Connector $service_connector, $service_data) { | ||
$this->service_connector = $service_connector; | ||
$this->service_data = $service_data; | ||
} | ||
|
||
public function get_groups() { | ||
|
||
$groups = []; | ||
|
||
$next_page = $this->service_data['context_groups_url']; | ||
|
||
while ($next_page) { | ||
$page = $this->service_connector->make_service_request( | ||
$this->service_data['scope'], | ||
'GET', | ||
$next_page, | ||
null, | ||
null, | ||
'application/vnd.ims.lti-gs.v1.contextgroupcontainer+json' | ||
); | ||
|
||
$groups = array_merge($groups, $page['body']['groups']); | ||
|
||
$next_page = false; | ||
foreach($page['headers'] as $header) { | ||
if (preg_match(LTI_Service_Connector::NEXT_PAGE_REGEX, $header, $matches)) { | ||
$next_page = $matches[1]; | ||
break; | ||
} | ||
} | ||
} | ||
return $groups; | ||
|
||
} | ||
|
||
public function get_sets() { | ||
|
||
$sets = []; | ||
|
||
// Sets are optional. | ||
if (!isset($this->service_data['context_group_sets_url'])) { | ||
return []; | ||
} | ||
|
||
$next_page = $this->service_data['context_group_sets_url']; | ||
|
||
while ($next_page) { | ||
$page = $this->service_connector->make_service_request( | ||
$this->service_data['scope'], | ||
'GET', | ||
$next_page, | ||
null, | ||
null, | ||
'application/vnd.ims.lti-gs.v1.contextgroupcontainer+json' | ||
); | ||
|
||
$sets = array_merge($sets, $page['body']['sets']); | ||
|
||
$next_page = false; | ||
foreach($page['headers'] as $header) { | ||
if (preg_match(LTI_Service_Connector::NEXT_PAGE_REGEX, $header, $matches)) { | ||
$next_page = $matches[1]; | ||
break; | ||
} | ||
} | ||
} | ||
return $sets; | ||
|
||
} | ||
|
||
public function get_groups_by_set() { | ||
$groups = $this->get_groups(); | ||
$sets = $this->get_sets(); | ||
|
||
$groups_by_set = []; | ||
$unsetted = []; | ||
|
||
foreach ($sets as $key => $set) { | ||
$groups_by_set[$set['id']] = $set; | ||
$groups_by_set[$set['id']]['groups'] = []; | ||
} | ||
|
||
foreach ($groups as $key => $group) { | ||
if (isset($group['set_id']) && isset($groups_by_set[$group['set_id']])) { | ||
$groups_by_set[$group['set_id']]['groups'][$group['id']] = $group; | ||
} else { | ||
$unsetted[$group['id']] = $group; | ||
} | ||
} | ||
|
||
if (!empty($unsetted)) { | ||
$groups_by_set['none'] = [ | ||
"name" => "None", | ||
"id" => "none", | ||
"groups" => $unsetted, | ||
]; | ||
} | ||
|
||
return $groups_by_set; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class LTI_Grade_Submission_Review { | ||
private $reviewable_status; | ||
private $label; | ||
private $url; | ||
private $custom; | ||
|
||
/** | ||
* Static function to allow for method chaining without having to assign to a variable first. | ||
*/ | ||
public static function new() { | ||
return new LTI_Grade_Submission_Review(); | ||
} | ||
|
||
public function get_reviewable_status() { | ||
return $this->reviewable_status; | ||
} | ||
|
||
public function set_reviewable_status($value) { | ||
$this->reviewable_status = $value; | ||
return $this; | ||
} | ||
|
||
public function get_label() { | ||
return $this->label; | ||
} | ||
|
||
public function set_label($value) { | ||
$this->label = $value; | ||
return $this; | ||
} | ||
|
||
public function get_url() { | ||
return $this->url; | ||
} | ||
|
||
public function set_url($url) { | ||
$this->url = $url; | ||
return $this; | ||
} | ||
|
||
public function get_custom() { | ||
return $this->custom; | ||
} | ||
|
||
public function set_custom($value) { | ||
$this->custom = $value; | ||
return $this; | ||
} | ||
|
||
public function __toString() { | ||
return json_encode(array_filter([ | ||
"reviewableStatus" => $this->reviewable_status, | ||
"label" => $this->label, | ||
"url" => $this->url, | ||
"custom" => $this->custom, | ||
])); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/lti/message_validators/submission_review_message_validator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
namespace IMSGlobal\LTI; | ||
|
||
class Submission_Review_Message_Validator implements Message_Validator { | ||
public function can_validate($jwt_body) { | ||
return $jwt_body['https://purl.imsglobal.org/spec/lti/claim/message_type'] === 'LtiSubmissionReviewRequest'; | ||
} | ||
|
||
public function validate($jwt_body) { | ||
if (empty($jwt_body['sub'])) { | ||
throw new LTI_Exception('Must have a user (sub)'); | ||
} | ||
if ($jwt_body['https://purl.imsglobal.org/spec/lti/claim/version'] !== '1.3.0') { | ||
throw new LTI_Exception('Incorrect version, expected 1.3.0'); | ||
} | ||
if (!isset($jwt_body['https://purl.imsglobal.org/spec/lti/claim/roles'])) { | ||
throw new LTI_Exception('Missing Roles Claim'); | ||
} | ||
if (empty($jwt_body['https://purl.imsglobal.org/spec/lti/claim/resource_link']['id'])) { | ||
throw new LTI_Exception('Missing Resource Link Id'); | ||
} | ||
if (empty($jwt_body['https://purl.imsglobal.org/spec/lti/claim/for_user'])) { | ||
throw new LTI_Exception('Missing For User'); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
?> |