mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-34794: Add reset course feature in mod_assign (new assignment (2.3+))
This commit is contained in:
parent
5d6285c220
commit
d38dc52f39
@ -91,6 +91,7 @@ $string['cutoffdatefromdatevalidation'] = 'Cut-off date must be after the allow
|
|||||||
$string['defaultplugins'] = 'Default assignment settings';
|
$string['defaultplugins'] = 'Default assignment settings';
|
||||||
$string['defaultplugins_help'] = 'These settings define the defaults for all new assignments.';
|
$string['defaultplugins_help'] = 'These settings define the defaults for all new assignments.';
|
||||||
$string['defaultteam'] = 'Default team';
|
$string['defaultteam'] = 'Default team';
|
||||||
|
$string['deleteallsubmissions'] = 'Delete all submissions';
|
||||||
$string['deletepluginareyousure'] = 'Delete assignment plugin {$a}: are you sure?';
|
$string['deletepluginareyousure'] = 'Delete assignment plugin {$a}: are you sure?';
|
||||||
$string['deletepluginareyousuremessage'] = 'You are about to completely delete the assignment plugin {$a}. This will completely delete everything in the database associated with this assignment plugin. Are you SURE you want to continue?';
|
$string['deletepluginareyousuremessage'] = 'You are about to completely delete the assignment plugin {$a}. This will completely delete everything in the database associated with this assignment plugin. Are you SURE you want to continue?';
|
||||||
$string['deletingplugin'] = 'Deleting plugin {$a}.';
|
$string['deletingplugin'] = 'Deleting plugin {$a}.';
|
||||||
|
@ -54,6 +54,72 @@ function assign_delete_instance($id) {
|
|||||||
return $assignment->delete_instance();
|
return $assignment->delete_instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used by the reset_course_userdata function in moodlelib.
|
||||||
|
* This function will remove all assignment submissions and feedbacks in the database
|
||||||
|
* and clean up any related data.
|
||||||
|
* @param $data the data submitted from the reset course.
|
||||||
|
* @return array status array
|
||||||
|
*/
|
||||||
|
function assign_reset_userdata($data) {
|
||||||
|
global $CFG, $DB;
|
||||||
|
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||||
|
|
||||||
|
$status = array();
|
||||||
|
$params = array('courseid'=>$data->courseid);
|
||||||
|
$sql = "SELECT a.id FROM {assign} a WHERE a.course=:courseid";
|
||||||
|
$course = $DB->get_record('course', array('id'=> $data->courseid), '*', MUST_EXIST);
|
||||||
|
if ($assigns = $DB->get_records_sql($sql,$params)) {
|
||||||
|
foreach ($assigns as $assign) {
|
||||||
|
$cm = get_coursemodule_from_instance('assign', $assign->id, $data->courseid, false, MUST_EXIST);
|
||||||
|
$context = context_module::instance($cm->id);
|
||||||
|
$assignment = new assign($context, $cm, $course);
|
||||||
|
$status = array_merge($status, $assignment->reset_userdata($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all grades from gradebook
|
||||||
|
*
|
||||||
|
* @param int $courseid The ID of the course to reset
|
||||||
|
* @param string $type Optional type of assignment to limit the reset to a particular assignment type
|
||||||
|
*/
|
||||||
|
function assign_reset_gradebook($courseid, $type='') {
|
||||||
|
global $CFG, $DB;
|
||||||
|
|
||||||
|
$params = array('moduletype'=>'assign','courseid'=>$courseid);
|
||||||
|
$sql = 'SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
|
||||||
|
FROM {assign} a, {course_modules} cm, {modules} m
|
||||||
|
WHERE m.name=:moduletype AND m.id=cm.module AND cm.instance=a.id AND a.course=:courseid';
|
||||||
|
|
||||||
|
if ($assignments = $DB->get_records_sql($sql,$params)) {
|
||||||
|
foreach ($assignments as $assignment) {
|
||||||
|
assign_grade_item_update($assignment, 'reset');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the function for printing the form elements that control
|
||||||
|
* whether the course reset functionality affects the assignment.
|
||||||
|
* @param $mform form passed by reference
|
||||||
|
*/
|
||||||
|
function assign_reset_course_form_definition(&$mform) {
|
||||||
|
$mform->addElement('header', 'assignheader', get_string('modulenameplural', 'assign'));
|
||||||
|
$mform->addElement('advcheckbox', 'reset_assign_submissions', get_string('deleteallsubmissions','assign'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Course reset form defaults.
|
||||||
|
* @param object $course
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function assign_reset_course_form_defaults($course) {
|
||||||
|
return array('reset_assign_submissions'=>1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an assignment instance
|
* Update an assignment instance
|
||||||
*
|
*
|
||||||
|
@ -552,6 +552,82 @@ class assign {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actual implementation of the reset course functionality, delete all the
|
||||||
|
* assignment submissions for course $data->courseid.
|
||||||
|
*
|
||||||
|
* @param $data the data submitted from the reset course.
|
||||||
|
* @return array status array
|
||||||
|
*/
|
||||||
|
public function reset_userdata($data) {
|
||||||
|
global $CFG,$DB;
|
||||||
|
|
||||||
|
$componentstr = get_string('modulenameplural', 'assign');
|
||||||
|
$status = array();
|
||||||
|
|
||||||
|
$fs = get_file_storage();
|
||||||
|
if (!empty($data->reset_assign_submissions)) {
|
||||||
|
// Delete files associated with this assignment.
|
||||||
|
foreach ($this->submissionplugins as $plugin) {
|
||||||
|
$fileareas = array();
|
||||||
|
$plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
|
||||||
|
$fileareas = $plugin->get_file_areas();
|
||||||
|
foreach ($fileareas as $filearea) {
|
||||||
|
$fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$plugin->delete_instance()) {
|
||||||
|
$status[] = array('component'=>$componentstr,
|
||||||
|
'item'=>get_string('deleteallsubmissions','assign'),
|
||||||
|
'error'=>$plugin->get_error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->feedbackplugins as $plugin) {
|
||||||
|
$fileareas = array();
|
||||||
|
$plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
|
||||||
|
$fileareas = $plugin->get_file_areas();
|
||||||
|
foreach ($fileareas as $filearea) {
|
||||||
|
$fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$plugin->delete_instance()) {
|
||||||
|
$status[] = array('component'=>$componentstr,
|
||||||
|
'item'=>get_string('deleteallsubmissions','assign'),
|
||||||
|
'error'=>$plugin->get_error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$assignssql = "SELECT a.id
|
||||||
|
FROM {assign} a
|
||||||
|
WHERE a.course=:course";
|
||||||
|
$params = array ("course" => $data->courseid);
|
||||||
|
|
||||||
|
$DB->delete_records_select('assign_submission', "assignment IN ($assignssql)", $params);
|
||||||
|
$status[] = array('component'=>$componentstr,
|
||||||
|
'item'=>get_string('deleteallsubmissions','assign'),
|
||||||
|
'error'=>false);
|
||||||
|
|
||||||
|
if (empty($data->reset_gradebook_grades)) {
|
||||||
|
// Remove all grades from gradebook.
|
||||||
|
require_once($CFG->dirroot.'/mod/assign/lib.php');
|
||||||
|
assign_reset_gradebook($data->courseid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Updating dates - shift may be negative too.
|
||||||
|
if ($data->timeshift) {
|
||||||
|
shift_course_mod_dates('assign',
|
||||||
|
array('duedate', 'allowsubmissionsfromdate','cutoffdate'),
|
||||||
|
$data->timeshift,
|
||||||
|
$data->courseid);
|
||||||
|
$status[] = array('component'=>$componentstr,
|
||||||
|
'item'=>get_string('datechanged'),
|
||||||
|
'error'=>false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the settings for a single plugin
|
* Update the settings for a single plugin
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user