| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class CourseMember extends Component
- {
- public $records = array();
- public $courses = [];
- public $course_frequencies = [];
- public $course_types = [];
- public $course_levels = [];
- public $course_years = [];
- public $filterCourse = "";
- public $filterLevel = "";
- public $filterType = "";
- public $filterFrequency = "";
- public $filterDays = "";
- public $filterHours = "";
- public $filterSubscription = "";
- public $filterStatus = "";
- public $filterYear = "";
- public $chkCertificateNormal = 0;
- public $chkCertificateAgonistico = 0;
- public $chkCertificateScaduti = 0;
- public $chkCertificateScadenza = 0;
- public $chkCard = [];
- public $filter = '';
- public function mount()
- {
- $this->course_types = \App\Models\CourseType::select('*')->where('enabled', true)->get();
- $this->course_frequencies = \App\Models\CourseFrequency::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->filterFrequency != "")
- {
- $course_ids = \App\Models\Course::where('course_frequency_id', $this->filterFrequency)->pluck('id');
- $datas = $datas->whereIn('course_id', $course_ids);
- $this->filter .= $this->filter != '' ? ', ' : '';
- $this->filter .= "Durata : " . \App\Models\CourseFrequency::findOrFail($this->filterFrequency)->name . " ";
- }
- if ($this->filterDays != "")
- {
- $members_ids = \App\Models\MemberCourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('member_id');
- $datas = $datas->whereIn('member_id', $members_ids);
- $this->filter .= $this->filter != '' ? ', ' : '';
- $this->filter .= "Giorni : " . $this->filterDays . " ";
- }
- if ($this->filterHours != "")
- {
- $members_ids = \App\Models\MemberCourse::where('when', 'like', '%"from":"' . $this->filterHours . "%")->pluck('member_id');
- $datas = $datas->whereIn('member_id', $members_ids);
- $this->filter .= $this->filter != '' ? ', ' : '';
- $this->filter .= "Ore : " . $this->filterHours . " ";
- }
- if ($this->filterSubscription != "")
- {
- $ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
- $datas = $datas->whereIn('id', $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->filterFrequency = "";
- $this->filterDays = "";
- $this->filterHours = "";
- $this->filterSubscription = "";
- $this->filterStatus = "";
- $this->chkCertificateNormal = 0;
- $this->chkCertificateAgonistico = 0;
- $this->chkCertificateScaduti = 0;
- $this->chkCertificateScadenza = 0;
- $this->chkCard = [];
- }
- }
|