-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPresentation.php
98 lines (86 loc) · 2.59 KB
/
Presentation.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
<?php
namespace App\Livewire\Schedule;
use Carbon\Carbon;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
class Presentation extends Component
{
public $id;
public $presentation;
public $height;
public $marginTop;
public $details;
public $colors;
/**
* Initializes the component
* @param $presentation
* @return void
*/
public function mount($presentation)
{
$this->presentation = $presentation;
$this->id = $this->presentation->id;
$this->height = $this->calculateHeightInREM();
$this->marginTop = $this->calculateMarginTopInREM();
$this->details = $this->getDetails();
$this->colors = $this->getColors();
}
/**
* Calculates the height of the element in REM based on it's duration
* @return float
*/
protected function calculateHeightInREM()
{
return $this->presentation->duration * (14 / 30) * 0.25;
}
/**
* Calculates the margin top of the element in REM based on how later
* the presentation starts in comparison to the beginning of the timeslot
* @return float
*/
protected function calculateMarginTopInREM()
{
$presentationStart = Carbon::parse($this->presentation->start);
$timeslotStart = Carbon::parse($this->presentation->timeslot->start);
$diff = $timeslotStart->copy()->diffInMinutes($presentationStart);
return $diff * (14 / 30) * 0.25;
}
/**
* Decides whether to display company name or independent speakers name
* @return mixed
*/
protected function getDetails()
{
return is_null($this->presentation->company)
? $this->presentation->speakers->first()->name
: $this->presentation->company->name;
}
/**
* Decides in what color to color the presentation based on the presentation type
* @return string
*/
protected function getColors()
{
return $this->presentation->type == 'lecture' ? 'bg-crew-300' : 'bg-apricot-peach-300';
}
/**
* Listens for an update event to be dispatched from the parent to refresh the component
* @return void
*/
#[On("update-presentation-{id}")]
public function refresh()
{
$this->presentation = $this->presentation->refresh();
$this->height = $this->calculateHeightInREM();
$this->marginTop = $this->calculateMarginTopInREM();
}
/**
* Renders the component
* @return View
*/
public function render() : View
{
return view('livewire.schedule.presentation');
}
}