Commit 21d93554 authored by Ferran Recio Calderó's avatar Ferran Recio Calderó
Browse files

MDL-71863 courseformat: create courseformat subsystem

parent a747fd30
......@@ -58,7 +58,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
'enablecompletion' => COMPLETION_ENABLED),
array('createsections' => true));
$courseobject = core_course\course_format::instance($course->id);
$courseobject = core_courseformat\base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
$data = array('id' => $section->id,
......@@ -91,7 +91,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
'enablecompletion' => COMPLETION_ENABLED),
array('createsections' => true));
$courseobject = core_course\course_format::instance($course->id);
$courseobject = core_courseformat\base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 1), '*', MUST_EXIST);
$data = array('id' => $section->id,
......@@ -134,7 +134,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
array('createsections' => true));
// Set section 2 to have both options, and a name.
$courseobject = core_course\course_format::instance($course->id);
$courseobject = core_courseformat\base::instance($course->id);
$section = $DB->get_record('course_sections',
array('course' => $course->id, 'section' => 2), '*', MUST_EXIST);
$data = array('id' => $section->id,
......@@ -151,7 +151,7 @@ class core_backup_moodle2_course_format_testcase extends advanced_testcase {
// Check that the section contains the options suitable for the new
// format and that even the one with the same name as from the old format
// has NOT been set.
$newcourseobject = core_course\course_format::instance($newcourse->id);
$newcourseobject = core_courseformat\base::instance($newcourse->id);
$sectionoptions = $newcourseobject->get_format_options(2);
$this->assertArrayHasKey('numdaystocomplete', $sectionoptions);
$this->assertArrayNotHasKey('secondparameter', $sectionoptions);
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -16,13 +16,13 @@
/**
* Generic reactive module used in the course editor.
*
* @module core_course/courseeditor
* @module core_courseformat/courseeditor
* @copyright 2021 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import DefaultMutations from 'core_course/local/courseeditor/mutations';
import CourseEditor from 'core_course/local/courseeditor/courseeditor';
import DefaultMutations from 'core_courseformat/local/courseeditor/mutations';
import CourseEditor from 'core_courseformat/local/courseeditor/courseeditor';
import events from 'core_course/events';
/**
......
......@@ -24,8 +24,8 @@ import ajax from 'core/ajax';
* All formats can register new components on this object to create new reactive
* UI components that watch the current course state.
*
* @module core_course/local/courseeditor/courseeditor
* @class core_course/local/courseeditor/courseeditor
* @module core_courseformat/local/courseeditor/courseeditor
* @class core_courseformat/local/courseeditor/courseeditor
* @copyright 2021 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
......@@ -36,7 +36,7 @@ export default class extends Reactive {
*
* The course can only be loaded once per instance. Otherwise an error is thrown.
*
* @param {int} courseId course id
* @param {number} courseId course id
*/
async loadCourse(courseId) {
......@@ -70,7 +70,7 @@ export default class extends Reactive {
*/
async getServerCourseState() {
const courseState = await ajax.call([{
methodname: 'core_course_get_state',
methodname: 'core_courseformat_get_state',
args: {
courseid: this.courseId,
}
......
......@@ -18,8 +18,8 @@ import ajax from 'core/ajax';
/**
* Default mutation manager
*
* @module core_course/local/courseeditor/mutations
* @class core_course/local/courseeditor/mutations
* @module core_courseformat/local/courseeditor/mutations
* @class core_courseformat/local/courseeditor/mutations
* @copyright 2021 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
......@@ -28,16 +28,16 @@ export default class {
// All course editor mutations for Moodle 4.0 will be located in this file.
/**
* Private method to call core_course_update_course webservice.
* Private method to call core_courseformat_update_course webservice.
*
* @method _callEditWebservice
* @param {string} action
* @param {int} courseId
* @param {number} courseId
* @param {array} ids
*/
async _callEditWebservice(action, courseId, ids) {
let ajaxresult = await ajax.call([{
methodname: 'core_course_update_course',
methodname: 'core_courseformat_update_course',
args: {
action,
courseid: courseId,
......
......@@ -15,14 +15,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains the default activity list from a section.
* Contains the base definition class for any course format plugin.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course;
namespace core_courseformat;
use navigation_node;
use moodle_page;
......@@ -39,13 +39,13 @@ use lang_string;
use completion_info;
use external_api;
use stdClass;
use core_course\output\course_format\legacy_format_renderer;
use core_courseformat\output\legacy_renderer;
/**
* Base class for course formats
*
* Each course format must declare class
* class format_FORMATNAME extends core_course\course_format {}
* class format_FORMATNAME extends core_courseformat\base {}
* in file lib.php
*
* For each course just one instance of this class is created and it will always be returned by
......@@ -62,11 +62,11 @@ use core_course\output\course_format\legacy_format_renderer;
* it to format_FORMATNAME, then move the code from your callback functions into
* appropriate functions of the class.
*
* @package core_course
* @package core_courseformat
* @copyright 2012 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class course_format {
abstract class base {
/** @var int Id of the course in this instance (maybe 0) */
protected $courseid;
/** @var string format used for this course. Please note that it can be different from
......@@ -1066,7 +1066,7 @@ abstract class course_format {
"The '{$formatname}' course format does not define the {$expectedrenderername} renderer class. This is required since Moodle 4.0.",
DEBUG_DEVELOPER
);
$renderer = new legacy_format_renderer($page, null);
$renderer = new legacy_renderer($page, null);
}
return $renderer;
......@@ -1081,10 +1081,10 @@ abstract class course_format {
*/
public function get_output_classname(string $outputname): string {
// The core output class.
$baseclass = "core_course\\output\\$outputname";
$baseclass = "core_courseformat\\output\\local\\$outputname";
// Check if there is a specific format class.
$component = 'format_'. $this->get_format();
$outputclass = "$component\\output\\$outputname";
$outputclass = "$component\\output\\courseformat\\$outputname";
if (class_exists($outputclass)) {
// Check that the outputclass is a subclass of the base class.
if (!is_subclass_of($outputclass, $baseclass)) {
......
......@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_course\external;
namespace core_courseformat\external;
defined('MOODLE_INTERNAL') || die();
......@@ -54,14 +54,14 @@ class get_state extends external_api {
* build using the specifics "state" output components.
*
* By default, the states are generated by:
* - core_course\output\course_format\state
* - core_course\output\section_format\state
* - core_course\output\cm_format\state
* - core_courseformat\output\state\course
* - core_courseformat\output\state\section
* - core_courseformat\output\state\cm
*
* As the other main course outputs, format plugins can override those output components
* to send more information to the frontend course editor. These extended classes should
* be located in format_XXX\output\course_format\state, format_XXX\output\section_format\state
* or format_XXX\output\cm_format\state.
* be located in format_XXX\output\courseformat\state\course, format_XXX\output\section_format\state\section
* or format_XXX\output\cm_format\state\cm.
*
* @param int $courseid the course id
* @return string Course state in JSON
......@@ -91,9 +91,9 @@ class get_state extends external_api {
];
// Load the output class names.
$courseclass = $courseformat->get_output_classname('course_format\state');
$sectionclass = $courseformat->get_output_classname('section_format\state');
$cmclass = $courseformat->get_output_classname('cm_format\state');
$courseclass = $courseformat->get_output_classname('state\\course');
$sectionclass = $courseformat->get_output_classname('state\\section');
$cmclass = $courseformat->get_output_classname('state\\cm');
// General state.
$coursestate = new $courseclass($courseformat);
......
......@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_course\external;
namespace core_courseformat\external;
defined('MOODLE_INTERNAL') || die();
......@@ -113,8 +113,8 @@ class update_course extends external_api {
$courseformat = course_get_format($courseid);
// Create a course changes tracker object.
$defaultupdatesclass = 'core_course\\stateupdates';
$updatesclass = 'format_' . $courseformat->get_format() . '\\stateupdates';
$defaultupdatesclass = 'core_courseformat\\stateupdates';
$updatesclass = 'format_' . $courseformat->get_format() . '\\courseformat\\stateupdates';
if (!class_exists($updatesclass)) {
$updatesclass = $defaultupdatesclass;
}
......@@ -125,9 +125,9 @@ class update_course extends external_api {
}
// Get the actions class from the course format.
$actionsclass = 'format_'. $courseformat->get_format().'\\stateactions';
$actionsclass = 'format_'. $courseformat->get_format().'\\courseformat\\stateactions';
if (!class_exists($actionsclass)) {
$actionsclass = 'core_course\\stateactions';
$actionsclass = 'core_courseformat\\stateactions';
}
$actions = new $actionsclass();
......
......@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_courseformat\output;
use core_courseformat\output\section_renderer;
/**
* Legacy course format renderer.
*
......@@ -22,17 +26,9 @@
* This legacy class has been created for backward compatibility, to avoid some errors with course formats (such as social)
* without this renderer.php file.
*
* @package core_course
* @package core_courseformat
* @copyright 2021 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output\course_format;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/course/format/renderer.php');
class legacy_format_renderer extends \format_section_renderer_base {
class legacy_renderer extends section_renderer {
}
......@@ -17,14 +17,14 @@
/**
* Contains the main course format out class.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output;
namespace core_courseformat\output\local;
use core_course\course_format as course_format_base;
use core_courseformat\base as course_format;
use course_modinfo;
use renderable;
use templatable;
......@@ -33,13 +33,13 @@ use stdClass;
/**
* Base class to render a course format.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_format implements renderable, templatable {
class content implements renderable, templatable {
/** @var core_course\course_format the course format class */
/** @var core_courseformat\base the course format class */
protected $format;
/** @var string the section format class */
......@@ -57,16 +57,16 @@ class course_format implements renderable, templatable {
/**
* Constructor.
*
* @param course_format_base $format the coruse format
* @param course_format $format the coruse format
*/
public function __construct(course_format_base $format) {
public function __construct(course_format $format) {
$this->format = $format;
// Load output classes names from format.
$this->sectionclass = $format->get_output_classname('section_format');
$this->addsectionclass = $format->get_output_classname('course_format\\addsection');
$this->sectionnavigationclass = $format->get_output_classname('course_format\\sectionnavigation');
$this->sectionselectorclass = $format->get_output_classname('course_format\\sectionselector');
$this->sectionclass = $format->get_output_classname('content\\section');
$this->addsectionclass = $format->get_output_classname('content\\addsection');
$this->sectionnavigationclass = $format->get_output_classname('content\\sectionnavigation');
$this->sectionselectorclass = $format->get_output_classname('content\\sectionselector');
}
/**
......
......@@ -17,14 +17,14 @@
/**
* Contains the default section course format output class.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output\course_format;
namespace core_courseformat\output\local\content;
use core_course\course_format;
use core_courseformat\base as course_format;
use renderable;
use templatable;
use moodle_url;
......@@ -33,7 +33,7 @@ use stdClass;
/**
* Base class to render a course add section buttons.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
......
......@@ -19,14 +19,14 @@
*
* The frontpage has a different wat of rendering the main topic.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\output\course_format;
namespace core_courseformat\output\local\content;
use core_course\course_format;
use core_courseformat\base as course_format;
use renderable;
use templatable;
use section_info;
......@@ -37,7 +37,7 @@ use stdClass;
/**
* Represents the frontpage section 1.
*
* @package core_course
* @package core_courseformat
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
......@@ -63,7 +63,7 @@ class frontpagesection implements renderable, templatable {
$this->section = $section;
// Get the necessary classes.
$this->sectionclass = $format->get_output_classname('section_format');
$this->sectionclass = $format->get_output_classname('content\\section');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment