change icons, css, add routing to merchandise, add mail templater, fixes
This commit is contained in:
26
app/Repositories/Core/Mail/MailLogs.php
Normal file
26
app/Repositories/Core/Mail/MailLogs.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailLog;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class MailLogs
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getSubject($id)
|
||||
{
|
||||
return MailParser::getSubject(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getParsed($id)
|
||||
{
|
||||
return MailParser::getParsed(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return MailLog::query();
|
||||
}
|
||||
}
|
||||
89
app/Repositories/Core/Mail/MailParser.php
Normal file
89
app/Repositories/Core/Mail/MailParser.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use ZBateson\MailMimeParser\Header\HeaderConsts;
|
||||
use ZBateson\MailMimeParser\MailMimeParser;
|
||||
|
||||
class MailParser
|
||||
{
|
||||
public static function getParsed($mail)
|
||||
{
|
||||
$model = self::getModel($mail);
|
||||
|
||||
return [
|
||||
'from' => self::getFromByModel($model),
|
||||
'subject' => self::getSubjectByModel($model),
|
||||
'content' => self::getHtmlByModel($model),
|
||||
'to_name' => self::getToNameByModel($model),
|
||||
'to_email' => self::getToEmailByModel($model),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSubject($mail)
|
||||
{
|
||||
return self::getSubjectByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getText($mail)
|
||||
{
|
||||
return self::getTextByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getHtml($mail)
|
||||
{
|
||||
return self::getHtmlByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getFrom($mail)
|
||||
{
|
||||
return self::getFromByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToName($mail)
|
||||
{
|
||||
return self::getToNameByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToEmail($mail)
|
||||
{
|
||||
return self::getToEmailByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getSubjectByModel($model)
|
||||
{
|
||||
return $model->getHeaderValue(HeaderConsts::SUBJECT);
|
||||
}
|
||||
|
||||
public static function getTextByModel($model)
|
||||
{
|
||||
return $model->getTextContent();
|
||||
}
|
||||
|
||||
public static function getFromByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::FROM)->getPersonName();
|
||||
}
|
||||
|
||||
public static function getToNameByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getName();
|
||||
}
|
||||
|
||||
public static function getToEmailByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getEmail();
|
||||
}
|
||||
|
||||
public static function getHtmlByModel($model)
|
||||
{
|
||||
return $model->getHtmlContent();
|
||||
}
|
||||
|
||||
public static function getModel($mail)
|
||||
{
|
||||
$mailParser = new MailMimeParser();
|
||||
|
||||
return $mailParser->parse($mail, false);
|
||||
}
|
||||
}
|
||||
64
app/Repositories/Core/Mail/MailTemplates.php
Normal file
64
app/Repositories/Core/Mail/MailTemplates.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Traits\Model\Basic;
|
||||
use Mustache_Engine;
|
||||
|
||||
class MailTemplates
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'mailables' => Mailables::getList(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$data = self::get($id)->toArray();
|
||||
$mailable = $data['mailable'];
|
||||
$data['vars'] = $mailable::getVariables();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getVarsByMailable($mailable)
|
||||
{
|
||||
return $mailable::getVariables();
|
||||
}
|
||||
|
||||
public static function getDataFormodalPreview($id)
|
||||
{
|
||||
$template = self::get($id);
|
||||
$mailable = $template->mailable;
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'users' => $mailable::getUsers(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function preview($id, $user_id)
|
||||
{
|
||||
$template = self::get($id);
|
||||
$mailable = $template->mailable;
|
||||
$data = $mailable::getDataByUser($user_id);
|
||||
$html_template = $template->toArray()['html_template_translations'][$data['lang']] ?? false;
|
||||
if ($html_template) {
|
||||
$m = new Mustache_Engine();
|
||||
|
||||
return $m->render($html_template, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return MailTemplate::query();
|
||||
}
|
||||
}
|
||||
18
app/Repositories/Core/Mail/Mailables.php
Normal file
18
app/Repositories/Core/Mail/Mailables.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
class Mailables
|
||||
{
|
||||
public static function getList()
|
||||
{
|
||||
$data = [];
|
||||
$files = glob(app_path('Mail').'/*.php');
|
||||
foreach ($files as $file) {
|
||||
$class = basename($file, '.php');
|
||||
$data['App\Mail\\'.$class] = $class;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
18
app/Repositories/Core/Mail/Mailer.php
Normal file
18
app/Repositories/Core/Mail/Mailer.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
public static function getTemplates()
|
||||
{
|
||||
return MailTemplates::getOptions();
|
||||
}
|
||||
|
||||
public static function getTemplate($template_id)
|
||||
{
|
||||
$templates = self::getTemplates();
|
||||
|
||||
return $templates[$template_id];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user