]> _ Git - psq.git/commitdiff
new template variables, WantsPdfNotification.php, mag date
authorLouis Jeckel <louis.jeckel@outlook.com>
Thu, 29 Oct 2020 10:54:10 +0000 (11:54 +0100)
committerLouis Jeckel <louis.jeckel@outlook.com>
Thu, 29 Oct 2020 10:54:10 +0000 (11:54 +0100)
app/Http/Controllers/AccountController.php
app/Notifications/WantsPdfNotification.php [new file with mode: 0644]
app/Nova/Actions/SendNotification.php
app/Observers/UserObserver.php
app/TemplateVariables.php
app/User.php
resources/views/home/index.blade.php
resources/views/mag/index.blade.php
routes/web.php

index 36da5bc0c93d795dc57bfc25a034b6aa5252c892..690e94af1cde017d1c678e9b11e1280f674cf662 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\LoginToken;
+use App\Notifications\WantsPdfNotification;
 use App\User;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Validator;
@@ -134,7 +135,29 @@ class AccountController extends Controller
 
     }
 
+    /**
+     * @param Request $request
+     * @param User $user
+     * @return \Illuminate\Http\RedirectResponse
+     */
+    public function askPdf(Request $request, User $user)
+    {
+        if (! $request->hasValidSignature()) {
+            abort(401);
+        }
+        $user->update(['wants_pdf' => true]);
 
+
+        Session::flash('message', 'Votre demande à bien été prise en compte, merci !');
+        return redirect()->route('home');
+
+    }
+
+    /**
+     * @param Request $request
+     * @param User $user
+     * @return string
+     */
     public function unsubscribe(Request $request, User $user)
     {
         if (! $request->hasValidSignature()) {
@@ -145,7 +168,6 @@ class AccountController extends Controller
 
         return "Désinscription bien prise en compte";
 
-
     }
 
 }
diff --git a/app/Notifications/WantsPdfNotification.php b/app/Notifications/WantsPdfNotification.php
new file mode 100644 (file)
index 0000000..ee0d3bc
--- /dev/null
@@ -0,0 +1,67 @@
+<?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 WantsPdfNotification extends Notification
+{
+    use Queueable;
+
+    /**
+     * @var User
+     */
+    private User $user;
+
+    /**
+     * Create a new notification instance.
+     *
+     * @return void
+     */
+    public function __construct(User $user)
+    {
+        $this->user = $user;
+    }
+
+    /**
+     * 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("{$this->user} a demandé à reçevoir la version PDF.")
+                    ->greeting('Bonjour,')
+                    ->line("{$this->user} a demandé à reçevoir la version PDF de la lettre à l'adresse **{$this->user->email}**");
+    }
+
+    /**
+     * Get the array representation of the notification.
+     *
+     * @param  mixed  $notifiable
+     * @return array
+     */
+    public function toArray($notifiable)
+    {
+        return [
+            //
+        ];
+    }
+}
index 9a0e25feb833d5d0092a962913f7f6ba04047f88..de793e97d9f8c1d57b512a4926b1f14893655554 100644 (file)
@@ -37,7 +37,7 @@ class SendNotification extends Action
     public function handle(ActionFields $fields, Collection $models)
     {
 
-        $models->map(fn($sendsEmail) => $sendsEmail->sendEmailFromTemplate($fields->notification));
+        $models->map(fn($sendsEmail) => $sendsEmail->sendEmailFromTemplate(EmailTemplate::findOrFail($fields->notification)));
 
         return Action::message(sprintf('%d messages envoyés', $models->count()));
     }
@@ -50,7 +50,7 @@ class SendNotification extends Action
     public function fields()
     {
         $options = EmailTemplate::query()
-            ->pluck('name', 'slug')
+            ->pluck('name', 'id')
             ->toArray();
 
         return [
index ffb38c229752342dd0771d92dab0afdf92d19402..6795b19f3f5ec4d29fcb3cde8c2d7280ac37669f 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Observers;
 
+use App\Notifications\WantsPdfNotification;
 use App\User;
 
 class UserObserver
@@ -43,6 +44,18 @@ class UserObserver
             \Session::flash('registration_complete');
         }
 
+
+        if(
+            $user->wants_pdf === true &&
+            $user->isDirty('wants_pdf') &&
+            $user->getOriginal()['wants_pdf'] === false
+        ) {
+            \Notification::route('mail', config('app.emails.subscriptions'))
+                ->notify(new WantsPdfNotification($user));
+        }
+
+
+
     }
 
 
index 5f2fe047a4e37c844d1ecd151b42d2b2a4c9627a..d3f7710176c7cb2855899aad6cc268140cd56de6 100644 (file)
@@ -124,4 +124,25 @@ trait TemplateVariables
 
     }
 
+    /**
+     * @return string
+     * @throws \Throwable
+     */
+    public function getAskPdfButtonTemplate()
+    {
+        $route = \URL::signedRoute('account.ask-pdf', ['user' => $this->id]);
+        return EmailTemplate::button(
+            $route,
+            'Reçevoir le PDF'
+        );
+    }
+
+
+    /**
+     * @return string
+     */
+    public function getOrganizationTemplate()
+    {
+        return (string) $this->organization;
+    }
 }
index 53010dda3bb72269be80cf7adeb9709a51a8b7f6..8458b83c1e16dc29db32d8ce901180b94abcaa63 100644 (file)
@@ -590,6 +590,13 @@ class User extends Authenticatable implements MustVerifyEmail, SendsEmails
     }
 
 
+    /**
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->name;
+    }
 
 
 }
index 26e45acd294f290db69c4d07ad8ce11569f882bb..39e7ae396b667da000c0842daf2154b93bff6246 100644 (file)
@@ -49,7 +49,7 @@
                 <x-pill-box class="my-5" title="Nous suivre">
                     <section class="social-box mx-3">
                         <p><i class="fab fa-twitter-square mr-2"></i><a target="_blank" href="https://twitter.com/PSLeQuotidien">@PSLeQuotidien</a></p>
-                        <p><i class="fab fa-linkedin mr-2"></i><a target="_blank" href="https://fr.linkedin.com/in/prescription-sant%C3%A9-le-quotidien-747b14159">LinkedIn</a></p>
+                        <p><i class="fab fa-linkedin mr-2"></i><a target="_blank" href="https://www.linkedin.com/company/prescription-sant%C3%A9/">LinkedIn</a></p>
                     </section>
                 </x-pill-box>
 
index 8124e85b48a277b032dada5e56832fa5c9200af7..84136f34f3ce354463004d3b175b0bebb2e7a7f6 100644 (file)
@@ -22,7 +22,7 @@
                     LE 20 SEPTEMBRE PROCHAIN : MISE EN LIGNE DU SOMMAIRE COMPLET DE CE PREMIER NUMÉRO
                 </p>
                 <p style="font-size: larger;" class="font-weight-bold mb-0">
-                    N°1 : LE 25 OCTOBRE 2020
+                    N°1 : JANVIER / FÉVRIER 2021
                 </p>
                 <p>
                     <a href="mailto:publicite@prescription-quotidien.com">
index 809f4326315ae5d1eb7b37fc9ab318661a3f1b6a..f694cd22a452548c0e28f06506140d0c553833d8 100644 (file)
@@ -42,6 +42,7 @@ Route::domain(env('CLIENT_DOMAIN_NAME'))->group(function() {
         Route::post('password', 'AccountController@password')->name('account.password');
 
     });
+    Route::get('compte/{user}/demander-pdf', 'AccountController@askPdf')->name('account.ask-pdf');
 
     /** Stripe Payment */
     Route::prefix('pay')->middleware('auth')->group(function() {