| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class CourseMember extends Component
- {
- public $records = array();
- public $courses = [];
- public $course_durations = [];
- public $course_types = [];
- public $course_levels = [];
- public $course_years = [];
- public $filterCourse = "";
- public $filterLevel = "";
- public $filterType = "";
- public $filterDuration = "";
- 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 function mount()
- {
- $this->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::select('*')->orderBy('name', 'ASC')->get();
- }
- public function render()
- {
- // Carico tutti i corsi associati
- $datas = \App\Models\MemberCourse::with('member');
- if ($this->filterCourse != "")
- $datas = $datas->where('course_id', $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);
- }
- if ($this->filterType != "")
- {
- $course_ids = \App\Models\Course::where('course_type_id', $this->filterType)->pluck('id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- if ($this->filterDuration != "")
- {
- $course_ids = \App\Models\Course::where('course_duration_id', $this->filterDuration)->pluck('id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- if ($this->filterDays != "")
- {
- $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterDays . "%")->pluck('course_id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- if ($this->filterHours != "")
- {
- $course_ids = \App\Models\Membercourse::where('when', 'like', "%" . $this->filterHours . "%")->pluck('course_id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- if ($this->filterSubscription != "")
- {
- $course_ids = \App\Models\MemberCourse::where('subscribed', $this->filterSubscription == 1 ? true : false)->pluck('id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- if ($this->chkCertificateNormal > 0)
- {
- $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
- $datas = $datas->whereIn('member_id', $normal);;
- }
- if ($this->chkCertificateAgonistico > 0)
- {
- $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
- $datas = $datas->whereIn('member_id', $agonistic);
- }
- if ($this->chkCertificateScaduti > 0)
- {
- $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
- $datas = $datas->whereIn('member_id', $scaduto);
- }
- 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);
- }
- 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);
- }
- if ($this->filterYear != "")
- {
- $course_ids = \App\Models\Course::where('year', $this->filterYear)->pluck('id');
- $datas = $datas->whereIn('course_id', $course_ids);
- }
- $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 = [];
- }
- }
|