diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 957259ff..8c2d5b4d 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -458,6 +458,7 @@ class CalendarController extends Controller public function patch($id) { $schedule = Schedule::find($id); + $original = clone($schedule); $schedule->date = request('event_date'); $schedule->type = request('event_type'); @@ -519,6 +520,169 @@ class CalendarController extends Controller $schedule->save(); + /** Notification */ + $asChange = false; + $userToNotify = $schedule->getUserToNotify(); + $changes = []; + $found = false; + + if ($schedule->type == "regular") { + for ($p=1; $p < 3; $p++) { + for ($n=1; $n < 4; $n++) { + $pUser = \App\User::find($schedule->data['n'.$n.'_p'.$p.'_instructor']); + foreach ($userToNotify as $user) { + if ($user->id == $pUser->id) { + $found = true; + } + } + if (!$found) { + $userToNotify->push($pUser); + } + } + } + } + + if ($schedule->data['event_begin_time'] != $original->data['event_begin_time']) { + array_push($changes,"L'heure de début a été modifié de ".$original->data['event_begin_time']." à ".$schedule->data['event_begin_time']); + } + if ($schedule->data['event_end_time'] != $original->data['event_end_time']) { + array_push($changes,"L'heure de fin a été modifié de ".$original->data['event_end_time']." à ".$schedule->data['event_end_time']); + } + if ($schedule->type != $original->type) { + array_push($changes,"Le type d'évenement a été modifié de ".$original->type." à ".$schedule->type); + } + if ($schedule->data['event_name'] != $original->data['event_name']) { + array_push($changes,"Le nom de l'évenement a été modifié de ".$original->data['event_name']." à ".$schedule->data['event_name']); + } + if ($schedule->data['is_event_mandatory'] != $original->data['is_event_mandatory']) { + if ($schedule->data['is_event_mandatory'] == "on") { + array_push($changes,"L'évenement est maintenant obligatoire"); + } else { + array_push($changes,"L'évenement n'est plus obligatoire"); + } + } + if ($schedule->data['event_location'] != $original->data['event_location']) { + array_push($changes,"Le lieu de l'évenement a été modifié de ".$original->data['event_location']." à ".$schedule->data['event_location']); + } + if ($schedule->data['event_desc'] != $original->data['event_desc']) { + array_push($changes,"La description de l'évenement a été modifié de ".$original->data['event_desc']." à ".$schedule->data['event_desc']); + } + + if ($schedule->type == "regular") { + /** Check Instructor */ + if ($schedule->data['n1_p1_instructor'] != $original->data['n1_p1_instructor']) { + array_push($changes,"L'instructeur du niveau 1 pour la première période a été changé de ".$original->data['n1_p1_instructor']." à ".$schedule->data['n1_p1_instructor']); + \Notification::send(\App\User::find($original->data['n1_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n1_p1_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n1_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n1_p1_name']." du ".$schedule->date." vous a été ajouté.")); + } + if ($schedule->data['n1_p2_instructor'] != $original->data['n1_p2_instructor']) { + array_push($changes,"L'instructeur du niveau 1 pour la deuxième période a été changé de ".$original->data['n1_p2_instructor']." à ".$schedule->data['n1_p2_instructor']); + \Notification::send(\App\User::find($original->data['n1_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n1_p2_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n1_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n1_p2_name']." du ".$schedule->date." vous a été ajouté.")); + } + if ($schedule->data['n2_p1_instructor'] != $original->data['n2_p1_instructor']) { + array_push($changes,"L'instructeur du niveau 2 pour la première période a été changé de ".$original->data['n2_p1_instructor']." à ".$schedule->data['n2_p1_instructor']); + \Notification::send(\App\User::find($original->data['n2_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n2_p1_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n2_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n2_p1_name']." du ".$schedule->date." vous a été ajouté.")); + } + if ($schedule->data['n2_p2_instructor'] != $original->data['n2_p2_instructor']) { + array_push($changes,"L'instructeur du niveau 2 pour la deuxième période a été changé de ".$original->data['n2_p2_instructor']." à ".$schedule->data['n2_p2_instructor']); + \Notification::send(\App\User::find($original->data['n2_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n2_p2_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n2_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n2_p2_name']." du ".$schedule->date." vous a été ajouté.")); + } + if ($schedule->data['n3_p1_instructor'] != $original->data['n3_p1_instructor']) { + array_push($changes,"L'instructeur du niveau 3 pour la première période a été changé de ".$original->data['n3_p1_instructor']." à ".$schedule->data['n3_p1_instructor']); + \Notification::send(\App\User::find($original->data['n3_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n3_p1_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n3_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n3_p1_name']." du ".$schedule->date." vous a été ajouté.")); + } + if ($schedule->data['n3_p2_instructor'] != $original->data['n3_p2_instructor']) { + array_push($changes,"L'instructeur du niveau 3 pour la deuxième période a été changé de ".$original->data['n3_p2_instructor']." à ".$schedule->data['n3_p2_instructor']); + \Notification::send(\App\User::find($original->data['n3_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$original->data['n3_p2_name']." du ".$original->date." vous a été retiré.")); + \Notification::send(\App\User::find($schedule->data['n3_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le cours ".$schedule->data['n3_p2_name']." du ".$schedule->date." vous a été ajouté.")); + } + /** Check OCOM */ + if ($schedule->data['n1_p1_ocom'] != $original->data['n1_p1_ocom']) { + array_push($changes,"L'OCOM du niveau 1 pour la première période a été changé de ".$original->data['n1_p1_ocom']." à ".$schedule->data['n1_p1_ocom']); + \Notification::send(\App\User::find($schedule->data['n1_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n1_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n1_p1_ocom'])); + } + if ($schedule->data['n1_p2_ocom'] != $original->data['n1_p2_ocom']) { + array_push($changes,"L'OCOM du niveau 1 pour la deuxième période a été changé de ".$original->data['n1_p2_ocom']." à ".$schedule->data['n1_p2_ocom']); + \Notification::send(\App\User::find($schedule->data['n1_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n1_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n1_p2_ocom'])); + } + if ($schedule->data['n2_p1_ocom'] != $original->data['n2_p1_ocom']) { + array_push($changes,"L'OCOM du niveau 2 pour la première période a été changé de ".$original->data['n2_p1_ocom']." à ".$schedule->data['n2_p1_ocom']); + \Notification::send(\App\User::find($schedule->data['n2_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n2_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n2_p1_ocom'])); + } + if ($schedule->data['n2_p2_ocom'] != $original->data['n2_p2_ocom']) { + array_push($changes,"L'OCOM du niveau 2 pour la deuxième période a été changé de ".$original->data['n2_p2_ocom']." à ".$schedule->data['n2_p2_ocom']); + \Notification::send(\App\User::find($schedule->data['n2_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n2_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n2_p2_ocom'])); + } + if ($schedule->data['n3_p1_ocom'] != $original->data['n3_p1_ocom']) { + array_push($changes,"L'OCOM du niveau 3 pour la première période a été changé de ".$original->data['n3_p1_ocom']." à ".$schedule->data['n3_p1_ocom']); + \Notification::send(\App\User::find($schedule->data['n3_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n3_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n3_p1_ocom'])); + } + if ($schedule->data['n3_p2_ocom'] != $original->data['n3_p2_ocom']) { + array_push($changes,"L'OCOM du niveau 3 pour la deuxième période a été changé de ".$original->data['n3_p2_ocom']." à ".$schedule->data['n3_p2_ocom']); + \Notification::send(\App\User::find($schedule->data['n3_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","L'ocom du cours ".$schedule->data['n3_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n3_p2_ocom'])); + } + /** Check Local */ + if ($schedule->data['n1_p1_local'] != $original->data['n1_p1_local']) { + array_push($changes,"Le local du niveau 1 pour la première période a été changé de ".$original->data['n1_p1_local']." à ".$schedule->data['n1_p1_local']); + } + if ($schedule->data['n1_p2_local'] != $original->data['n1_p2_local']) { + array_push($changes,"Le local du niveau 1 pour la deuxième période a été changé de ".$original->data['n1_p2_local']." à ".$schedule->data['n1_p2_local']); + } + if ($schedule->data['n2_p1_local'] != $original->data['n2_p1_local']) { + array_push($changes,"Le local du niveau 2 pour la première période a été changé de ".$original->data['n2_p1_local']." à ".$schedule->data['n2_p1_local']); + } + if ($schedule->data['n2_p2_local'] != $original->data['n2_p2_local']) { + array_push($changes,"Le local du niveau 2 pour la deuxième période a été changé de ".$original->data['n2_p2_local']." à ".$schedule->data['n2_p2_local']); + } + if ($schedule->data['n3_p1_local'] != $original->data['n3_p1_local']) { + array_push($changes,"Le local du niveau 3 pour la première période a été changé de ".$original->data['n3_p1_local']." à ".$schedule->data['n3_p1_local']); + } + if ($schedule->data['n3_p2_local'] != $original->data['n3_p2_local']) { + array_push($changes,"Le local du niveau 3 pour la deuxième période a été changé de ".$original->data['n3_p2_local']." à ".$schedule->data['n3_p2_local']); + } + /** Check Name */ + if ($schedule->data['n1_p1_name'] != $original->data['n1_p1_name']) { + array_push($changes,"Le nom du cours niveau 1 pour la première période a été changé de ".$original->data['n1_p1_name']." à ".$schedule->data['n1_p1_name']); + \Notification::send(\App\User::find($schedule->data['n1_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n1_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n1_p1_name'])); + } + if ($schedule->data['n1_p2_name'] != $original->data['n1_p2_name']) { + array_push($changes,"Le nom du cours niveau 1 pour la deuxième période a été changé de ".$original->data['n1_p2_name']." à ".$schedule->data['n1_p2_name']); + \Notification::send(\App\User::find($schedule->data['n1_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n1_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n1_p2_name'])); + } + if ($schedule->data['n2_p1_name'] != $original->data['n2_p1_name']) { + array_push($changes,"Le nom du cours niveau 2 pour la première période a été changé de ".$original->data['n2_p1_name']." à ".$schedule->data['n2_p1_name']); + \Notification::send(\App\User::find($schedule->data['n2_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n2_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n2_p1_name'])); + } + if ($schedule->data['n2_p2_name'] != $original->data['n2_p2_name']) { + array_push($changes,"Le nom du cours niveau 2 pour la deuxième période a été changé de ".$original->data['n2_p2_name']." à ".$schedule->data['n2_p2_name']); + \Notification::send(\App\User::find($schedule->data['n2_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n2_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n2_p2_name'])); + } + if ($schedule->data['n3_p1_name'] != $original->data['n3_p1_name']) { + array_push($changes,"Le nom du cours niveau 3 pour la première période a été changé de ".$original->data['n3_p1_name']." à ".$schedule->data['n3_p1_name']); + \Notification::send(\App\User::find($schedule->data['n3_p1_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n3_p1_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n3_p1_name'])); + } + if ($schedule->data['n3_p2_name'] != $original->data['n3_p2_name']) { + array_push($changes,"Le nom du cours niveau 3 pour la deuxième période a été changé de ".$original->data['n3_p2_name']." à ".$schedule->data['n3_p2_name']); + \Notification::send(\App\User::find($schedule->data['n3_p2_instructor']), new mail(\Auth::User(),"Modification d'un de vos cours","Le nom du cours ".$original->data['n3_p2_name']." du ".$schedule->date." a été changé pour ".$schedule->data['n3_p2_name'])); + } + } + + \Notification::send($userToNotify, new Alert(\Auth::User()->id,"Modification de l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date,"/admin/calendar")); + + $string_Change = "
{{\App\Rank::find($user->job)->name}}
+
+ Genre
+ @if ($user->sexe == "m")
+
+ @elseif($user->sexe == "f")
+
+ @else
+
+ @endif
+
+ Age
+ @if ($user->age != "Inconnu")
+ {{$user->age}} ans
+ @else
+ Inconnu
+ @endif
+
Téléphone
+ @if ($user->telephone != "Inconnu")
+ @php
+ $data = '+'.$user->telephone;
+ if(preg_match( '/^\+\d(\d{3})(\d{3})(\d{4})$/',$data,$matches))
+ {
+ $result = $matches[1] . '-' .$matches[2] . '-' . $matches[3];
+ echo $result;
+ }
+ @endphp
+ @else
+ Inconnu
+ @endif
+
Adresse
+ {{$user->adress}}
+
Dernières activitées de l'utilisateur
+| Horodatage | +Action | +
|---|---|
| {{$log->created_at}} | +{{$log->action}} | +