MDL-38415 course: Reformat edit form

AMOS BEGIN
 MOV [availability_help,core],[visible_help,core]
 MOV [category_help,core],[coursecategory_help,core]
AMOS END
This commit is contained in:
Frederic Massart
2013-04-23 10:12:23 +08:00
parent 3e8e66f454
commit aec15827b5
2 changed files with 103 additions and 114 deletions
+101 -112
View File
@@ -46,35 +46,6 @@ class course_edit_form extends moodleform {
$mform->setType('returnto', PARAM_ALPHANUM);
$mform->setConstant('returnto', $returnto);
// verify permissions to change course category or keep current
if (empty($course->id)) {
if (has_capability('moodle/course:create', $categorycontext)) {
$displaylist = coursecat::make_categories_list('moodle/course:create');
$mform->addElement('select', 'category', get_string('category'), $displaylist);
$mform->addHelpButton('category', 'category');
$mform->setDefault('category', $category->id);
} else {
$mform->addElement('hidden', 'category', null);
$mform->setType('category', PARAM_INT);
$mform->setConstant('category', $category->id);
}
} else {
if (has_capability('moodle/course:changecategory', $coursecontext)) {
$displaylist = coursecat::make_categories_list('moodle/course:create');
if (!isset($displaylist[$course->category])) {
//always keep current
$displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name();
}
$mform->addElement('select', 'category', get_string('category'), $displaylist);
$mform->addHelpButton('category', 'category');
} else {
//keep current
$mform->addElement('hidden', 'category', null);
$mform->setType('category', PARAM_INT);
$mform->setConstant('category', $course->category);
}
}
$mform->addElement('text','fullname', get_string('fullnamecourse'),'maxlength="254" size="50"');
$mform->addHelpButton('fullname', 'fullnamecourse');
$mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client');
@@ -93,15 +64,6 @@ class course_edit_form extends moodleform {
$mform->setConstant('shortname', $course->shortname);
}
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercourse');
$mform->setType('idnumber', PARAM_RAW);
if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}
$mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions);
$mform->addHelpButton('summary_editor', 'coursesummary');
$mform->setType('summary_editor', PARAM_RAW);
@@ -117,6 +79,84 @@ class course_edit_form extends moodleform {
$mform->hardFreeze($summaryfields);
}
// Verify permissions to change course category or keep current.
if (empty($course->id)) {
if (has_capability('moodle/course:create', $categorycontext)) {
$displaylist = coursecat::make_categories_list('moodle/course:create');
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
$mform->addHelpButton('category', 'coursecategory');
$mform->setDefault('category', $category->id);
} else {
$mform->addElement('hidden', 'category', null);
$mform->setType('category', PARAM_INT);
$mform->setConstant('category', $category->id);
}
} else {
if (has_capability('moodle/course:changecategory', $coursecontext)) {
$displaylist = coursecat::make_categories_list('moodle/course:create');
if (!isset($displaylist[$course->category])) {
//always keep current
$displaylist[$course->category] = coursecat::get($course->category)->get_formatted_name();
}
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
$mform->addHelpButton('category', 'coursecategory');
} else {
//keep current
$mform->addElement('hidden', 'category', null);
$mform->setType('category', PARAM_INT);
$mform->setConstant('category', $course->category);
}
}
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercourse');
$mform->setType('idnumber', PARAM_RAW);
if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}
$choices = array();
$choices['0'] = get_string('hide');
$choices['1'] = get_string('show');
$mform->addElement('select', 'visible', get_string('visible'), $choices);
$mform->addHelpButton('visible', 'visible');
$mform->setDefault('visible', $courseconfig->visible);
if (!has_capability('moodle/course:visibility', $context)) {
$mform->hardFreeze('visible');
if (!empty($course->id)) {
$mform->setConstant('visible', $course->visible);
} else {
$mform->setConstant('visible', $courseconfig->visible);
}
}
$mform->addElement('date_selector', 'startdate', get_string('startdate'));
$mform->addHelpButton('startdate', 'startdate');
$mform->setDefault('startdate', time() + 3600 * 24);
if (completion_info::is_enabled_for_site()) {
$mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'),
array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion')));
$mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
} else {
$mform->addElement('hidden', 'enablecompletion');
$mform->setType('enablecompletion', PARAM_INT);
$mform->setDefault('enablecompletion',0);
}
// Handle non-existing $course->maxbytes on course creation.
$coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;
// Let's prepare the maxbytes popup.
$choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
$mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
$mform->addHelpButton('maxbytes', 'maximumupload');
$mform->setDefault('maxbytes', $courseconfig->maxbytes);
// Appearance.
$mform->addElement('header', 'appearancehdr', get_string('appearance'));
$courseformats = get_sorted_course_formats(true);
$formcourseformats = array();
foreach ($courseformats as $courseformat) {
@@ -135,13 +175,31 @@ class course_edit_form extends moodleform {
$mform->addHelpButton('format', 'format');
$mform->setDefault('format', $courseconfig->format);
// button to update format-specific options on format change (will be hidden by JavaScript)
// Button to update format-specific options on format change (will be hidden by JavaScript).
$mform->registerNoSubmitButton('updatecourseformat');
$mform->addElement('submit', 'updatecourseformat', get_string('courseformatudpate'));
$mform->addElement('date_selector', 'startdate', get_string('startdate'));
$mform->addHelpButton('startdate', 'startdate');
$mform->setDefault('startdate', time() + 3600 * 24);
// Just a placeholder for the course format options.
$mform->addElement('hidden', 'addcourseformatoptionshere');
$mform->setType('addcourseformatoptionshere', PARAM_BOOL);
if (!empty($CFG->allowcoursethemes)) {
$themeobjects = get_list_of_themes();
$themes=array();
$themes[''] = get_string('forceno');
foreach ($themeobjects as $key=>$theme) {
if (empty($theme->hidefromselector)) {
$themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
}
}
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
}
$languages=array();
$languages[''] = get_string('forceno');
$languages += get_string_manager()->get_list_of_translations();
$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
$mform->setDefault('lang', $courseconfig->lang);
$options = range(0, 10);
$mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
@@ -156,15 +214,6 @@ class course_edit_form extends moodleform {
$mform->addHelpButton('showreports', 'showreports');
$mform->setDefault('showreports', $courseconfig->showreports);
// Handle non-existing $course->maxbytes on course creation.
$coursemaxbytes = !isset($course->maxbytes) ? null : $course->maxbytes;
// Let's prepare the maxbytes popup.
$choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $coursemaxbytes);
$mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices);
$mform->addHelpButton('maxbytes', 'maximumupload');
$mform->setDefault('maxbytes', $courseconfig->maxbytes);
if (!empty($course->legacyfiles) or !empty($CFG->legacyfilesinnewcourses)) {
if (empty($course->legacyfiles)) {
//0 or missing means no legacy files ever used in this course - new course or nobody turned on legacy files yet
@@ -181,23 +230,6 @@ class course_edit_form extends moodleform {
$mform->setDefault('legacyfiles', $courseconfig->legacyfiles);
}
if (!empty($CFG->allowcoursethemes)) {
$themeobjects = get_list_of_themes();
$themes=array();
$themes[''] = get_string('forceno');
foreach ($themeobjects as $key=>$theme) {
if (empty($theme->hidefromselector)) {
$themes[$key] = get_string('pluginname', 'theme_'.$theme->name);
}
}
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
}
//--------------------------------------------------------------------------------
// Just a placeholder..
$mform->addElement('hidden', 'addcourseformatoptionshere');
$mform->setType('addcourseformatoptionshere', PARAM_BOOL);
//--------------------------------------------------------------------------------
enrol_course_edit_form($mform, $course, $context);
@@ -212,10 +244,7 @@ class course_edit_form extends moodleform {
$mform->addHelpButton('groupmode', 'groupmode', 'group');
$mform->setDefault('groupmode', $courseconfig->groupmode);
$choices = array();
$choices['0'] = get_string('no');
$choices['1'] = get_string('yes');
$mform->addElement('select', 'groupmodeforce', get_string('groupmodeforce', 'group'), $choices);
$mform->addElement('selectyesno', 'groupmodeforce', get_string('groupmodeforce', 'group'));
$mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
$mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
@@ -225,43 +254,6 @@ class course_edit_form extends moodleform {
$mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
//--------------------------------------------------------------------------------
$mform->addElement('header','availability', get_string('availability'));
$choices = array();
$choices['0'] = get_string('courseavailablenot');
$choices['1'] = get_string('courseavailable');
$mform->addElement('select', 'visible', get_string('availability'), $choices);
$mform->addHelpButton('visible', 'availability');
$mform->setDefault('visible', $courseconfig->visible);
if (!has_capability('moodle/course:visibility', $context)) {
$mform->hardFreeze('visible');
if (!empty($course->id)) {
$mform->setConstant('visible', $course->visible);
} else {
$mform->setConstant('visible', $courseconfig->visible);
}
}
//--------------------------------------------------------------------------------
$mform->addElement('header','language', get_string('language'));
$languages=array();
$languages[''] = get_string('forceno');
$languages += get_string_manager()->get_list_of_translations();
$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
$mform->setDefault('lang', $courseconfig->lang);
//--------------------------------------------------------------------------------
if (completion_info::is_enabled_for_site()) {
$mform->addElement('header','progress', get_string('progress','completion'));
$mform->addElement('select', 'enablecompletion', get_string('completion','completion'),
array(0=>get_string('completiondisabled','completion'), 1=>get_string('completionenabled','completion')));
$mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
} else {
$mform->addElement('hidden', 'enablecompletion');
$mform->setType('enablecompletion', PARAM_INT);
$mform->setDefault('enablecompletion',0);
}
/// customizable role names in this course
//--------------------------------------------------------------------------------
@@ -309,9 +301,6 @@ class course_edit_form extends moodleform {
$formatvalue = $mform->getElementValue('format');
if (is_array($formatvalue) && !empty($formatvalue)) {
$courseformat = course_get_format((object)array('format' => $formatvalue[0]));
$newel = $mform->createElement('header', 'courseformatoptions', get_string('courseformatoptions', 'moodle',
$courseformat->get_format_name()));
$mform->insertElementBefore($newel, 'addcourseformatoptionshere');
$elements = $courseformat->create_edit_form_elements($mform);
for ($i = 0; $i < count($elements); $i++) {
+2 -2
View File
@@ -156,7 +156,6 @@ $string['autosubscribe'] = 'Forum auto-subscribe';
$string['autosubscribeno'] = 'No: don\'t automatically subscribe me to forums';
$string['autosubscribeyes'] = 'Yes: when I post, subscribe me to that forum';
$string['availability'] = 'Availability';
$string['availability_help'] = 'This setting determines whether the course appears in the list of courses. Apart from teachers and administrators, users are not allowed to enter the course.';
$string['availablecourses'] = 'Available courses';
$string['back'] = 'Back';
$string['backto'] = 'Back to {$a}';
@@ -215,7 +214,6 @@ $string['cancel'] = 'Cancel';
$string['cancelled'] = 'Cancelled';
$string['categories'] = 'Course categories';
$string['category'] = 'Category';
$string['category_help'] = 'This setting determines the category in which the course will appear in the list of courses.';
$string['categoryadded'] = 'The category \'{$a}\' was added';
$string['categorycontents'] = 'Subcategories and courses';
$string['categorycurrentcontents'] = 'Contents of {$a}';
@@ -293,6 +291,7 @@ $string['courseavailablenot'] = 'This course is not available to students';
$string['coursebackup'] = 'Course backup';
$string['coursecategories'] = 'Course categories';
$string['coursecategory'] = 'Course category';
$string['coursecategory_help'] = 'This setting determines the category in which the course will appear in the list of courses.';
$string['coursecategorydeleted'] = 'Deleted course category {$a}';
$string['coursecompletion'] = 'Course completion';
$string['coursecompletions'] = 'Course completions';
@@ -1798,6 +1797,7 @@ $string['virusfoundsubject'] = '{$a}: Virus found!';
$string['virusfounduser'] = 'The file you have uploaded, {$a->filename}, has been scanned by a virus checker and found to be infected! Your file upload was NOT successful.';
$string['virusplaceholder'] = 'This file that has been uploaded was found to contain a virus and has been moved or deleted and the user notified.';
$string['visible'] = 'Visible';
$string['visible_help'] = 'This setting determines whether the course appears in the list of courses. Apart from teachers and administrators, users are not allowed to enter the course.';
$string['visibletostudents'] = 'Visible to {$a}';
$string['warning'] = 'Warning';
$string['warningdeleteresource'] = 'Warning: {$a} is referred in a resource. Would you like to update the resource?';