Skip to content
GitLab
Menu
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
ef8a733a
Commit
ef8a733a
authored
Mar 08, 2013
by
Charles Fulton
Browse files
MDL-36024 enrol: enable grade recovery for all enrol plugins
parent
cf5a3296
Changes
5
Hide whitespace changes
Inline
Side-by-side
enrol/flatfile/lib.php
View file @
ef8a733a
...
@@ -138,10 +138,11 @@ class enrol_flatfile_plugin extends enrol_plugin {
...
@@ -138,10 +138,11 @@ class enrol_flatfile_plugin extends enrol_plugin {
* @param int $timestart 0 means unknown
* @param int $timestart 0 means unknown
* @param int $timeend 0 means forever
* @param int $timeend 0 means forever
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param bool $recovergrades restore grade history
* @return void
* @return void
*/
*/
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
null
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
null
)
{
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
null
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
null
,
$recovergrades
=
null
)
{
parent
::
enrol_user
(
$instance
,
$userid
,
null
,
$timestart
,
$timeend
,
$status
);
parent
::
enrol_user
(
$instance
,
$userid
,
null
,
$timestart
,
$timeend
,
$status
,
$recovergrades
);
if
(
$roleid
)
{
if
(
$roleid
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
,
MUST_EXIST
);
$context
=
context_course
::
instance
(
$instance
->
courseid
,
MUST_EXIST
);
role_assign
(
$roleid
,
$userid
,
$context
->
id
,
'enrol_'
.
$this
->
get_name
(),
$instance
->
id
);
role_assign
(
$roleid
,
$userid
,
$context
->
id
,
'enrol_'
.
$this
->
get_name
(),
$instance
->
id
);
...
...
enrol/guest/lib.php
View file @
ef8a733a
...
@@ -52,7 +52,7 @@ class enrol_guest_plugin extends enrol_plugin {
...
@@ -52,7 +52,7 @@ class enrol_guest_plugin extends enrol_plugin {
}
}
}
}
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
NULL
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
NULL
)
{
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
null
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
null
,
$recovergrades
=
null
)
{
// no real enrolments here!
// no real enrolments here!
return
;
return
;
}
}
...
...
enrol/manual/ajax.php
View file @
ef8a733a
...
@@ -136,11 +136,7 @@ switch ($action) {
...
@@ -136,11 +136,7 @@ switch ($action) {
}
}
$plugin
=
$plugins
[
$instance
->
enrol
];
$plugin
=
$plugins
[
$instance
->
enrol
];
if
(
$plugin
->
allow_enrol
(
$instance
)
&&
has_capability
(
'enrol/'
.
$plugin
->
get_name
()
.
':enrol'
,
$context
))
{
if
(
$plugin
->
allow_enrol
(
$instance
)
&&
has_capability
(
'enrol/'
.
$plugin
->
get_name
()
.
':enrol'
,
$context
))
{
$plugin
->
enrol_user
(
$instance
,
$user
->
id
,
$roleid
,
$timestart
,
$timeend
);
$plugin
->
enrol_user
(
$instance
,
$user
->
id
,
$roleid
,
$timestart
,
$timeend
,
null
,
$recovergrades
);
if
(
$recovergrades
)
{
require_once
(
$CFG
->
libdir
.
'/gradelib.php'
);
grade_recover_history_grades
(
$user
->
id
,
$instance
->
courseid
);
}
}
else
{
}
else
{
throw
new
enrol_ajax_exception
(
'enrolnotpermitted'
);
throw
new
enrol_ajax_exception
(
'enrolnotpermitted'
);
}
}
...
...
enrol/upgrade.txt
View file @
ef8a733a
...
@@ -6,6 +6,7 @@ information provided here is intended especially for developers.
...
@@ -6,6 +6,7 @@ information provided here is intended especially for developers.
* plugins may use general enrol/editenrolment.php page to let users edit
* plugins may use general enrol/editenrolment.php page to let users edit
enrolments manually
enrolments manually
* new support for grade recovery in enrol_plugin::enrol_user() method
=== 2.4 ===
=== 2.4 ===
...
@@ -32,4 +33,4 @@ required changes in code:
...
@@ -32,4 +33,4 @@ required changes in code:
=== 2.0 ===
=== 2.0 ===
required changes in code:
required changes in code:
* enrolment plugins need to be rewritten to use new API - see inline phpdocs and official plugins
* enrolment plugins need to be rewritten to use new API - see inline phpdocs and official plugins
\ No newline at end of file
lib/enrollib.php
View file @
ef8a733a
...
@@ -1244,9 +1244,10 @@ abstract class enrol_plugin {
...
@@ -1244,9 +1244,10 @@ abstract class enrol_plugin {
* @param int $timestart 0 means unknown
* @param int $timestart 0 means unknown
* @param int $timeend 0 means forever
* @param int $timeend 0 means forever
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param bool $recovergrades restore grade history
* @return void
* @return void
*/
*/
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
NULL
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
NULL
)
{
public
function
enrol_user
(
stdClass
$instance
,
$userid
,
$roleid
=
null
,
$timestart
=
0
,
$timeend
=
0
,
$status
=
null
,
$recovergrades
=
null
)
{
global
$DB
,
$USER
,
$CFG
;
// CFG necessary!!!
global
$DB
,
$USER
,
$CFG
;
// CFG necessary!!!
if
(
$instance
->
courseid
==
SITEID
)
{
if
(
$instance
->
courseid
==
SITEID
)
{
...
@@ -1260,6 +1261,9 @@ abstract class enrol_plugin {
...
@@ -1260,6 +1261,9 @@ abstract class enrol_plugin {
throw
new
coding_exception
(
'invalid enrol instance!'
);
throw
new
coding_exception
(
'invalid enrol instance!'
);
}
}
$context
=
context_course
::
instance
(
$instance
->
courseid
,
MUST_EXIST
);
$context
=
context_course
::
instance
(
$instance
->
courseid
,
MUST_EXIST
);
if
(
!
isset
(
$recovergrades
))
{
$recovergrades
=
$CFG
->
recovergradesdefault
;
}
$inserted
=
false
;
$inserted
=
false
;
$updated
=
false
;
$updated
=
false
;
...
@@ -1314,6 +1318,12 @@ abstract class enrol_plugin {
...
@@ -1314,6 +1318,12 @@ abstract class enrol_plugin {
}
}
}
}
// Recover old grades if present.
if
(
$recovergrades
)
{
require_once
(
"
$CFG->libdir
/gradelib.php"
);
grade_recover_history_grades
(
$userid
,
$courseid
);
}
// reset current user enrolment caching
// reset current user enrolment caching
if
(
$userid
==
$USER
->
id
)
{
if
(
$userid
==
$USER
->
id
)
{
if
(
isset
(
$USER
->
enrol
[
'enrolled'
][
$courseid
]))
{
if
(
isset
(
$USER
->
enrol
[
'enrolled'
][
$courseid
]))
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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