Skip to content

Commit

Permalink
MDL-68800 mod_lti: apply format fixes per guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
claudevervoort committed May 26, 2020
1 parent 71965a8 commit 6f85c23
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 57 deletions.
8 changes: 4 additions & 4 deletions mod/lti/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ function lti_get_launch_data($instance, $nonce = '') {

$launchcontainer = lti_get_launch_container($instance, $typeconfig);
$returnurlparams = array('course' => $course->id,
'launch_container' => $launchcontainer,
'instanceid' => $instance->id,
'sesskey' => sesskey());
'launch_container' => $launchcontainer,
'instanceid' => $instance->id,
'sesskey' => sesskey());

// Add the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns.
$url = new \moodle_url('/mod/lti/return.php', $returnurlparams);
Expand Down Expand Up @@ -1185,7 +1185,7 @@ function lti_build_content_item_selection_request($id, $course, moodle_url $retu
$services = lti_get_services();
foreach ($services as $service) {
$serviceparameters = $service->get_launch_parameters('ContentItemSelectionRequest',
$course->id, $USER->id , $id);
$course->id, $USER->id , $id);
foreach ($serviceparameters as $paramkey => $paramvalue) {
$requestparams['custom_' . $paramkey] = lti_parse_custom_parameter($toolproxy, $tool, $requestparams, $paramvalue,
$islti2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function get_request($response, $item, $typeid) {

$response->set_content_type($this->formats[0]);
$lineitem = gradebookservices::item_for_json($item, substr(parent::get_endpoint(),
0, strrpos(parent::get_endpoint(), "/", -10)), $typeid);
0, strrpos(parent::get_endpoint(), "/", -10)), $typeid);
$response->set_body(json_encode($lineitem));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function execute($response) {
$typeid = $this->get_service()->get_type()->id;
if (empty($contextid) || !($container ^ ($response->get_request_method() === self::HTTP_POST)) ||
(!empty($contenttype) && !in_array($contenttype, $this->formats))) {
throw new \Exception('No context or unsupported content type', 400);
throw new \Exception('No context or unsupported content type', 400);
}
if (!($course = $DB->get_record('course', array('id' => $contextid), 'id', IGNORE_MISSING))) {
throw new \Exception("Not Found: Course {$contextid} doesn't exist", 404);
Expand Down Expand Up @@ -267,16 +267,8 @@ private function get_json_for_post_request($body, $contextid, $typeid) {
$baseurl = lti_get_type_type_config($typeid)->lti_toolurl;
}
$gradebookservices = new gradebookservices();
$id = $gradebookservices->add_standalone_lineitem($contextid,
$json->label,
$max,
$baseurl,
$ltilinkid,
$resourceid,
$tag,
$typeid,
$toolproxyid);

$id = $gradebookservices->add_standalone_lineitem($contextid, $json->label,
$max, $baseurl, $ltilinkid, $resourceid, $tag, $typeid, $toolproxyid);
if (is_null($typeid)) {
$json->id = parent::get_endpoint() . "/{$id}/lineitem";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function get_launch_parameters($messagetype, $courseid, $user, $typeid, $
// Only inject parameters if the service is enabled for this tool.
if (isset($this->get_typeconfig()['ltiservice_gradesynchronization'])) {
if ($this->get_typeconfig()['ltiservice_gradesynchronization'] == self::GRADEBOOKSERVICES_READ ||
$this->get_typeconfig()['ltiservice_gradesynchronization'] == self::GRADEBOOKSERVICES_FULL) {
$this->get_typeconfig()['ltiservice_gradesynchronization'] == self::GRADEBOOKSERVICES_FULL) {
// Check for used in context is only needed because there is no explicit site tool - course relation.
if ($this->is_allowed_in_context($typeid, $courseid)) {
$id = null;
Expand Down Expand Up @@ -235,12 +235,10 @@ public function get_lineitems($courseid, $resourceid, $ltilinkid, $tag, $limitfr
array_push($lineitemstoreturn, $lineitem);
}
}
} else if (($lineitem->itemtype == 'mod'
&& $lineitem->itemmodule == 'lti'
&& !isset($resourceid)
&& !isset($tag)
&& (!isset($ltilinkid) || (isset($ltilinkid)
&& $lineitem->iteminstance == $ltilinkid)))) {
} else if (($lineitem->itemtype == 'mod' && $lineitem->itemmodule == 'lti'
&& !isset($resourceid) && !isset($tag)
&& (!isset($ltilinkid) || (isset($ltilinkid)
&& $lineitem->iteminstance == $ltilinkid)))) {
// We will need to check if the activity related belongs to our tool proxy.
$ltiactivity = $DB->get_record('lti', array('id' => $lineitem->iteminstance));
if (($ltiactivity) && (isset($ltiactivity->typeid))) {
Expand Down Expand Up @@ -343,15 +341,9 @@ public function get_lineitem($courseid, $itemid, $typeid) {
*
* @return int id of the created gradeitem
*/
public function add_standalone_lineitem(string $courseid,
string $label,
float $maximumscore,
string $baseurl,
?int $ltilinkid,
?string $resourceid,
?string $tag,
int $typeid,
int $toolproxyid = null) : int {
public function add_standalone_lineitem(string $courseid, string $label, float $maximumscore,
string $baseurl, ?int $ltilinkid, ?string $resourceid, ?string $tag, int $typeid,
int $toolproxyid = null) : int {
global $DB;
$params = array();
$params['itemname'] = $label;
Expand Down Expand Up @@ -428,7 +420,7 @@ public function save_grade_item($gradeitem, $score, $userid) {
}
$feedbackformat = FORMAT_MOODLE;
$feedback = null;
if (isset($score->comment) && !empty($score->comment)) {
if (!empty($score->comment)) {
$feedback = $score->comment;
$feedbackformat = FORMAT_PLAIN;
}
Expand All @@ -447,9 +439,8 @@ public function save_grade_item($gradeitem, $score, $userid) {
$grade->feedback = $feedback;
$grade->rawgrade = $finalgrade;
$status = grade_update($source, $gradeitem->courseid,
$gradeitem->itemtype, $gradeitem->itemmodule,
$gradeitem->iteminstance, $gradeitem->itemnumber,
$grade);
$gradeitem->itemtype, $gradeitem->itemmodule,
$gradeitem->iteminstance, $gradeitem->itemnumber, $grade);

$result = ($status == GRADE_UPDATE_OK);
}
Expand Down Expand Up @@ -621,9 +612,7 @@ public static function check_lti_1x_id($linkid, $course, $typeid) {
* @param string|null $tag The tag to apply to the lineitem. If empty string which will be stored as null.
*
*/
public static function update_coupled_gradebookservices(object $ltiinstance,
?string $resourceid,
?string $tag) : void {
public static function update_coupled_gradebookservices(object $ltiinstance, ?string $resourceid, ?string $tag) : void {
global $DB;

if ($ltiinstance && $ltiinstance->typeid) {
Expand Down
29 changes: 11 additions & 18 deletions mod/lti/service/gradebookservices/tests/gradebookservices_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ public function test_get_launch_parameters_decoupled() {
* @param string|null $resourceid resourceid the line item should have
* @param string|null $tag tag the line item should have
*/
private function assert_lineitems(object $course,
int $typeid,
string $label,
?object $ltiinstance,
?string $resourceid,
?string $tag) : void {
private function assert_lineitems(object $course, int $typeid,
string $label, ?object $ltiinstance, ?string $resourceid, ?string $tag) : void {
$gbservice = new gradebookservices();
$gradeitems = $gbservice->get_lineitems($course->id, null, null, null, null, null, $typeid);

Expand Down Expand Up @@ -211,11 +207,11 @@ private function assert_lineitems(object $course,
private function create_graded_lti(int $typeid, object $course, ?string $resourceid, ?string $tag) : object {

$lti = ['course' => $course->id,
'typeid' => $typeid,
'instructorchoiceacceptgrades' => LTI_SETTING_ALWAYS,
'grade' => 10,
'lineitemresourceid' => $resourceid,
'lineitemtag' => $tag];
'typeid' => $typeid,
'instructorchoiceacceptgrades' => LTI_SETTING_ALWAYS,
'grade' => 10,
'lineitemresourceid' => $resourceid,
'lineitemtag' => $tag];

return $this->getDataGenerator()->create_module('lti', $lti, array());
}
Expand All @@ -231,8 +227,8 @@ private function create_graded_lti(int $typeid, object $course, ?string $resourc
private function create_notgraded_lti(int $typeid, object $course) : object {

$lti = ['course' => $course->id,
'typeid' => $typeid,
'instructorchoiceacceptgrades' => LTI_SETTING_NEVER];
'typeid' => $typeid,
'instructorchoiceacceptgrades' => LTI_SETTING_NEVER];

return $this->getDataGenerator()->create_module('lti', $lti, array());
}
Expand All @@ -247,11 +243,8 @@ private function create_notgraded_lti(int $typeid, object $course) : object {
* @param int|null $ltiinstanceid Id of the LTI instance the standalone line item will be related to.
*
*/
private function create_standalone_lineitem(int $courseid,
int $typeid,
?string $resourceid,
?string $tag,
int $ltiinstanceid = null) : void {
private function create_standalone_lineitem(int $courseid, int $typeid, ?string $resourceid,
?string $tag, int $ltiinstanceid = null) : void {
$gbservice = new gradebookservices();
$gbservice->add_standalone_lineitem($courseid,
"manualtest",
Expand Down

0 comments on commit 6f85c23

Please sign in to comment.