CourseMember.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 $filter = '';
  27. public function mount()
  28. {
  29. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  30. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  31. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  32. $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
  33. $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  34. }
  35. public function render()
  36. {
  37. // Carico tutti i corsi associati
  38. $this->filter = '';
  39. $datas = \App\Models\MemberCourse::with('member');
  40. if ($this->filterCourse != "")
  41. {
  42. $course_ids = \App\Models\Course::where('name', 'like', '%' . $this->filterCourse . "%")->pluck('id');
  43. $datas = $datas->whereIn('course_id', $course_ids);
  44. $this->filter .= $this->filter != '' ? ', ' : '';
  45. $this->filter .= "Corso : " . $this->filterCourse . " ";
  46. }
  47. if ($this->filterLevel != "")
  48. {
  49. $course_ids = \App\Models\Course::where('course_level_id', $this->filterLevel)->pluck('id');
  50. $datas = $datas->whereIn('course_id', $course_ids);
  51. $this->filter .= $this->filter != '' ? ', ' : '';
  52. $this->filter .= "Livello : " . \App\Models\CourseLevel::findOrFail($this->filterLevel)->name . " ";
  53. }
  54. if ($this->filterType != "")
  55. {
  56. $course_ids = \App\Models\Course::where('course_type_id', $this->filterType)->pluck('id');
  57. $datas = $datas->whereIn('course_id', $course_ids);
  58. $this->filter .= $this->filter != '' ? ', ' : '';
  59. $this->filter .= "Tipologia : " . \App\Models\CourseType::findOrFail($this->filterType)->name . " ";
  60. }
  61. if ($this->filterDuration != "")
  62. {
  63. $course_ids = \App\Models\Course::where('course_duration_id', $this->filterDuration)->pluck('id');
  64. $datas = $datas->whereIn('course_id', $course_ids);
  65. $this->filter .= $this->filter != '' ? ', ' : '';
  66. $this->filter .= "Durata : " . \App\Models\CourseDuration::findOrFail($this->filterDuration)->name . " ";
  67. }
  68. if ($this->filterDays != "")
  69. {
  70. $course_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('course_id');
  71. $datas = $datas->whereIn('course_id', $course_ids);
  72. $this->filter .= $this->filter != '' ? ', ' : '';
  73. $this->filter .= "Giorni : " . $this->filterDays . " ";
  74. }
  75. if ($this->filterHours != "")
  76. {
  77. $course_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterHours . "%")->pluck('course_id');
  78. $datas = $datas->whereIn('course_id', $course_ids);
  79. $this->filter .= $this->filter != '' ? ', ' : '';
  80. $this->filter .= "Ore : " . $this->filterHours . " ";
  81. }
  82. if ($this->filterSubscription != "")
  83. {
  84. $course_ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
  85. $datas = $datas->whereIn('course_id', $course_ids);
  86. $this->filter .= $this->filter != '' ? ', ' : '';
  87. $this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  88. }
  89. if ($this->chkCertificateNormal > 0)
  90. {
  91. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  92. $datas = $datas->whereIn('member_id', $normal);
  93. $this->filter .= $this->filter != '' ? ', ' : '';
  94. $this->filter .= "Certificato normale : SI ";
  95. }
  96. if ($this->chkCertificateAgonistico > 0)
  97. {
  98. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  99. $datas = $datas->whereIn('member_id', $agonistic);
  100. $this->filter .= $this->filter != '' ? ', ' : '';
  101. $this->filter .= "Certificato agonistico : SI ";
  102. }
  103. if ($this->chkCertificateScaduti > 0)
  104. {
  105. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  106. $datas = $datas->whereIn('member_id', $scaduto);
  107. $this->filter .= $this->filter != '' ? ', ' : '';
  108. $this->filter .= "Certificato scaduto : SI ";
  109. }
  110. if ($this->chkCertificateScadenza > 0)
  111. {
  112. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  113. $datas = $datas->whereIn('member_id', $scadenza);
  114. $this->filter .= $this->filter != '' ? ', ' : '';
  115. $this->filter .= "Certificato in scadenza : SI ";
  116. }
  117. if (sizeof($this->chkCard) > 0)
  118. {
  119. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->chkCard)->pluck('member_id');
  120. $datas = $datas->whereIn('member_id', $card_ids);
  121. $this->filter .= $this->filter != '' ? ', ' : '';
  122. $this->filter .= "Tessera : ";
  123. foreach($this->chkCard as $card)
  124. {
  125. $this->filter .= \App\Models\Card::findOrFail($card)->name . " ";
  126. }
  127. }
  128. if ($this->filterYear != "")
  129. {
  130. $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id');
  131. $datas = $datas->whereIn('course_id', $course_ids);
  132. $this->filter .= $this->filter != '' ? ', ' : '';
  133. $this->filter .= "Anno : " . $this->filterYear . " ";
  134. }
  135. $aRet = [];
  136. if ($this->filterStatus != "")
  137. {
  138. foreach($datas->get() as $aaa)
  139. {
  140. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  141. if ($state["status"] == $this->filterStatus)
  142. $aRet[] = $aaa;
  143. }
  144. }
  145. else
  146. $aRet = $datas->get();
  147. $this->records = $aRet;;
  148. $this->emit('load-data-table');
  149. return view('livewire.course_member');
  150. }
  151. public function search()
  152. {
  153. }
  154. public function disableSearch()
  155. {
  156. $this->filterCourse = "";
  157. $this->filterLevel = "";
  158. $this->filterType = "";
  159. $this->filterDuration = "";
  160. $this->filterDays = "";
  161. $this->filterHours = "";
  162. $this->filterSubscription = "";
  163. $this->filterStatus = "";
  164. $this->chkCertificateNormal = 0;
  165. $this->chkCertificateAgonistico = 0;
  166. $this->chkCertificateScaduti = 0;
  167. $this->chkCertificateScadenza = 0;
  168. $this->chkCard = [];
  169. }
  170. }