-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReplacePresentation.php
71 lines (61 loc) · 2.31 KB
/
ReplacePresentation.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
<?php
namespace App\Http\Livewire\Schedule;
use App\Models\Presentation;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Livewire\Component;
class ReplacePresentation extends Component
{
public Presentation $presentationToBeReplaced;
public $availablePresentations;
public $newPresentationId;
/**
* Triggered on initializing the component
* @return void
*/
public function mount()
{
$this->availablePresentations = Presentation::all()->filter(function ($presentation) {
return !$presentation->isScheduled
&& $presentation->type == $this->presentationToBeReplaced->type;
});
if ($this->availablePresentations->count() > 0) {
$this->newPresentationId = $this->availablePresentations->first()->id;
}
}
/**
* Replaces the presentation that has been passed with the one chosen -> detaches
* all participants of the replaced participants as well
* @return RedirectResponse
*/
public function replace()
{
$newPresentation = Presentation::find($this->newPresentationId);
if (is_null($newPresentation)) {
return redirect(route('moderator.schedule.presentation', $this->presentationToBeReplaced))
->with(
'error',
'An issue occurred with replacement of the presentation.
Please try again later or contact the dev team'
);
}
$newPresentation->room_id = $this->presentationToBeReplaced->room_id;
$newPresentation->timeslot_id = $this->presentationToBeReplaced->timeslot_id;
$newPresentation->save();
$this->presentationToBeReplaced->room_id = null;
$this->presentationToBeReplaced->timeslot_id = null;
$this->presentationToBeReplaced->participants()->detach();
$this->presentationToBeReplaced->save();
return redirect()->to(route('moderator.schedule.index'));
}
/**
* Renders the component
* @return View|Application|Factory|\Illuminate\Contracts\Foundation\Application
*/
public function render()
{
return view('moderator.schedule.presentations.replace-presentation');
}
}