access - модуль

This commit is contained in:
2019-10-22 18:03:40 +03:00
parent 562c4a925e
commit 34dd9f3f37
21 changed files with 1790 additions and 524 deletions

View File

@ -14,6 +14,9 @@ return [
'bootstrap' => ['log'],
'modules' => [
'accesses' => [
'class' => 'backend\modules\accesses\Accesses',
],
'settings' => [
'class' => 'backend\modules\settings\Settings',
],

View File

@ -0,0 +1,24 @@
<?php
namespace backend\modules\accesses;
/**
* accesses module definition class
*/
class Accesses extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'app\modules\accesses\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,130 @@
<?php
namespace app\modules\accesses\controllers;
use common\classes\Debug;
use common\models\ProjectAccesses;
use common\models\UserCardAccesses;
use Yii;
use common\models\Accesses;
use app\modules\accesses\models\AccessesSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* AccessesController implements the CRUD actions for Accesses model.
*/
class AccessesController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Accesses models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new AccessesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Accesses model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Accesses model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Accesses();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Accesses model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Accesses model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Accesses model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Accesses the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Accesses::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\modules\accesses\controllers;
use yii\web\Controller;
/**
* Default controller for the `accesses` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace app\modules\accesses\models;
use common\classes\Debug;
use Yii;
/**
* This is the model class for table "accesses".
*
* @property int $id
* @property string $name
* @property string $access
*/
class Accesses extends \common\models\Accesses
{
}

View File

@ -0,0 +1,69 @@
<?php
namespace app\modules\accesses\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Accesses;
/**
* AccessesSearch represents the model behind the search form of `common\models\Accesses`.
*/
class AccessesSearch extends Accesses
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['name', 'access'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Accesses::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'access', $this->access]);
return $dataProvider;
}
}

View File

@ -0,0 +1,61 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
/* @var $this yii\web\View */
/* @var $model common\models\Accesses */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="accesses-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'access')->textarea(['maxlength' => true]) ?>
<div class="row">
<div class="col-xs-12">
<?= Select2::widget(
[
'model' => $model,
'attribute' => '_projects',
'data' => \yii\helpers\ArrayHelper::map(\common\models\Project::find()->all(), 'id', 'name'),
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
'pluginOptions' => [
'allowClear' => true
],
]
) ?>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<text>Пользователи</text>
<?= Select2::widget(
[
'model'=> $model,
'attribute' => '_users',
'data' => \yii\helpers\ArrayHelper::map(\common\models\UserCard::find()->all(), 'id', 'fio'),
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
'pluginOptions' => [
'allowClear' => true
],
]
) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,31 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\modules\accesses\models\AccessesSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="accesses-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'access') ?>
<div class="form-group">
<?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Сброс', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Accesses */
$this->title = 'Добавить доступ';
$this->params['breadcrumbs'][] = ['label' => 'Accesses', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="accesses-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,50 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\accesses\models\AccessesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Доступы';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="accesses-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Добавить доступ', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'access',
[
'attribute' => 'userCard.fio',
'format' => 'raw',
'value' => function(\common\models\Accesses $model){
return $model->getUserCardName();
},
],
[
'attribute' => 'projects.name',
'format' => 'raw',
'value' => function(\common\models\Accesses $model){
return $model->getProjectName();
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Accesses */
$this->title = 'Редактировать доступ: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Accesses', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="accesses-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,51 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\Accesses */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Accesses', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="accesses-view">
<p>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Вы уверены, что хотите удалить эот элемент?',
'method' => 'post',
],
]) ?>
<?= Html::a('Список', ['index', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'name',
'access',
[
'attribute' => 'userCard.fio',
'format' => 'raw',
'value' => function(\common\models\Accesses $model){
return $model->getUserCardName();
},
],
[
'attribute' => 'projects.name',
'format' => 'raw',
'value' => function(\common\models\Accesses $model){
return $model->getProjectName();
},
],
],
]) ?>
</div>

View File

@ -0,0 +1,12 @@
<div class="accesses-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -43,6 +43,7 @@
],
['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance']],
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday']],
['label' => 'Доступы', 'icon' => '', 'url' => ['/accesses/accesses']],
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],
['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug']],