CourseList.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 $filterCourse = [];
  10. public $filterLevel = [];
  11. public $filterFrequency = [];
  12. public $filterType = [];
  13. public $filterDuration = [];
  14. public $course_durations = [];
  15. public $course_types = [];
  16. public $course_frequencies = [];
  17. public $course_levels = [];
  18. public $months = array('Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic');
  19. public function mount()
  20. {
  21. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  22. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  23. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  24. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get();
  25. $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  26. //if (sizeof($this->courses) > 0)
  27. // $this->courseId = $this->courses[0]->id;
  28. }
  29. public function render()
  30. {
  31. // Carico tutti i corsi associati
  32. /*
  33. if ($this->courseId > 0)
  34. $member_course = \App\Models\MemberCourse::where('course_id', $this->courseId)->with('member'); //->get();
  35. else
  36. $member_course = \App\Models\MemberCourse::with('member'); //->get();
  37. */
  38. $member_course = \App\Models\MemberCourse::with('member');
  39. if (sizeof($this->filterCourse) > 0)
  40. {
  41. $course_ids = [];
  42. foreach($this->filterCourse as $c)
  43. {
  44. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  45. foreach($all as $a)
  46. {
  47. $course_ids[] = $a->id;
  48. }
  49. //$course_ids = array_merge($course_ids, $a);
  50. }
  51. //$course_ids = \App\Models\Course::where('name', 'like', '%' . $this->filterCourse . "%")->pluck('id');
  52. $member_course = $member_course->whereIn('course_id', $course_ids);
  53. }
  54. if (sizeof($this->filterLevel) > 0)
  55. {
  56. $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
  57. $member_course = $member_course->whereIn('course_id', $course_ids);
  58. }
  59. if (sizeof($this->filterFrequency) > 0)
  60. {
  61. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
  62. $member_course = $member_course->whereIn('course_id', $course_ids);
  63. }
  64. if (sizeof($this->filterType) > 0)
  65. {
  66. $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
  67. $member_course = $member_course->whereIn('course_id', $course_ids);
  68. }
  69. if (sizeof($this->filterDuration) > 0)
  70. {
  71. $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
  72. $member_course = $member_course->whereIn('course_id', $course_ids);
  73. }
  74. $member_course = $member_course->get();
  75. $this->records = array();
  76. foreach($member_course as $x)
  77. {
  78. $this->records[] = array(
  79. $x->member_id . "§" . $x->member->first_name . " " . $x->member->last_name,
  80. $this->getColor($x->months, 1),
  81. $this->getColor($x->months, 2),
  82. $this->getColor($x->months, 3),
  83. $this->getColor($x->months, 4),
  84. $this->getColor($x->months, 5),
  85. $this->getColor($x->months, 6),
  86. $this->getColor($x->months, 7),
  87. $this->getColor($x->months, 8),
  88. $this->getColor($x->months, 9),
  89. $this->getColor($x->months, 10),
  90. $this->getColor($x->months, 11),
  91. $this->getColor($x->months, 12),
  92. $x->course_id,
  93. $x->id,
  94. );
  95. }
  96. $this->emit('load-data-table');
  97. return view('livewire.course_list');
  98. }
  99. public function getColor($months, $m)
  100. {
  101. $class = "grey";
  102. foreach(json_decode($months) as $mm)
  103. {
  104. if ($mm->m == $m)
  105. {
  106. if ($mm->status == "")
  107. {
  108. $class = "orange";
  109. }
  110. if ($mm->status == "1")
  111. {
  112. $class = "green";
  113. }
  114. if ($mm->status == "2")
  115. {
  116. $class = "yellow";
  117. }
  118. }
  119. }
  120. return $class;
  121. }
  122. public function search()
  123. {
  124. }
  125. public function newPayment($course_id, $month, $member_id, $id)
  126. {
  127. $c = \App\Models\Course::findOrFail($course_id);
  128. return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=0&months=' . $month . '&price=' . $c->price . '&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
  129. }
  130. }