6
6
7
7
use ArtisanBuild \Adverbs \Traits \ReturnsModelInstanceOnHandle ;
8
8
use ArtisanBuild \Hallway \Calendar \Enums \InvitationLevels ;
9
+ use ArtisanBuild \Hallway \Calendar \States \CalendarRangeState ;
9
10
use ArtisanBuild \Hallway \Calendar \States \GatheringState ;
10
11
use ArtisanBuild \Hallway \Members \Actions \GetMemberTimeZone ;
11
12
use ArtisanBuild \Hallway \Members \Enums \MemberRoles ;
15
16
use ArtisanBuild \VerbsFlux \Attributes \EventInput ;
16
17
use ArtisanBuild \VerbsFlux \Enums \InputTypes ;
17
18
use Carbon \Carbon ;
19
+ use Thunk \Verbs \Attributes \Autodiscovery \AppliesToSingletonState ;
18
20
use Thunk \Verbs \Attributes \Autodiscovery \StateId ;
19
21
use Thunk \Verbs \Event ;
20
22
23
+ #[AppliesToSingletonState(CalendarRangeState::class)]
21
24
#[EventForm(
22
25
submit_text: 'Create New Gathering ' ,
23
26
has_time_machine: true ,
@@ -35,7 +38,6 @@ class GatheringCreated extends Event
35
38
#[StateId(GatheringState::class)]
36
39
public ?int $ gathering_id = null ;
37
40
38
-
39
41
#[EventInput(
40
42
type: InputTypes::Text,
41
43
)]
@@ -73,6 +75,7 @@ class GatheringCreated extends Event
73
75
options: ['No ' , 'Yes ' ],
74
76
)]
75
77
public bool $ published = false ;
78
+
76
79
public ?Carbon $ cancelled_at = null ;
77
80
78
81
#[EventInput(
@@ -93,18 +96,24 @@ class GatheringCreated extends Event
93
96
)]
94
97
public ?string $ url = null ;
95
98
96
- public function apply ( GatheringState $ state ): void
99
+ public function applyToCalendarRangeState ( CalendarRangeState $ range ): void
97
100
{
98
- $ start = Carbon::parse ($ this ->start ->format ('Y-m-d\TH:i ' ), $ this ->timezone )->setTimezone ('UTC ' );
101
+ $ end = $ this ->start ->copy ()->addMinutes ($ this ->duration );
102
+ $ range ->first_gathering_start = $ range ->first_gathering_start ?->isBefore($ this ->start ) ? $ range ->first_gathering_start : $ this ->start ;
103
+ $ range ->last_gathering_end = $ range ->last_gathering_end ?->isAfter($ end ) ? $ range ->last_gathering_end : $ end ;
104
+ }
99
105
106
+ public function applyToGatheringState (GatheringState $ gathering ): void
107
+ {
108
+ $ start = Carbon::parse ($ this ->start ->format ('Y-m-d\TH:i ' ), $ this ->timezone )->setTimezone ('UTC ' );
100
109
101
- $ state ->title = $ this ->title ;
102
- $ state ->description = $ this ->description ;
103
- $ state ->start = $ start ;
104
- $ state ->end = $ start ->copy ()->addMinutes ($ this ->duration );
105
- $ state ->published_at = $ this ->published ? now () : null ;
106
- $ state ->cancelled_at = $ this ->cancelled_at ;
107
- $ state ->invitation_level = $ this ->invitation_level ;
110
+ $ gathering ->title = $ this ->title ;
111
+ $ gathering ->description = $ this ->description ;
112
+ $ gathering ->start = $ start ;
113
+ $ gathering ->end = $ start ->copy ()->addMinutes ($ this ->duration );
114
+ $ gathering ->published_at = $ this ->published ? now () : null ;
115
+ $ gathering ->cancelled_at = $ this ->cancelled_at ;
116
+ $ gathering ->invitation_level = $ this ->invitation_level ;
117
+ $ gathering ->capacity = $ this ->capacity ;
108
118
}
109
-
110
119
}
0 commit comments