names = \App\Models\Calendar::orderBy('name')->groupBy('name')->pluck('name')->toArray(); $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get(); $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get(); $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get(); $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get(); $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get(); $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->get(); $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->get(); if (isset($_GET["name_filter"])) $this->name_filter = $_GET["name_filter"]; } public function render() { $reload = false; $this->records = []; if ($this->name_filter != null && $this->name_filter != "") { $calendars = \App\Models\Calendar::where('name', $this->name_filter)->get(); $reload = true; } else $calendars = \App\Models\Calendar::get(); foreach($calendars as $c) { $data = array('id' => $c->id, 'title' => $c->course ? $c->course->name : $c->name . ($c->status == 99 ? ' (annullata)' : ''), 'start' => $c->from, 'end' => $c->to); if ($c->course && $c->course->color != '') $data['color'] = $c->course->color; if ($c->status == 99) $data['color'] = "#808080"; $this->records[] = $data; } if ($reload) $this->emit('reload-calendar', ["'" . json_encode($this->records) . "'"]); return view('livewire.calendar'); } public function createCalendar() { $calendar = new \App\Models\Calendar(); $calendar->course_id = null; $calendar->court_id = $this->court_id != '' ? $this->court_id : null; $calendar->name = $this->name; $calendar->course_type_id = $this->course_type_id != '' ? $this->course_type_id : null; $calendar->course_duration_id = $this->course_duration_id != '' ? $this->course_duration_id : null; $calendar->course_frequency_id = $this->course_frequency_id != '' ? $this->course_frequency_id : null; $calendar->course_level_id = $this->course_level_id != '' ? $this->course_level_id : null; $calendar->instructor_id = $this->instructor_id != '' ? $this->instructor_id : null; $calendar->from = $this->from; $calendar->to = $this->to; $calendar->note = $this->note; $calendar->status = 0; $calendar->manual = 1; $calendar->save(); return redirect()->to('/presences?calendarId=' . $calendar->id); } public function cancelCalendar($id, $motivation_id) { $calendar = \App\Models\Calendar::findOrFail($id); $calendar->motivation_id = $motivation_id; $calendar->status = 99; $calendar->save(); return redirect()->to('/calendar'); } }