';
- }
-
- public function add($date)
- {
- $lang = str_replace('_', '-', app()->getLocale());
- setlocale(LC_ALL, $lang.'_'.strtoupper($lang).'.utf8','fra');
-
- $date = str_replace("_", "-", $date);
-
- $UserList = User::all();
- $LocalList = Local::all();
-
- return view('admin.calendar.calendar_add' ,[
- 'RequestDate' => $date,
- 'Userslist' => $UserList,
- 'LocalsList' => $LocalList,
- 'ComplementaryActivity' => \App\ComplementaryActivity::all()]);
- }
-
- public function edit($id)
- {
- $schedule = Schedule::find($id);
- $UserList = User::all();
- $LocalList = Local::all();
-
- return view('admin.calendar.calendar_edit' ,['RequestSchedule' => $schedule, 'Userslist' => $UserList, 'LocalsList' => $LocalList]);
- }
-
- public function store()
- {
- $schedule = new Schedule;
-
- $schedule->date = request('event_date');
- $schedule->type = request('event_type');
-
- if(request('event_type') == "regular")
- {
- $eventData = [
- "event_name" => request('event_name'),
- "is_event_mandatory" => request('is_event_mandatory'),
- "event_date" => request('event_date'),
- "event_begin_time" => request('event_begin_time'),
- "event_end_time" => request('event_end_time'),
- "event_location" => request('event_location'),
- "event_desc" => request('event_desc'),
- "n1_p1_name" => request('n1_p1_name'),
- "n1_p1_ocom" => request('n1_p1_ocom'),
- "n1_p1_instructor" => request('n1_p1_instructor'),
- "n1_p1_local" => request('n1_p1_local'),
- "n1_p1_plandone" => request('n1_p1_plandone'),
- "n1_p2_name" => request('n1_p2_name'),
- "n1_p2_ocom" => request('n1_p2_ocom'),
- "n1_p2_instructor" => request('n1_p2_instructor'),
- "n1_p2_local" => request('n1_p2_local'),
- "n1_p2_plandone" => request('n1_p2_plandone'),
- "n2_p1_name" => request('n2_p1_name'),
- "n2_p1_ocom" => request('n2_p1_ocom'),
- "n2_p1_instructor" => request('n2_p1_instructor'),
- "n2_p1_local" => request('n2_p1_local'),
- "n2_p1_plandone" => request('n2_p1_plandone'),
- "n2_p2_name" => request('n2_p2_name'),
- "n2_p2_ocom" => request('n2_p2_ocom'),
- "n2_p2_instructor" => request('n2_p2_instructor'),
- "n2_p2_local" => request('n2_p2_local'),
- "n2_p2_plandone" => request('n2_p2_plandone'),
- "n3_p1_name" => request('n3_p1_name'),
- "n3_p1_ocom" => request('n3_p1_ocom'),
- "n3_p1_instructor" => request('n3_p1_instructor'),
- "n3_p1_local" => request('n3_p1_local'),
- "n3_p1_plandone" => request('n3_p1_plandone'),
- "n3_p2_name" => request('n3_p2_name'),
- "n3_p2_ocom" => request('n3_p2_ocom'),
- "n3_p2_instructor" => request('n3_p2_instructor'),
- "n3_p2_local" => request('n3_p2_local'),
- "n3_p2_plandone" => request('n3_p2_plandone'),
- ];
- } else {
- $eventData = [
- "event_name" => request('event_name'),
- "is_event_mandatory" => request('is_event_mandatory'),
- "event_date" => request('event_date'),
- "event_begin_time" => request('event_begin_time'),
- "event_end_time" => request('event_end_time'),
- "event_location" => request('event_location'),
- "event_desc" => request('event_desc'),
- ];
- }
-
- $schedule->data = $eventData;
-
- $schedule->save();
-
-
- $userToNotify = $schedule->getUserToNotify();
- \Notification::send($userToNotify, new Alert(\Auth::User()->id,"Ajout de l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date,"/admin/calendar"));
-
- if(\App\Config::where('name','is_schedule_build')->first()->state == 1)
- {
- \Notification::send($userToNotify, new mail(\Auth::User(),"Ajout d'une activité a l'horaire",\Auth::User()->fullname()." à ajouté l'activité, ".$schedule->data['event_name']." à l'horaire le ".$schedule->date));
- }
- return redirect('/admin/calendar');
-
- }
-
- public function patch($id)
- {
- $schedule = Schedule::find($id);
- $original = clone($schedule);
-
- $schedule->date = request('event_date');
- $schedule->type = request('event_type');
-
- if(request('event_type') == "regular")
- {
- $eventData = [
- "event_name" => request('event_name'),
- "is_event_mandatory" => request('is_event_mandatory'),
- "event_date" => request('event_date'),
- "event_begin_time" => request('event_begin_time'),
- "event_end_time" => request('event_end_time'),
- "event_location" => request('event_location'),
- "event_desc" => request('event_desc'),
- "n1_p1_name" => request('n1_p1_name'),
- "n1_p1_ocom" => request('n1_p1_ocom'),
- "n1_p1_instructor" => request('n1_p1_instructor'),
- "n1_p1_local" => request('n1_p1_local'),
- "n1_p1_plandone" => request('n1_p1_plandone'),
- "n1_p2_name" => request('n1_p2_name'),
- "n1_p2_ocom" => request('n1_p2_ocom'),
- "n1_p2_instructor" => request('n1_p2_instructor'),
- "n1_p2_local" => request('n1_p2_local'),
- "n1_p2_plandone" => request('n1_p2_plandone'),
- "n2_p1_name" => request('n2_p1_name'),
- "n2_p1_ocom" => request('n2_p1_ocom'),
- "n2_p1_instructor" => request('n2_p1_instructor'),
- "n2_p1_local" => request('n2_p1_local'),
- "n2_p1_plandone" => request('n2_p1_plandone'),
- "n2_p2_name" => request('n2_p2_name'),
- "n2_p2_ocom" => request('n2_p2_ocom'),
- "n2_p2_instructor" => request('n2_p2_instructor'),
- "n2_p2_local" => request('n2_p2_local'),
- "n2_p2_plandone" => request('n2_p2_plandone'),
- "n3_p1_name" => request('n3_p1_name'),
- "n3_p1_ocom" => request('n3_p1_ocom'),
- "n3_p1_instructor" => request('n3_p1_instructor'),
- "n3_p1_local" => request('n3_p1_local'),
- "n3_p1_plandone" => request('n3_p1_plandone'),
- "n3_p2_name" => request('n3_p2_name'),
- "n3_p2_ocom" => request('n3_p2_ocom'),
- "n3_p2_instructor" => request('n3_p2_instructor'),
- "n3_p2_local" => request('n3_p2_local'),
- "n3_p2_plandone" => request('n3_p2_plandone'),
- ];
- } else {
- $eventData = [
- "event_name" => request('event_name'),
- "is_event_mandatory" => request('is_event_mandatory'),
- "event_date" => request('event_date'),
- "event_begin_time" => request('event_begin_time'),
- "event_end_time" => request('event_end_time'),
- "event_location" => request('event_location'),
- "event_desc" => request('event_desc'),
- ];
- }
-
- $schedule->data = $eventData;
-
- $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 ".\App\User::find($original->data['n1_p1_instructor'])->fullname()." à ".\App\User::find($schedule->data['n1_p1_instructor'])->fullname());
- \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 ".\App\User::find($original->data['n1_p2_instructor'])->fullname()." à ".\App\User::find($schedule->data['n1_p2_instructor'])->fullname());
- \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 ".\App\User::find($original->data['n2_p1_instructor'])->fullname()." à ".\App\User::find($schedule->data['n2_p1_instructor'])->fullname());
- \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 ".\App\User::find($original->data['n2_p2_instructor'])->fullname()." à ".\App\User::find($schedule->data['n2_p2_instructor'])->fullname());
- \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 ".\App\User::find($original->data['n3_p1_instructor'])->fullname()." à ".\App\User::find($schedule->data['n3_p1_instructor'])->fullname());
- \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 ".\App\User::find($original->data['n3_p2_instructor'])->fullname()." à ".\App\User::find($schedule->data['n3_p2_instructor'])->fullname());
- \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 = "