CourseMember.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 $course_years = [];
  12. public $filterCourse = "";
  13. public $filterLevel = "";
  14. public $filterType = "";
  15. public $filterDuration = "";
  16. public $filterDays = "";
  17. public $filterHours = "";
  18. public $filterSubscription = "";
  19. public $filterStatus = "";
  20. public $filterYear = "";
  21. public $chkCertificateNormal = 0;
  22. public $chkCertificateAgonistico = 0;
  23. public $chkCertificateScaduti = 0;
  24. public $chkCertificateScadenza = 0;
  25. public $chkCard = [];
  26. public function mount()
  27. {
  28. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  29. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  30. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  31. $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
  32. $this->courses = \App\Models\Course::select('*')->orderBy('name', 'ASC')->get();
  33. }
  34. public function render()
  35. {
  36. // Carico tutti i corsi associati
  37. $datas = \App\Models\MemberCourse::with('member');
  38. if ($this->filterCourse != "")
  39. $datas = $datas->where('course_id', $this->filterCourse);
  40. if ($this->filterLevel != "")
  41. {
  42. $course_ids = \App\Models\Course::where('course_level_id', $this->filterLevel)->pluck('id');
  43. $datas = $datas->whereIn('course_id', $course_ids);
  44. }
  45. if ($this->filterType != "")
  46. {
  47. $course_ids = \App\Models\Course::where('course_type_id', $this->filterType)->pluck('id');
  48. $datas = $datas->whereIn('course_id', $course_ids);
  49. }
  50. if ($this->filterDuration != "")
  51. {
  52. $course_ids = \App\Models\Course::where('course_duration_id', $this->filterDuration)->pluck('id');
  53. $datas = $datas->whereIn('course_id', $course_ids);
  54. }
  55. if ($this->filterDays != "")
  56. {
  57. $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('course_id');
  58. $datas = $datas->whereIn('course_id', $course_ids);
  59. }
  60. if ($this->filterHours != "")
  61. {
  62. $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterHours . "%")->pluck('course_id');
  63. $datas = $datas->whereIn('course_id', $course_ids);
  64. }
  65. if ($this->filterSubscription != "")
  66. {
  67. $course_ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
  68. $datas = $datas->whereIn('course_id', $course_ids);
  69. }
  70. if ($this->chkCertificateNormal > 0)
  71. {
  72. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  73. $datas = $datas->whereIn('member_id', $normal);;
  74. }
  75. if ($this->chkCertificateAgonistico > 0)
  76. {
  77. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  78. $datas = $datas->whereIn('member_id', $agonistic);
  79. }
  80. if ($this->chkCertificateScaduti > 0)
  81. {
  82. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  83. $datas = $datas->whereIn('member_id', $scaduto);
  84. }
  85. if ($this->chkCertificateScadenza > 0)
  86. {
  87. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  88. $datas = $datas->whereIn('member_id', $scadenza);
  89. }
  90. if (sizeof($this->chkCard) > 0)
  91. {
  92. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->chkCard)->pluck('member_id');
  93. $datas = $datas->whereIn('member_id', $card_ids);
  94. }
  95. if ($this->filterYear != "")
  96. {
  97. $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id');
  98. $datas = $datas->whereIn('course_id', $course_ids);
  99. }
  100. $aRet = [];
  101. if ($this->filterStatus != "")
  102. {
  103. foreach($datas->get() as $aaa)
  104. {
  105. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  106. if ($state["status"] == $this->filterStatus)
  107. $aRet[] = $aaa;
  108. }
  109. }
  110. else
  111. $aRet = $datas->get();
  112. $this->records = $aRet;;
  113. $this->emit('load-data-table');
  114. return view('livewire.course_member');
  115. }
  116. public function search()
  117. {
  118. }
  119. public function disableSearch()
  120. {
  121. $this->filterCourse = "";
  122. $this->filterLevel = "";
  123. $this->filterType = "";
  124. $this->filterDuration = "";
  125. $this->filterDays = "";
  126. $this->filterHours = "";
  127. $this->filterSubscription = "";
  128. $this->filterStatus = "";
  129. $this->chkCertificateNormal = 0;
  130. $this->chkCertificateAgonistico = 0;
  131. $this->chkCertificateScaduti = 0;
  132. $this->chkCertificateScadenza = 0;
  133. $this->chkCard = [];
  134. }
  135. }