mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
MDL-31405 Assignment: Fixed date in reset to be called for every assignment
This commit is contained in:
parent
f8eff10319
commit
e63515ba93
@ -5140,18 +5140,24 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
|
||||
* @param array $fields array of date fields from mod table
|
||||
* @param int $timeshift time difference
|
||||
* @param int $courseid
|
||||
* @param int $modid (Optional) passed if specific mod instance in course needs to be updated.
|
||||
* @return bool success
|
||||
*/
|
||||
function shift_course_mod_dates($modname, $fields, $timeshift, $courseid) {
|
||||
function shift_course_mod_dates($modname, $fields, $timeshift, $courseid, $modid = 0) {
|
||||
global $CFG, $DB;
|
||||
include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
|
||||
|
||||
$return = true;
|
||||
$params = array($timeshift, $courseid);
|
||||
foreach ($fields as $field) {
|
||||
$updatesql = "UPDATE {".$modname."}
|
||||
SET $field = $field + ?
|
||||
WHERE course=? AND $field<>0";
|
||||
$return = $DB->execute($updatesql, array($timeshift, $courseid)) && $return;
|
||||
if ($modid) {
|
||||
$updatesql .= ' AND id=?';
|
||||
$params[] = $modid;
|
||||
}
|
||||
$return = $DB->execute($updatesql, $params) && $return;
|
||||
}
|
||||
|
||||
$refreshfunction = $modname.'_refresh_events';
|
||||
|
@ -47,6 +47,8 @@ information provided here is intended especially for developers.
|
||||
backups which supports both compression formats; get_file_packer('application/vnd.moodle.backup').
|
||||
* New optional parameter to stored_file::get_content_file_handle to open file handle with 'gzopen' instead
|
||||
of 'fopen' to read gzip-compressed files if required.
|
||||
* shift_course_mod_dates() has been modified to accept optional mod instance id. If mod instance id is passed then
|
||||
dates changed will happen only on specific module instance and not on all instances of that module in course.
|
||||
|
||||
DEPRECATIONS:
|
||||
Various previously deprecated functions have now been altered to throw DEBUG_DEVELOPER debugging notices
|
||||
|
@ -742,7 +742,7 @@ class assign {
|
||||
shift_course_mod_dates('assign',
|
||||
array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'),
|
||||
$data->timeshift,
|
||||
$data->courseid);
|
||||
$data->courseid, $this->get_instance()->id);
|
||||
$status[] = array('component'=>$componentstr,
|
||||
'item'=>get_string('datechanged'),
|
||||
'error'=>false);
|
||||
|
@ -250,6 +250,34 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
|
||||
// Reload the instance data.
|
||||
$instance = $DB->get_record('assign', array('id'=>$assign->get_instance()->id));
|
||||
$this->assertEquals($now + 24*60*60, $instance->duedate);
|
||||
|
||||
// Test reset using assign_reset_userdata().
|
||||
$assignduedate = $instance->duedate; // Keep old updated value for comparison.
|
||||
$data->timeshift = 2*24*60*60;
|
||||
assign_reset_userdata($data);
|
||||
$instance = $DB->get_record('assign', array('id' => $assign->get_instance()->id));
|
||||
$this->assertEquals($assignduedate + 2*24*60*60, $instance->duedate);
|
||||
|
||||
// Create one more assignment and reset, make sure time shifted for previous assignment is not changed.
|
||||
$assign2 = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1,
|
||||
'duedate' => $now));
|
||||
$assignduedate = $instance->duedate;
|
||||
$data->timeshift = 3*24*60*60;
|
||||
$assign2->reset_userdata($data);
|
||||
$instance = $DB->get_record('assign', array('id' => $assign->get_instance()->id));
|
||||
$this->assertEquals($assignduedate, $instance->duedate);
|
||||
$instance2 = $DB->get_record('assign', array('id' => $assign2->get_instance()->id));
|
||||
$this->assertEquals($now + 3*24*60*60, $instance2->duedate);
|
||||
|
||||
// Reset both assignments using assign_reset_userdata() and make sure both assignments have same date.
|
||||
$assignduedate = $instance->duedate;
|
||||
$assign2duedate = $instance2->duedate;
|
||||
$data->timeshift = 4*24*60*60;
|
||||
assign_reset_userdata($data);
|
||||
$instance = $DB->get_record('assign', array('id' => $assign->get_instance()->id));
|
||||
$this->assertEquals($assignduedate + 4*24*60*60, $instance->duedate);
|
||||
$instance2 = $DB->get_record('assign', array('id' => $assign2->get_instance()->id));
|
||||
$this->assertEquals($assign2duedate + 4*24*60*60, $instance2->duedate);
|
||||
}
|
||||
|
||||
public function test_plugin_settings() {
|
||||
|
@ -2368,12 +2368,6 @@ class assignment_base {
|
||||
}
|
||||
}
|
||||
|
||||
/// updating dates - shift may be negative too
|
||||
if ($data->timeshift) {
|
||||
shift_course_mod_dates('assignment', array('timedue', 'timeavailable'), $data->timeshift, $data->courseid);
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('datechanged').': '.$typestr, 'error'=>false);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
@ -3886,6 +3880,23 @@ function assignment_reset_userdata($data) {
|
||||
$status = array_merge($status, $ass->reset_userdata($data));
|
||||
}
|
||||
|
||||
// Updating dates - shift may be negative too.
|
||||
if ($data->timeshift) {
|
||||
$plugintypestrkey = 'type'.$this->type;
|
||||
if (get_string_manager()->string_exists($plugintypestrkey, 'assignment')) {
|
||||
$typestr = get_string_manager()->get_string($plugintypestrkey, 'assignment');
|
||||
} else {
|
||||
$typestr = get_string_manager()->get_string($plugintypestrkey, 'assignment_'.$this->type);
|
||||
}
|
||||
shift_course_mod_dates('assignment',
|
||||
array('timedue', 'timeavailable'),
|
||||
$data->timeshift,
|
||||
$data->courseid);
|
||||
$status[] = array('component' => get_string('modulenameplural', 'assignment'),
|
||||
'item' => get_string('datechanged').': '.$typestr,
|
||||
'error' => false);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user