\App\Config::all()]); } public function update() { $configs = ['admin_periode_nb']; foreach ($configs as $config) { $c = \App\Config::all()->where('name',$config)->first(); $c->data = [request($config)]; $c->save(); } $new_admin_periode_begin = []; $new_admin_periode_end = []; for ($i=1; $i <= request('admin_periode_nb'); $i++) { if(request('admin_periode_begin_'.$i)) { $new_admin_periode_begin[$i] = request('admin_periode_begin_'.$i); } else { $new_admin_periode_begin[$i] = "00:00"; } if(request('admin_periode_end_'.$i)) { $new_admin_periode_end[$i] = request('admin_periode_end_'.$i); } else { $new_admin_periode_end[$i] = "00:00"; } } $temp = \App\Config::all()->where('name','admin_periode_begin')->first(); $temp->data = $new_admin_periode_begin; $temp->save(); $temp = \App\Config::all()->where('name','admin_periode_end')->first(); $temp->data = $new_admin_periode_end; $temp->save(); return redirect('/admin/config/schedule')->with('success','Modification sauvegarder avec succès !'); } public function apiIndex() { $start = strtotime(request()->start); $end = strtotime(request()->end); $allschedules = Schedule::all(); $allevents = \App\Event::all(); $events = []; $jsonevents = []; $schedules = []; foreach ($allschedules as $schedule) { if(strtotime($schedule->date) >= $start && strtotime($schedule->date) <= $end) { array_push($schedules,$schedule); } } foreach ($allevents as $event) { if(strtotime($event->date_begin) >= $start && strtotime($event->date_begin) <= $end) { array_push($events,$event); } else if(strtotime($event->date_end) >= $start && strtotime($event->date_end) <= $end) { array_push($events,$event); } } foreach ($schedules as $schedule) { $color = $this->getColor($schedule->type); $event = [ 'title' => $schedule->data['event_name'], 'start' => date('c',strtotime($schedule->date.'T'.$schedule->data['event_begin_time'])), 'end' => date('c',strtotime($schedule->date.'T'.$schedule->data['event_end_time'])), 'color' => $color, 'source' => 'schedule', 'id' => $schedule->id ]; array_push($jsonevents,$event); } foreach ($events as $event) { if($event->calendar_color == null) { $color = $this->getColor($event->type); } else { $color = $event->calendar_color; } if($event->calendar_icon == null) { $icon = ""; } else { $icon = $event->calendar_icon; } $myevent = [ 'title' => $event->name, 'start' => date('c',strtotime($event->date_begin)), 'end' => date('c',strtotime($event->date_end)), 'color' => $color, 'extraParams' => [ 'db_type' => 'event'], 'id' => $event->id, 'icon' => $icon ]; array_push($jsonevents,$myevent); } return json_encode($jsonevents); } public function loadModal($id,$db_type) { if($db_type == "event") { $event = \App\Event::find($id); } else { $event = \App\Schedule::find($id); } return view('public.modal.schedule',['event' => $event]); } public function loadModalFull($id,$db_type) { if($db_type == "event") { $event = \App\Event::find($id); } else { $event = \App\Schedule::find($id); } return view('admin.schedule.modal.show',['event' => $event]); } public function getColor($type) { $activity = \App\ComplementaryActivity::all(); $color = 'blue'; switch ($type) { case 'regular': $color = 'orange'; break; case 'pilotage': $color = '#58D3F7'; break; case 'drill': $color = 'blue'; break; case 'music': $color = 'green'; break; case 'biathlon': $color = 'red'; break; case 'marksmanship': $color = 'grey'; break; case 'founding': $color = '#00FF40'; break; case 'volunteer': $color = '#DF0174'; break; case 'other': $color = '#DF0174'; break; default: if ($activity->find($type)) { $color = $activity->find($type)->calendar_color; } break; }; return $color; } public function printtopdf($id) { $event = \App\Event::find($id); //return view('admin.schedule.print.event',['event' => $event]); $pdf = PDF::loadView('admin.schedule.print.event',['event' => $event])->setPaper('8.5x11', 'landscape'); return $pdf->download($event->date_begin.'.pdf'); } public function create($date) { $date = str_replace('/','-',$date); return view('admin.schedule.event.add',['date' => $date]); } public function loadModalDefautType($type,$date) { $activity = \App\ComplementaryActivity::find($type); $begin_time = $date." ".$activity->begin_time; $end_time = $date." ".$activity->end_time; $msg_time = Date('c',strtotime($begin_time.'-4day')); return view('admin.schedule.modal.add',[ 'activity' => \App\ComplementaryActivity::find($type), 'begin_time' => $begin_time, 'end_time' => $end_time, 'msg_time' => $msg_time ]); } public function delete($id) { $event = \App\Event::find($id); $event->delete(); } }