391 Notification refactorings (#441)
* Refactor notifications to allow easier plugins * Notification refactoring * Formatting * Move news to NewsService; cleanup of events * More refactoring; added send email out for news item and the template * Formatting * Formatting
This commit is contained in:
38
app/Notifications/Messages/AdminUserRegistered.php
Normal file
38
app/Notifications/Messages/AdminUserRegistered.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class AdminUserRegistered extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->user = $user;
|
||||
$this->setMailable(
|
||||
'A new user registered',
|
||||
'notifications.mail.admin.user.registered',
|
||||
['user' => $user]
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'user_id' => $this->user->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
40
app/Notifications/Messages/NewsAdded.php
Normal file
40
app/Notifications/Messages/NewsAdded.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\News;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class NewsAdded extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $news;
|
||||
|
||||
public function __construct(News $news)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->news = $news;
|
||||
$this->setMailable(
|
||||
$news->subject,
|
||||
'notifications.mail.news',
|
||||
['news' => $news]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'news_id' => $this->news->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Notifications/Messages/PirepAccepted.php
Normal file
50
app/Notifications/Messages/PirepAccepted.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
/**
|
||||
* Send the PIREP accepted message to a particular user
|
||||
*/
|
||||
class PirepAccepted extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $pirep;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param \App\Models\Pirep $pirep
|
||||
*/
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->pirep = $pirep;
|
||||
|
||||
$this->setMailable(
|
||||
'PIREP Accepted!',
|
||||
'notifications.mail.pirep.accepted',
|
||||
['pirep' => $this->pirep]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'pirep_id' => $this->pirep->id,
|
||||
'user_id' => $this->pirep->user_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Notifications/Messages/PirepRejected.php
Normal file
47
app/Notifications/Messages/PirepRejected.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class PirepRejected extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $pirep;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param \App\Models\Pirep $pirep
|
||||
*/
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->pirep = $pirep;
|
||||
|
||||
$this->setMailable(
|
||||
'PIREP Rejected!',
|
||||
'notifications.mail.pirep.rejected',
|
||||
['pirep' => $this->pirep]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'pirep_id' => $this->pirep->id,
|
||||
'user_id' => $this->pirep->user_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Notifications/Messages/PirepSubmitted.php
Normal file
47
app/Notifications/Messages/PirepSubmitted.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class PirepSubmitted extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $pirep;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param \App\Models\Pirep $pirep
|
||||
*/
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->pirep = $pirep;
|
||||
|
||||
$this->setMailable(
|
||||
'New PIREP Submitted',
|
||||
'notifications.mail.admin.pirep.submitted',
|
||||
['pirep' => $this->pirep]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'pirep_id' => $this->pirep->id,
|
||||
'user_id' => $this->pirep->user_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Notifications/Messages/UserPending.php
Normal file
42
app/Notifications/Messages/UserPending.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserPending extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
$this->setMailable(
|
||||
'Your registration is pending',
|
||||
'notifications.mail.user.pending',
|
||||
['user' => $this->user]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'user_id' => $this->user->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Notifications/Messages/UserRegistered.php
Normal file
39
app/Notifications/Messages/UserRegistered.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserRegistered extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->setMailable(
|
||||
'Welcome to '.config('app.name').'!',
|
||||
'notifications.mail.user.registered',
|
||||
['user' => $this->user]
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'user_id' => $this->user->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
44
app/Notifications/Messages/UserRejected.php
Normal file
44
app/Notifications/Messages/UserRejected.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserRejected extends BaseNotification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param \App\Models\User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->setMailable(
|
||||
'Your registration has been denied',
|
||||
'notifications.mail.user.rejected',
|
||||
['user' => $this->user]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'user_id' => $this->user->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user