-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGridParentComponent.php
119 lines (103 loc) · 3.35 KB
/
GridParentComponent.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace App\Livewire\Schedule;
use App\Models\Presentation;
use App\Models\Room;
use App\Models\Sponsorship;
use App\Models\Timeslot;
use Carbon\Carbon;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
class GridParentComponent extends Component
{
public $rooms;
public $timeslots;
public $unscheduledPresentations;
public $lectureCount;
public $workshopCount;
/**
* Initializes the component
* @return void
*/
public function mount()
{
$this->rooms = Room::all();
$this->timeslots = Timeslot::all();
$this->refreshUnscheduledPresentations();
}
/**
* Fetches the data for the unscheduled presentations from the database
*
* @return void
*/
public function refreshUnscheduledPresentations()
{
$this->unscheduledPresentations = Presentation::where(function ($presentation) {
return $presentation->whereNull(['timeslot_id', 'room_id', 'start']);
})->get()->where('is_approved', '=', 1);
$this->lectureCount = $this->unscheduledPresentations->where('type', 'lecture')->count();
$this->workshopCount = $this->unscheduledPresentations->where('type', 'workshop')->count();
}
/**
* Listens for a moving event sent by the children (cells) to relocate presentations
* and dispatches an event to the children to update
* @param $data
* @return void
*/
#[On('move-presentation')]
public function proccessMovingPresentation($data)
{
$this->authorize('edit-schedule');
$presentation = Presentation::find($data['presentation_id']);
$oldRoom = $presentation->room;
$oldTimeslot = $presentation->timeslot;
$presentation->update([
'room_id' => $data['new_room_id'],
'timeslot_id' => $data['new_timeslot_id'],
'start' => $data['new_time']
]);
$presentation->save();
$presentation->refresh();
if ($oldRoom && $oldTimeslot) {
$this->dispatch("update-cell-r-{$oldRoom->id}-t-{$oldTimeslot->id}");
} else {
$this->refreshUnscheduledPresentations();
}
$this->dispatch("update-cell-r-{$presentation->room->id}-t-{$presentation->timeslot->id}");
$this->dispatch("check-programme-status");
}
/**
* Responsible for handling the removing of presentation
* from the schedule
*
* @param $data
* @return void
*/
#[On('remove-presentation')]
public function removeScheduledPresentation($data)
{
$presentation = Presentation::find($data['presentation_id']);
$oldRoomId = $presentation->room_id;
$oldTimeslotId = $presentation->timeslot_id;
$presentation->update([
'start' => null
]);
$presentation->room()->dissociate();
$presentation->timeslot()->dissociate();
$presentation->save();
$presentation->refresh();
$this->refreshUnscheduledPresentations();
$this->dispatch("update-cell-r-{$oldRoomId}-t-{$oldTimeslotId}");
$this->dispatch("check-programme-status");
}
/**
* Renders the component
*
* @return View
*/
public function render(): View
{
return view('livewire.schedule.grid-parent-component');
}
}