CourseList.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 $courseId = 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. if ($this->courseId > 0)
  20. $member_course = \App\Models\MemberCourse::where('course_id', $this->courseId)->with('member')->get();
  21. else
  22. $member_course = \App\Models\MemberCourse::with('member')->get();
  23. $this->records = array();
  24. foreach($member_course as $x)
  25. {
  26. $this->records[] = array(
  27. $x->member_id . "§" . $x->member->first_name . " " . $x->member->last_name,
  28. $this->getColor($x->months, 1),
  29. $this->getColor($x->months, 2),
  30. $this->getColor($x->months, 3),
  31. $this->getColor($x->months, 4),
  32. $this->getColor($x->months, 5),
  33. $this->getColor($x->months, 6),
  34. $this->getColor($x->months, 7),
  35. $this->getColor($x->months, 8),
  36. $this->getColor($x->months, 9),
  37. $this->getColor($x->months, 10),
  38. $this->getColor($x->months, 11),
  39. $this->getColor($x->months, 12)
  40. );
  41. }
  42. return view('livewire.course_list');
  43. }
  44. public function getColor($months, $m)
  45. {
  46. $class = "grey";
  47. foreach(json_decode($months) as $mm)
  48. {
  49. if ($mm->m == $m)
  50. {
  51. if ($mm->status == "")
  52. {
  53. $class = "orange";
  54. }
  55. if ($mm->status == "1")
  56. {
  57. $class = "green";
  58. }
  59. if ($mm->status == "2")
  60. {
  61. $class = "yellow";
  62. }
  63. }
  64. }
  65. return $class;
  66. }
  67. }