mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-59921 calendar: replace selector for course events
This commit is contained in:
parent
d8e9a23c48
commit
4b9c662b2a
@ -132,6 +132,10 @@ class create extends \moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
if ($eventtype == 'course' && empty($data['courseid'])) {
|
||||
$errors['courseid'] = get_string('selectacourse');
|
||||
}
|
||||
|
||||
if ($data['duration'] == 1 && $data['timestart'] > $data['timedurationuntil']) {
|
||||
$errors['durationgroup'] = get_string('invalidtimedurationuntil', 'calendar');
|
||||
} else if ($data['duration'] == 2 && (trim($data['timedurationminutes']) == '' || $data['timedurationminutes'] < 1)) {
|
||||
@ -237,13 +241,7 @@ class create extends \moodleform {
|
||||
}
|
||||
|
||||
if (isset($eventtypes['course'])) {
|
||||
$courseoptions = [];
|
||||
foreach ($eventtypes['course'] as $course) {
|
||||
$courseoptions[$course->id] = format_string($course->fullname, true,
|
||||
['context' => \context_course::instance($course->id)]);
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'courseid', get_string('course'), $courseoptions);
|
||||
$mform->addElement('course', 'courseid', get_string('course'), ['limittoenrolled' => true]);
|
||||
$mform->hideIf('courseid', 'eventtype', 'noteq', 'course');
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,10 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||
$data->groupid = "{$legacyevent->courseid}-{$legacyevent->groupid}";
|
||||
$data->groupcourseid = $legacyevent->courseid;
|
||||
}
|
||||
|
||||
if ($legacyevent->eventtype == 'course') {
|
||||
// Set up the correct value for the to display on the form.
|
||||
$data->courseid = $legacyevent->courseid;
|
||||
}
|
||||
$data->description = [
|
||||
'text' => $data->description,
|
||||
'format' => $data->format
|
||||
@ -87,6 +90,19 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||
|
||||
// Undo the form definition work around to allow us to have two different
|
||||
// course selectors present depending on which event type the user selects.
|
||||
if ($data->eventtype == 'course') {
|
||||
// Default course id if none is set.
|
||||
if (!isset($properties->courseid)) {
|
||||
if ($properties->eventtype === 'site') {
|
||||
$properties->courseid = SITEID;
|
||||
} else {
|
||||
$properties->courseid = 0;
|
||||
}
|
||||
} else {
|
||||
$properties->courseid = $data->courseid;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->groupcourseid)) {
|
||||
$properties->courseid = $data->groupcourseid;
|
||||
unset($properties->groupcourseid);
|
||||
@ -99,14 +115,6 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||
$properties->groupid = $groupid;
|
||||
}
|
||||
|
||||
// Default course id if none is set.
|
||||
if (!isset($properties->courseid)) {
|
||||
if ($properties->eventtype === 'site') {
|
||||
$properties->courseid = SITEID;
|
||||
} else {
|
||||
$properties->courseid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Decode the form fields back into valid event property.
|
||||
$properties->timeduration = $this->get_time_duration_from_form_data($data);
|
||||
|
@ -2481,7 +2481,7 @@ function calendar_get_all_allowed_types() {
|
||||
if (!isset($types['course'])) {
|
||||
$types['course'] = [$course];
|
||||
} else {
|
||||
$types['course'][] = $course;
|
||||
$types['course'][$course->id] = $course;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user