From: Louis Jeckel Date: Thu, 17 Dec 2020 11:16:46 +0000 (+0100) Subject: email batch review X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=276aa8b2f6668c7591cd9b139c0148ccb5e67d57;p=psq.git email batch review --- diff --git a/app/BelongsToPdfFile.php b/app/BelongsToPdfFile.php index 4be5069..f78e54d 100644 --- a/app/BelongsToPdfFile.php +++ b/app/BelongsToPdfFile.php @@ -6,7 +6,7 @@ namespace App; /** * Trait BelongsToPdfFile * @package App - * @property PdfFile $file + * @property PdfFile|null $file * @property int $file_id */ trait BelongsToPdfFile diff --git a/app/EmailBatch.php b/app/EmailBatch.php index 5fc020d..b999e1f 100644 --- a/app/EmailBatch.php +++ b/app/EmailBatch.php @@ -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 index 0000000..a9ac4aa --- /dev/null +++ b/app/Http/Controllers/Admin/EmailBatchController.php @@ -0,0 +1,52 @@ + 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'); + } + +} diff --git a/app/Http/Controllers/Admin/PdfFileController.php b/app/Http/Controllers/Admin/PdfFileController.php index ede45d9..a7b4e79 100644 --- a/app/Http/Controllers/Admin/PdfFileController.php +++ b/app/Http/Controllers/Admin/PdfFileController.php @@ -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'); diff --git a/app/Http/Controllers/Admin/PublishController.php b/app/Http/Controllers/Admin/PublishController.php index 3a144f3..068b983 100644 --- a/app/Http/Controllers/Admin/PublishController.php +++ b/app/Http/Controllers/Admin/PublishController.php @@ -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 index 0000000..31086f5 --- /dev/null +++ b/app/Http/Requests/Admin/EmailBatchRequest.php @@ -0,0 +1,18 @@ + $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; diff --git a/app/Mail/BatchMail.php b/app/Mail/BatchMail.php index 65c2c2f..177be53 100644 --- a/app/Mail/BatchMail.php +++ b/app/Mail/BatchMail.php @@ -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 index 0000000..20964b0 --- /dev/null +++ b/app/Repositories/EmailBatchRepository.php @@ -0,0 +1,17 @@ +model = $model; + } +} diff --git a/config/twill-navigation.php b/config/twill-navigation.php index cfd6b58..744e729 100644 --- a/config/twill-navigation.php +++ b/config/twill-navigation.php @@ -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 index 0000000..d1e0fa9 --- /dev/null +++ b/database/migrations/2020_12_17_102534_soft_delete_email_batches.php @@ -0,0 +1,32 @@ +softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('email_batches', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + } +} diff --git a/resources/views/admin/pdfFiles/show.blade.php b/resources/views/admin/pdfFiles/show.blade.php index 843125e..a9fe84d 100644 --- a/resources/views/admin/pdfFiles/show.blade.php +++ b/resources/views/admin/pdfFiles/show.blade.php @@ -5,27 +5,37 @@
-
- - Lire - @foreach($pdf->headlines ?? [] as $headline) - - - @endforeach +
+ @if($batch) +

Email envoyé :

+ + @endif + @if($pdf) +
+

Lettre :

+ Cover + Lire + @foreach($pdf->headlines ?? [] as $headline) + + + @endforeach + @endif
-
-

{{$pdf->title}}

-

Publié le {{$pdf->created_at}}

+
+

{{$batch->subject ?? $pdf->title}}

+

{{$batch->dateString ?? $pdf->created_at}}

-
-

Statistiques de lecture

-
-
- -
-
- -
+ @if($pdf) +
+

Statistiques de lecture

+
+
+ +
+
+ +
+ @endif @unless($stats === null)

Statistiques mailing

@@ -43,31 +53,33 @@
@else -
+

Cette lettre n'a pas été envoyée via la plateforme. Les statistiques d'envoi ne sont pas disponibles

@endif
-
-

Links

- - - - - - - - - @foreach($pdf->trackedLinks as $link) + @if($pdf) +
+

Links

+
TitreClicks
+ - - + + - @endforeach - -
{!! $link->title !!}{{$link->clicks}}TitreClics
-
+ + + @foreach($pdf->trackedLinks as $link) + + {!! $link->title !!} + {{$link->clicks}} + + @endforeach + + +
+ @endif
diff --git a/routes/admin.php b/routes/admin.php index a3e93e5..8813f59 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -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');