File tree Expand file tree Collapse file tree 4 files changed +90
-0
lines changed
Expand file tree Collapse file tree 4 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Listeners ;
4+
5+ use App \Events \SpeedtestCompleted ;
6+ use App \Models \Result ;
7+ use App \Models \User ;
8+ use Filament \Actions \Action ;
9+ use Filament \Notifications \Notification ;
10+
11+ class ProcessCompletedSpeedtest
12+ {
13+ /**
14+ * Handle the event.
15+ */
16+ public function handle (SpeedtestCompleted $ event ): void
17+ {
18+ $ result = $ event ->result ;
19+
20+ if ($ result ->dispatched_by && ! $ result ->scheduled ) {
21+ $ this ->notifyDispatchingUser ($ result );
22+ }
23+ }
24+
25+ /**
26+ * Notify the user who dispatched the speedtest.
27+ */
28+ private function notifyDispatchingUser (Result $ result ): void
29+ {
30+ $ user = User::find ($ result ->dispatched_by );
31+
32+ $ user ->notify (
33+ Notification::make ()
34+ ->title (__ ('results.speedtest_completed ' ))
35+ ->actions ([
36+ Action::make ('view ' )
37+ ->label (__ ('general.view ' ))
38+ ->url (route ('filament.admin.resources.results.index ' )),
39+ ])
40+ ->success ()
41+ ->toDatabase (),
42+ );
43+ }
44+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Listeners ;
4+
5+ use App \Events \SpeedtestFailed ;
6+ use App \Models \Result ;
7+ use App \Models \User ;
8+ use Filament \Actions \Action ;
9+ use Filament \Notifications \Notification ;
10+
11+ class ProcessFailedSpeedtest
12+ {
13+ /**
14+ * Handle the event.
15+ */
16+ public function handle (SpeedtestFailed $ event ): void
17+ {
18+ $ result = $ event ->result ;
19+
20+ if ($ result ->dispatched_by && ! $ result ->scheduled ) {
21+ $ this ->notifyDispatchingUser ($ result );
22+ }
23+ }
24+
25+ /**
26+ * Notify the user who dispatched the speedtest.
27+ */
28+ private function notifyDispatchingUser (Result $ result ): void
29+ {
30+ $ user = User::find ($ result ->dispatched_by );
31+
32+ $ user ->notify (
33+ Notification::make ()
34+ ->title (__ ('results.speedtest_failed ' ))
35+ ->actions ([
36+ Action::make ('view ' )
37+ ->label (__ ('general.view ' ))
38+ ->url (route ('filament.admin.resources.results.index ' )),
39+ ])
40+ ->warning ()
41+ ->toDatabase (),
42+ );
43+ }
44+ }
Original file line number Diff line number Diff line change 1616 'no ' => 'No ' ,
1717 'options ' => 'Options ' ,
1818 'details ' => 'Details ' ,
19+ 'view ' => 'View ' ,
1920
2021 // Common labels
2122 'name ' => 'Name ' ,
Original file line number Diff line number Diff line change 6363 // Notifications
6464 'speedtest_started ' => 'Speedtest started ' ,
6565 'speedtest_completed ' => 'Speedtest completed ' ,
66+ 'speedtest_failed ' => 'Speedtest failed ' ,
6667 'download_threshold_breached ' => 'Download threshold breached! ' ,
6768 'upload_threshold_breached ' => 'Upload threshold breached! ' ,
6869 'ping_threshold_breached ' => 'Ping threshold breached! ' ,
You can’t perform that action at this time.
0 commit comments