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:
Nabeel S
2019-11-20 10:16:01 -05:00
committed by GitHub
parent 02973a0f22
commit ea3ab21beb
66 changed files with 754 additions and 718 deletions

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}

View 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,
];
}
}