MDL-49224 course: allow setting fullname and summary in course generator

This commit is contained in:
Jetha Chan 2015-02-17 17:47:10 +08:00
parent 95751e81ac
commit 343b11a3fa
5 changed files with 101 additions and 8 deletions

View File

@ -83,6 +83,21 @@ class tool_generator_course_backend extends tool_generator_backend {
*/
private $shortname;
/**
* @var string Course fullname.
*/
private $fullname = "";
/**
* @var string Course summary.
*/
private $summary = "";
/**
* @var string Course summary format, defaults to FORMAT_HTML.
*/
private $summaryformat = FORMAT_HTML;
/**
* @var testing_data_generator Data generator
*/
@ -107,10 +122,33 @@ class tool_generator_course_backend extends tool_generator_backend {
* @param int|bool $filesizelimit The max number of bytes for a generated file
* @param bool $progress True if progress information should be displayed
*/
public function __construct($shortname, $size, $fixeddataset = false, $filesizelimit = false, $progress = true) {
public function __construct(
$shortname,
$size,
$fixeddataset = false,
$filesizelimit = false,
$progress = true,
$fullname = null,
$summary = null,
$summaryformat = FORMAT_HTML) {
// Set parameters.
$this->shortname = $shortname;
if (is_null($fullname)) {
$this->fullname = get_string(
'fullname',
'tool_generator',
array(
'size' => get_string('shortsize_' . $size, 'tool_generator')
)
);
} else {
$this->fullname = $fullname;
}
if (!is_null($summary)) {
$this->summary = $summary;
$this->summaryformat = $summaryformat;
}
parent::__construct($size, $fixeddataset, $filesizelimit, $progress);
}
@ -208,10 +246,16 @@ class tool_generator_course_backend extends tool_generator_backend {
*/
private function create_course() {
$this->log('createcourse', $this->shortname);
$courserecord = array('shortname' => $this->shortname,
'fullname' => get_string('fullname', 'tool_generator',
array('size' => get_string('shortsize_' . $this->size, 'tool_generator'))),
'numsections' => self::$paramsections[$this->size]);
$courserecord = array(
'shortname' => $this->shortname,
'fullname' => $this->fullname,
'numsections' => self::$paramsections[$this->size]
);
if (strlen($this->summary) > 0) {
$courserecord['summary'] = $this->summary;
$courserecord['summary_format'] = $this->summaryformat;
}
return $this->generator->create_course($courserecord, array('createsections' => true));
}

View File

@ -51,6 +51,12 @@ class tool_generator_make_course_form extends moodleform {
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);
$mform->addElement('text', 'fullname', get_string('fullnamecourse'));
$mform->setType('fullname', PARAM_TEXT);
$mform->addElement('editor', 'summary', get_string('coursesummary'));
$mform->setType('summary', PARAM_RAW);
$mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator'));
}

View File

@ -33,6 +33,8 @@ list($options, $unrecognized) = cli_get_params(
array(
'help' => false,
'shortname' => false,
'fullname' => false,
'summary' => false,
'size' => false,
'fixeddataset' => false,
'filesizelimit' => false,
@ -54,6 +56,8 @@ level.
Options:
--shortname Shortname of course to create (required)
--fullname Fullname of course to create (optional)
--summary Course summary, in double quotes (optional)
--size Size of course to create XS, S, M, L, XL, or XXL (required)
--fixeddataset Use a fixed data set instead of randomly generated data
--filesizelimit Limits the size of the generated files to the specified bytes
@ -76,6 +80,8 @@ if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) {
// Get options.
$shortname = $options['shortname'];
$fullname = $options['fullname'];
$summary = $options['summary'];
$sizename = $options['size'];
$fixeddataset = $options['fixeddataset'];
$filesizelimit = $options['filesizelimit'];
@ -96,5 +102,14 @@ if ($error = tool_generator_course_backend::check_shortname_available($shortname
\core\session\manager::set_user(get_admin());
// Do backend code to generate course.
$backend = new tool_generator_course_backend($shortname, $size, $fixeddataset, $filesizelimit, empty($options['quiet']));
$backend = new tool_generator_course_backend(
$shortname,
$size,
$fixeddataset,
$filesizelimit,
empty($options['quiet']),
$fullname,
$summary,
FORMAT_HTML
);
$id = $backend->make();

View File

@ -54,7 +54,16 @@ $mform = new tool_generator_make_course_form('maketestcourse.php');
if ($data = $mform->get_data()) {
// Do actual work.
echo $OUTPUT->heading(get_string('creating', 'tool_generator'));
$backend = new tool_generator_course_backend($data->shortname, $data->size);
$backend = new tool_generator_course_backend(
$data->shortname,
$data->size,
false,
false,
true,
$data->fullname,
$data->summary['text'],
$data->summary['format']
);
$id = $backend->make();
echo html_writer::div(

View File

@ -34,8 +34,20 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$this->resetAfterTest();
$this->setAdminUser();
$expectedshortname = 'TOOL_MAKELARGECOURSE_XS';
$expectedfullname = 'Ridiculous fullname';
$expectedsummary = 'who even knows what this is about';
// Create the XS course.
$backend = new tool_generator_course_backend('TOOL_MAKELARGECOURSE_XS', 0, false, false, false);
$backend = new tool_generator_course_backend(
$expectedshortname,
0,
false,
false,
false,
$expectedfullname,
$expectedsummary
);
$courseid = $backend->make();
// Get course details.
@ -43,6 +55,13 @@ class tool_generator_maketestcourse_testcase extends advanced_testcase {
$context = context_course::instance($courseid);
$modinfo = get_fast_modinfo($course);
// Check course names.
$this->assertEquals($expectedshortname, $course->shortname);
$this->assertEquals($expectedfullname, $course->fullname);
// Check course summary.
$this->assertEquals($expectedsummary, $course->summary);
// Check sections (just section 0 plus one other).
$this->assertEquals(2, count($modinfo->get_section_info_all()));