MDL-65974 course: move format renderers to outputs

This commit is contained in:
Ferran Recio
2021-03-11 17:36:34 +01:00
parent 1c839f9072
commit 8e7dc42440
49 changed files with 3553 additions and 1958 deletions
+13 -5
View File
@@ -967,7 +967,6 @@ abstract class course_format {
public function editsection_form($action, $customdata = array()) {
global $CFG;
require_once($CFG->dirroot. '/course/editsection_form.php');
$context = context_course::instance($this->courseid);
if (!array_key_exists('course', $customdata)) {
$customdata['course'] = $this->get_course();
}
@@ -1091,6 +1090,18 @@ abstract class course_format {
return ($sectionnum && ($course = $this->get_course()) && $course->marker == $sectionnum);
}
/**
* return true if the course editor must be displayed.
*
* @return bool true if edit controls must be displayed
*/
public function show_editor(): bool {
global $PAGE;
$course = $this->get_course();
$coursecontext = context_course::instance($course->id);
return $PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext);
}
/**
* Allows to specify for modinfo that section is not available even when it is visible and conditionally available.
*
@@ -1387,16 +1398,13 @@ abstract class course_format {
}
// Load the cmlist output.
$cmitemclass = $this->get_output_classname('section_format\\cmitem');
$renderer = $this->get_renderer($PAGE);
$coursesections = $modinfo->sections;
if (array_key_exists($section->section, $coursesections)) {
$completioninfo = new completion_info($course);
foreach ($coursesections[$section->section] as $cmid) {
$cm = $modinfo->get_cm($cmid);
$cmitem = new $cmitemclass($this, $section, $cm);
$modules[] = $renderer->render($cmitem);
$modules[] = $renderer->course_section_updated_cm_item($this, $section, $cm);
}
}