CourseList.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class CourseList extends Component
  5. {
  6. public $records = array();
  7. public $courses = array();
  8. public $counrsId = 0;
  9. public $months = array('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic');
  10. public function mount()
  11. {
  12. $this->courses = \App\Models\Course::orderBy('name')->get();
  13. if (sizeof($this->courses) > 0)
  14. $this->courseId = $this->courses[0]->id;
  15. }
  16. public function render()
  17. {
  18. // Carico tutti i corsi associati
  19. $member_course = \App\Models\MemberCourse::where('course_id', $this->courseId)->with('member')->get();
  20. $this->records = array();
  21. foreach($member_course as $x)
  22. {
  23. $this->records[] = array(
  24. $x->member_id . "§" . $x->member->first_name . " " . $x->member->last_name,
  25. $this->getColor($x->months, 1),
  26. $this->getColor($x->months, 2),
  27. $this->getColor($x->months, 3),
  28. $this->getColor($x->months, 4),
  29. $this->getColor($x->months, 5),
  30. $this->getColor($x->months, 6),
  31. $this->getColor($x->months, 7),
  32. $this->getColor($x->months, 8),
  33. $this->getColor($x->months, 9),
  34. $this->getColor($x->months, 10),
  35. $this->getColor($x->months, 11),
  36. $this->getColor($x->months, 12)
  37. );
  38. }
  39. return view('livewire.course_list');
  40. }
  41. public function getColor($months, $m)
  42. {
  43. $class = "grey";
  44. foreach(json_decode($months) as $mm)
  45. {
  46. if ($mm->m == $m)
  47. {
  48. if ($mm->status == "")
  49. {
  50. $class = "orange";
  51. }
  52. if ($mm->status == "1")
  53. {
  54. $class = "green";
  55. }
  56. if ($mm->status == "2")
  57. {
  58. $class = "yellow";
  59. }
  60. }
  61. }
  62. return $class;
  63. }
  64. }