mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-59921 calendar: replace selector for course events
This commit is contained in:
parent
d8e9a23c48
commit
4b9c662b2a
3 changed files with 23 additions and 17 deletions
|
@ -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']) {
|
if ($data['duration'] == 1 && $data['timestart'] > $data['timedurationuntil']) {
|
||||||
$errors['durationgroup'] = get_string('invalidtimedurationuntil', 'calendar');
|
$errors['durationgroup'] = get_string('invalidtimedurationuntil', 'calendar');
|
||||||
} else if ($data['duration'] == 2 && (trim($data['timedurationminutes']) == '' || $data['timedurationminutes'] < 1)) {
|
} else if ($data['duration'] == 2 && (trim($data['timedurationminutes']) == '' || $data['timedurationminutes'] < 1)) {
|
||||||
|
@ -237,13 +241,7 @@ class create extends \moodleform {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($eventtypes['course'])) {
|
if (isset($eventtypes['course'])) {
|
||||||
$courseoptions = [];
|
$mform->addElement('course', 'courseid', get_string('course'), ['limittoenrolled' => true]);
|
||||||
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->hideIf('courseid', 'eventtype', 'noteq', 'course');
|
$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->groupid = "{$legacyevent->courseid}-{$legacyevent->groupid}";
|
||||||
$data->groupcourseid = $legacyevent->courseid;
|
$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 = [
|
$data->description = [
|
||||||
'text' => $data->description,
|
'text' => $data->description,
|
||||||
'format' => $data->format
|
'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
|
// Undo the form definition work around to allow us to have two different
|
||||||
// course selectors present depending on which event type the user selects.
|
// 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)) {
|
if (isset($data->groupcourseid)) {
|
||||||
$properties->courseid = $data->groupcourseid;
|
$properties->courseid = $data->groupcourseid;
|
||||||
unset($properties->groupcourseid);
|
unset($properties->groupcourseid);
|
||||||
|
@ -99,14 +115,6 @@ class create_update_form_mapper implements create_update_form_mapper_interface {
|
||||||
$properties->groupid = $groupid;
|
$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.
|
// Decode the form fields back into valid event property.
|
||||||
$properties->timeduration = $this->get_time_duration_from_form_data($data);
|
$properties->timeduration = $this->get_time_duration_from_form_data($data);
|
||||||
|
|
|
@ -2481,7 +2481,7 @@ function calendar_get_all_allowed_types() {
|
||||||
if (!isset($types['course'])) {
|
if (!isset($types['course'])) {
|
||||||
$types['course'] = [$course];
|
$types['course'] = [$course];
|
||||||
} else {
|
} else {
|
||||||
$types['course'][] = $course;
|
$types['course'][$course->id] = $course;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue