-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegistrationInfoView.php
93 lines (80 loc) · 2.19 KB
/
RegistrationInfoView.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
<?php
namespace App\Livewire;
use App\Models\Event;
use App\Models\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Livewire\Component;
class RegistrationInfoView extends Component
{
/**
* @var Event
*/
public $event;
/**
* @var Collection<int, User>
*/
public $attendees;
/**
* @var ?int;
*/
public $currentPosition;
/**
* @var ?User
*/
public $currentAttendee;
public function mount(): void
{
$this->attendees = $this
->event
->attendees
->sortBy([['first_name', 'asc'], ['family_name', 'asc']])
->values();
if ($this->attendees != null && count($this->attendees) > 0) {
$this->currentPosition = 0;
$this->currentAttendee = $this->attendees->first();
} else {
$this->attendees = Collection::empty();
}
}
public function render(): View|Factory
{
return view('livewire.registration-info-view');
}
public function updatedCurrentPosition(int $position): void
{
$newCurrent = $this->attendees->slice($position, 1)->first();
if ($newCurrent != null) {
$this->currentAttendee = $newCurrent;
}
}
public function goToPrevious(): void
{
if ($this->hasPrevious()) {
$this->currentPosition = $this->currentPosition - 1;
$this->currentAttendee = $this->attendees[$this->currentPosition];
}
}
/**
* Indicates whether there is a previous attendee to show details for.
*/
public function hasPrevious(): bool
{
return ! $this->currentAttendee?->is($this->attendees->first());
}
public function goToNext(): void
{
if ($this->hasNext()) {
$this->currentPosition = $this->currentPosition + 1;
$this->currentAttendee = $this->attendees[$this->currentPosition];
}
}
/**
* Indicates whether there is a next attendee to show details for.
*/
public function hasNext(): bool
{
return ! $this->currentAttendee?->is($this->attendees->last());
}
}