-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
74 deletions.
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 |
---|---|---|
|
@@ -19,10 +19,12 @@ | |
|
||
namespace mod_kialo\grading; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Represents a line item in the LTI 1.3 Assignment and Grading Service. | ||
* | ||
* @package mod_kialo | ||
* @copyright 2023 onwards, Kialo GmbH <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class line_item { | ||
/** | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,58 +15,50 @@ | |
// along with Moodle. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* When an LTI message is launching a resource associated to one and only one lineitem, | ||
* the claim must include the endpoint URL for accessing the associated line item; | ||
* in all other cases, this property must be either blank or not included in the claim. | ||
* | ||
* Handles GET and POST (/scores) requests for LTI 1.3 Assignment and Grading Service line items. | ||
* See LTI 1.3 Assignment and Grading Service specification: https://www.imsglobal.org/spec/lti-ags/v2p0. | ||
* | ||
* @package mod_kialo | ||
* @copyright 2023 onwards, Kialo GmbH <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* | ||
* @var moodle_database $DB | ||
* @var stdClass $CFG see moodle's config.php | ||
*/ | ||
|
||
// phpcs:disable moodle.Files.RequireLogin.Missing | ||
|
||
require_once(__DIR__ . '/../../config.php'); | ||
require_once(__DIR__ . '/lib.php'); | ||
require_once(__DIR__ . '/constants.php'); | ||
require_once(__DIR__ . '/vendor/autoload.php'); | ||
require_once($CFG->libdir . '/gradelib.php'); | ||
|
||
use mod_kialo\grading\line_item; | ||
use mod_kialo\kialo_logger; | ||
use mod_kialo\lti_flow; | ||
use OAT\Library\Lti1p3Core\Exception\LtiException; | ||
|
||
$logger = new kialo_logger("lti_lineitem"); | ||
$logger->info("LTI lineitem request received.", $_POST ?? $_GET ?? []); | ||
|
||
//lti_flow::authenticate_service_request(MOD_KIALO_LTI_AGS_SCOPES); | ||
lti_flow::authenticate_service_request(MOD_KIALO_LTI_AGS_SCOPES); | ||
|
||
$courseid = required_param('course_id', PARAM_INT); | ||
$cmid = required_param('cmid', PARAM_INT); | ||
$resourcelinkid = required_param('resource_link_id', PARAM_TEXT); | ||
$module = get_coursemodule_from_id('kialo', $cmid, $courseid); | ||
if (!$module) { | ||
die("Module $cmid not found"); | ||
} | ||
$module = get_coursemodule_from_id('kialo', $cmid, $courseid, false, MUST_EXIST); | ||
$moduleinstance = $DB->get_record('kialo', ['id' => $module->instance], '*', MUST_EXIST); | ||
|
||
$gradeitem = grade_item::fetch(['iteminstance' => $module->instance, 'itemtype' => 'mod']); | ||
if (!$gradeitem) { | ||
die("Grade item for module CMID=$cmid (instance={$module->instance}) not found"); | ||
throw new LtiException("Grade item for module CMID=$cmid (instance={$module->instance}) not found"); | ||
} | ||
|
||
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/scores') { | ||
// Parse JSON POST request body. | ||
// Receive a score for the line item via JSON request body. | ||
$input = file_get_contents('php://input'); | ||
$data = json_decode($input, true); | ||
|
||
$userid = $data['userId']; | ||
$scoregiven = isset($data['scoreGiven']) ? max(0, min($data['scoreGiven'], $gradeitem->grademax)) : null; | ||
$scoregiven = isset($data['scoreGiven']) ? max(0, min(floatval($data['scoreGiven']), $gradeitem->grademax)) : null; | ||
$comment = $data['comment']; | ||
$timestamp = isset($data['timestamp']) ? strtotime($data['timestamp']) : time(); | ||
$activityprogress = $data['activityProgress']; | ||
$gradingprogress = $data['gradingProgress']; | ||
|
||
if ($scoregiven < 0 && $scoregiven > $gradeitem->grademax) { | ||
$logger->error("Invalid score given: $scoregiven"); | ||
die("Invalid score given: $scoregiven"); | ||
} | ||
|
||
$grades = [ | ||
'userid' => $userid, | ||
|
@@ -78,9 +70,8 @@ | |
} | ||
|
||
kialo_grade_item_update($moduleinstance, $grades); | ||
|
||
} else { | ||
// Handle GET request | ||
// Return the line item information. | ||
$lineitem = new line_item(); | ||
$lineitem->id = (new moodle_url($_SERVER['REQUEST_URI']))->out(false); | ||
$lineitem->label = $module->name; | ||
|
@@ -90,4 +81,3 @@ | |
header('Content-Type: application/json; utf-8'); | ||
echo json_encode($lineitem, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | ||
} | ||
|
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 |
---|---|---|
|
@@ -15,26 +15,25 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This endpoint returns a service access token for the use with the LTI services (e.g. for grading). | ||
* See also https://github.com/oat-sa/lib-lti1p3-core/blob/master/doc/service/service-server.md. | ||
* | ||
* @package mod_kialo | ||
* @copyright 2023 onwards, Kialo GmbH <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
// phpcs:disable moodle.Files.RequireLogin.Missing | ||
define('NO_DEBUG_DISPLAY', true); | ||
define('NO_MOODLE_COOKIES', true); | ||
|
||
require_once(__DIR__ . '/../../config.php'); | ||
require_once(__DIR__ . '/lib.php'); | ||
require_once(__DIR__ . '/constants.php'); | ||
require_once('vendor/autoload.php'); | ||
|
||
use mod_kialo\kialo_view; | ||
use mod_kialo\lti_flow; | ||
|
||
$response = lti_flow::generate_service_access_token(); | ||
|
||
// Write the response. | ||
$statusline = sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase()); | ||
header($statusline, true); /* The header replaces a previous similar header. */ | ||
|
||
foreach ($response->getHeaders() as $name => $values) { | ||
foreach ($values as $value) { | ||
header(sprintf('%s: %s', $name, $value), false); | ||
} | ||
} | ||
|
||
echo $response->getBody(); | ||
kialo_view::write_response($response); |
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