CourseMember.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. class CourseMember extends Component
  5. {
  6. public $records = array();
  7. public $courses = [];
  8. public $course_durations = [];
  9. public $course_types = [];
  10. public $course_levels = [];
  11. public $filterCourse = "";
  12. public $filterLevel = "";
  13. public $filterType = "";
  14. public $filterDuration = "";
  15. public $filterDays = "";
  16. public $filterHours = "";
  17. public $filterSubscription = "";
  18. public function mount()
  19. {
  20. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  21. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  22. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  23. $this->courses = \App\Models\Course::select('*')->orderBy('name', 'ASC')->get();
  24. }
  25. public function render()
  26. {
  27. // Carico tutti i corsi associati
  28. $datas = \App\Models\MemberCourse::with('member');
  29. if ($this->filterCourse != "")
  30. $datas = $datas->where('course_id', $this->filterCourse);
  31. if ($this->filterLevel != "")
  32. {
  33. $course_ids = \App\Models\Course::where('course_level_id', $this->filterLevel)->pluck('id');
  34. $datas = $datas->whereIn('course_id', $course_ids);
  35. }
  36. if ($this->filterType != "")
  37. {
  38. $course_ids = \App\Models\Course::where('course_type_id', $this->filterType)->pluck('id');
  39. $datas = $datas->whereIn('course_id', $course_ids);
  40. }
  41. if ($this->filterDuration != "")
  42. {
  43. $course_ids = \App\Models\Course::where('course_duration_id', $this->filterDuration)->pluck('id');
  44. $datas = $datas->whereIn('course_id', $course_ids);
  45. }
  46. if ($this->filterDays != "")
  47. {
  48. $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('course_id');
  49. $datas = $datas->whereIn('course_id', $course_ids);
  50. }
  51. if ($this->filterHours != "")
  52. {
  53. $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterHours . "%")->pluck('course_id');
  54. $datas = $datas->whereIn('course_id', $course_ids);
  55. }
  56. if ($this->filterSubscription != "")
  57. {
  58. $course_ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
  59. $datas = $datas->whereIn('course_id', $course_ids);
  60. }
  61. $this->records = $datas->get();
  62. $this->emit('load-data-table');
  63. return view('livewire.course_member');
  64. }
  65. public function search()
  66. {
  67. }
  68. public function disableSearch()
  69. {
  70. $this->filterCourse = "";
  71. $this->filterLevel = "";
  72. $this->filterType = "";
  73. $this->filterDuration = "";
  74. $this->filterDays = "";
  75. $this->filterHours = "";
  76. $this->filterSubscription = "";
  77. }
  78. }