Skip to content

Commit

Permalink
Merge pull request #4 from dmstr/feature/refactor-2021-04-14
Browse files Browse the repository at this point in the history
added backend overview, moved access control to module
  • Loading branch information
schmunk42 authored Apr 19, 2021
2 parents 2218de9 + 2c6e435 commit 97502e6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 23 deletions.
13 changes: 12 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

namespace dmstr\modules\contact;

use dmstr\web\traits\AccessBehaviorTrait;

/**
* @property string $defaultRoute
* @property string $frontendLayout
* @property string $backendLayout
*/
class Module extends \yii\base\Module
{
use AccessBehaviorTrait;

/**
* @inheritdoc
*/
public $defaultRoute = 'crud/contact-log';
public $defaultRoute = 'backend';
public $frontendLayout = '//main';
public $backendLayout = '@backend/views/layouts/box';

public function beforeAction($action)
{
\Yii::$app->controller->view->params['breadcrumbs'][] = ['label' => 'Contact', 'url' => ['/'.$this->id]];

return parent::beforeAction($action);
}
}
18 changes: 18 additions & 0 deletions src/controllers/BackendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace dmstr\modules\contact\controllers;

class BackendController extends \yii\web\Controller
{
public function init()
{
parent::init();
$this->layout = $this->module->backendLayout;
}

public function actionIndex()
{
return $this->render('index');
}

}
15 changes: 0 additions & 15 deletions src/controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ class ExportController extends Controller

protected $schemaSettings = [];

public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access'] = [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['Editor']
]
]
];
return $behaviors;
}

public function init()
{
parent::init();
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/crud/ContactLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

namespace dmstr\modules\contact\controllers\crud;

use dmstr\web\traits\AccessBehaviorTrait;

/**
* This is the class for controller "ContactLogController".
*/
class ContactLogController extends \dmstr\modules\contact\controllers\crud\base\ContactLogController
{
use AccessBehaviorTrait;


public function init()
{
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/crud/ContactTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

namespace dmstr\modules\contact\controllers\crud;

use dmstr\web\traits\AccessBehaviorTrait;

/**
* This is the class for controller "ContactTemplateController".
*/
class ContactTemplateController extends \dmstr\modules\contact\controllers\crud\base\ContactTemplateController
{
use AccessBehaviorTrait;


public function init()
{
Expand Down
20 changes: 20 additions & 0 deletions src/views/backend/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/* @var $this yii\web\View */

use yii\helpers\Html;
use Yii;

?>
<h1><?= Yii::t('contact', 'Overview') ?></h1>

<p>
<?= Html::a(Yii::t('contact', 'Templates'), ['crud/contact-template']) ?>
</p>

<p>
<?= Html::a(Yii::t('contact', 'Logs'), ['crud/contact-log']) ?>
</p>

<p>
<?= Html::a(Yii::t('contact', 'Export'), ['export/index']) ?>
</p>
2 changes: 1 addition & 1 deletion src/views/crud/contact-log/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'encodeLabels' => false,
'items' => [
[
'url' => ['/crud/contact-template/index'],
'url' => ['/'.$this->context->module->id.'/crud/contact-template/index'],
'label' => '<i class="glyphicon glyphicon-arrow-left"></i> ' . Yii::t('models', 'Contact Template'),
],

Expand Down
4 changes: 2 additions & 2 deletions src/views/crud/contact-log/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
'format' => 'html',
'attribute' => 'contact_template_id',
'value' => ($model->contactTemplate ?
Html::a('<i class="glyphicon glyphicon-list"></i>', ['/crud/contact-template/index']).' '.
Html::a('<i class="glyphicon glyphicon-circle-arrow-right"></i> '.$model->contactTemplate->name, ['/crud/contact-template/view', 'id' => $model->contactTemplate->id, ]).' '.
Html::a('<i class="glyphicon glyphicon-list"></i>', ['/'.$this->context->module->id.'/crud/contact-template/index']).' '.
Html::a('<i class="glyphicon glyphicon-circle-arrow-right"></i> '.$model->contactTemplate->name, ['/'.$this->context->module->id.'/crud/contact-template/view', 'id' => $model->contactTemplate->id, ]).' '.
Html::a('<i class="glyphicon glyphicon-paperclip"></i>', ['create', 'ContactLog'=>['contact_template_id' => $model->contact_template_id]])
:
'<span class="label label-warning">?</span>'),
Expand Down

0 comments on commit 97502e6

Please sign in to comment.