public $timestamps = false;
+ /**
+ * @param $slug
+ * @return EmailTemplate
+ */
+ public static function findSlug($slug)
+ {
+ return self::query()
+ ->where('slug', $slug)
+ ->firstOrFail();
+ }
+
/**
* @param $user
* @param $content
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
-use App\Notifications\EmailValidated;
use App\Providers\RouteServiceProvider;
+use App\User;
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Http\Request;
*/
protected function verified(Request $request)
{
- $request->user()->notify(new EmailValidated);
+ /** @var User $user */
+ $user = $request->user();
+
+ $template = ($user->self_registered && $user->type === User::TYPE_DISCOVER) ?
+ 'email_validated_with_trial' :
+ 'email_validated';
+
+ $user->sendEmailFromTemplate($template);
}
}
namespace App\Jobs;
-use App\Notifications\TrialExpired;
-use App\Notifications\TrialExpiresSoon;
+
use App\User;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
*/
public function handle()
{
- self::getExpiresSoonProfiles()->map(fn(User $user) => $user->notify(new TrialExpiresSoon));
+// self::getExpiresSoonProfiles()->map(fn(User $user) => $user->notify(new TrialExpiresSoon));
- self::getLastEditionTodayProfiles()->map(fn(User $user) => $user->notify(new TrialExpired));
+// self::getLastEditionTodayProfiles()->map(fn(User $user) => $user->notify(new TrialExpired));
}
* Create a new message instance.
*
* @param $content
+ * @param $subject
*/
- public function __construct($content)
+ public function __construct($content, $subject)
{
$this->content = $content;
+ $this->subject = $subject;
}
/**
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use App\User;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Notifications\Messages\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class EmailValidated extends Notification
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- return (new MailMessage)
- ->subject('Email validé !')
- ->line("Votre adresse email à bien été validée.");
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use App\Mail\MailMessage;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use Illuminate\Notifications\Notification;
-
-class JustSubscribed extends Notification
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- $message = (new MailMessage)
- ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Abonnement activé !')
- ->line('Votre abonnement à PRESCRIPTION SANTÉ QUOTIDIEN est désormais actif !')
- ->addTag('just-subscribed');
-
-
- if($notifiable->reg_complete) {
- $message->line("Votre compte est déjà activé, vous n'avez rien de plus à faire.");
- } else {
- $link = $notifiable->routeWithToken('account.complete-reg', [], now()->addDays(7));
- $message
- ->line("Cliquez sur le bouton ci-dessous pour créer un mot de passe et activer votre compte pour ne rater aucun numéro de notre quotidien !")
- ->action('Créer mon mot de passe', $link)
- ->line("Cela ne prendra pas plus d'une minute !");
- }
-
- return $message;
-
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class RegistrationComplete extends Notification implements ShouldQueue
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- return (new MailMessage)
- ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Activation réussie !')
- ->success()
- ->greeting('Cher lecteur,')
- ->line("Votre compte à bien été activé !")
- ->line("Vous allez pouvoir recevoir les prochains numéros de *Prescription Santé : Le Quotidien*")
- ->addTag('reg_complete');
-
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use App\User;
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class RegistrationPending extends Notification implements ShouldQueue
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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 User $notifiable
- * @return \Illuminate\Notifications\Messages\MailMessage
- */
- public function toMail($notifiable)
- {
-
- $link = $notifiable->routeWithToken('account.complete-reg', [], now()->addDays(14));
- return (new MailMessage)
- ->subject('[Relance] PRESCRIPTION SANTÉ QUOTIDIEN : Activation en attente')
- ->greeting('Cher lecteur,')
- ->line("Nous avons remarqué que votre compte n'est toujours pas activé.")
- ->line("Veuillez cliquer sur ce lien pour créer votre mot de passe et ne rater aucun numéro de *Prescription Santé : Le Quotidien* !")
- ->line("Cela ne vous prendra pas plus d'une minute.")
- ->action('Compléter mon inscription', $link)
- ->addTag('reg_pending');
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class TrialExpired extends Notification
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- return (new MailMessage)
- ->addTag('trial-expired')
- ->subject("Votre période découverte est arrivée à son terme !")
- ->greeting('Cher Lecteur,')
- ->line("Au cours des deux dernières semaines, vous avez reçu gratuitement les éditions de **Prescription Santé Quotidien** dans le cadre de notre offre Découverte.")
- ->line("Malheureusement, cette offre, non reconductible, est arrivée à son terme aujourd’hui et l'édition transmise ce matin est donc la dernière. **Vous pouvez dès maintenant nous contacter en cliquant sur le bouton ci-dessous** pour nous préciser le cadre d’un éventuel abonnement, et ce afin de ne pas rater une seule de nos éditions.")
- ->action("Nous contacter", route('contact.index'))
- ->line("Nous vous répondrons sous 24 heures et vous pourrez ainsi faire un choix éclairé.")
- ->line("En espérant vous compter bientôt parmi nos abonnés")
- ->salutation("LE RÉDACTEUR EN CHEF, OLIVIER ROBICHON");
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class TrialExpiresSoon extends Notification
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- return (new MailMessage)
- ->addTag('trial-expires-soon')
- ->subject("Votre période découverte expire bientôt !")
- ->greeting('Cher Lecteur,')
- ->line("Depuis quelques jours vous recevez gratuitement les éditions de **Prescription Santé Quotidien** dans le cadre de notre offre Découverte.")
- ->line("Nous espérons que vous appréciez ce média différent à destination des acteurs industriels de la santé et de leurs partenaires.")
- ->line("**Dans 48 heures cette offre, non reconductible, arrivera à son terme.** Vous pouvez dès maintenant **nous contacter en cliquant sur le bouton ci-dessous** pour nous préciser le cadre d’un éventuel abonnement, et ce afin de ne pas rater une seule de nos éditions.")
- ->action("Nous contacter", route('contact.index'))
- ->line("Nous vous répondrons sous 24 heures et vous pourrez ainsi faire un choix éclairé.")
- ->line("En espérant vous compter bientôt parmi nos abonnés")
- ->salutation("LE RÉDACTEUR EN CHEF, OLIVIER ROBICHON");
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
+++ /dev/null
-<?php
-
-namespace App\Notifications;
-
-use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
-use App\Mail\MailMessage;
-use Illuminate\Notifications\Notification;
-
-class Welcome extends Notification implements ShouldQueue
-{
- use Queueable;
-
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
-
- /**
- * 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)
- {
- $link = $notifiable->routeWithToken('account.index', [], now()->addDays(7));
- return (new MailMessage)
- ->subject('PRESCRIPTION SANTÉ QUOTIDIEN : Votre nouvelle plateforme')
- ->greeting('Cher Lecteur abonné à notre « petit » quotidien !')
- ->line("Ce dernier est justement de moins en moins petit et nous allons donc vous faire profiter, dès lundi d’une nouvelle formule dont le contenu comme la forme seront tout à la fois plus riches et plus « agréables » à lire.")
- ->line("Mais pour cela, nous devons vous demander un tout petit effort de quelques secondes à peine !")
- ->line("En cliquant sur le bouton ci-dessous vous devez vous créer un mot de passe.")
- ->action('Créer mon mot de passe', $link)
- ->line("Ainsi dès Lundi prochain vous pourrez accéder en un clic à votre quotidien préféré.")
- ->line("A très vite, donc ! ")
- ->salutation("OLIVIER ROBICHON")
- ->addTag('welcome');
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
-}
namespace App\Nova\Actions;
+use App\EmailTemplate;
use App\User;
use FontLib\Table\Type\name;
use Illuminate\Bus\Queueable;
*/
public function handle(ActionFields $fields, Collection $models)
{
- $models->map(fn(User $user) => $user->notify(new $fields->notification));
+
+ $models->map(fn(User $user) => $user->sendEmailFromTemplate($fields->notification));
+
return Action::message(sprintf('%d messages envoyés', $models->count()));
}
*/
public function fields()
{
+ $options = EmailTemplate::query()
+ ->pluck('name', 'slug')
+ ->toArray();
+
return [
- Select::make('Notification')->options([
-// Notifications\Welcome::class => 'Message de bienvenue',
- Notifications\RegistrationPending::class => 'Rappel',
- Notifications\JustSubscribed::class => 'Message abonnement activé'
- ])
+ Select::make('Notification')->options($options)
];
}
}
namespace App\Nova\Actions;
use App\User;
+use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
+use Laravel\Nova\Fields\Date;
+use Laravel\Nova\Fields\Number;
+use Laravel\Nova\Fields\Trix;
class StartTrial extends Action
{
public $showOnTableRow = true;
public $confirmButtonText = "Appliquer";
- public $name = "Démarrer période de découverte";
+ public $name = "Période de découverte";
+
public function __construct()
{
*/
public function handle(ActionFields $fields, Collection $models)
{
- $models->map->startDiscover();
+ $endDate = Carbon::parse($fields->end_date)->endOfDay();
+ $models->map(function(User $user) use($endDate){
+ $wasOnTrial = $user->onTrial() || $user->isOnDiscoverUser();
+
+ if($user->reg_complete) {
+ $user->startTrial($endDate);
+ } else {
+ $user->startDiscover($endDate);
+ }
+
+ if(! $wasOnTrial){
+ $user->sendEmailFromTemplate('start_trial');
+ }
+ });
return Action::message(sprintf("La période de découverte à bien été activée pour %d utilisteur(s)", $models->count()));
}
*/
public function fields()
{
- return [];
+ return [
+ Date::make('Date de fin', 'end_date')
+ ->withMeta(['value' => now()->addMonth()->format('Y-m-d')])
+ ->firstDayOfWeek(1)
+ ];
}
}
$user->organization()->associate(\App\Organization::query()->findOrFail($fields->org_id));
$user->save();
if(! $fields->dont_notify) {
- $user->notify(new JustSubscribed);
+ $template = $user->reg_complete ?
+ 'just_subscribed_reg_ok' :
+ 'just_subscribed_need_reg';
+ $user->sendEmailFromTemplate($template);
}
});
{
use InteractsWithQueue, Queueable;
+ public $name = "Validation Mailgun";
/**
* Perform the action on the given models.
*
Text::make('Nom code', 'slug')->hideFromIndex(),
Text::make('Nom', 'name'),
Text::make('Sujet', 'subject'),
- CKEditor5Classic::make('Contenu', 'content')->alwaysShow(),
+ Trix::make('Contenu', 'content')->alwaysShow(),
];
}
new ImportUsers,
new SendNotification,
new StartTrial,
- new VerifyEmail,
+// new VerifyEmail,
new ValidateAddress,
];
}
namespace App\Observers;
-use App\Notifications\RegistrationComplete;
use App\User;
class UserObserver
$user->isDirty('reg_complete') &&
$user->getOriginal()['reg_complete'] === false
) {
- $user->notify(new RegistrationComplete);
+ $user->sendEmailFromTemplate('reg_complete');
\Session::flash('registration_complete');
}
if($user->receives_pdf) {
return $this->getDownloadUrl();
}
- return ($user->type === User::TYPE_DISCOVER && !$user->self_registered) ?
+ return ($user->type === User::TYPE_DISCOVER && !$user->reg_complete) ?
$this->getSignedUrl($user) :
$this->getUrlWithToken($user);
namespace App;
+use App\Mail\TemplateMail;
use Illuminate\Support\Str;
trait TemplateVariables
];
+ /**
+ * @param string|EmailTemplate $template
+ */
+ public function sendEmailFromTemplate($template)
+ {
+ if(is_string($template)) {
+ $template = EmailTemplate::findSlug($template);
+ }
+
+ \Mail::to($this)->send(new TemplateMail(
+ $template->fillFor($this),
+ $template->subject
+ ));
+ }
+
/**
* Determine if a getter exists for a template attribute.
*
* @return string
* @throws \Throwable
*/
- public function getMyAccountTemplate()
+ public function getMyAccountButtonTemplate()
{
return EmailTemplate::button(
- $this->routeWithToken('account.index'),
+ $this->routeWithToken('account.index', [], now()->addDays(7)),
'Accéder à mon compte'
);
}
+
+ /**
+ * @return string
+ * @throws \Throwable
+ */
+ public function getCompleteRegistrationButtonTemplate()
+ {
+ return EmailTemplate::button(
+ $this->routeWithToken('account.complete-reg', [], now()->addDays(7)),
+ 'Créer mon mot de passe'
+ );
+
+ }
+
+
+ /**
+ * @return string
+ * @throws \Throwable
+ */
+ public function getContactButtonTemplate()
+ {
+ return EmailTemplate::button(
+ route('contact.index'),
+ 'Nous contacter'
+ );
+
+ }
+
}
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Arr;
-use Illuminate\Support\Carbon;
+use Carbon\Carbon;
use Laravel\Cashier\Billable;
use Laravel\Scout\Searchable;
'position',
'wants_pdf',
'accepts_polls',
+ 'self_registered'
];
/**
/**
* Trial duration in days
*/
- public const TRIAL_DURATION_DAYS = 15;
+ public const TRIAL_DURATION_DAYS = 30;
+
/**
* Discover duration in days
*/
- public const DISCOVER_DURATION_DAYS = 15;
+ public const DISCOVER_DURATION_DAYS = 30;
/**
* Possible Statuses
/**
* Starts trial period
+ * @param Carbon|null $endDate
*/
- public function startTrial(): void
+ public function startTrial(?Carbon $endDate = null): void
{
- $this->trial_ends_at = now()->addDays(self::TRIAL_DURATION_DAYS)->endOfDay();
+ $this->trial_ends_at = $endDate ?? now()->addDays(self::TRIAL_DURATION_DAYS)->endOfDay();
$this->save();
}
/**
* Starts discover period
+ * @param Carbon|null $endDate
*/
- public function startDiscover(): void
+ public function startDiscover(?Carbon $endDate = null): void
{
- $this->discover_ends_at = now()->addDays(self::DISCOVER_DURATION_DAYS)->endOfDay();
+ $this->discover_ends_at = $endDate ?? now()->addDays( self::DISCOVER_DURATION_DAYS)->endOfDay();
$this->type = self::TYPE_DISCOVER;
$this->save();
}