CourseMember.php 11 KB

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