change icons, css, add routing to merchandise, add mail templater, fixes
This commit is contained in:
53
app/Datatables/Admin/Core/Mail/MailLogsDataTable.php
Normal file
53
app/Datatables/Admin/Core/Mail/MailLogsDataTable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Admin\Core\Mail;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Core\Mail\MailLog;
|
||||
use App\Repositories\Core\Mail\MailParser;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class MailLogsDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'mail_logs';
|
||||
|
||||
public $sortedColumn = 0;
|
||||
|
||||
public $sortedOrder = 'desc';
|
||||
|
||||
public $stateSave = true;
|
||||
|
||||
public function query(MailLog $model)
|
||||
{
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('sent_to', function (MailLog $log) {
|
||||
return MailParser::getToEmail($log->event);
|
||||
})
|
||||
->editColumn('subject', function (MailLog $log) {
|
||||
return MailParser::getSubject($log->event);
|
||||
})
|
||||
->rawColumns(['action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
return self::getButtonShow();
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('created_at')->title(__('sent')),
|
||||
Column::make('sent_to')->title(__('user')),
|
||||
Column::make('subject')->title(__('subject')),
|
||||
$this->makeColumnButtons()->width('60'),
|
||||
];
|
||||
}
|
||||
}
|
||||
49
app/Datatables/Admin/Core/Mail/MailTemplatesDataTable.php
Normal file
49
app/Datatables/Admin/Core/Mail/MailTemplatesDataTable.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Admin\Core\Mail;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class MailTemplatesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'mail_templates';
|
||||
|
||||
public $sortedColumn = 0;
|
||||
|
||||
public $sortedOrder = 'desc';
|
||||
|
||||
public $stateSave = true;
|
||||
|
||||
public function query(MailTemplate $model)
|
||||
{
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
$buttons = '';
|
||||
if (Users::hasPermission('mail_templates_view')) {
|
||||
$buttons .= self::getButtonShow();
|
||||
}
|
||||
if (Users::hasPermission('mail_templates_update')) {
|
||||
$buttons .= self::getButtonEdit();
|
||||
}
|
||||
if (Users::hasPermission('mail_templates_delete')) {
|
||||
$buttons .= self::getButtonDel();
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('subject')->title(__('Core.subject')),
|
||||
Column::make('mailable')->title(__('Mailable')),
|
||||
$this->makeColumnButtons()->width('60'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Datatables\Shop;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\ArticleNature;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
|
||||
class ArticleNaturesDataTable extends DataTable
|
||||
{
|
||||
@@ -16,11 +17,22 @@ class ArticleNaturesDataTable extends DataTable
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('product_type', function (ArticleNature $nature) {
|
||||
return ArticleNatures::getProductTypeName($nature->product_type);
|
||||
})
|
||||
->rawColumns(['action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('product_type')->title('Famille de produit')->width(140),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('articles_count')->title('#Art')->addClass('text-right')->searchable(false)->width(60),
|
||||
Column::make('articles_count')->title('Nb Art.')->addClass('text-right')->searchable(false)->width(60),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ class InvoicesDataTable extends DataTable
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
|
||||
Column::make('status'),
|
||||
Column::make('created_at')->title('Date'),
|
||||
Column::make('ref')->title('Ref')->width(80),
|
||||
Column::make('status')->width(60),
|
||||
Column::make('created_at')->title('Date')->width(100),
|
||||
Column::make('customer.last_name')->title('Client')->default(''),
|
||||
Column::make('total')->addClass('text-right'),
|
||||
$this->makeColumnButtons(),
|
||||
|
||||
@@ -44,6 +44,7 @@ class OrdersDataTable extends DataTable
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('ref')->title('Ref'),
|
||||
Column::make('status')->title('Statut'),
|
||||
Column::make('created_at')->title('Date'),
|
||||
Column::make('customer.last_name')->title('Client'),
|
||||
|
||||
9
app/Http/Controllers/Admin/Core/Mail/Controller.php
Normal file
9
app/Http/Controllers/Admin/Core/Mail/Controller.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Core\Mail;
|
||||
|
||||
use App\Http\Controllers\Controller as ParentController;
|
||||
|
||||
class Controller extends ParentController
|
||||
{
|
||||
}
|
||||
26
app/Http/Controllers/Admin/Core/Mail/MailLogController.php
Normal file
26
app/Http/Controllers/Admin/Core/Mail/MailLogController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Core\Mail;
|
||||
|
||||
use App\Datatables\Admin\Core\Mail\MailLogsDataTable;
|
||||
use App\Repositories\Core\Mail\MailLogs;
|
||||
|
||||
class MailLogController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('ability:admin');
|
||||
}
|
||||
|
||||
public function index(MailLogsDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('admin.Core.Mail.MailLog.index', $data ?? []);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data['message'] = MailLogs::getParsed($id);
|
||||
|
||||
return view('admin.Core.Mail.MailLog.modal', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Core\Mail;
|
||||
|
||||
use App\Datatables\Admin\Core\Mail\MailTemplatesDataTable;
|
||||
use App\Repositories\Core\Mail\MailTemplates;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MailTemplateController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('ability:admin');
|
||||
}
|
||||
|
||||
public function index(MailTemplatesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Admin.Core.Mail.MailTemplate.index', $data ?? []);
|
||||
}
|
||||
|
||||
public function modalCreate()
|
||||
{
|
||||
$data = MailTemplates::init();
|
||||
return view('Admin.Core.Mail.MailTemplate.modal', $data ?? []);
|
||||
}
|
||||
|
||||
public function modalEdit($id = false)
|
||||
{
|
||||
$data = MailTemplates::init();
|
||||
$data['mail_template'] = MailTemplates::edit($id);
|
||||
|
||||
return view('Admin.Core.Mail.MailTemplate.modal', $data);
|
||||
}
|
||||
|
||||
public function storeAjax(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
unset($data['proengsoft_jsvalidation']);
|
||||
$ret = MailTemplates::store($data);
|
||||
|
||||
return response()->json(['error' => 0]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id = false)
|
||||
{
|
||||
$id = $id ?? $request->input('id');
|
||||
MailTemplates::destroy($id);
|
||||
|
||||
return response()->json(['error' => 0]);
|
||||
}
|
||||
|
||||
public function getVarsByMailable($mailable)
|
||||
{
|
||||
$data['vars'] = MailTemplates::getVarsByMailable($mailable);
|
||||
|
||||
return view('Admin.Core.Mail.MailTemplate.partials.vars', $data);
|
||||
}
|
||||
|
||||
public function preview($template_id, $user_id)
|
||||
{
|
||||
return MailTemplates::preview($template_id, $user_id);
|
||||
}
|
||||
|
||||
public function modalPreview($template_id)
|
||||
{
|
||||
$data = MailTemplates::getDataFormodalPreview($template_id);
|
||||
|
||||
return view('Admin.Core.Mail.MailTemplate.partials.modalPreview', $data);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,9 @@ class ArticleNatureController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data['article_nature'] = ArticleNatures::get($id);
|
||||
$data['product_types'] = ArticleNatures::getProductTypes();
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Admin.Shop.ArticleNatures.edit', $data);
|
||||
}
|
||||
|
||||
@@ -42,8 +45,9 @@ class ArticleNatureController extends Controller
|
||||
return ArticleNatures::destroy($id);
|
||||
}
|
||||
|
||||
public static function getOptions($product_type)
|
||||
public static function getOptions(Request $request)
|
||||
{
|
||||
return response()->json(['0' => ''] + ArticleNatures::getOptionsByProductType($product_type));
|
||||
$data = ArticleNatures::getOptionsByProductTypeModel($request->input('product_type'));
|
||||
return response()->json(['0' => ''] + $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class ArticleController extends Controller
|
||||
{
|
||||
$data['article'] = Articles::getArticleToSell($id);
|
||||
// $data['breadcrumb'] = Categories::getAncestorsByCategory($category_id);
|
||||
$data['offers2'] = Articles::getSiblings($id)->toArray();
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Shop.Articles.show', $data);
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Repositories\Shop\Categories;
|
||||
use App\Repositories\Shop\TagGroups;
|
||||
|
||||
use App\Datatables\Shop\CategoriesDataTable;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
@@ -18,43 +19,52 @@ class CategoryController extends Controller
|
||||
return $dataTable->render('Shop.Categories.list');
|
||||
}
|
||||
|
||||
public function show(Request $request, $category_id)
|
||||
public function show(Request $request, $category_id, $article_nature_id = false)
|
||||
{
|
||||
switch ($request->input('article_nature')) {
|
||||
case 'semences':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 1;
|
||||
break;
|
||||
case 'plants':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 2;
|
||||
break;
|
||||
case 'legumes':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 3;
|
||||
break;
|
||||
default:
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 1;
|
||||
break;
|
||||
if ($article_nature_id) {
|
||||
$product_type = ArticleNatures::getProductType($article_nature_id);
|
||||
dump($product_type);
|
||||
exit;
|
||||
} else {
|
||||
// $product_type = Articles::getProductTypeByCategory($category_id);
|
||||
// dump($product_type);
|
||||
switch ($request->input('article_nature')) {
|
||||
case 'semences':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 1;
|
||||
break;
|
||||
case 'plants':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 2;
|
||||
break;
|
||||
case 'legumes':
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 3;
|
||||
break;
|
||||
default:
|
||||
$product_type = 'botanic';
|
||||
$article_nature_id = 1;
|
||||
break;
|
||||
}
|
||||
// $product_type = ArticleNatures::getProductType($article_nature_id);
|
||||
// dump($product_type);
|
||||
}
|
||||
$data = [
|
||||
'category' => Categories::getFull($category_id),
|
||||
'breadcrumb' => Categories::getAncestorsByCategory($category_id),
|
||||
'display_by_rows' => $request->input('display_by_rows') ?? false,
|
||||
'product_type' => $product_type,
|
||||
'article_nature' => $request->input('article_nature'),
|
||||
'article_nature' => $article_nature_id,
|
||||
'tags_selected' => $request->input('tags') ?? [],
|
||||
'articles' => Articles::getArticlesToSell([
|
||||
'category_id' => $category_id,
|
||||
'tags' => $request->input('tags') ?? [],
|
||||
'product_type' => $product_type,
|
||||
'product_type' => $product_type ?? false,
|
||||
'article_nature_id' => $article_nature_id ?? false,
|
||||
]),
|
||||
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
|
||||
];
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Shop.Shelves.shelve', $data);
|
||||
}
|
||||
|
||||
|
||||
23
app/Menu/Contents.php
Normal file
23
app/Menu/Contents.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Menu;
|
||||
|
||||
use Sebastienheyd\Boilerplate\Menu\Builder;
|
||||
|
||||
class Contents
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add('Contenus', ['icon' => 'newspaper' ])
|
||||
->id('contents')
|
||||
->order(6);
|
||||
|
||||
$menu->addTo('contents', 'Contenus', [
|
||||
'route' => 'Admin.Shop.Homepages.index',
|
||||
])->activeIfRoute(['Admin.Shop.Homepages.*'])->order(1);
|
||||
|
||||
$menu->addTo('contents', 'Template de Mails', [
|
||||
'route' => 'Admin.Core.Mail.MailTemplate.index',
|
||||
])->activeIfRoute(['Admin.Core.Mail.MailTemplate.*'])->order(2);
|
||||
}
|
||||
}
|
||||
@@ -55,10 +55,6 @@ class Shop
|
||||
$menu->addTo('shop', 'Unités', [
|
||||
'route' => 'Admin.Shop.Unities.index',
|
||||
])->activeIfRoute(['Admin.Shop.Unities.*'])->order(14);
|
||||
|
||||
$menu->addTo('shop', 'Contenus', [
|
||||
'route' => 'Admin.Shop.Homepages.index',
|
||||
])->activeIfRoute(['Admin.Shop.Homepages.*'])->order(15);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
21
app/Models/Core/Mail/MailLog.php
Normal file
21
app/Models/Core/Mail/MailLog.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core\Mail;
|
||||
|
||||
use App\Repositories\Core\DateTime;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MailLog extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function scopeByDestination($query, $email)
|
||||
{
|
||||
return $query->where('sent_to', $email);
|
||||
}
|
||||
|
||||
public function getCreatedAtAttribute($value)
|
||||
{
|
||||
return DateTime::DateTimeToLocale($value);
|
||||
}
|
||||
}
|
||||
21
app/Models/Core/Mail/MailTemplate.php
Normal file
21
app/Models/Core/Mail/MailTemplate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core\Mail;
|
||||
|
||||
use App\Traits\HasTranslations;
|
||||
use Spatie\MailTemplates\Models\MailTemplate as parentMailTemplate;
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
class MailTemplate extends parentMailTemplate
|
||||
{
|
||||
use HasTranslations, RevisionableTrait, Userstamps;
|
||||
|
||||
protected $connection = 'central';
|
||||
|
||||
public $translatable = ['subject', 'html_template', 'text_template'];
|
||||
|
||||
protected $revisionCreationsEnabled = false;
|
||||
|
||||
protected $keepRevisionOf = ['subject', 'html_template', 'text_template'];
|
||||
}
|
||||
@@ -141,12 +141,12 @@ class Article extends Model implements HasMedia
|
||||
|
||||
public function scopeByProduct($query, $model)
|
||||
{
|
||||
return $query->where($this->table . '.product_type', $model);
|
||||
return $model ? $query->where($this->table . '.product_type', $model) : $query;
|
||||
}
|
||||
|
||||
public function scopeByProductId($query, $model_id)
|
||||
public function scopeByProductId($query, $product_id)
|
||||
{
|
||||
return $query->where($this->table . '.product_id', $model_id);
|
||||
return $product_id ? $query->where($this->table . '.product_id', $product_id) : $query;
|
||||
}
|
||||
|
||||
public function scopeByTag($query, $tag_id)
|
||||
|
||||
@@ -25,14 +25,14 @@ class ArticleNature extends Model
|
||||
return $query->where($this->table . '.id', $id);
|
||||
}
|
||||
|
||||
public function scopeByBotanic($query);
|
||||
public function scopeByBotanic($query)
|
||||
{
|
||||
return $query->where($this->table . '.product_type', 1);
|
||||
return $query->ByProductType(1);
|
||||
}
|
||||
|
||||
public function scopeByMerchandise($query);
|
||||
public function scopeByMerchandise($query)
|
||||
{
|
||||
return $query->where($this->table . '.product_type', 2);
|
||||
return $query->ByProductType(2);
|
||||
}
|
||||
|
||||
public function scopeByProductType($query, $type)
|
||||
|
||||
45
app/Repositories/Core/Export/HelperExcel.php
Normal file
45
app/Repositories/Core/Export/HelperExcel.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Export;
|
||||
|
||||
class HelperExcel
|
||||
{
|
||||
public static function getHeaderStyle($color = 'ffffff', $bgcolor = '00a3cb')
|
||||
{
|
||||
return [
|
||||
'fill' => self::setFill($bgcolor),
|
||||
'borders' => self::setBorders($bgcolor),
|
||||
'font' => self::setFont($color, 14, true),
|
||||
];
|
||||
}
|
||||
|
||||
public static function setFill($color)
|
||||
{
|
||||
return [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'startColor' => [
|
||||
'rgb' => $color,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function setBorders($color)
|
||||
{
|
||||
return [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
|
||||
'color' => ['argb' => $color],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function setFont($color, $size = 12, $bold = false, $font = 'Calibri')
|
||||
{
|
||||
return [
|
||||
'name' => $font,
|
||||
'size' => $size,
|
||||
'bold' => $bold,
|
||||
'color' => ['argb' => $color],
|
||||
];
|
||||
}
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\ArticleNature;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Botanic\Specie;
|
||||
use App\Models\Botanic\Variety;
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
class ArticleNatures
|
||||
{
|
||||
@@ -11,9 +15,36 @@ class ArticleNatures
|
||||
return ArticleNature::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByMerchandise()
|
||||
public static function getProductType($id)
|
||||
{
|
||||
return self::getOptionsByProductType(2);
|
||||
$type = self::get($id)->product_type ?? false;
|
||||
return $type ? self::getProductTypes()[$type] : false;
|
||||
}
|
||||
|
||||
public static function getProductTypeName($type)
|
||||
{
|
||||
return self::getProductTypes()[$type] ?? false;
|
||||
}
|
||||
|
||||
public static function getProductTypeByModel($model)
|
||||
{
|
||||
switch ($model) {
|
||||
case Specie::class:
|
||||
$type = 1;
|
||||
break;
|
||||
case Variety::class:
|
||||
$type = 1;
|
||||
break;
|
||||
case Merchandise::class:
|
||||
$type = 2;
|
||||
break;
|
||||
}
|
||||
return $type ?? false;
|
||||
}
|
||||
|
||||
public static function getProductTypes()
|
||||
{
|
||||
return ['', 'botanic', 'merchandise'];
|
||||
}
|
||||
|
||||
public static function getOptionsByBotanic()
|
||||
@@ -21,9 +52,30 @@ class ArticleNatures
|
||||
return self::getOptionsByProductType(1);
|
||||
}
|
||||
|
||||
public static function getOptionsByMerchandise()
|
||||
{
|
||||
return self::getOptionsByProductType(2);
|
||||
}
|
||||
|
||||
public static function getOptionsByProductTypeModel($model)
|
||||
{
|
||||
$type = self::getProductTypeByModel($model);
|
||||
return self::getOptionsByProductType($type);
|
||||
}
|
||||
|
||||
public static function getOptionsByProductType($type)
|
||||
{
|
||||
return ArticleNature::byProductType($type)->get()->pluck('name', 'id')->toArray();
|
||||
return self::getByProductType($type)->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getByProductType($type)
|
||||
{
|
||||
return ArticleNature::byProductType($type)->get();
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('article_nature_id')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
@@ -106,7 +107,7 @@ class Articles
|
||||
$data['description'] = self::getFullDescriptionByArticle($article);
|
||||
$images = self::getFullImagesByArticle($article);
|
||||
$data['image'] = self::getPreviewSrc($images[0] ?? false);
|
||||
$data['images'] = $images;
|
||||
$data['images'] = count($images) ? $images : false;
|
||||
$data['image_big'] = self::getImageSrc($images[0] ?? false);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
@@ -376,6 +377,22 @@ class Articles
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getProductTypeByCategory($category_id)
|
||||
{
|
||||
$models = self::getProductTypesModelsByCategory($category_id);
|
||||
return (($models[0] ?? false) == Merchandise::class) ? 'merchandise' : 'botanic';
|
||||
}
|
||||
|
||||
public static function getProductTypesModelsByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function countProductTypesByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->count();
|
||||
}
|
||||
|
||||
public static function getCategoriesNameByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('name', 'id')->toArray();
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Order;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Orders
|
||||
{
|
||||
@@ -70,6 +71,8 @@ class Orders
|
||||
public static function create($data)
|
||||
{
|
||||
OrderStats::increase();
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
return Order::create($data);
|
||||
}
|
||||
|
||||
@@ -111,4 +114,12 @@ class Orders
|
||||
{
|
||||
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
|
||||
}
|
||||
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Order::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
127
app/Traits/Model/Basic.php
Normal file
127
app/Traits/Model/Basic.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait Basic
|
||||
{
|
||||
public static function toggle($id, $field = 'active')
|
||||
{
|
||||
return self::update([$field => ! self::getField($id, $field)], $id);
|
||||
}
|
||||
|
||||
public static function getIDs()
|
||||
{
|
||||
return self::getAll()->pluck('id');
|
||||
}
|
||||
|
||||
public static function getOptions($field = 'name')
|
||||
{
|
||||
$data = self::getModel()->pluck($field, 'id')->toArray();
|
||||
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getName($id)
|
||||
{
|
||||
return self::getField($id, 'name');
|
||||
}
|
||||
|
||||
public static function getByUUID($uuid)
|
||||
{
|
||||
return self::getByField('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
public static function getFields($field)
|
||||
{
|
||||
return self::getAll()->pluck($field);
|
||||
}
|
||||
|
||||
public static function getByField($field, $value)
|
||||
{
|
||||
return self::getModel()->where($field, $value);
|
||||
}
|
||||
|
||||
public static function getField($id, $field)
|
||||
{
|
||||
$model = self::get($id);
|
||||
|
||||
return $model ? $model->$field : false;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return self::get($id)->toArray();
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return self::getModel()->create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
$model->update($data);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
$model = self::get($id);
|
||||
|
||||
return $model ? $model->delete() : false;
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return self::getModel()->count();
|
||||
}
|
||||
|
||||
public static function firstOrCreate($search, $data)
|
||||
{
|
||||
return self::getModel()::firstOrCreate($search, $data);
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false, $relations_count = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relations_count)->find($id);
|
||||
}
|
||||
|
||||
public static function getAll($relations = false, $relations_count = false)
|
||||
{
|
||||
return self::getModelRelations($relations, $relations_count)->get();
|
||||
}
|
||||
|
||||
public static function getModelRelations($relations = false, $relations_count = false)
|
||||
{
|
||||
$model = $relations ? self::getModelWithRelations($relations) : false;
|
||||
$model = $relations_count ? self::getModelWithCountRelations($relations_count, $model) : $model;
|
||||
|
||||
return $model ? $model : self::getModel();
|
||||
}
|
||||
|
||||
public static function getModelWithRelations($relations = false, $model = false)
|
||||
{
|
||||
return is_object($model) ? $model->with($relations) : self::getModel()->with($relations);
|
||||
}
|
||||
|
||||
public static function getModelWithCountRelations($relations = false, $model = false)
|
||||
{
|
||||
return is_object($model) ? $model->withCount($relations) : self::getModel()->withCount($relations);
|
||||
}
|
||||
|
||||
public static function getModel(): Model
|
||||
{
|
||||
return new Model();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ trait Imageable
|
||||
|
||||
public static function getPreviewSrc($image, $with_undefined = true)
|
||||
{
|
||||
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
|
||||
return $image ? Medias::getPreviewSrc($image) : ($with_undefined ? self::getUnknown() : '');
|
||||
}
|
||||
|
||||
public static function getNormal($image, $with_undefined = true)
|
||||
@@ -46,7 +46,7 @@ trait Imageable
|
||||
|
||||
public static function getNormalSrc($image, $with_undefined = true)
|
||||
{
|
||||
return $image ? Medias::getNormalSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
|
||||
return $image ? Medias::getNormalSrc($image) : ($with_undefined ? self::getUnknown() : '');
|
||||
}
|
||||
|
||||
public static function getImage($image, $with_undefined = true)
|
||||
@@ -57,7 +57,12 @@ trait Imageable
|
||||
|
||||
public static function getImageSrc($image, $with_undefined = true)
|
||||
{
|
||||
return $image ? Medias::getImageSrc($image) : ($with_undefined ? '/img/visuel-non-disponible.jpg' : '');
|
||||
return $image ? Medias::getImageSrc($image) : ($with_undefined ? self::getUnknown() : '');
|
||||
}
|
||||
|
||||
public static function getUnknown()
|
||||
{
|
||||
return '/img/visuel-non-disponible.jpg';
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
|
||||
Reference in New Issue
Block a user