CourseMember.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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_frequencies = [];
  9. public $course_types = [];
  10. public $course_levels = [];
  11. public $course_durations = [];
  12. public $course_years = [];
  13. public $fromYear = "";
  14. public $toYear = "";
  15. public $fromFromYear = "";
  16. public $toToYear = "";
  17. public $filterCourse = [];
  18. public $filterLevel = [];
  19. public $filterFrequency = [];
  20. public $filterType = [];
  21. public $filterDuration = [];
  22. public $filterDays = [];
  23. public $filterHours = [];
  24. public $filterSubscription = "";
  25. public $filterStatus = [];
  26. public $filterYear = "";
  27. /*public $chkCertificateNormal = 0;
  28. public $chkCertificateAgonistico = 0;
  29. public $chkCertificateScaduti = 0;*/
  30. public $chkCertificateType = "";
  31. public $chkCertificateScadenza = 0;
  32. public $chkCard = [];
  33. public $filter = '';
  34. public $filterFromPrevious = '';
  35. public function mount()
  36. {
  37. if (isset($_GET["id"]))
  38. {
  39. $this->filterFromPrevious = $_GET["id"];
  40. }
  41. $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
  42. $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get();
  43. $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get();
  44. $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get();
  45. $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year');
  46. $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
  47. }
  48. public function render()
  49. {
  50. // Carico tutti i corsi associati
  51. $this->filter = '';
  52. $datas = \App\Models\MemberCourse::with('member');
  53. if (sizeof($this->filterCourse) > 0)
  54. {
  55. $course_ids = [];
  56. foreach($this->filterCourse as $c)
  57. {
  58. $all = \App\Models\Course::where('name', 'like', '%' . $c . "%")->get();
  59. foreach($all as $a)
  60. {
  61. $course_ids[] = $a->id;
  62. }
  63. }
  64. $datas = $datas->whereIn('course_id', $course_ids);
  65. }
  66. if (sizeof($this->filterLevel) > 0)
  67. {
  68. $course_ids = \App\Models\Course::whereIn('course_level_id', $this->filterLevel)->pluck('id');
  69. $datas = $datas->whereIn('course_id', $course_ids);
  70. }
  71. if (sizeof($this->filterFrequency) > 0)
  72. {
  73. $course_ids = \App\Models\Course::whereIn('course_frequency_id', $this->filterFrequency)->pluck('id');
  74. $datas = $datas->whereIn('course_id', $course_ids);
  75. }
  76. if (sizeof($this->filterType) > 0)
  77. {
  78. $course_ids = \App\Models\Course::whereIn('course_type_id', $this->filterType)->pluck('id');
  79. $datas = $datas->whereIn('course_id', $course_ids);
  80. }
  81. if (sizeof($this->filterDuration) > 0)
  82. {
  83. $course_ids = \App\Models\Course::whereIn('course_duration_id', $this->filterDuration)->pluck('id');
  84. $datas = $datas->whereIn('course_id', $course_ids);
  85. }
  86. if (sizeof($this->filterDays) > 0)
  87. {
  88. $m_ids = [];
  89. foreach($this->filterDays as $c)
  90. {
  91. $all = \App\Models\MemberCourse::where('when', 'like', "%" . $c . "%")->get();
  92. foreach($all as $a)
  93. {
  94. $m_ids[] = $a->member_id;
  95. }
  96. }
  97. $datas = $datas->whereIn('member_id', $m_ids);
  98. }
  99. if (sizeof($this->filterHours) > 0)
  100. {
  101. $m_ids = [];
  102. foreach($this->filterHours as $c)
  103. {
  104. $all = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $c . "%")->get();
  105. foreach($all as $a)
  106. {
  107. $m_ids[] = $a->member_id;
  108. }
  109. }
  110. $datas = $datas->whereIn('member_id', $m_ids);
  111. }
  112. /*if ($this->filterDays != "")
  113. {
  114. $members_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('member_id');
  115. $datas = $datas->whereIn('member_id', $members_ids);
  116. $this->filter .= $this->filter != '' ? ', ' : '';
  117. $this->filter .= "Giorni : " . $this->filterDays . " ";
  118. }
  119. if ($this->filterHours != "")
  120. {
  121. $members_ids = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $this->filterHours . "%")->pluck('member_id');
  122. $datas = $datas->whereIn('member_id', $members_ids);
  123. $this->filter .= $this->filter != '' ? ', ' : '';
  124. $this->filter .= "Ore : " . $this->filterHours . " ";
  125. }*/
  126. if ($this->filterSubscription != "")
  127. {
  128. $ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
  129. $datas = $datas->whereIn('id', $ids);
  130. $this->filter .= $this->filter != '' ? ', ' : '';
  131. $this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " ";
  132. }
  133. if ($this->chkCertificateType != "")
  134. {
  135. $types = \App\Models\MemberCertificate::where('type', $this->chkCertificateType)->pluck('member_id');
  136. $datas = $datas->whereIn('member_id', $types);
  137. }
  138. if ($this->chkCertificateScadenza > 0)
  139. {
  140. if ($this->chkCertificateScadenza == "1")
  141. $scad = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  142. if ($this->chkCertificateScadenza == "2")
  143. $scad = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  144. $datas = $datas->whereIn('member_id', $scad);
  145. }
  146. if ($this->fromYear != "")
  147. {
  148. $m_ids = \App\Models\Member::where('birth_date', '<', date("Y-m-d", strtotime("-" . $this->fromYear . " year", time())))->pluck('id');
  149. $datas = $datas->whereIn('member_id', $m_ids);
  150. }
  151. if ($this->toYear != "")
  152. {
  153. $m_ids = \App\Models\Member::where('birth_date', '>', date("Y-m-d", strtotime("-" . $this->toYear . " year", time())))->pluck('id');
  154. $datas = $datas->whereIn('member_id', $m_ids);
  155. }
  156. if ($this->fromFromYear != "")
  157. {
  158. $m_ids = \App\Models\Member::whereYear('birth_date', '>=', $this->fromFromYear)->pluck('id');
  159. $datas = $datas->whereIn('member_id', $m_ids);
  160. }
  161. if ($this->toToYear != "")
  162. {
  163. $m_ids = \App\Models\Member::whereYear('birth_date', '<=', $this->toToYear)->pluck('id');
  164. $datas = $datas->whereIn('member_id', $m_ids);
  165. }
  166. /*if ($_GET["toYear"] != "")
  167. {
  168. $x = $x->where('birth_date', '>', date("Y-m-d", strtotime("-" . $_GET["toYear"] . " year", time())));
  169. }
  170. if ($_GET["fromYearYear"] != "")
  171. {
  172. $x = $x->whereYear('birth_date', '>=', $_GET["fromYearYear"]);
  173. }
  174. if ($_GET["toYearYear"] != "")
  175. {
  176. $x = $x->whereYear('birth_date', '<=', $_GET["toYearYear"]);
  177. }*/
  178. /*
  179. if ($this->chkCertificateNormal > 0)
  180. {
  181. $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
  182. $datas = $datas->whereIn('member_id', $normal);
  183. $this->filter .= $this->filter != '' ? ', ' : '';
  184. $this->filter .= "Certificato normale : SI ";
  185. }
  186. if ($this->chkCertificateAgonistico > 0)
  187. {
  188. $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
  189. $datas = $datas->whereIn('member_id', $agonistic);
  190. $this->filter .= $this->filter != '' ? ', ' : '';
  191. $this->filter .= "Certificato agonistico : SI ";
  192. }
  193. if ($this->chkCertificateScaduti > 0)
  194. {
  195. $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
  196. $datas = $datas->whereIn('member_id', $scaduto);
  197. $this->filter .= $this->filter != '' ? ', ' : '';
  198. $this->filter .= "Certificato scaduto : SI ";
  199. }
  200. if ($this->chkCertificateScadenza > 0)
  201. {
  202. $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
  203. $datas = $datas->whereIn('member_id', $scadenza);
  204. $this->filter .= $this->filter != '' ? ', ' : '';
  205. $this->filter .= "Certificato in scadenza : SI ";
  206. }*/
  207. if (sizeof($this->chkCard) > 0)
  208. {
  209. $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->chkCard)->pluck('member_id');
  210. $datas = $datas->whereIn('member_id', $card_ids);
  211. $this->filter .= $this->filter != '' ? ', ' : '';
  212. $this->filter .= "Tessera : ";
  213. foreach($this->chkCard as $card)
  214. {
  215. $this->filter .= \App\Models\Card::findOrFail($card)->name . " ";
  216. }
  217. }
  218. if ($this->filterYear != "")
  219. {
  220. $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id');
  221. $datas = $datas->whereIn('course_id', $course_ids);
  222. $this->filter .= $this->filter != '' ? ', ' : '';
  223. $this->filter .= "Anno : " . $this->filterYear . " ";
  224. }
  225. $aRet = [];
  226. if (sizeof($this->filterStatus) > 0)
  227. {
  228. foreach($this->filterStatus as $s)
  229. {
  230. foreach($datas->get() as $aaa)
  231. {
  232. $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive();
  233. if ($state["status"] == $s)
  234. $aRet[] = $aaa;
  235. }
  236. }
  237. }
  238. else
  239. $aRet = $datas->get();
  240. $this->records = $aRet;
  241. $this->emit('load-data-table');
  242. return view('livewire.course_member');
  243. }
  244. public function disableSearch()
  245. {
  246. $this->filterCourse = [];
  247. $this->filterLevel = [];
  248. $this->filterType = [];
  249. $this->filterDuration = [];
  250. $this->filterFrequency = [];
  251. $this->filterDays = [];
  252. $this->filterHours = [];
  253. $this->filterSubscription = "";
  254. $this->filterStatus = [];
  255. $this->chkCertificateNormal = 0;
  256. $this->chkCertificateAgonistico = 0;
  257. $this->chkCertificateScaduti = 0;
  258. $this->chkCertificateScadenza = 0;
  259. $this->chkCard = [];
  260. $this->filterYear = "";
  261. $this->fromYear = "";
  262. $this->toYear = "";
  263. $this->fromFromYear = "";
  264. $this->toToYear = "";
  265. }
  266. }