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
eb89f7cb
Commit
eb89f7cb
authored
Sep 29, 2015
by
Andrew Nicols
Browse files
Merge branch 'MDL-43594-master' of
git://github.com/junpataleta/moodle
parents
853555f9
418a0d04
Changes
2
Hide whitespace changes
Inline
Side-by-side
mod/assign/lib.php
View file @
eb89f7cb
...
...
@@ -87,6 +87,55 @@ function assign_reset_userdata($data) {
return
$status
;
}
/**
* This standard function will check all instances of this module
* and make sure there are up-to-date events created for each of them.
* If courseid = 0, then every assignment event in the site is checked, else
* only assignment events belonging to the course specified are checked.
*
* @param int $courseid
* @return bool
*/
function
assign_refresh_events
(
$courseid
=
0
)
{
global
$CFG
,
$DB
;
require_once
(
$CFG
->
dirroot
.
'/mod/assign/locallib.php'
);
if
(
$courseid
)
{
// Make sure that the course id is numeric.
if
(
!
is_numeric
(
$courseid
))
{
return
false
;
}
if
(
!
$assigns
=
$DB
->
get_records
(
'assign'
,
array
(
'course'
=>
$courseid
)))
{
return
false
;
}
// Get course from courseid parameter.
if
(
!
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$courseid
),
'*'
))
{
return
false
;
}
}
else
{
if
(
!
$assigns
=
$DB
->
get_records
(
'assign'
))
{
return
false
;
}
}
foreach
(
$assigns
as
$assign
)
{
// Use assignment's course column if courseid parameter is not given.
if
(
!
$courseid
)
{
$courseid
=
$assign
->
course
;
if
(
!
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$courseid
),
'*'
))
{
continue
;
}
}
if
(
!
$cm
=
get_coursemodule_from_instance
(
'assign'
,
$assign
->
id
,
$courseid
,
false
))
{
continue
;
}
$context
=
context_module
::
instance
(
$cm
->
id
);
$assignment
=
new
assign
(
$context
,
$cm
,
$course
);
$assignment
->
update_calendar
(
$cm
->
id
);
}
return
true
;
}
/**
* Removes all grades from gradebook
*
...
...
mod/assign/tests/lib_test.php
View file @
eb89f7cb
...
...
@@ -327,4 +327,43 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
$this
->
assertTrue
(
$result
);
}
/**
* Tests for mod_assign_refresh_events.
*/
public
function
test_assign_refresh_events
()
{
global
$DB
;
$duedate
=
time
();
$this
->
setAdminUser
();
$assign
=
$this
->
create_instance
(
array
(
'duedate'
=>
$duedate
));
// Normal case, with existing course.
$this
->
assertTrue
(
assign_refresh_events
(
$this
->
course
->
id
));
$instance
=
$assign
->
get_instance
();
$eventparams
=
array
(
'modulename'
=>
'assign'
,
'instance'
=>
$instance
->
id
);
$event
=
$DB
->
get_record
(
'event'
,
$eventparams
,
'*'
,
MUST_EXIST
);
$this
->
assertEquals
(
$event
->
timestart
,
$duedate
);
// In case the course ID is passed as a numeric string.
$this
->
assertTrue
(
assign_refresh_events
(
''
.
$this
->
course
->
id
));
// Course ID not provided.
$this
->
assertTrue
(
assign_refresh_events
());
$eventparams
=
array
(
'modulename'
=>
'assign'
);
$events
=
$DB
->
get_records
(
'event'
,
$eventparams
);
foreach
(
$events
as
$event
)
{
if
(
$event
->
modulename
===
'assign'
&&
$event
->
instance
===
$instance
->
id
)
{
$this
->
assertEquals
(
$event
->
timestart
,
$duedate
);
}
}
// Non-existing course ID.
$this
->
assertFalse
(
assign_refresh_events
(
-
1
));
// Invalid course ID.
$this
->
assertFalse
(
assign_refresh_events
(
'aaa'
));
}
}
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