]> _ Git - psq.git/commitdiff
email batch review
authorLouis Jeckel <louis.jeckel@outlook.com>
Thu, 17 Dec 2020 11:16:46 +0000 (12:16 +0100)
committerLouis Jeckel <louis.jeckel@outlook.com>
Thu, 17 Dec 2020 11:16:46 +0000 (12:16 +0100)
13 files changed:
app/BelongsToPdfFile.php
app/EmailBatch.php
app/Http/Controllers/Admin/EmailBatchController.php [new file with mode: 0644]
app/Http/Controllers/Admin/PdfFileController.php
app/Http/Controllers/Admin/PublishController.php
app/Http/Requests/Admin/EmailBatchRequest.php [new file with mode: 0644]
app/Jobs/ProcessEmailBatch.php
app/Mail/BatchMail.php
app/Repositories/EmailBatchRepository.php [new file with mode: 0644]
config/twill-navigation.php
database/migrations/2020_12_17_102534_soft_delete_email_batches.php [new file with mode: 0644]
resources/views/admin/pdfFiles/show.blade.php
routes/admin.php

index 4be5069dc6730f84e075ed7434aebac494980080..f78e54daedf8a5b83e4d7add6609155937925a78 100644 (file)
@@ -6,7 +6,7 @@ namespace App;
 /**
  * Trait BelongsToPdfFile
  * @package App
- * @property PdfFile $file
+ * @property PdfFile|null $file
  * @property int $file_id
  */
 trait BelongsToPdfFile
index 5fc020d2b0186bc09c4d6355b1f93ee1080fb88f..b999e1fb20c02d86b4929d8056e4080feaed2834 100644 (file)
@@ -2,8 +2,11 @@
 
 namespace App;
 
+use App\Mail\BatchMail;
+use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Model;
 use \Illuminate\Database\Eloquent\Relations;
+use A17\Twill\Models\Model as TwillModel;
 
 
 /**
@@ -13,17 +16,24 @@ use \Illuminate\Database\Eloquent\Relations;
  * @property string $subject
  * @property array $content
  * @property array $sent_to
+ * @property Carbon $created_at
  */
-class EmailBatch extends Model
+class EmailBatch extends TwillModel
 {
     protected $guarded = [];
+    protected $softDeletes = false;
     use BelongsToPdfFile;
 
+
     protected $casts = [
         'content' => 'array',
         'sent_to' => 'array'
     ];
 
+    protected $hidden = [
+        'sent_to'
+    ];
+
     /**
      * @return Relations\HasMany
      */
@@ -53,4 +63,43 @@ class EmailBatch extends Model
         return 'batch_id_'.$this->id;
     }
 
+
+    /**
+     * @return string
+     */
+    public function render(): string
+    {
+        return $this->content['html'] ?? $this->renderFromContent();
+    }
+
+    /**
+     * @return string
+     * @throws \ReflectionException
+     */
+    public function renderFromContent(): string
+    {
+       return (new BatchMail(
+                $this->content['body'],
+                $this->subject,
+                $this->content['link'] ?? null,
+                optional($this->file)->coverUrl
+            ))->render();
+    }
+
+    /**
+     * @return string
+     */
+    public function getDateStringAttribute(): string
+    {
+        return $this->created_at->translatedFormat('D d/m/Y à H\hi');
+    }
+
+    /**
+     * @return string
+     */
+    public function __toString(): string
+    {
+        return $this->subject;
+    }
+
 }
diff --git a/app/Http/Controllers/Admin/EmailBatchController.php b/app/Http/Controllers/Admin/EmailBatchController.php
new file mode 100644 (file)
index 0000000..a9ac4aa
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use A17\Twill\Http\Controllers\Admin\ModuleController;
+use App\EmailBatch;
+use App\PdfFile;
+
+class EmailBatchController extends ModuleController
+{
+    protected $moduleName = 'emailBatches';
+
+
+    protected $titleColumnKey = 'subject';
+
+    protected $indexOptions = [
+        'create' => false,
+        'publish' => false,
+        'delete' => false,
+        'restore' => false,
+    ];
+
+    protected $indexColumns = [
+        'subject' => [
+            'title' => 'Objet',
+            'field' => 'subject'
+        ],
+        'date' => [
+            'title' => 'Envoyé le',
+            'field' => 'date_string',
+        ]
+//        'viewCount' => [
+//            'title' => 'Vues',
+//            'field' => 'viewCount'
+//        ]
+    ];
+
+    public function edit($id, $submoduleId = null)
+    {
+        /** @var EmailBatch $batch */
+        $batch = EmailBatch::findOrFail($id);
+
+        $pdf = $batch->file;
+
+        \View::share('pdf', $pdf);
+        \View::share('batch', $batch);
+        \View::share('stats', $batch->statistics());
+
+        return view('admin.pdfFiles.show');
+    }
+
+}
index ede45d94cd9463d7c5960dde6ff792c249a6624c..a7b4e798d5545a1602bf661edcb119243374a57a 100644 (file)
@@ -35,6 +35,8 @@ class PdfFileController extends ModuleController
             ->find($id);
 
         \View::share('pdf', $pdf);
+        \View::share('batch', $pdf->emailBatch);
+
         \View::share('stats', optional($pdf->emailBatch)->statistics());
 
         return view('admin.pdfFiles.show');
index 3a144f31e7618d307efc13099a177e821d6aa246..068b9830aa26ca78896a43270f17dbef927dd3a0 100644 (file)
@@ -76,9 +76,10 @@ class PublishController extends Controller
      */
     public function collections()
     {
-        $files = FileCollection::query()->with(['files' => function($builder) {
-            return $builder->orderByDesc('updated_at')->first();
-        }])->get();
+        $files = FileCollection::all()->map(function(FileCollection $fileCollection) {
+            $fileCollection->files = [$fileCollection->files()->orderByDesc('updated_at')->first()];
+            return $fileCollection;
+        });
 
         return new ResourceCollection($files);
     }
@@ -139,7 +140,6 @@ class PublishController extends Controller
         return (new BatchMail(
             $request->input('content'),
             $request->input('subject'),
-            $request->input('type'),
             $request->input('link'),
             $request->input('image'),
         ))->render();
diff --git a/app/Http/Requests/Admin/EmailBatchRequest.php b/app/Http/Requests/Admin/EmailBatchRequest.php
new file mode 100644 (file)
index 0000000..31086f5
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Http\Requests\Admin;
+
+use A17\Twill\Http\Requests\Admin\Request;
+
+class EmailBatchRequest extends Request
+{
+    public function rulesForCreate()
+    {
+        return [];
+    }
+
+    public function rulesForUpdate()
+    {
+        return [];
+    }
+}
index 93f6b542a87079ed0a51addb5ce46fe7ab1bf3ee..a146c598501fcb33665fc67200dd7f8459b4b6d2 100644 (file)
@@ -115,17 +115,11 @@ class ProcessEmailBatch implements ShouldQueue
                     'name' => $user->name ?? '',
                     ], $fileVar)
                 ];
-            }), JSON_THROW_ON_ERROR, 512);
+            }), JSON_THROW_ON_ERROR);
 
 
 
-            $view = ($this->type == 1) ? (new BatchMail(
-                $this->batch->content['body'],
-                $this->batch->subject,
-                $this->type,
-                $this->batch->content['link'] ?? null,
-                optional($this->batch->file)->coverUrl
-            ))->render() : $this->html;
+            $view = ($this->type == 1) ? $this->batch->renderFromContent() : $this->html;
 
 
 
index 65c2c2f73bb361e0b451eeaed4a493c852644db4..177be53678f162d917cf0922135b1b0ba73649cd 100644 (file)
@@ -42,11 +42,10 @@ class BatchMail extends Mailable
      *
      * @param string $content
      * @param string $subject
-     * @param $type
      * @param string|null $link
      * @param null $image
      */
-    public function __construct($content, $subject, $type, $link = null, $image = null)
+    public function __construct($content, $subject, $link = null, $image = null)
     {
         //
         $this->subject = $subject;
@@ -54,7 +53,7 @@ class BatchMail extends Mailable
         $this->image = $image;
 
 
-        $this->emailView = self::getView($type);
+        $this->emailView = self::getView(self::MAIL_TYPE_PDF_FILE);
 
         $this->content = $this->emailView === 'batch-pdf' ?
             (Html2Markdown::convert($content)) :
diff --git a/app/Repositories/EmailBatchRepository.php b/app/Repositories/EmailBatchRepository.php
new file mode 100644 (file)
index 0000000..20964b0
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Repositories;
+
+
+use A17\Twill\Repositories\ModuleRepository;
+use App\EmailBatch;
+
+class EmailBatchRepository extends ModuleRepository
+{
+
+
+    public function __construct(EmailBatch $model)
+    {
+        $this->model = $model;
+    }
+}
index cfd6b5832b883803ca9d96fd9c558b291c68dcef..744e729d052620a4dc855b800cad9f84b6ead124 100644 (file)
@@ -89,9 +89,14 @@ return [
     ],
     'otherContent' => [
         'title' => 'Autre contenu',
-        'route' => 'socialArticles.index',
+        'route' => 'emailBatches.index',
         'module'  => true,
         'primary_navigation' => [
+            'emailBatches' => [
+                'title' => 'Emails envoyés',
+                'module' => true
+            ],
+
             'socialArticles' => [
                 'title' => 'Articles réseaux sociaux',
                 'module' => true
diff --git a/database/migrations/2020_12_17_102534_soft_delete_email_batches.php b/database/migrations/2020_12_17_102534_soft_delete_email_batches.php
new file mode 100644 (file)
index 0000000..d1e0fa9
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class SoftDeleteEmailBatches extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('email_batches', function (Blueprint $table) {
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('email_batches', function (Blueprint $table) {
+            $table->dropSoftDeletes();
+        });
+    }
+}
index 843125e2cb2a12688b245db498f9a73a313e35de..a9fe84d725332415ec13093d6ce87895238659d1 100644 (file)
@@ -5,27 +5,37 @@
     <div class="bootstrap">
         <div class="container mt-4">
             <div class="row">
-                <div class="col-4">
-                    <img src="{{$pdf->coverUrl}}" alt="" class="w-100">
-                    <a href="{{route('admin.preview', ['slug' => $pdf->slug])}}" target="_blank" class="btn btn-primary mt-3">Lire</a>
-                    @foreach($pdf->headlines ?? [] as $headline)
-                        <x-headline :headline="$headline" class="mt-3">
-                        </x-headline>
-                    @endforeach
+                <div class="col-6">
+                    @if($batch)
+                    <h3>Email envoyé : </h3>
+                    <iframe class="mb-4" width="100%" height="600px" srcdoc="{{ $batch->render() }}" frameborder="0"></iframe>
+                    @endif
+                    @if($pdf)
+                    <hr>
+                    <h3>Lettre :</h3>
+                    <img src="{{$pdf->coverUrl}}" alt="Cover" style="max-width: 400px;" class="d-block m-auto">
+                        <a href="{{route('admin.preview', ['slug' => $pdf->slug])}}" target="_blank" class="btn btn-primary mt-3">Lire</a>
+                        @foreach($pdf->headlines ?? [] as $headline)
+                            <x-headline :headline="$headline" class="mt-3">
+                            </x-headline>
+                        @endforeach
+                    @endif
                 </div>
-                <div class="col-8">
-                    <h1>{{$pdf->title}}</h1>
-                    <p>Publié le {{$pdf->created_at}}</p>
+                <div class="col-6">
+                    <h1>{{$batch->subject ?? $pdf->title}}</h1>
+                    <p>{{$batch->dateString ?? $pdf->created_at}}</p>
                     <div class="row">
-                        <div class="col-12">
-                            <h3>Statistiques de lecture</h3>
-                        </div>
-                        <div class="col-md-6 mt-2">
-                            <mg-stats icon="opened" custom-metric="{{$pdf->viewCount}}" custom-label="Lectures authentifiées"></mg-stats>
-                        </div>
-                        <div class="col-md-6 mt-2">
-                            <mg-stats icon="opened" custom-metric="{{$pdf->accessLogs()->count()}}" custom-label="Lectures totales"></mg-stats>
-                        </div>
+                        @if($pdf)
+                            <div class="col-12">
+                                <h3>Statistiques de lecture</h3>
+                            </div>
+                            <div class="col-md-6 mt-2">
+                                <mg-stats icon="opened" custom-metric="{{$pdf->viewCount}}" custom-label="Lectures authentifiées"></mg-stats>
+                            </div>
+                            <div class="col-md-6 mt-2">
+                                <mg-stats icon="opened" custom-metric="{{$pdf->accessLogs()->count()}}" custom-label="Lectures totales"></mg-stats>
+                            </div>
+                        @endif
                         @unless($stats === null)
                             <div class="col-12">
                                 <h3 class="mt-3">Statistiques mailing</h3>
                                 <mg-stats icon="failed" current="{{$stats['failed'] ?? 0}}" total="{{$stats['total'] ?? 0}}" text="erreur"></mg-stats>
                             </div>
                         @else
-                            <div class="col-12">
+                            <div class="col-12 mt-3">
                                 <p>Cette lettre n'a pas été envoyée via la plateforme. Les statistiques d'envoi ne sont pas disponibles</p>
                             </div>
                         @endif
                     </div>
 
-                    <div class="mt-5">
-                        <h2>Links</h2>
-                        <table class="table table-hover">
-                            <thead>
-                            <tr>
-                                <th>Titre</th>
-                                <th>Clicks</th>
-                            </tr>
-                            </thead>
-                            <tbody>
-                            @foreach($pdf->trackedLinks as $link)
+                    @if($pdf)
+                        <div class="mt-5 box p-2">
+                            <h2>Links</h2>
+                            <table class="table table-hover">
+                                <thead>
                                 <tr>
-                                    <td><a href="{!! $link->target !!}" target="_blank">{!! $link->title !!}</a></td>
-                                    <td>{{$link->clicks}}</td>
+                                    <th>Titre</th>
+                                    <th>Clics</th>
                                 </tr>
-                            @endforeach
-                            </tbody>
-                        </table>
-                    </div>
+                                </thead>
+                                <tbody>
+                                @foreach($pdf->trackedLinks as $link)
+                                    <tr>
+                                        <td><a href="{!! $link->target !!}" target="_blank">{!! $link->title !!}</a></td>
+                                        <td>{{$link->clicks}}</td>
+                                    </tr>
+                                @endforeach
+                                </tbody>
+                            </table>
+                        </div>
+                    @endif
 
                 </div>
             </div>
index a3e93e5b427cc5707bb5698e68f0eeb3fe0ebc20..8813f59f96a1806a24b0f87f7f186d949f0bbeb1 100644 (file)
@@ -26,6 +26,8 @@ Route::prefix('otherContent')->group(function () {
      Route::module('socialArticles');
      Route::module('printableArticles');
      Route::module('polls');
+         Route::module('emailBatches');
+
 
      Route::prefix('pollAnswers')->group(function() {
         Route::get('/', 'PollController@answers')->name('otherContent.pollAnswers');