Unverified Commit 61c1c511 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #58 from bvipul/vs_refactor_email_temp_module

Refactored Email Template Module
parents 92c5ecca 4f75d30b
......@@ -23,9 +23,9 @@ class EmailTemplatesController extends Controller
protected $emailtemplates;
/**
* Setting the EmailTemplatesRepository instance to class variable.
* __construct
*
* @param EmailTemplatesRepository $emailtemplates
* @param \App\Repositories\Backend\EmailTemplates\EmailTemplatesRepository $emailtemplates
*/
public function __construct(EmailTemplatesRepository $emailtemplates)
{
......@@ -33,9 +33,7 @@ class EmailTemplatesController extends Controller
}
/**
* Use to load index view of EmailTmplates.
*
* @param ManageEmailTemplatesRequest $request
* @param \App\Http\Requests\Backend\EmailTemplates\ManageEmailTemplatesRequest $request
*
* @return mixed
*/
......@@ -45,18 +43,16 @@ class EmailTemplatesController extends Controller
}
/**
* Use to load edit form of Emailtemplate.
*
* @param EmailTemplate $emailtemplate
* @param EditEmailTemplatesRequest $request
* @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* @param \App\Http\Requests\Backend\EmailTemplates\EditEmailTemplatesRequest $request
*
* @return mixed
*/
public function edit(EmailTemplate $emailtemplate, EditEmailTemplatesRequest
$request)
{
$emailtemplateTypes = EmailTemplateType::pluck('name', 'id');
$emailtemplatePlaceholders = EmailTemplatePlaceholder::pluck('name', 'id');
$emailtemplateTypes = EmailTemplateType::getSelectData();
$emailtemplatePlaceholders = EmailTemplatePlaceholder::getSelectData();
return view('backend.emailtemplates.edit')
->withEmailtemplate($emailtemplate)
......@@ -65,27 +61,23 @@ class EmailTemplatesController extends Controller
}
/**
* Use to update an Emailtemplate.
*
* @param EmailTemplate $emailtemplate
* @param UpdateEmailTemplatesRequest $request
* @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* @param \App\Http\Requests\Backend\EmailTemplates\UpdateEmailTemplatesRequest $request
*
* @return mixed
*/
public function update(EmailTemplate $emailtemplate, UpdateEmailTemplatesRequest
$request)
{
$this->emailtemplates->update($emailtemplate, $request->all());
$this->emailtemplates->update($emailtemplate, $request->except(['_method', '_token', 'placeholder']));
return redirect()->route('admin.emailtemplates.index')
->withFlashSuccess(trans('alerts.backend.emailtemplates.updated'));
}
/**
* Use to delete an Emailtemplate.
*
* @param EmailTemplate $emailtemplate
* @param DeleteEmailTemplatesRequest $request
* @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* @param \App\Http\Requests\Backend\EmailTemplates\DeleteEmailTemplatesRequest $request
*
* @return mixed
*/
......
......@@ -19,7 +19,7 @@ class EmailTemplatesTableController extends Controller
protected $emailtemplates;
/**
* @param EmailTemplatesRepository $emailtemplates
* @param \App\Repositories\Backend\EmailTemplates\EmailTemplatesRepository $emailtemplates
*/
public function __construct(EmailTemplatesRepository $emailtemplates)
{
......@@ -27,7 +27,7 @@ class EmailTemplatesTableController extends Controller
}
/**
* @param ManageEmailTemplatesRequest $request
* @param \App\Http\Requests\Backend\EmailTemplates\ManageEmailTemplatesRequest $request
*
* @return mixed
*/
......@@ -36,11 +36,7 @@ class EmailTemplatesTableController extends Controller
return Datatables::of($this->emailtemplates->getForDataTable())
->escapeColumns(['title'])
->addColumn('status', function ($emailtemplates) {
if ($emailtemplates->status) {
return '<span class="label label-success">Active</span>';
}
return '<span class="label label-danger">Inactive</span>';
return $emailtemplates->status_label;
})
->addColumn('created_at', function ($emailtemplates) {
return Carbon::parse($emailtemplates->created_at)->toDateString();
......
......@@ -16,6 +16,6 @@ class EmailTemplatePlaceholder extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.email_template_placeholders_table');
$this->table = config('module.email_templates.placeholders_table');
}
}
......@@ -16,6 +16,6 @@ class EmailTemplateType extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.email_template_types_table');
$this->table = config('module.email_templates.types_table');
}
}
......@@ -15,6 +15,8 @@ class EmailTemplate extends BaseModel
// EmailTemplateAttribute::getEditButtonAttribute insteadof ModelTrait;
}
protected $guarded = ['id'];
/**
* The database table used by the model.
*
......@@ -25,6 +27,6 @@ class EmailTemplate extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.email_templates_table');
$this->table = config('module.email_templates.table');
}
}
......@@ -14,4 +14,25 @@ trait EmailTemplateAttribute
{
return '<div class="btn-group action-btn">'.$this->getEditButtonAttribute('edit-email-template', 'admin.emailtemplates.edit').'</div>';
}
/**
* @return string
*/
public function getStatusLabelAttribute()
{
if ($this->isActive()) {
return "<label class='label label-success'>".trans('labels.general.active').'</label>';
}
return "<label class='label label-danger'>".trans('labels.general.inactive').'</label>';
}
/**
* @return bool
*/
public function isActive()
{
return $this->status == 1;
}
}
......@@ -26,60 +26,53 @@ class EmailTemplatesRepository extends BaseRepository
{
return $this->query()
->select([
config('access.email_templates_table').'.id',
config('access.email_templates_table').'.title',
config('access.email_templates_table').'.subject',
config('access.email_templates_table').'.status',
config('access.email_templates_table').'.created_at',
config('access.email_templates_table').'.updated_at',
config('module.email_templates.table').'.id',
config('module.email_templates.table').'.title',
config('module.email_templates.table').'.subject',
config('module.email_templates.table').'.status',
config('module.email_templates.table').'.created_at',
config('module.email_templates.table').'.updated_at',
]);
}
/**
* @param Model $permission
* @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* @param $input
*
* @throws GeneralException
*
* return bool
*/
public function update(Model $emailtemplate, array $input)
public function update(EmailTemplate $emailtemplate, array $input)
{
$emailtemplate->title = $input['title'];
$emailtemplate->body = $input['body'];
$emailtemplate->type_id = $input['type_id'];
$emailtemplate->subject = $input['subject'];
$emailtemplate->status = (isset($input['is_active']) && $input['is_active'] == 1) ? 1 : 0;
$emailtemplate->updated_by = access()->user()->id;
$input['status'] = isset($input['is_active']) ? 1 : 0;
unset($input['is_active']);
$input['updated_by'] = access()->user()->id;
DB::transaction(function () use ($emailtemplate, $input) {
if ($emailtemplate->save()) {
event(new EmailTemplateUpdated($emailtemplate));
if ($emailtemplate->update($input)) {
event(new EmailTemplateUpdated($emailtemplate));
return true;
}
return true;
}
throw new GeneralException(trans('exceptions.backend.emailtemplates.update_error'));
});
throw new GeneralException(trans('exceptions.backend.emailtemplates.update_error'));
}
/**
* @param Model $emailtemplate
* @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
*
* @throws GeneralException
*
* @return bool
*/
public function delete(Model $emailtemplate)
public function delete(EmailTemplate $emailtemplate)
{
DB::transaction(function () use ($emailtemplate) {
if ($emailtemplate->delete()) {
event(new EmailTemplateDeleted($emailtemplate));
if ($emailtemplate->delete()) {
event(new EmailTemplateDeleted($emailtemplate));
return true;
}
return true;
}
throw new GeneralException(trans('exceptions.backend.emailtemplates.delete_error'));
});
throw new GeneralException(trans('exceptions.backend.emailtemplates.delete_error'));
}
}
......@@ -60,21 +60,6 @@ return [
*/
'cities_table' => 'cities',
/*
* email template placeholders table used to store email template placeholders
*/
'email_template_placeholders_table' => 'email_template_placeholders',
/*
* email template types table used to store email template types
*/
'email_template_types_table' => 'email_template_types',
/*
* Email templates table used to store Email templates
*/
'email_templates_table' => 'email_templates',
/*
* Email templates table used to store Email templates
*/
......
......@@ -4,4 +4,9 @@ return [
'pages' => [
'table' => 'pages',
],
'email_templates'=> [
'table' => 'email_templates',
'placeholders_table' => 'email_template_placeholders',
'types_table' => 'email_template_types'
]
];
......@@ -14,7 +14,7 @@ class EmailTemplatePlaceholderTableSeeder extends Seeder
public function run()
{
if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_template_placeholders_table'))->truncate();
DB::table(config('module.email_templates.placeholder_table'))->truncate();
}
$data = [
......@@ -75,6 +75,6 @@ class EmailTemplatePlaceholderTableSeeder extends Seeder
],
];
DB::table(config('access.email_template_placeholders_table'))->insert($data);
DB::table(config('module.email_templates.placeholder_table'))->insert($data);
}
}
......@@ -14,7 +14,7 @@ class EmailTemplateTableSeeder extends Seeder
public function run()
{
if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_templates_table'))->truncate();
DB::table(config('module.email_templates.table'))->truncate();
}
$data = [
......@@ -285,6 +285,6 @@ class EmailTemplateTableSeeder extends Seeder
],
];
DB::table(config('access.email_templates_table'))->insert($data);
DB::table(config('module.email_templates.table'))->insert($data);
}
}
......@@ -14,7 +14,7 @@ class EmailTemplateTypeTableSeeder extends Seeder
public function run()
{
if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_template_types_table'))->truncate();
DB::table(config('module.email_templates.types_table'))->truncate();
}
$data = [
......@@ -43,6 +43,6 @@ class EmailTemplateTypeTableSeeder extends Seeder
],
];
DB::table(config('access.email_template_types_table'))->insert($data);
DB::table(config('module.email_templates.types_table'))->insert($data);
}
}
......@@ -18,7 +18,7 @@ class PagesTableSeeder extends Seeder
public function run()
{
$this->disableForeignKeys();
$this->truncate(config('access.pages_table'));
$this->truncate(config('module.pages.table'));
$page = [
[
......@@ -32,7 +32,7 @@ class PagesTableSeeder extends Seeder
],
];
DB::table(config('access.pages_table'))->insert($page);
DB::table(config('module.pages.table'))->insert($page);
$this->enableForeignKeys();
}
......
......@@ -92,11 +92,11 @@
type: 'post'
},
columns: [
{data: 'title', name: '{{config('access.email_templates_table')}}.title'},
{data: 'subject', name: '{{config('access.email_templates_table')}}.subject'},
{data: 'status', name: '{{config('access.email_templates_table')}}.status'},
{data: 'created_at', name: '{{config('access.email_templates_table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.email_templates_table')}}.updated_at'},
{data: 'title', name: '{{config('module.email_templates.table')}}.title'},
{data: 'subject', name: '{{config('module.email_templates.table')}}.subject'},
{data: 'status', name: '{{config('module.email_templates.table')}}.status'},
{data: 'created_at', name: '{{config('module.email_templates.table')}}.created_at'},
{data: 'updated_at', name: '{{config('module.email_templates.table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[3, "asc"]],
......
......@@ -20,17 +20,6 @@ Route::any('generateSlug', function (\Illuminate\Http\Request $request) {
return str_slug($request['text']);
})->name('generate.slug');
/*
* Email Templates Management
*/
Route::group(['namespace' => 'EmailTemplates'], function () {
Route::resource('emailtemplates', 'EmailTemplatesController', ['except' => ['show', 'create', 'save']]);
//For DataTables
Route::post('emailtemplates/get', 'EmailTemplatesTableController')
->name('emailtemplates.get');
});
/*
* Settings Management
*/
......
<?php
/*
* Email Templates Management
*/
Route::group(['namespace' => 'EmailTemplates'], function () {
Route::resource('emailtemplates', 'EmailTemplatesController', ['except' => ['show', 'create', 'save']]);
//For DataTables
Route::post('emailtemplates/get', 'EmailTemplatesTableController')
->name('emailtemplates.get');
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment