CourseList.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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('Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago');
  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, 9),
  81. $this->getColor($x->months, 10),
  82. $this->getColor($x->months, 11),
  83. $this->getColor($x->months, 12),
  84. $this->getColor($x->months, 1),
  85. $this->getColor($x->months, 2),
  86. $this->getColor($x->months, 3),
  87. $this->getColor($x->months, 4),
  88. $this->getColor($x->months, 5),
  89. $this->getColor($x->months, 6),
  90. $this->getColor($x->months, 7),
  91. $this->getColor($x->months, 8),
  92. $x->course_id,
  93. $x->id,
  94. $x->subscribed
  95. );
  96. }
  97. $this->emit('load-data-table');
  98. return view('livewire.course_list');
  99. }
  100. public function getColor($months, $m)
  101. {
  102. $class = "grey";
  103. foreach(json_decode($months) as $mm)
  104. {
  105. if ($mm->m == $m)
  106. {
  107. if ($mm->status == "")
  108. {
  109. $class = "orange";
  110. }
  111. if ($mm->status == "1")
  112. {
  113. $class = "green";
  114. }
  115. if ($mm->status == "2")
  116. {
  117. $class = "yellow";
  118. }
  119. }
  120. }
  121. return $class;
  122. }
  123. public function search()
  124. {
  125. }
  126. public function newPayment($course_id, $month, $member_id, $id)
  127. {
  128. if ($month < 5) $month += 12;
  129. if ($month >= 5) $month -= 4;
  130. $c = \App\Models\Course::findOrFail($course_id);
  131. 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);
  132. }
  133. public function newSubscription($course_id, $member_id, $id)
  134. {
  135. $c = \App\Models\Course::findOrFail($course_id);
  136. return redirect()->to('/in?new=1&memberId=' . $member_id . '&causalId=' . $c->causal_id . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=1&price=0.00&subscription_price=' . $c->subscription_price . "&courseId=" . $id);
  137. }
  138. public function disableSearch()
  139. {
  140. $this->filterCourse = [];
  141. $this->filterLevel = [];
  142. $this->filterType = [];
  143. $this->filterDuration = [];
  144. $this->filterFrequency = [];
  145. }
  146. }