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(); } public function render() { $this->records = []; if ($this->course_type_id != null && $this->course_type_id != "") { $course_ids = \App\Models\Course::where('course_type_id', $this->course_type_id)->pluck('id')->toArray(); $calendars = \App\Models\Calendar::whereIn('course_id', $course_ids)->get(); } 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; $this->records[] = $data; } return view('livewire.calendar'); } public function createCalendar() { $calendar = new \App\Models\Calendar(); $calendar->course_id = null; $calendar->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 = null; $calendar->from = $this->from; $calendar->to = $this->to; $calendar->note = ''; $calendar->status = 0; $calendar->save(); return redirect()->to('/presences?calendarId=' . $calendar->id); } }