. /** * Contains the default section course format output class. * * @package core_courseformat * @copyright 2020 Ferran Recio * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_courseformat\output; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/course/renderer.php'); use action_menu; use action_menu_link_secondary; use cm_info; use coding_exception; use context_course; use core_course_renderer; use core_courseformat\base as course_format; use completion_info; use html_writer; use moodle_page; use moodle_url; use pix_icon; use renderable; use section_info; use templatable; use url_select; /** * Base class to render a course add section buttons. * * @package core_courseformat * @copyright 2020 Ferran Recio * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class section_renderer extends core_course_renderer { /** * @var core_course_renderer contains an instance of core course renderer * @deprecated since 4.0 - use $this to access course renderer methods */ protected $courserenderer; /** * Constructor method, calls the parent constructor. * * @deprecated since 4.0 * * Note: this method exists only for compatibilitiy with legacy course formats. Legacy formats * depends on $this->courserenderer to access the course renderer methods. Since Moodle 4.0 * core_courseformat\output\section_renderer extends core_course_renderer and all metdhos can be used directly from $this. * * @param moodle_page $page * @param string $target one of rendering target constants */ public function __construct(moodle_page $page, $target) { parent::__construct($page, $target); $this->courserenderer = $this->page->get_renderer('core', 'course'); } /** * Renders the provided widget and returns the HTML to display it. * * Course format templates uses a similar subfolder structure to the renderable classes. * This method find out the specific template for a course widget. That's the reason why * this render method is different from the normal plugin renderer one. * * course format templatables can be rendered using the core_course/local/* templates. * Format plugins are free to override the default template location using render_xxx methods as usual. * * @param renderable $widget instance with renderable interface * @return string the widget HTML */ public function render(renderable $widget) { global $CFG; $fullpath = str_replace('\\', '/', get_class($widget)); $classparts = explode('/', $fullpath); // Strip namespaces. $classname = array_pop($classparts); // Remove _renderable suffixes. $classname = preg_replace('/_renderable$/', '', $classname); $rendermethod = 'render_' . $classname; if (method_exists($this, $rendermethod)) { return $this->$rendermethod($widget); } // Check for special course format templatables. if ($widget instanceof templatable) { // Templatables from both core_courseformat\output\xxx_format\* and format_xxx\output\xxx_format\* // use core_crouseformat/local/xxx_format templates by default. $corepath = 'core_courseformat\/output\/local'; $pluginpath = 'format_.+\/output\/courseformat'; $specialrenderers = '/^(?' . $corepath . '|' . $pluginpath . ')\/(?