Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Malebestia committed Sep 4, 2023
1 parent 810772f commit 7019f84
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Models/Panels/Actions/TryAlertAction.php
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);
}
}
7 changes: 7 additions & 0 deletions Models/Panels/Policies/_ModulePanelPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions Models/Panels/_ModulePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ public function actions(): array {
new Actions\TestMailAction(),
new Actions\TrySendMailAction(),
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 42aa20e (.)
=======
>>>>>>> 3a62aee (up)
=======
new Actions\TryAlertAction(),
>>>>>>> 626ce4c (up)
];
}
}
84 changes: 84 additions & 0 deletions Notifications/Alert.php
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 [
];
}
}

0 comments on commit 7019f84

Please sign in to comment.