Skip to content

Commit

Permalink
Merge pull request #4 from updivision/feature/bugfixes
Browse files Browse the repository at this point in the history
Feature/bugfixes
  • Loading branch information
Paul Duca authored Jan 25, 2018
2 parents 55df4ce + 4c35510 commit bb7c3bb
Show file tree
Hide file tree
Showing 53 changed files with 2,461 additions and 777 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/Admin/CartRuleCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ public function setFields()
// INFORMATION TAB
[
'name' => 'name',
'label' => trans('cartrule.name') . ' *',
'label' => trans('cartrule.name'),
'type' => 'text',
'attributes'=> ['required' => 'true'],
'tab' => trans('cartrule.information_tab'),
],
[
'name' => 'code',
'label' => trans('cartrule.code') . ' *',
'label' => trans('cartrule.code'),
'tab' => trans('cartrule.information_tab'),
],
[
Expand All @@ -213,7 +213,7 @@ public function setFields()
],
[
'name' => 'priority',
'label' => trans('cartrule.priority') . ' *',
'label' => trans('cartrule.priority'),
'type' => 'number',
'attributes'=> [
'step' => 'any',
Expand Down Expand Up @@ -251,13 +251,13 @@ public function setFields()
],
[
'name' => 'start_date',
'label' => trans('cartrule.start_date') . ' *',
'label' => trans('cartrule.start_date'),
'type' => 'datetime_picker',
'tab' => trans('cartrule.conditions_tab'),
],
[
'name' => 'expiration_date',
'label' => trans('cartrule.expiration_date') . ' *',
'label' => trans('cartrule.expiration_date'),
'type' => 'datetime_picker',
'tab' => trans('cartrule.conditions_tab'),
],
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/Admin/ClientCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public function setup()

public function setFields()
{

// dd($this->crud->model->find(1)->roles->first()->name);

$this->crud->addFields([
[
'name' => 'salutation',
Expand Down Expand Up @@ -203,9 +200,13 @@ public function setFields()

public function store(StoreRequest $request)
{
$clientRoleName = env('CLIENT_ROLE_NAME');

$this->handlePasswordInput($request);

$redirect_location = parent::storeCrud($request);
// $clientRoleID = \DB::table('roles')->whereName($clientRoleName ?: 'client')->first()->id;
// $this->crud->entry->roles()->attach($clientRoleID);

return $redirect_location;
}
Expand Down
218 changes: 218 additions & 0 deletions app/Http/Controllers/Admin/NotificationTemplateCrudController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\NotificationTemplateRequest as StoreRequest;
use App\Http\Requests\NotificationTemplateRequest as UpdateRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Illuminate\Http\Request;

class NotificationTemplateCrudController extends CrudController
{

public function setUp()
{

/*
|--------------------------------------------------------------------------
| BASIC CRUD INFORMATION
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\NotificationTemplate');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/notification-templates');
$this->crud->setEntityNameStrings(trans('notification_templates.notification_template'), trans('notification_templates.notification_templates'));

/*
|--------------------------------------------------------------------------
| COLUMNS
|--------------------------------------------------------------------------
*/
$this->crud->addColumns([
[
'name' => 'name',
'label' => trans('notification_templates.name'),
],
[
'name' => 'slug',
'label' => trans('notification_templates.slug'),
],
[
'name' => 'body',
'label' => trans('notification_templates.body'),
],
]);

/*
|--------------------------------------------------------------------------
| PERMISSIONS
|-------------------------------------------------------------------------
*/
$this->setPermissions();

/*
|--------------------------------------------------------------------------
| FIELDS
|--------------------------------------------------------------------------
*/
$this->setFields();

}

public function setPermissions()
{
// Get authenticated user
$user = auth()->user();

// Deny all accesses
$this->crud->denyAccess(['list', 'create', 'update', 'delete']);

// Allow list access
if ($user->can('list_notification_templates')) {
$this->crud->allowAccess('list');
}

// Allow create access
if ($user->can('create_notification_template')) {
$this->crud->allowAccess('create');
}

// Allow update access
if ($user->can('update_notification_template')) {
$this->crud->allowAccess('update');
}

// Uncomment if you want to allow delete functionality
// Allow delete access
// if ($user->can('delete_notification_template')) {
// $this->crud->allowAccess('delete');
// }
}

public function setFields()
{
$availableModels = [
'User' => 'App\Models\User',
'Order' => 'App\Models\Order'
];

$this->crud->addFields([
[
'name' => 'name',
'label' => trans('notification_templates.name'),
'type' => 'text',
],
[
'name' => 'slug',
'label' => trans('notification_templates.slug'),
'type' => 'slug',
// 'attributes' => ['disabled' => 'disabled']
],
[
'name' => 'model',
'label' => trans('notification_templates.model'),
'type' => 'select2_from_array_notification_template_model',
'options' => $availableModels
],
[
'name' => 'body',
'label' => trans('notification_templates.body'),
'type' => 'ckeditor',
'wrapperAttributes' => [
'class' => 'form-group col-md-9 col-xs-12'
]
],
[
'name' => 'notification_list_variables',
'label' => trans('notification_templates.available_variables'),
'type' => 'notification_list_variables',
'wrapperAttributes' => [
'class' => 'form-group available-variables col-md-3 col-xs-12'
]
],
]);
}

public function listModelVars(Request $request)
{
$modelClass = 'App\\Models\\'.$request->input('model');

if ($request->input('model') === 'User') {
$modelClass = 'App\\'.$request->input('model');
}

if (class_exists($modelClass)) {
$model = new $modelClass;

return response()->json($model->notificationVars);
}

return null;
}


/**
* Get model variables available to use in an email template
* @param string $modelName
* @return array
*/
public function getModelVariables($modelName)
{
$modelClass = 'App\\Models\\'.$modelName;

if ($modelName === 'User') {
$modelClass = 'App\\'.$modelName;
}

if (class_exists($modelClass)) {
$model = new $modelClass;
}

return $model->notificationVars;
}

/**
* Check variables in body to match the available variables from the model
* @param $request
* @return boolean
*/
public function checkModelVariables($request) {
preg_match_all('/(\{{2}\s?(.*?)\s?\}{2})/mi',
$request->body,
$out, PREG_PATTERN_ORDER);

if (count(array_diff($out[2], $this->getModelVariables($request->model))) > 0) {
return false;
}
return true;
}


public function store(StoreRequest $request)
{
if (!$this->checkModelVariables($request)) {
\Alert::error(trans('notification_templates.variables_error'))->flash();
return redirect()->back()->withInput();
}

// your additional operations before save here
$redirect_location = parent::storeCrud();
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}


public function update(UpdateRequest $request)
{
if (!$this->checkModelVariables($request)) {
\Alert::error(trans('notification_templates.variables_error'))->flash();
return redirect()->back()->withInput();
}

// your additional operations before save here
$redirect_location = parent::updateCrud();
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/Admin/OrderStatusCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function setUp()
[
'name' => 'name',
'label' => trans('order.status_name'),
],
[
'name' => 'notification',
'label' => trans('order.notification'),
'type' => 'boolean',
'options' => [0 => 'Disabled', 1 => 'Enabled']
]
]);

Expand Down Expand Up @@ -94,6 +100,14 @@ public function setFields()
'name' => 'name',
'label' => trans('order.status_name'),
'type' => 'text',
],
[
'name' => 'notification',
'type' => 'select_from_array',
'options' => [
1 => 'Enabled',
0 => 'Disabled'
]
]
]);
}
Expand Down
Loading

0 comments on commit bb7c3bb

Please sign in to comment.