course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get(); $this->course_durations = \App\Models\CourseDuration::select('*')->where('enabled', true)->get(); $this->course_levels = \App\Models\CourseLevel::select('*')->where('enabled', true)->get(); $this->course_years = \App\Models\Course::select('year')->where('year', '<>', '')->groupBy('year')->pluck('year'); $this->courses = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name'); } public function render() { // Carico tutti i corsi associati $this->filter = ''; $datas = \App\Models\MemberCourse::with('member'); if ($this->filterCourse != "") { $course_ids = \App\Models\Course::where('name', 'like', '%' . $this->filterCourse . "%")->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Corso : " . $this->filterCourse . " "; } if ($this->filterLevel != "") { $course_ids = \App\Models\Course::where('course_level_id', $this->filterLevel)->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Livello : " . \App\Models\CourseLevel::findOrFail($this->filterLevel)->name . " "; } if ($this->filterType != "") { $course_ids = \App\Models\Course::where('course_type_id', $this->filterType)->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Tipologia : " . \App\Models\CourseType::findOrFail($this->filterType)->name . " "; } if ($this->filterDuration != "") { $course_ids = \App\Models\Course::where('course_duration_id', $this->filterDuration)->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Durata : " . \App\Models\CourseDuration::findOrFail($this->filterDuration)->name . " "; } if ($this->filterDays != "") { $course_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('course_id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Giorni : " . $this->filterDays . " "; } if ($this->filterHours != "") { $course_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterHours . "%")->pluck('course_id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Ore : " . $this->filterHours . " "; } if ($this->filterSubscription != "") { $course_ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Pagata sottoscrizione : " . ($this->filterSubscription == 1 ? "SI" : "NO") . " "; } if ($this->chkCertificateNormal > 0) { $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id'); $datas = $datas->whereIn('member_id', $normal); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Certificato normale : SI "; } if ($this->chkCertificateAgonistico > 0) { $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id'); $datas = $datas->whereIn('member_id', $agonistic); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Certificato agonistico : SI "; } if ($this->chkCertificateScaduti > 0) { $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id'); $datas = $datas->whereIn('member_id', $scaduto); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Certificato scaduto : SI "; } if ($this->chkCertificateScadenza > 0) { $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id'); $datas = $datas->whereIn('member_id', $scadenza); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Certificato in scadenza : SI "; } if (sizeof($this->chkCard) > 0) { $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->chkCard)->pluck('member_id'); $datas = $datas->whereIn('member_id', $card_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Tessera : "; foreach($this->chkCard as $card) { $this->filter .= \App\Models\Card::findOrFail($card)->name . " "; } } if ($this->filterYear != "") { $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id'); $datas = $datas->whereIn('course_id', $course_ids); $this->filter .= $this->filter != '' ? ', ' : ''; $this->filter .= "Anno : " . $this->filterYear . " "; } $aRet = []; if ($this->filterStatus != "") { foreach($datas->get() as $aaa) { $state = \App\Models\Member::findOrFail($aaa->member_id)->isActive(); if ($state["status"] == $this->filterStatus) $aRet[] = $aaa; } } else $aRet = $datas->get(); $this->records = $aRet;; $this->emit('load-data-table'); return view('livewire.course_member'); } public function search() { } public function disableSearch() { $this->filterCourse = ""; $this->filterLevel = ""; $this->filterType = ""; $this->filterDuration = ""; $this->filterDays = ""; $this->filterHours = ""; $this->filterSubscription = ""; $this->filterStatus = ""; $this->chkCertificateNormal = 0; $this->chkCertificateAgonistico = 0; $this->chkCertificateScaduti = 0; $this->chkCertificateScadenza = 0; $this->chkCard = []; } }