-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRoomAndTimeslotSelector.php
104 lines (87 loc) · 2.98 KB
/
RoomAndTimeslotSelector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace App\Http\Livewire;
use App\Http\Controllers\Crew\ScheduleController;
use App\Models\DefaultPresentation;
use App\Models\Room;
use App\Models\Timeslot;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Contracts\View\Factory;
use Illuminate\Foundation\Application;
use Livewire\Component;
class RoomAndTimeslotSelector extends Component
{
public $presentation;
public $rooms;
public $timeslots;
public $maxParticipants;
public $selectedRoom;
/**
* Triggered on initializing the component
* @return void
*/
public function mount()
{
$this->rooms = Room::all();
if ($this->presentation->room) {
$this->selectedRoom = $this->presentation->room_id;
$this->updatedSelectedRoom($this->presentation->room_id);
}
}
/**
* @param $value
* @return void
*/
public function updatedSelectedRoom($value)
{
if ($this->selectedRoom) {
$allTimeslots = Timeslot::where('duration', $this->presentation->type == 'lecture' ? 30 : 80)
->get();
$room = Room::find($this->selectedRoom);
$timeslotIds = $allTimeslots->filter(function ($timeslot) use ($room) {
return (new ScheduleController())->checkIfTimeslotAndRoomAreAvailable($room, $timeslot);
})->pluck('id');
if ($this->selectedRoom == $this->presentation->room_id) {
$timeslotIds[] = $this->presentation->timeslot_id;
}
if (DefaultPresentation::opening() && DefaultPresentation::closing()) {
$this->timeslots = Timeslot::whereIn('id', $timeslotIds)
->whereNotIn('id', [
DefaultPresentation::opening()->timeslot->id,
DefaultPresentation::closing()->timeslot->id
])
->get();
} else {
$this->timeslots = Timeslot::whereIn('id', $timeslotIds)->get();
}
$this->getMaxParticipants();
}
}
/**
* @return void
*/
public function getMaxParticipants(): void
{
$this->maxParticipants =
Room::find($this->selectedRoom)->max_participants < $this->presentation->max_participants
? Room::find($this->selectedRoom)->max_participants
: $this->presentation->max_participants;
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function resetTimeslot()
{
$this->presentation->timeslot_id = null;
$this->presentation->room_id = null;
$this->presentation->save();
return redirect()->to(route('moderator.schedule.presentation', $this->presentation));
}
/**
* Render the component
* @return Factory|Application|\Illuminate\Contracts\View\View|ApplicationContract
*/
public function render()
{
return view('livewire.room-and-timeslot-selector');
}
}