| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use App\Http\Middleware\TenantMiddleware;
- use Livewire\WithPagination;
- use Illuminate\Support\Facades\Auth;
- class Courses extends Component
- {
- public $level_1 = [];
- public $level_2 = [];
- public $level_3 = [];
- public $level_1_id = 0;
- public $level_2_id = 0;
- public $level_3_id = 0;
- public $course_id = null;
- public function boot()
- {
- app(TenantMiddleware::class)->setupTenantConnection();
- }
- public function mount($course_id)
- {
- $this->course_id = $course_id;
- if ($this->course_id != null)
- {
- $c = \App\Models\Course::findOrFail($this->course_id);
- $ids = array_reverse($c->recursiveParent($c->parent_id, [$c->id]));
- foreach($ids as $ii => $i)
- {
- if ($ii == 0)
- {
- $this->level_1_id = $i;
- }
- if ($ii == 1)
- {
- $this->level_2_id = $i;
- }
- if ($ii == 2)
- {
- $this->level_3_id = $i;
- }
- }
- }
- }
- public function updatedLevel1Id() {
- $this->emit('setCourse', null);
- $this->level_2_id = 0;
- $this->level_2 = [];
- $this->level_3_id = 0;
- $this->level_3 = [];
- }
- public function updatedLevel2Id() {
- $this->emit('setCourse', null);
- $this->level_3_id = 0;
- $this->level_3 = [];
- }
- public function updatedLevel3Id() {
- $this->emit('setCourse', null);
- }
- public function render()
- {
- $reset = false;
- if ($this->level_1_id > 0)
- {
- $this->level_2 = \App\Models\Course::where('parent_id', $this->level_1_id)->orderBy('name')->get();
- if (sizeof($this->level_2) == 0)
- {
- $this->emit('setCourse', $this->level_1_id);
- $reset = true;
- }
- }
- if ($this->level_2_id > 0)
- {
- $this->level_3 = \App\Models\Course::where('parent_id', $this->level_2_id)->orderBy('name')->get();
- if (sizeof($this->level_3) == 0)
- {
- $this->emit('setCourse', $this->level_2_id);
- $reset = true;
- }
- }
- if ($this->level_3_id > 0)
- {
- $this->emit('setCourse', $this->level_3_id);
- $reset = true;
- }
- $this->level_1 = \App\Models\Course::where('parent_id', null)->orderBy('name')->get();
- return view('livewire.courses');
- }
- }
|