Presence.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class Presence extends Component
  5. {
  6. public $calendar;
  7. public $records;
  8. public $court_id, $instructor_id, $note;
  9. public $courts = [];
  10. public $instructors = [];
  11. public $ids = [];
  12. public function mount()
  13. {
  14. $this->calendar = \App\Models\Calendar::findOrFail($_GET["calendarId"]);
  15. $this->court_id = $this->calendar->court_id;
  16. $this->instructor_id = $this->calendar->instructor_id;
  17. $this->note = $this->calendar->note;
  18. $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get();
  19. $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->get();
  20. }
  21. public function render()
  22. {
  23. $this->records = [];
  24. // Carco tutti gli iscritti a quel corso
  25. $members_courses = \App\Models\MemberCourse::where('course_id', $this->calendar->course_id)->pluck('member_id')->toArray();
  26. $members = \App\Models\Member::whereIn('id', $members_courses)->get();
  27. $presences = \App\Models\Presence::where('calendar_id', $this->calendar->id)->pluck('member_id')->toArray();
  28. foreach($members as $member)
  29. {
  30. $this->records[] = array('id' => $member->id, 'first_name' => $member->first_name, 'last_name' => $member->first_name, 'certificate' => '', 'presence' => in_array($member->id, $presences));
  31. }
  32. /*$calendars = \App\Models\Calendar::get();
  33. foreach($calendars as $c)
  34. {
  35. $this->records[] = array('id' => $c->id, 'title' => $c->course->name, 'start' => $c->from, 'end' => $c->to);
  36. }*/
  37. return view('livewire.presence');
  38. }
  39. public function save($ids)
  40. {
  41. $this->calendar->court_id = $this->court_id;
  42. $this->calendar->instructor_id = $this->instructor_id;
  43. $this->calendar->note = $this->note;
  44. $this->calendar->save();
  45. \App\Models\Presence::where('calendar_id', $this->calendar->id)->delete();
  46. foreach($ids as $id)
  47. {
  48. $p = new \App\Models\Presence();
  49. $p->member_id = $id;
  50. $p->calendar_id = $this->calendar->id;
  51. $p->save();
  52. }
  53. return redirect()->to('/calendar');
  54. }
  55. }