diff --git a/Models/Panels/Actions/TryAlertAction.php b/Models/Panels/Actions/TryAlertAction.php new file mode 100644 index 00000000..b96175b0 --- /dev/null +++ b/Models/Panels/Actions/TryAlertAction.php @@ -0,0 +1,49 @@ +Try Alert'; + + /** + * @return mixed + */ + public function handle() { + $data = request()->all(); + + if (! isset($data['user_id'])) { + abort(403, 'Devi specificare uno user_id'); + } + + // dddx(User::find($data['user_id'])); + + $user = User::find($data['user_id']); + + $user->notify(new Alert($user)); + + $view = ThemeService::getView(); + + $view_params = [ + 'view' => $view, + ]; + + return view()->make($view, $view_params); + } +} diff --git a/Models/Panels/Policies/_ModulePanelPolicy.php b/Models/Panels/Policies/_ModulePanelPolicy.php index 8238eb9a..1bb41c68 100755 --- a/Models/Panels/Policies/_ModulePanelPolicy.php +++ b/Models/Panels/Policies/_ModulePanelPolicy.php @@ -47,4 +47,11 @@ public function testMail(UserContract $user,PanelContract $panel):bool{ >>>>>>> 9f492fe (up) return true; } + + /** + * --. + */ + public function TryAlert(UserContract $user, PanelContract $panel): bool { + return true; + } } diff --git a/Models/Panels/_ModulePanel.php b/Models/Panels/_ModulePanel.php index 66a79401..0948157b 100755 --- a/Models/Panels/_ModulePanel.php +++ b/Models/Panels/_ModulePanel.php @@ -16,10 +16,14 @@ public function actions(): array { new Actions\TestMailAction(), new Actions\TrySendMailAction(), <<<<<<< HEAD +<<<<<<< HEAD ======= >>>>>>> 42aa20e (.) ======= >>>>>>> 3a62aee (up) +======= + new Actions\TryAlertAction(), +>>>>>>> 626ce4c (up) ]; } } diff --git a/Notifications/Alert.php b/Notifications/Alert.php new file mode 100644 index 00000000..e760d777 --- /dev/null +++ b/Notifications/Alert.php @@ -0,0 +1,84 @@ +user = $user; + $this->userAlerts = ProfileService::make()->alerts()->get(); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * + * @return array + */ + public function via($notifiable) { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) { + $email = (new MailMessage()) + ->from(ProfileService::make()->getUser()->email) + ->subject("Alerts {$this->user->first_name}!") + ->line("Buongiorno: {$this->user->first_name}") + ->line('Questi sono i tuoi alert:'); + + $model = Press::make(); + $panel = PanelService::make()->get($model); + + $presses = []; + foreach ($this->userAlerts as $userAlert) { + /* $panel->rowsPaginated($userAlert), */ + + $presses = array_merge($presses, $panel->rowsPaginated($userAlert->toArray())->all()); + + foreach ($presses as $press) { + $email = $email->line($press->title); + } + } + + $email = $email->line('Grazie per aver utilizzato la nostra applicazione!'); + + return $email; + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * + * @return array + */ + public function toArray($notifiable) { + return [ + ]; + } +}