Merge branch 'MDL-30328' of git://github.com/scriby/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-11-21 02:22:40 +01:00
commit 27e5ce8b9f
3 changed files with 56 additions and 42 deletions

View File

@ -234,15 +234,15 @@ function lti_build_request($instance, $typeconfig, $course) {
}
$requestparams = array(
"resource_link_id" => $instance->id,
"resource_link_title" => $instance->name,
"resource_link_description" => $instance->intro,
"user_id" => $USER->id,
"roles" => $role,
"context_id" => $course->id,
"context_label" => $course->shortname,
"context_title" => $course->fullname,
"launch_presentation_locale" => $locale,
'resource_link_id' => $instance->id,
'resource_link_title' => $instance->name,
'resource_link_description' => $instance->intro,
'user_id' => $USER->id,
'roles' => $role,
'context_id' => $course->id,
'context_label' => $course->shortname,
'context_title' => $course->fullname,
'launch_presentation_locale' => $locale,
);
$placementsecret = $instance->servicesalt;
@ -254,40 +254,32 @@ function lti_build_request($instance, $typeconfig, $course) {
if ( isset($placementsecret) &&
( $typeconfig['acceptgrades'] == LTI_SETTING_ALWAYS ||
( $typeconfig['acceptgrades'] == LTI_SETTING_DELEGATE && $instance->instructorchoiceacceptgrades == LTI_SETTING_ALWAYS ) ) ) {
$requestparams["lis_result_sourcedid"] = $sourcedid;
$requestparams['lis_result_sourcedid'] = $sourcedid;
$serviceurl = $CFG->wwwroot . '/mod/lti/service.php';
//Add outcome service URL
$serviceurl = new moodle_url('/mod/lti/service.php');
$serviceurl = $serviceurl->out();
if ($typeconfig['forcessl'] == '1') {
$serviceurl = lti_ensure_url_is_https($serviceurl);
}
$requestparams["ext_ims_lis_basic_outcome_url"] = $serviceurl;
$requestparams['lis_outcome_service_url'] = $serviceurl;
}
/*if ( isset($placementsecret) &&
( $typeconfig['allowroster'] == LTI_SETTING_ALWAYS ||
( $typeconfig['allowroster'] == LTI_SETTING_DELEGATE && $instance->instructorchoiceallowroster == LTI_SETTING_ALWAYS ) ) ) {
$requestparams["ext_ims_lis_memberships_id"] = $sourcedid;
$requestparams["ext_ims_lis_memberships_url"] = $CFG->wwwroot.'/mod/lti/service.php';
}*/
// Send user's name and email data if appropriate
if ( $typeconfig['sendname'] == LTI_SETTING_ALWAYS ||
( $typeconfig['sendname'] == LTI_SETTING_DELEGATE && $instance->instructorchoicesendname == LTI_SETTING_ALWAYS ) ) {
$requestparams["lis_person_name_given"] = $USER->firstname;
$requestparams["lis_person_name_family"] = $USER->lastname;
$requestparams["lis_person_name_full"] = $USER->firstname." ".$USER->lastname;
$requestparams['lis_person_name_given'] = $USER->firstname;
$requestparams['lis_person_name_family'] = $USER->lastname;
$requestparams['lis_person_name_full'] = $USER->firstname." ".$USER->lastname;
}
if ( $typeconfig['sendemailaddr'] == LTI_SETTING_ALWAYS ||
( $typeconfig['sendemailaddr'] == LTI_SETTING_DELEGATE && $instance->instructorchoicesendemailaddr == LTI_SETTING_ALWAYS ) ) {
$requestparams["lis_person_contact_email_primary"] = $USER->email;
$requestparams['lis_person_contact_email_primary'] = $USER->email;
}
//Add outcome service URL
$url = new moodle_url('/mod/lti/service.php');
$requestparams['lis_outcome_service_url'] = $url->out();
// Concatenate the custom parameters from the administrator and the instructor
// Instructor parameters are only taken into consideration if the administrator
// has giver permission
@ -315,20 +307,19 @@ function lti_build_request($instance, $typeconfig, $course) {
// Make sure we let the tool know what LMS they are being called from
$requestparams["ext_lms"] = "moodle-2";
$requestparams['tool_consumer_info_product_family_code'] = 'moodle';
$requestparams['tool_consumer_info_version'] = strval($CFG->version);
// Add oauth_callback to be compliant with the 1.0A spec
$requestparams["oauth_callback"] = "about:blank";
$requestparams['oauth_callback'] = 'about:blank';
//The submit button needs to be part of the signature as it gets posted with the form.
//This needs to be here to support launching without javascript.
$submittext = get_string('press_to_submit', 'lti');
$requestparams["ext_submit"] = $submittext;
$requestparams['ext_submit'] = $submittext;
$requestparams["lti_version"] = "LTI-1p0";
$requestparams["lti_message_type"] = "basic-lti-launch-request";
/* Suppress this for now - Chuck
if ( $orgdesc ) $requestparams["tool_consumer_instance_description"] = $orgdesc;
*/
$requestparams['lti_version'] = 'LTI-1p0';
$requestparams['lti_message_type'] = 'basic-lti-launch-request';
return $requestparams;
}
@ -432,7 +423,7 @@ function lti_split_custom_parameters($customstr) {
continue;
}
$key = trim($textlib->substr($line, 0, $pos));
$val = trim($textlib->substr($line, $pos+1));
$val = trim($textlib->substr($line, $pos+1, strlen($line)));
$key = lti_map_keyname($key);
$retval['custom_'.$key] = $val;
}

View File

@ -62,7 +62,18 @@ foreach ($body->children() as $child) {
switch ($messagetype) {
case 'replaceResultRequest':
$parsed = lti_parse_grade_replace_message($xml);
try {
$parsed = lti_parse_grade_replace_message($xml);
} catch (Exception $e) {
$responsexml = lti_get_response_xml(
'failure',
$e->getMessage(),
uniqid(),
'replaceResultResponse');
echo $responsexml->asXML();
break;
}
$ltiinstance = $DB->get_record('lti', array('id' => $parsed->instanceid));
@ -71,7 +82,7 @@ switch ($messagetype) {
$gradestatus = lti_update_grade($ltiinstance, $parsed->userid, $parsed->launchid, $parsed->gradeval);
$responsexml = lti_get_response_xml(
$gradestatus ? 'success' : 'error',
$gradestatus ? 'success' : 'failure',
'Grade replace response',
$parsed->messageid,
'replaceResultResponse'
@ -95,14 +106,16 @@ switch ($messagetype) {
$grade = lti_read_grade($ltiinstance, $parsed->userid);
$responsexml = lti_get_response_xml(
isset($grade) ? 'success' : 'error',
isset($grade) ? 'success' : 'failure',
'Result read',
$parsed->messageid,
'readResultResponse'
);
$node = $responsexml->imsx_POXBody->readResultResponse;
$node->addChild('result')->addChild('resultScore')->addChild('textString', isset($grade) ? $grade : '');
$node = $node->addChild('result')->addChild('resultScore');
$node->addChild('language', 'en');
$node->addChild('textString', isset($grade) ? $grade : '');
echo $responsexml->asXML();
@ -118,7 +131,7 @@ switch ($messagetype) {
$gradestatus = lti_delete_grade($ltiinstance, $parsed->userid);
$responsexml = lti_get_response_xml(
$gradestatus ? 'success' : 'error',
$gradestatus ? 'success' : 'failure',
'Grade delete request',
$parsed->messageid,
'deleteResultResponse'

View File

@ -67,7 +67,15 @@ function lti_parse_grade_replace_message($xml) {
$resultjson = json_decode((string)$node);
$node = $xml->imsx_POXBody->replaceResultRequest->resultRecord->result->resultScore->textString;
$grade = floatval((string)$node);
$score = (string) $node;
if ( ! is_numeric($score) ) {
throw new Exception('Score must be numeric');
}
$grade = floatval($score);
if ( $grade < 0.0 || $grade > 1.0 ) {
throw new Exception('Score not between 0.0 and 1.0');
}
$parsed = new stdClass();
$parsed->gradeval = $grade * 100;
@ -164,6 +172,7 @@ function lti_read_grade($ltiinstance, $userid) {
if (isset($grades) && isset($grades->items[0]) && is_array($grades->items[0]->grades)) {
foreach ($grades->items[0]->grades as $agrade) {
$grade = $agrade->grade;
$grade = $grade / 100.0;
break;
}
}
@ -212,3 +221,4 @@ function lti_verify_sourcedid($ltiinstance, $parsed) {
throw new Exception('SourcedId hash not valid');
}
}