Merge branch 'MDL-78530-master' of https://github.com/aanabit/moodle
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace core_completion;
|
||||
|
||||
use core\context;
|
||||
use stdClass;
|
||||
use context_course;
|
||||
use cm_info;
|
||||
@@ -56,6 +57,20 @@ class manager {
|
||||
$this->courseid = $courseid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current course context or system level for $SITE courseid.
|
||||
*
|
||||
* @return context The course based on current courseid or system context.
|
||||
*/
|
||||
protected function get_context(): context {
|
||||
global $SITE;
|
||||
|
||||
if ($this->courseid && $this->courseid != $SITE->id) {
|
||||
return context_course::instance($this->courseid);
|
||||
}
|
||||
return \context_system::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data (context) to be used with the bulkactivitycompletion template.
|
||||
*
|
||||
@@ -220,13 +235,13 @@ class manager {
|
||||
$data->helpicon = $OUTPUT->help_icon('bulkcompletiontracking', 'core_completion');
|
||||
// Add icon information.
|
||||
$data->modules = array_values($modules);
|
||||
$coursecontext = context_course::instance($this->courseid);
|
||||
$canmanage = has_capability('moodle/course:manageactivities', $coursecontext);
|
||||
$context = $this->get_context();
|
||||
$canmanage = has_capability('moodle/course:manageactivities', $context);
|
||||
$course = get_course($this->courseid);
|
||||
foreach ($data->modules as $module) {
|
||||
$module->icon = $OUTPUT->image_url('monologo', $module->name)->out();
|
||||
$module->formattedname = format_string(get_string('modulename', 'mod_' . $module->name),
|
||||
true, ['context' => $coursecontext]);
|
||||
true, ['context' => $context]);
|
||||
$module->canmanage = $canmanage && course_allowed_module($course, $module->name);
|
||||
if ($includedefaults) {
|
||||
$defaults = self::get_default_completion($course, $module, false);
|
||||
@@ -550,9 +565,18 @@ class manager {
|
||||
* @return stdClass
|
||||
*/
|
||||
public static function get_default_completion($course, $module, $flatten = true, string $suffix = '') {
|
||||
global $DB, $CFG;
|
||||
if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
|
||||
'completion, completionview, completionexpected, completionusegrade, completionpassgrade, customrules')) {
|
||||
global $DB, $CFG, $SITE;
|
||||
|
||||
$fields = 'completion, completionview, completionexpected, completionusegrade, completionpassgrade, customrules';
|
||||
// Check course default completion values.
|
||||
$params = ['course' => $course->id, 'module' => $module->id];
|
||||
$data = $DB->get_record('course_completion_defaults', $params, $fields);
|
||||
if (!$data && $course->id != $SITE->id) {
|
||||
// If there is no course default completion, check site level default completion values ($SITE->id).
|
||||
$params['course'] = $SITE->id;
|
||||
$data = $DB->get_record('course_completion_defaults', $params, $fields);
|
||||
}
|
||||
if ($data) {
|
||||
if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
|
||||
// MDL-72375 This will override activity id for new mods. Skip this field, it is already exposed as courseid.
|
||||
unset($customrules['id']);
|
||||
@@ -569,13 +593,6 @@ class manager {
|
||||
} else {
|
||||
$data = new stdClass();
|
||||
$data->completion = COMPLETION_TRACKING_NONE;
|
||||
if ($CFG->completiondefault) {
|
||||
$completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
|
||||
if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
|
||||
$data->completion = COMPLETION_TRACKING_MANUAL;
|
||||
$data->completionview = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the suffix is not empty, the completion rules need to be renamed to avoid conflicts.
|
||||
|
||||
Reference in New Issue
Block a user