accesses new

This commit is contained in:
akosse
2020-01-21 17:33:07 +03:00
parent 188758c79c
commit 6880eaa2ba
20 changed files with 575 additions and 98 deletions

124
frontend/modules/access/controllers/AccessController.php Executable file → Normal file
View File

@ -3,28 +3,128 @@
namespace frontend\modules\access\controllers;
use Yii;
use yii\web\Controller;
use yii\data\ActiveDataProvider;
use common\models\Accesses;
use frontend\modules\access\models\AccessSearch;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* AccessController implements the CRUD actions for Accesses model.
*/
class AccessController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Accesses models.
* @return mixed
*/
public function actionIndex()
{
$id_user = Yii::$app->user->id;
$query = "SELECT accesses.name, accesses.access FROM `accesses`, `user_card`, `user_card_accesses` WHERE user_card.id_user =" . $id_user . " AND user_card_accesses.user_card_id = user_card.id AND accesses.id = user_card_accesses.accesses_id ";
$access = Accesses::findBySql($query);
$dataProvider = new ActiveDataProvider([
'query' => $access,
'pagination' => [
'pageSize' => 200,
],
$dataProvider = new ActiveDataProvider(['query' => Accesses::find()
->where(['user_card.id_user' => Yii::$app->user->identity->id])
->innerJoin('user_card_accesses', 'accesses.id = user_card_accesses.accesses_id')
->innerJoin('user_card', 'user_card_accesses.user_card_id = user_card.id')
]);
return $this->render('index', compact('dataProvider', $dataProvider));
return $this->render('index', [
'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 \frontend\modules\access\models\Access();
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,29 @@
<?php
namespace frontend\modules\access\models;
use common\classes\Debug;
use common\models\UserCardAccesses;
use frontend\modules\card\models\UserCard;
use Yii;
class Access extends \common\models\Accesses
{
public function init()
{
parent::init();
}
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
$user_card = UserCard::findOne(['id_user' => Yii::$app->user->identity->id]);
$user_card_access = new UserCardAccesses();
$user_card_access->user_card_id = $user_card->id;
$user_card_access->accesses_id = $this->id;
$user_card_access->save();
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace frontend\modules\access\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Accesses;
/**
* AccessSearch represents the model behind the search form of `common\models\Accesses`.
*/
class AccessSearch extends Accesses
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id'], 'integer'],
[['name', 'login', 'password', 'link', 'project', 'info'], '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', 'login', $this->login])
->andFilterWhere(['like', 'password', $this->password])
->andFilterWhere(['like', 'link', $this->link])
->andFilterWhere(['like', 'project', $this->project])
->andFilterWhere(['like', 'info', $this->info]);
return $dataProvider;
}
}

View File

@ -0,0 +1,33 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @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, 'login')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>
<?= $form->field($model, 'link')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'project')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'info')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\access\models\AccessSearch */
/* @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, 'login') ?>
<?= $form->field($model, 'password') ?>
<?= $form->field($model, 'link') ?>
<?php // echo $form->field($model, 'project') ?>
<?php // echo $form->field($model, 'info') ?>
<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>

41
frontend/modules/access/views/access/index.php Executable file → Normal file
View File

@ -1,14 +1,37 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
$this->title = 'Доступы';
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\access\models\AccessSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'access',
],
]);
$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,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'login',
'password',
'link',
'project',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update}',
],
],
]); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Accesses */
$this->title = 'Изменить';
$this->params['breadcrumbs'][] = ['label' => 'Доступы', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Изменить';
?>
<div class="accesses-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,40 @@
<?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'], ['class' => 'btn btn-primary']) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'login',
'password',
'link',
'project',
'info:ntext',
],
]) ?>
</div>