Commit 55e00a0b authored by Abhishek's avatar Abhishek
Browse files

services added in the dta

parent 94412dd8
Pipeline #11967 passed with stage
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
defined('MOODLE_INTERNAL') || die();
/**
* Defines the web service parameters for the assignsubmission_dta plugin.
* This allows the standard mod_assign_save_submission function to accept
* the 'tasks_filemanager' parameter for this plugin.
*
* @package assignsubmission_dta
* @copyright 2023 onwards
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$functions = [
// This is our new, dedicated function to save a DTA submission.
// It bypasses the problematic core 'mod_assign_save_submission' function.
'assignsubmission_dta_save_submission' => [
'classname' => 'assign_submission_dta_external',
'methodname' => 'save_submission',
'description' => 'Saves a DTA submission and sends it to the backend.',
'type' => 'write',
'ajax' => true,
]
];
\ No newline at end of file
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php"); // Required for assign class
require_once("$CFG->dirroot/mod/assign/submission/dta/locallib.php"); // Required for your plugin's class
/**
* External library for the DTA submission plugin.
*
* @package assignsubmission_dta
* @copyright 2023 onwards
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_submission_dta_external extends external_api {
/**
* Defines parameters for our new save_submission function.
*
* @return external_function_parameters
*/
public static function save_submission_parameters(): external_function_parameters {
return new external_function_parameters([
'assignmentid' => new external_value(PARAM_INT, 'The assignment ID'),
'userid' => new external_value(PARAM_INT, 'The user ID of the student'),
'itemid' => new external_value(PARAM_INT, 'The draft file itemid for the submission file')
]);
}
/**
* Saves a DTA submission by calling the plugin's internal save method.
*
* @param int $assignmentid The assignment ID.
* @param int $userid The user ID of the student.
* @param int $itemid The draft file itemid.
* @return bool True on success.
* @throws moodle_exception
*/
public static function save_submission(int $assignmentid, int $userid, int $itemid): bool {
global $DB, $CFG;
// Validate parameters.
self::validate_parameters(self::save_submission_parameters(), [
'assignmentid' => $assignmentid,
'userid' => $userid,
'itemid' => $itemid
]);
// To properly instantiate the 'assign' class, we need more than just the ID.
// We need the context, the course module record (cm), and the course record.
// 1. Get the course module record for this assignment instance.
$cm = get_coursemodule_from_instance('assign', $assignmentid, 0, false, MUST_EXIST);
// 2. Get the course record from the course module.
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
// 3. Get the context from the course module.
$context = context_module::instance($cm->id);
// 4. Now, instantiate the 'assign' class with the correct parameters.
$assignment = new assign($context, $cm, $course);
// --- FIX ENDS HERE ---
$submission = $assignment->get_user_submission($userid, true); // Create if not exists.
// Instantiate the DTA plugin class.
$dta_plugin = new assign_submission_dta($assignment, $submission);
// Create a data object that mimics what a Moodle form would submit.
// The key 'tasks_filemanager' is critical and comes from your locallib.php.
$data = new stdClass();
$data->tasks_filemanager = $itemid;
// Call the original save method from your plugin's locallib.php.
// This preserves all existing logic, including calling the backend.
return $dta_plugin->save($submission, $data);
}
/**
* Describes what our new save_submission function returns.
*
* @return external_value
*/
public static function save_submission_returns(): external_value {
return new external_value(PARAM_BOOL, 'True if the submission was saved successfully.');
}
}
\ No newline at end of file
...@@ -86,3 +86,6 @@ function assignsubmission_dta_pluginfile( ...@@ -86,3 +86,6 @@ function assignsubmission_dta_pluginfile(
// Download MUST be forced - security! // Download MUST be forced - security!
send_stored_file($file, 0, 0, true); send_stored_file($file, 0, 0, true);
} }
function assignsubmission_dta_get_file_areas() {
return ['tasks'];
}
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2023123001; $plugin->version = 2023123002;
$plugin->requires = 2020061525; // Moodle 3.9 LTS. Older unsupported versions from the 3.x branch should also work. $plugin->requires = 2020061525; // Moodle 3.9 LTS. Older unsupported versions from the 3.x branch should also work.
$plugin->component = 'assignsubmission_dta'; $plugin->component = 'assignsubmission_dta';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment