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

View File

@ -18,7 +18,7 @@ class AccessesSearch extends Accesses
{ {
return [ return [
[['id'], 'integer'], [['id'], 'integer'],
[['name', 'access'], 'safe'], [['name', 'login', 'password', 'link', 'project', 'info'], 'safe'],
]; ];
} }
@ -62,7 +62,11 @@ class AccessesSearch extends Accesses
]); ]);
$query->andFilterWhere(['like', 'name', $this->name]) $query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'access', $this->access]); ->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; return $dataProvider;
} }

View File

@ -18,28 +18,38 @@ use kartik\select2\Select2;
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'access')->textarea(['maxlength' => true]) ?> <?= $form->field($model, 'login')->textInput(['maxlength' => true]) ?>
<div class="row"> <?= $form->field($model, 'password')->textInput(['maxlength' => true]) ?>
<div class="col-xs-12">
<?= Select2::widget( <?= $form->field($model, 'link')->textInput(['maxlength' => true]) ?>
[
'model' => $model, <?= $form->field($model, 'project')->textInput(['maxlength' => true]) ?>
'attribute' => '_projects',
'data' => \yii\helpers\ArrayHelper::map(\common\models\Project::find()->all(), 'id', 'name'), <?= $form->field($model, 'info')->textarea(['maxlength' => true]) ?>
'options' => ['placeholder' => '...', 'class' => 'form-control', 'multiple' => true],
'pluginOptions' => [ <!-- <div class="row">-->
'allowClear' => true <!-- <div class="col-xs-12">-->
], <!-- --><?php
] // echo Select2::widget(
) ?> // [
</div> // 'model' => $model,
</div> // '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="row">
<div class="col-xs-12"> <div class="col-xs-12">
<text>Пользователи</text> <text>Пользователи</text>
<?= Select2::widget( <?php
echo Select2::widget(
[ [
'model'=> $model, 'model'=> $model,
'attribute' => '_users', 'attribute' => '_users',
@ -48,13 +58,12 @@ use kartik\select2\Select2;
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true 'allowClear' => true
], ],
] ]); ?>
) ?>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?> <?= '<br>' . Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

View File

@ -19,8 +19,6 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'name') ?> <?= $form->field($model, 'name') ?>
<?= $form->field($model, 'access') ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?> <?= Html::submitButton('Поиск', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Сброс', ['class' => 'btn btn-default']) ?> <?= Html::resetButton('Сброс', ['class' => 'btn btn-default']) ?>

View File

@ -24,10 +24,11 @@ $this->params['breadcrumbs'][] = $this->title;
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
'name', 'name',
'access', 'login',
'password',
'link',
'project',
[ [
'attribute' => 'userCard.fio', 'attribute' => 'userCard.fio',
'format' => 'raw', 'format' => 'raw',
@ -35,15 +36,13 @@ $this->params['breadcrumbs'][] = $this->title;
return $model->getUserCardName(); return $model->getUserCardName();
}, },
], ],
// [
[ // 'attribute' => 'projects.name',
'attribute' => 'projects.name', // 'format' => 'raw',
'format' => 'raw', // 'value' => function(\common\models\Accesses $model){
'value' => function(\common\models\Accesses $model){ // return $model->getProjectName();
return $model->getProjectName(); // },
}, // ],
],
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn'],
], ],
]); ?> ]); ?>

View File

@ -30,21 +30,25 @@ $this->params['breadcrumbs'][] = $this->title;
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
'name', 'name',
'access', 'login',
[ 'password',
'attribute' => 'userCard.fio', 'link',
'format' => 'raw', 'project',
'value' => function(\common\models\Accesses $model){ 'info',
return $model->getUserCardName(); // [
}, // 'attribute' => 'userCard.fio',
], // 'format' => 'raw',
[ // 'value' => function(\common\models\Accesses $model){
'attribute' => 'projects.name', // return $model->getUserCardName();
'format' => 'raw', // },
'value' => function(\common\models\Accesses $model){ // ],
return $model->getProjectName(); // [
}, // 'attribute' => 'projects.name',
], // 'format' => 'raw',
// 'value' => function(\common\models\Accesses $model){
// return $model->getProjectName();
// },
// ],
], ],
]) ?> ]) ?>

View File

@ -1,8 +1,15 @@
<div class="calendar-default-index"> <?php
/* @var $searchModel backend\modules\card\models\UserCardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
use yii\grid\GridView;
use yii\widgets\Pjax;
?>
<p> <p>
<select id="options" class="btn btn-secondary dropdown-toggle"> <select id="options" class="btn btn-secondary dropdown-toggle">
<option selected="selected">Выберите месяц</option> <option selected="selected" value="?month=00">Выберите месяц</option>
<option value="?month=00">Показать все</option> <option value="?month=00">Показать все</option>
<option value="?month=01">январь</option> <option value="?month=01">январь</option>
<option value="?month=02">февраль</option> <option value="?month=02">февраль</option>
@ -20,13 +27,6 @@
</p> </p>
<?php <?php
/* @var $searchModel backend\modules\card\models\UserCardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
use yii\grid\GridView;
use yii\widgets\Pjax;
Pjax::begin(['id' => 'reload']); Pjax::begin(['id' => 'reload']);
echo GridView::widget([ echo GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,

View File

@ -121,7 +121,7 @@ class UserCard extends \common\models\UserCard
$user->save(); $user->save();
$log = "Логин: " . $email . " Пароль: " . $password . " | "; $log = "Логин: " . $email . " Пароль: " . $password . " | ";
//file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX); file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
return $user->id; return $user->id;
} }

View File

@ -11,7 +11,11 @@ use yii\helpers\ArrayHelper;
* *
* @property int $id * @property int $id
* @property string $name * @property string $name
* @property string $access * @property string $login
* @property string $password
* @property string $link
* @property string $project
* @property string $info
*/ */
class Accesses extends \yii\db\ActiveRecord class Accesses extends \yii\db\ActiveRecord
{ {
@ -32,8 +36,8 @@ class Accesses extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['name'], 'string', 'max' => 255], [['name', 'login', 'password', 'link', 'project' ], 'string', 'max' => 255],
[['access'], 'string'], [['info'], 'string'],
[['_projects'], 'safe'], [['_projects'], 'safe'],
[['_users'], 'safe'], [['_users'], 'safe'],
]; ];
@ -47,7 +51,11 @@ class Accesses extends \yii\db\ActiveRecord
return [ return [
'id' => 'ID', 'id' => 'ID',
'name' => 'Название', 'name' => 'Название',
'access' => 'Доступ', 'login' => 'Логин',
'password' => 'Пароль',
'link' => 'Ссылка',
'project' => 'Проект',
'info' => 'Дополнительная информация',
]; ];
} }

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles dropping columns from table `{{%accesses}}`.
*/
class m200121_115737_drop_access_column_from_accesses_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropColumn('{{%accesses}}', 'access');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->addColumn('{{%accesses}}', 'access', $this->string());
}
}

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles adding columns to table `{{%accesses}}`.
*/
class m200121_120006_add_login_column_to_accesses_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%accesses}}', 'login', $this->string());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%accesses}}', 'login');
}
}

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Migration;
/**
* Handles adding columns to table `{{%accesses}}`.
*/
class m200121_120121_add_password_column_to_accesses_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('{{%accesses}}', 'password', $this->string());
$this->addColumn('{{%accesses}}', 'link', $this->string());
$this->addColumn('{{%accesses}}', 'project', $this->string());
$this->addColumn('{{%accesses}}', 'info', $this->text());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('{{%accesses}}', 'password');
$this->dropColumn('{{%accesses}}', 'link');
$this->dropColumn('{{%accesses}}', 'project');
$this->dropColumn('{{%accesses}}', 'info');
}
}

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

@ -3,28 +3,128 @@
namespace frontend\modules\access\controllers; namespace frontend\modules\access\controllers;
use Yii; use Yii;
use yii\web\Controller;
use yii\data\ActiveDataProvider;
use common\models\Accesses; 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 class AccessController extends Controller
{ {
/** /**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Accesses models.
* @return mixed * @return mixed
*/ */
public function actionIndex() public function actionIndex()
{ {
$id_user = Yii::$app->user->id; $dataProvider = new ActiveDataProvider(['query' => Accesses::find()
$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 "; ->where(['user_card.id_user' => Yii::$app->user->identity->id])
$access = Accesses::findBySql($query); ->innerJoin('user_card_accesses', 'accesses.id = user_card_accesses.accesses_id')
->innerJoin('user_card', 'user_card_accesses.user_card_id = user_card.id')
$dataProvider = new ActiveDataProvider([
'query' => $access,
'pagination' => [
'pageSize' => 200,
],
]); ]);
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>

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

@ -1,14 +1,37 @@
<?php <?php
use yii\helpers\Html;
use yii\grid\GridView; 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([ $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, 'dataProvider' => $dataProvider,
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
'id',
'name', 'name',
'access', '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>