From: Louis Jeckel
Date: Thu, 29 Oct 2020 10:54:10 +0000 (+0100)
Subject: new template variables, WantsPdfNotification.php, mag date
X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=b5cdfa6b1059186713c53833fdd2f0fba3789bc1;p=psq.git
new template variables, WantsPdfNotification.php, mag date
---
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 36da5bc..690e94a 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -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
index 0000000..ee0d3bc
--- /dev/null
+++ b/app/Notifications/WantsPdfNotification.php
@@ -0,0 +1,67 @@
+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 [
+ //
+ ];
+ }
+}
diff --git a/app/Nova/Actions/SendNotification.php b/app/Nova/Actions/SendNotification.php
index 9a0e25f..de793e9 100644
--- a/app/Nova/Actions/SendNotification.php
+++ b/app/Nova/Actions/SendNotification.php
@@ -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 [
diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php
index ffb38c2..6795b19 100644
--- a/app/Observers/UserObserver.php
+++ b/app/Observers/UserObserver.php
@@ -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));
+ }
+
+
+
}
diff --git a/app/TemplateVariables.php b/app/TemplateVariables.php
index 5f2fe04..d3f7710 100644
--- a/app/TemplateVariables.php
+++ b/app/TemplateVariables.php
@@ -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;
+ }
}
diff --git a/app/User.php b/app/User.php
index 53010dd..8458b83 100644
--- a/app/User.php
+++ b/app/User.php
@@ -590,6 +590,13 @@ class User extends Authenticatable implements MustVerifyEmail, SendsEmails
}
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->name;
+ }
}
diff --git a/resources/views/home/index.blade.php b/resources/views/home/index.blade.php
index 26e45ac..39e7ae3 100644
--- a/resources/views/home/index.blade.php
+++ b/resources/views/home/index.blade.php
@@ -49,7 +49,7 @@
diff --git a/resources/views/mag/index.blade.php b/resources/views/mag/index.blade.php
index 8124e85..84136f3 100644
--- a/resources/views/mag/index.blade.php
+++ b/resources/views/mag/index.blade.php
@@ -22,7 +22,7 @@
LE 20 SEPTEMBRE PROCHAIN : MISE EN LIGNE DU SOMMAIRE COMPLET DE CE PREMIER NUMÃRO
- N°1 : LE 25 OCTOBRE 2020
+ N°1 : JANVIER / FÃVRIER 2021
diff --git a/routes/web.php b/routes/web.php
index 809f432..f694cd2 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -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() {