Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
fb032ccb
Commit
fb032ccb
authored
Oct 21, 2013
by
Dan Poltawski
Browse files
Merge branch 'wip-mdl-31405-new' of
git://github.com/rajeshtaneja/moodle
Conflicts: lib/upgrade.txt mod/upgrade.txt
parents
8173f4cf
e63515ba
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/moodlelib.php
View file @
fb032ccb
...
...
@@ -5148,18 +5148,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'
;
...
...
mod/assign/locallib.php
View file @
fb032ccb
...
...
@@ -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
);
...
...
mod/assign/tests/locallib_test.php
View file @
fb032ccb
...
...
@@ -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
()
{
...
...
mod/assignment/lib.php
View file @
fb032ccb
...
...
@@ -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
;
}
...
...
mod/upgrade.txt
View file @
fb032ccb
...
...
@@ -9,6 +9,8 @@ information provided here is intended especially for developers.
a custom help text set. Also instead of array it can now return
MOD_SUBTYPE_NO_CHILDREN. This is optional and still defaults to prior
behavior. See get_module_metadata() in course/lib.php for details.
* 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.
=== 2.5 ===
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment