| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class Calendar extends Component
- {
- public $records;
- public $names = [];
- public $course_types = [];
- public $course_durations = [];
- public $course_frequencies = [];
- public $course_levels = [];
- public $courts = [];
- public $instructors = [];
- public $motivations = [];
- public $name_filter = null;
- public $name = null;
- public $from = null;
- public $to = null;
-
- public $court_id = null;
- public $instructor_id = null;
- public $note = null;
-
- public $course_type_id = null;
- public $course_duration_id = null;
- public $course_frequency_id = null;
- public $course_level_id = null;
- public $motivation_id = null;
- public function mount()
- {
- $this->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;
- $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;
- $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;
- $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');
- }
- }
|