]> _ Git - psq.git/commitdiff
Notifications
authorLouis Jeckel <louis.jeckel@outlook.com>
Mon, 26 Oct 2020 12:12:38 +0000 (13:12 +0100)
committerLouis Jeckel <louis.jeckel@outlook.com>
Mon, 26 Oct 2020 12:12:38 +0000 (13:12 +0100)
app/Nova/Actions/SendCustomNotification.php
app/Nova/Actions/SendNotification.php
app/Nova/EmailTemplate.php
app/Nova/Organization.php
app/Nova/User.php
app/Organization.php
app/SendsEmails.php [new file with mode: 0644]
app/User.php
database/migrations/2020_10_20_132301_create_email_templates_table.php

index d298fb1ff74982172e12ce258120272a45275523..97f5b674aa506a7a8dad0cae117c2eeb9476ebe1 100644 (file)
@@ -23,6 +23,8 @@ class SendCustomNotification extends Action
      */
     private EmailTemplate $template;
 
+    public $showOnTableRow = true;
+
     public $confirmButtonText = "Envoyer";
 
     /**
@@ -48,7 +50,7 @@ class SendCustomNotification extends Action
      */
     public function handle(ActionFields $fields, Collection $models)
     {
-        $models->map(fn(User $user) => $user->sendTemplateEmail($fields->subject, $fields->content));
+        $models->map(fn($sendsEmail) => $sendsEmail->sendTemplateEmail($fields->subject, $fields->content));
 
         return Action::message(sprintf('%d messages envoyés', $models->count()));
     }
@@ -65,4 +67,14 @@ class SendCustomNotification extends Action
             Trix::make('Contenu', 'content')->withMeta(['value' => $this->template->content]),
         ];
     }
+
+    /**
+     * @return array
+     */
+    public static function getActions()
+    {
+         return \App\EmailTemplate::inActionsMenu()->get()->mapInto(self::class)->toArray();
+    }
 }
+
+
index b24e3e56c50fe60cfe50547343f2cd0f10eaa379..9a0e25feb833d5d0092a962913f7f6ba04047f88 100644 (file)
@@ -3,6 +3,7 @@
 namespace App\Nova\Actions;
 
 use App\EmailTemplate;
+use App\SendsEmails;
 use App\User;
 use FontLib\Table\Type\name;
 use Illuminate\Bus\Queueable;
@@ -36,7 +37,7 @@ class SendNotification extends Action
     public function handle(ActionFields $fields, Collection $models)
     {
 
-        $models->map(fn(User $user) => $user->sendEmailFromTemplate($fields->notification));
+        $models->map(fn($sendsEmail) => $sendsEmail->sendEmailFromTemplate($fields->notification));
 
         return Action::message(sprintf('%d messages envoyés', $models->count()));
     }
index 2a5e2e7148f300e22053ad3901bb648cf16f4159..220e7b8e7a6ff9ff755985324231d58ad6788e97 100644 (file)
@@ -56,9 +56,9 @@ class EmailTemplate extends Resource
     {
         return [
             Text::make('Nom code', 'slug')->hideFromIndex(),
-            Text::make('Nom', 'name'),
+            Text::make('Nom', 'name')->required(),
             Text::make('Sujet', 'subject'),
-            Trix::make('Contenu', 'content')->alwaysShow(),
+            Trix::make('Contenu', 'content')->alwaysShow()->required(),
             Boolean::make('Dans menu action ?', 'show_in_actions'),
         ];
     }
index 7c8f051b5bcf6737498af5e685db1b6d0afd9723..3ef8c5c18d260afa4a6a5f0e7c767f9e00cabf32 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace App\Nova;
 
+use App\Nova\Actions\SendCustomNotification;
+use App\Nova\Actions\SendNotification;
 use App\Nova\Actions\SetSubscriptionStatus;
 use App\Nova\Filters\SubscriptionStatusFilter;
 use App\Nova\Filters\TypeFilter;
@@ -109,9 +111,10 @@ class Organization extends Resource
      */
     public function actions(Request $request)
     {
-        return [
+        return array_merge([
             new SetSubscriptionStatus(true),
             new SetSubscriptionStatus(false),
-        ];
+            new SendNotification,
+        ], SendCustomNotification::getActions());
     }
 }
index c8406dd3345293fa5d1eaa28159f7886c5855fca..829c2be56b4f863cf005f63993d66a3e548f5311 100644 (file)
@@ -198,7 +198,7 @@ class User extends Resource
 //            new VerifyEmail,
             new ValidateAddress,
         ],
-            \App\EmailTemplate::inActionsMenu()->get()->mapInto(SendCustomNotification::class)->toArray(),
+            SendCustomNotification::getActions(),
         );
     }
 }
index 566ea485b022d1cd3e959b0a3fbaebe7f0f47178..3b561363b4823f72abd835279171d52e82e248bf 100644 (file)
@@ -14,7 +14,7 @@ use Laravel\Scout\Searchable;
  * @property string name
  * @property boolean $subscription_active
  */
-class Organization extends Model
+class Organization extends Model implements SendsEmails
 {
 
     use Searchable;
@@ -74,4 +74,21 @@ class Organization extends Model
         return $this->name;
     }
 
+
+    /**
+     * @param $template
+     */
+    public function sendEmailFromTemplate($template)
+    {
+        $this->members->map->sendEmailFromTemplate($template);
+    }
+
+    /**
+     * @param $subject
+     * @param $content
+     */
+    public function sendTemplateEmail($subject, $content)
+    {
+        $this->members->map->sendTemplateEmail($subject, $content);
+    }
 }
diff --git a/app/SendsEmails.php b/app/SendsEmails.php
new file mode 100644 (file)
index 0000000..7fad518
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+
+namespace App;
+
+
+interface SendsEmails
+{
+
+public function sendEmailFromTemplate($template);
+public function sendTemplateEmail($subject, $content);
+
+}
index ea073b33e50d0add798ab47492aad8024f1d506e..53010dda3bb72269be80cf7adeb9709a51a8b7f6 100644 (file)
@@ -39,7 +39,7 @@ use Laravel\Scout\Searchable;
  *
  * @property string $status
  */
-class User extends Authenticatable implements MustVerifyEmail
+class User extends Authenticatable implements MustVerifyEmail, SendsEmails
 {
     use Notifiable;
     use Searchable;
index 8f385cae3632bcc8fa2ca4d81da8efec20371f1b..7b2ab9c3c1429cbda6e786bd6a2acaecf5f87810 100644 (file)
@@ -15,7 +15,7 @@ class CreateEmailTemplatesTable extends Migration
     {
         Schema::create('email_templates', function (Blueprint $table) {
             $table->id();
-            $table->string('slug');
+            $table->string('slug')->nullable();
             $table->string('name');
             $table->text('subject')->nullable();
             $table->text('content');