MDL-57994 course: fix newsitems value

This commit is contained in:
Arnaud Trouve
2017-03-16 18:34:30 +01:00
parent 98c4094eac
commit 019186b7b5
2 changed files with 17 additions and 13 deletions
+9 -13
View File
@@ -217,6 +217,12 @@ class course_edit_form extends moodleform {
$mform->addElement('select', 'calendartype', get_string('forcecalendartype', 'calendar'), $calendars);
}
$options = range(0, 10);
$mform->addElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
$courseconfig = get_config('moodlecourse');
$mform->setDefault('newsitems', $courseconfig->newsitems);
$mform->addHelpButton('newsitems', 'newsitemsnumber');
$mform->addElement('selectyesno', 'showgrades', get_string('showgrades'));
$mform->addHelpButton('showgrades', 'showgrades');
$mform->setDefault('showgrades', $courseconfig->showgrades);
@@ -368,19 +374,9 @@ class course_edit_form extends moodleform {
'addcourseformatoptionshere');
}
if ($courseformat->supports_news()) {
// Show the news items select field if the course format supports news.
$options = range(0, 10);
$newsitems = $mform->createElement('select', 'newsitems', get_string('newsitemsnumber'), $options);
$mform->insertElementBefore($newsitems, 'showgrades');
$courseconfig = get_config('moodlecourse');
$mform->setDefault('newsitems', $courseconfig->newsitems);
$mform->addHelpButton('newsitems', 'newsitemsnumber');
} else {
// Otherwise, create a hidden newsitems element and set its value to 0.
$newsitems = $mform->addElement('hidden', 'newsitems', 0);
$mform->setType('newsitems', PARAM_INT);
$newsitems->setValue(0);
// Remove newsitems element if format does not support news.
if (!$courseformat->supports_news()) {
$mform->removeElement('newsitems');
}
}
}
+8
View File
@@ -2488,6 +2488,14 @@ function update_course($data, $editoroptions = NULL) {
}
}
// Set newsitems to 0 if format does not support announcements.
if (isset($data->format)) {
$newcourseformat = course_get_format((object)['format' => $data->format]);
if (!empty($data->newsitems) && !$newcourseformat->supports_news()) {
$data->newsitems = 0;
}
}
// Update with the new data
$DB->update_record('course', $data);
// make sure the modinfo cache is reset