Commit 4f75d30b authored by Vipul Basapati's avatar Vipul Basapati

Refactored Email Template Module

parent 92c5ecca
...@@ -23,9 +23,9 @@ class EmailTemplatesController extends Controller ...@@ -23,9 +23,9 @@ class EmailTemplatesController extends Controller
protected $emailtemplates; 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) public function __construct(EmailTemplatesRepository $emailtemplates)
{ {
...@@ -33,9 +33,7 @@ class EmailTemplatesController extends Controller ...@@ -33,9 +33,7 @@ class EmailTemplatesController extends Controller
} }
/** /**
* Use to load index view of EmailTmplates. * @param \App\Http\Requests\Backend\EmailTemplates\ManageEmailTemplatesRequest $request
*
* @param ManageEmailTemplatesRequest $request
* *
* @return mixed * @return mixed
*/ */
...@@ -45,18 +43,16 @@ class EmailTemplatesController extends Controller ...@@ -45,18 +43,16 @@ class EmailTemplatesController extends Controller
} }
/** /**
* Use to load edit form of Emailtemplate. * @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* * @param \App\Http\Requests\Backend\EmailTemplates\EditEmailTemplatesRequest $request
* @param EmailTemplate $emailtemplate
* @param EditEmailTemplatesRequest $request
* *
* @return mixed * @return mixed
*/ */
public function edit(EmailTemplate $emailtemplate, EditEmailTemplatesRequest public function edit(EmailTemplate $emailtemplate, EditEmailTemplatesRequest
$request) $request)
{ {
$emailtemplateTypes = EmailTemplateType::pluck('name', 'id'); $emailtemplateTypes = EmailTemplateType::getSelectData();
$emailtemplatePlaceholders = EmailTemplatePlaceholder::pluck('name', 'id'); $emailtemplatePlaceholders = EmailTemplatePlaceholder::getSelectData();
return view('backend.emailtemplates.edit') return view('backend.emailtemplates.edit')
->withEmailtemplate($emailtemplate) ->withEmailtemplate($emailtemplate)
...@@ -65,27 +61,23 @@ class EmailTemplatesController extends Controller ...@@ -65,27 +61,23 @@ class EmailTemplatesController extends Controller
} }
/** /**
* Use to update an Emailtemplate. * @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* * @param \App\Http\Requests\Backend\EmailTemplates\UpdateEmailTemplatesRequest $request
* @param EmailTemplate $emailtemplate
* @param UpdateEmailTemplatesRequest $request
* *
* @return mixed * @return mixed
*/ */
public function update(EmailTemplate $emailtemplate, UpdateEmailTemplatesRequest public function update(EmailTemplate $emailtemplate, UpdateEmailTemplatesRequest
$request) $request)
{ {
$this->emailtemplates->update($emailtemplate, $request->all()); $this->emailtemplates->update($emailtemplate, $request->except(['_method', '_token', 'placeholder']));
return redirect()->route('admin.emailtemplates.index') return redirect()->route('admin.emailtemplates.index')
->withFlashSuccess(trans('alerts.backend.emailtemplates.updated')); ->withFlashSuccess(trans('alerts.backend.emailtemplates.updated'));
} }
/** /**
* Use to delete an Emailtemplate. * @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* * @param \App\Http\Requests\Backend\EmailTemplates\DeleteEmailTemplatesRequest $request
* @param EmailTemplate $emailtemplate
* @param DeleteEmailTemplatesRequest $request
* *
* @return mixed * @return mixed
*/ */
......
...@@ -19,7 +19,7 @@ class EmailTemplatesTableController extends Controller ...@@ -19,7 +19,7 @@ class EmailTemplatesTableController extends Controller
protected $emailtemplates; protected $emailtemplates;
/** /**
* @param EmailTemplatesRepository $emailtemplates * @param \App\Repositories\Backend\EmailTemplates\EmailTemplatesRepository $emailtemplates
*/ */
public function __construct(EmailTemplatesRepository $emailtemplates) public function __construct(EmailTemplatesRepository $emailtemplates)
{ {
...@@ -27,7 +27,7 @@ class EmailTemplatesTableController extends Controller ...@@ -27,7 +27,7 @@ class EmailTemplatesTableController extends Controller
} }
/** /**
* @param ManageEmailTemplatesRequest $request * @param \App\Http\Requests\Backend\EmailTemplates\ManageEmailTemplatesRequest $request
* *
* @return mixed * @return mixed
*/ */
...@@ -36,11 +36,7 @@ class EmailTemplatesTableController extends Controller ...@@ -36,11 +36,7 @@ class EmailTemplatesTableController extends Controller
return Datatables::of($this->emailtemplates->getForDataTable()) return Datatables::of($this->emailtemplates->getForDataTable())
->escapeColumns(['title']) ->escapeColumns(['title'])
->addColumn('status', function ($emailtemplates) { ->addColumn('status', function ($emailtemplates) {
if ($emailtemplates->status) { return $emailtemplates->status_label;
return '<span class="label label-success">Active</span>';
}
return '<span class="label label-danger">Inactive</span>';
}) })
->addColumn('created_at', function ($emailtemplates) { ->addColumn('created_at', function ($emailtemplates) {
return Carbon::parse($emailtemplates->created_at)->toDateString(); return Carbon::parse($emailtemplates->created_at)->toDateString();
......
...@@ -16,6 +16,6 @@ class EmailTemplatePlaceholder extends BaseModel ...@@ -16,6 +16,6 @@ class EmailTemplatePlaceholder extends BaseModel
public function __construct(array $attributes = []) public function __construct(array $attributes = [])
{ {
parent::__construct($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 ...@@ -16,6 +16,6 @@ class EmailTemplateType extends BaseModel
public function __construct(array $attributes = []) public function __construct(array $attributes = [])
{ {
parent::__construct($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 ...@@ -15,6 +15,8 @@ class EmailTemplate extends BaseModel
// EmailTemplateAttribute::getEditButtonAttribute insteadof ModelTrait; // EmailTemplateAttribute::getEditButtonAttribute insteadof ModelTrait;
} }
protected $guarded = ['id'];
/** /**
* The database table used by the model. * The database table used by the model.
* *
...@@ -25,6 +27,6 @@ class EmailTemplate extends BaseModel ...@@ -25,6 +27,6 @@ class EmailTemplate extends BaseModel
public function __construct(array $attributes = []) public function __construct(array $attributes = [])
{ {
parent::__construct($attributes); parent::__construct($attributes);
$this->table = config('access.email_templates_table'); $this->table = config('module.email_templates.table');
} }
} }
...@@ -14,4 +14,25 @@ trait EmailTemplateAttribute ...@@ -14,4 +14,25 @@ trait EmailTemplateAttribute
{ {
return '<div class="btn-group action-btn">'.$this->getEditButtonAttribute('edit-email-template', 'admin.emailtemplates.edit').'</div>'; 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 ...@@ -26,60 +26,53 @@ class EmailTemplatesRepository extends BaseRepository
{ {
return $this->query() return $this->query()
->select([ ->select([
config('access.email_templates_table').'.id', config('module.email_templates.table').'.id',
config('access.email_templates_table').'.title', config('module.email_templates.table').'.title',
config('access.email_templates_table').'.subject', config('module.email_templates.table').'.subject',
config('access.email_templates_table').'.status', config('module.email_templates.table').'.status',
config('access.email_templates_table').'.created_at', config('module.email_templates.table').'.created_at',
config('access.email_templates_table').'.updated_at', config('module.email_templates.table').'.updated_at',
]); ]);
} }
/** /**
* @param Model $permission * @param \App\Models\EmailTemplates\EmailTemplate $emailtemplate
* @param $input * @param $input
* *
* @throws GeneralException * @throws GeneralException
* *
* return bool * return bool
*/ */
public function update(Model $emailtemplate, array $input) public function update(EmailTemplate $emailtemplate, array $input)
{ {
$emailtemplate->title = $input['title']; $input['status'] = isset($input['is_active']) ? 1 : 0;
$emailtemplate->body = $input['body']; unset($input['is_active']);
$emailtemplate->type_id = $input['type_id']; $input['updated_by'] = access()->user()->id;
$emailtemplate->subject = $input['subject'];
$emailtemplate->status = (isset($input['is_active']) && $input['is_active'] == 1) ? 1 : 0;
$emailtemplate->updated_by = access()->user()->id;
DB::transaction(function () use ($emailtemplate, $input) { if ($emailtemplate->update($input)) {
if ($emailtemplate->save()) { event(new EmailTemplateUpdated($emailtemplate));
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 * @throws GeneralException
* *
* @return bool * @return bool
*/ */
public function delete(Model $emailtemplate) public function delete(EmailTemplate $emailtemplate)
{ {
DB::transaction(function () use ($emailtemplate) { if ($emailtemplate->delete()) {
if ($emailtemplate->delete()) { event(new EmailTemplateDeleted($emailtemplate));
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 [ ...@@ -60,21 +60,6 @@ return [
*/ */
'cities_table' => 'cities', '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 * Email templates table used to store Email templates
*/ */
......
...@@ -4,4 +4,9 @@ return [ ...@@ -4,4 +4,9 @@ return [
'pages' => [ 'pages' => [
'table' => '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 ...@@ -14,7 +14,7 @@ class EmailTemplatePlaceholderTableSeeder extends Seeder
public function run() public function run()
{ {
if (env('DB_CONNECTION') == 'mysql') { if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_template_placeholders_table'))->truncate(); DB::table(config('module.email_templates.placeholder_table'))->truncate();
} }
$data = [ $data = [
...@@ -75,6 +75,6 @@ class EmailTemplatePlaceholderTableSeeder extends Seeder ...@@ -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 ...@@ -14,7 +14,7 @@ class EmailTemplateTableSeeder extends Seeder
public function run() public function run()
{ {
if (env('DB_CONNECTION') == 'mysql') { if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_templates_table'))->truncate(); DB::table(config('module.email_templates.table'))->truncate();
} }
$data = [ $data = [
...@@ -285,6 +285,6 @@ class EmailTemplateTableSeeder extends Seeder ...@@ -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 ...@@ -14,7 +14,7 @@ class EmailTemplateTypeTableSeeder extends Seeder
public function run() public function run()
{ {
if (env('DB_CONNECTION') == 'mysql') { if (env('DB_CONNECTION') == 'mysql') {
DB::table(config('access.email_template_types_table'))->truncate(); DB::table(config('module.email_templates.types_table'))->truncate();
} }
$data = [ $data = [
...@@ -43,6 +43,6 @@ class EmailTemplateTypeTableSeeder extends Seeder ...@@ -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 ...@@ -18,7 +18,7 @@ class PagesTableSeeder extends Seeder
public function run() public function run()
{ {
$this->disableForeignKeys(); $this->disableForeignKeys();
$this->truncate(config('access.pages_table')); $this->truncate(config('module.pages.table'));
$page = [ $page = [
[ [
...@@ -32,7 +32,7 @@ class PagesTableSeeder extends Seeder ...@@ -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(); $this->enableForeignKeys();
} }
......
...@@ -92,11 +92,11 @@ ...@@ -92,11 +92,11 @@
type: 'post' type: 'post'
}, },
columns: [ columns: [
{data: 'title', name: '{{config('access.email_templates_table')}}.title'}, {data: 'title', name: '{{config('module.email_templates.table')}}.title'},
{data: 'subject', name: '{{config('access.email_templates_table')}}.subject'}, {data: 'subject', name: '{{config('module.email_templates.table')}}.subject'},
{data: 'status', name: '{{config('access.email_templates_table')}}.status'}, {data: 'status', name: '{{config('module.email_templates.table')}}.status'},
{data: 'created_at', name: '{{config('access.email_templates_table')}}.created_at'}, {data: 'created_at', name: '{{config('module.email_templates.table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.email_templates_table')}}.updated_at'}, {data: 'updated_at', name: '{{config('module.email_templates.table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false} {data: 'actions', name: 'actions', searchable: false, sortable: false}
], ],
order: [[3, "asc"]], order: [[3, "asc"]],
......
...@@ -20,17 +20,6 @@ Route::any('generateSlug', function (\Illuminate\Http\Request $request) { ...@@ -20,17 +20,6 @@ Route::any('generateSlug', function (\Illuminate\Http\Request $request) {
return str_slug($request['text']); return str_slug($request['text']);
})->name('generate.slug'); })->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 * 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