Skip to content
Snippets Groups Projects
Commit 408bdb87 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

update consultation events when course or institute members change, fixes #675

Closes #675

Merge request studip/studip!972
parent f40481ca
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,52 @@ class ConsultationModule extends CorePlugin implements StudipModule, SystemPlugi ...@@ -9,6 +9,52 @@ class ConsultationModule extends CorePlugin implements StudipModule, SystemPlugi
{ {
parent::__construct(); parent::__construct();
// Update consultation events for the course when a member changes
foreach (['UserDidEnterCourse', 'UserDidLeaveCourse'] as $event) {
NotificationCenter::on($event, function ($event, $course_id) {
$course = Course::find($course_id);
if ($course) {
ConsultationSlot::findEachBySQL(
function (ConsultationSlot $slot) {
$slot->updateEvents();
},
"JOIN consultation_blocks USING (block_id)
WHERE range_id = ? AND range_type = 'course'",
[$course_id]
);
}
});
}
// Update consultation events for the course when a member changes
foreach (['InstituteMemberDidCreate', 'InstituteMemberDidDelete'] as $event) {
NotificationCenter::on($event, function ($event, InstituteMember $member) {
ConsultationSlot::findEachBySQL(
function (ConsultationSlot $slot) {
$slot->updateEvents();
},
"JOIN consultation_blocks USING (block_id)
WHERE range_id = ? AND range_type = 'institute'",
[$member->institut_id]
);
});
}
NotificationCenter::on('UserDidLeaveCourse', function ($event, $course_id) {
// Delete consultation events for the user and course
$course = Course::find($course_id);
if ($course) {
ConsultationSlot::findEachBySQL(
function (ConsultationSlot $slot) {
$slot->updateEvents();
},
"JOIN consultation_blocks USING (block_id)
WHERE range_id = ? AND range_type = 'course'",
[$course_id]
);
}
});
NotificationCenter::on('UserDidDelete', function ($event, $user) { NotificationCenter::on('UserDidDelete', function ($event, $user) {
// Delete consultation bookings and slots // Delete consultation bookings and slots
ConsultationBooking::deleteByUser_id($user->id); ConsultationBooking::deleteByUser_id($user->id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment