-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Malebestia
committed
Sep 4, 2023
1 parent
810772f
commit 7019f84
Showing
4 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* --. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Modules\Notify\Models\Panels\Actions; | ||
|
||
// -------- services -------- | ||
|
||
use Modules\LU\Models\User; | ||
use Modules\Notify\Notifications\Alert; | ||
use Modules\Theme\Services\ThemeService; | ||
use Modules\Xot\Models\Panels\Actions\XotBasePanelAction; | ||
|
||
// -------- bases ----------- | ||
|
||
/** | ||
* Class TestAction. | ||
*/ | ||
class TryAlertAction extends XotBasePanelAction { | ||
public bool $onItem = true; | ||
public string $icon = '<i class="fas fa-vial"></i>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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Modules\Notify\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use Modules\LU\Models\User; | ||
use Modules\LU\Services\ProfileService; | ||
use Modules\Mediamonitor\Models\Press; | ||
use Modules\Xot\Services\PanelService; | ||
|
||
class Alert extends Notification { | ||
use Queueable; | ||
|
||
private $user; | ||
private $userAlerts; | ||
|
||
/** | ||
* Create a new notification instance. | ||
*/ | ||
public function __construct(User $user) { | ||
$this->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 [ | ||
]; | ||
} | ||
} |