. /** * Base renderer for outputting course formats. * * @package core * @copyright 2012 Dan Poltawski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.3 */ defined('MOODLE_INTERNAL') || die(); use core_course\course_format; global $CFG; require_once($CFG->dirroot. '/course/renderer.php'); /** * This is a convenience renderer which can be used by section based formats * to reduce code duplication. It is not necessary for all course formats to * use this and its likely to change in future releases. * * @package core * @copyright 2012 Dan Poltawski * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 2.3 */ abstract class format_section_renderer_base 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 * format_section_renderer_base 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_course\output\xxx_format\* and format_xxx\output\xxx_format\* // use core_crouse/local/xxx_format templates by default. $specialrenderers = '/^(?core_course|format_.+)\/output\/(?