/**
* Trait BelongsToPdfFile
* @package App
- * @property PdfFile $file
+ * @property PdfFile|null $file
* @property int $file_id
*/
trait BelongsToPdfFile
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;
/**
* @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
*/
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;
+ }
+
}
--- /dev/null
+<?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');
+ }
+
+}
->find($id);
\View::share('pdf', $pdf);
+ \View::share('batch', $pdf->emailBatch);
+
\View::share('stats', optional($pdf->emailBatch)->statistics());
return view('admin.pdfFiles.show');
*/
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);
}
return (new BatchMail(
$request->input('content'),
$request->input('subject'),
- $request->input('type'),
$request->input('link'),
$request->input('image'),
))->render();
--- /dev/null
+<?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 [];
+ }
+}
'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;
*
* @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;
$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)) :
--- /dev/null
+<?php
+
+namespace App\Repositories;
+
+
+use A17\Twill\Repositories\ModuleRepository;
+use App\EmailBatch;
+
+class EmailBatchRepository extends ModuleRepository
+{
+
+
+ public function __construct(EmailBatch $model)
+ {
+ $this->model = $model;
+ }
+}
],
'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
--- /dev/null
+<?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();
+ });
+ }
+}
<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>
Route::module('socialArticles');
Route::module('printableArticles');
Route::module('polls');
+ Route::module('emailBatches');
+
Route::prefix('pollAnswers')->group(function() {
Route::get('/', 'PollController@answers')->name('otherContent.pollAnswers');