| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class Presence extends Component
- {
- public $calendar;
- public $records;
- public $court_id, $instructor_id, $note;
- public $courts = [];
- public $instructors = [];
- public $ids = [];
- public function mount()
- {
- $this->calendar = \App\Models\Calendar::findOrFail($_GET["calendarId"]);
- $this->court_id = $this->calendar->court_id;
- $this->instructor_id = $this->calendar->instructor_id;
- $this->note = $this->calendar->note;
- $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 = [];
-
- // Carco tutti gli iscritti a quel corso
- $members_courses = \App\Models\MemberCourse::where('course_id', $this->calendar->course_id)->pluck('member_id')->toArray();
- $members = \App\Models\Member::whereIn('id', $members_courses)->get();
- $presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->pluck('member_id')->toArray();
- foreach($members as $member)
- {
- $this->records[] = array('id' => $member->id, 'first_name' => $member->first_name, 'last_name' => $member->first_name, 'certificate' => '', 'presence' => in_array($member->id, $presences));
- }
- /*$calendars = \App\Models\Calendar::get();
- foreach($calendars as $c)
- {
- $this->records[] = array('id' => $c->id, 'title' => $c->course->name, 'start' => $c->from, 'end' => $c->to);
- }*/
- return view('livewire.presence');
- }
- public function save($ids)
- {
- $this->calendar->court_id = $this->court_id;
- $this->calendar->instructor_id = $this->instructor_id;
- $this->calendar->note = $this->note;
- $this->calendar->save();
- \App\Models\Presence::where('calendar_id', $this->calendar->id)->delete();
- foreach($ids as $id)
- {
- $p = new \App\Models\Presence();
- $p->member_id = $id;
- $p->calendar_id = $this->calendar->id;
- $p->save();
- }
- return redirect()->to('/calendar');
- }
- }
|