access - модуль
This commit is contained in:
parent
562c4a925e
commit
34dd9f3f37
@ -14,6 +14,9 @@ return [
|
||||
'bootstrap' => ['log'],
|
||||
|
||||
'modules' => [
|
||||
'accesses' => [
|
||||
'class' => 'backend\modules\accesses\Accesses',
|
||||
],
|
||||
'settings' => [
|
||||
'class' => 'backend\modules\settings\Settings',
|
||||
],
|
||||
|
24
backend/modules/accesses/Accesses.php
Normal file
24
backend/modules/accesses/Accesses.php
Normal 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
|
||||
}
|
||||
}
|
130
backend/modules/accesses/controllers/AccessesController.php
Normal file
130
backend/modules/accesses/controllers/AccessesController.php
Normal 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.');
|
||||
}
|
||||
}
|
20
backend/modules/accesses/controllers/DefaultController.php
Normal file
20
backend/modules/accesses/controllers/DefaultController.php
Normal 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');
|
||||
}
|
||||
}
|
21
backend/modules/accesses/models/Accesses.php
Normal file
21
backend/modules/accesses/models/Accesses.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
69
backend/modules/accesses/models/AccessesSearch.php
Normal file
69
backend/modules/accesses/models/AccessesSearch.php
Normal 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;
|
||||
}
|
||||
}
|
61
backend/modules/accesses/views/accesses/_form.php
Normal file
61
backend/modules/accesses/views/accesses/_form.php
Normal 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>
|
31
backend/modules/accesses/views/accesses/_search.php
Normal file
31
backend/modules/accesses/views/accesses/_search.php
Normal 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>
|
18
backend/modules/accesses/views/accesses/create.php
Normal file
18
backend/modules/accesses/views/accesses/create.php
Normal 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>
|
50
backend/modules/accesses/views/accesses/index.php
Normal file
50
backend/modules/accesses/views/accesses/index.php
Normal 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>
|
21
backend/modules/accesses/views/accesses/update.php
Normal file
21
backend/modules/accesses/views/accesses/update.php
Normal 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>
|
51
backend/modules/accesses/views/accesses/view.php
Normal file
51
backend/modules/accesses/views/accesses/view.php
Normal 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>
|
12
backend/modules/accesses/views/default/index.php
Normal file
12
backend/modules/accesses/views/default/index.php
Normal 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>
|
@ -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']],
|
||||
|
114
common/models/Accesses.php
Normal file
114
common/models/Accesses.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\classes\Debug;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "accesses".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $access
|
||||
*/
|
||||
class Accesses extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $_projects;
|
||||
public $_users;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'accesses';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'access'], 'string', 'max' => 255],
|
||||
[['_projects'], 'safe'],
|
||||
[['_users'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'name' => 'Название',
|
||||
'access' => 'Доступ',
|
||||
];
|
||||
}
|
||||
|
||||
public function getUserCardAccesses()
|
||||
{
|
||||
return $this->hasMany(UserCardAccesses::className(), ['accesses_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getUserCard()
|
||||
{
|
||||
return $this->hasMany(UserCard::className(), ['id' => 'user_card_id'])
|
||||
->via('userCardAccesses');
|
||||
}
|
||||
|
||||
public function getUserCardName()
|
||||
{
|
||||
return implode(', ', ArrayHelper::getColumn($this->userCard, 'fio'));
|
||||
}
|
||||
|
||||
public function getProjectName()
|
||||
{
|
||||
return implode(', ', ArrayHelper::getColumn($this->projects, 'name'));
|
||||
}
|
||||
|
||||
public function afterFind()
|
||||
{
|
||||
parent::afterFind(); // TODO: Change the autogenerated stub
|
||||
$this->_projects = ArrayHelper::getColumn($this->projectAccesses, 'project_id');
|
||||
$this->_users = ArrayHelper::getColumn($this->userCardAccesses, 'user_card_id');
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
{
|
||||
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
||||
ProjectAccesses::deleteAll(['accesses_id' => $this->id]);
|
||||
if ($this->_projects) {
|
||||
foreach ($this->_projects as $prj) {
|
||||
$m2 = new ProjectAccesses();
|
||||
$m2->project_id = $prj;
|
||||
$m2->accesses_id = $this->id;
|
||||
$m2->save();
|
||||
}
|
||||
}
|
||||
UserCardAccesses::deleteAll(['accesses_id' => $this->id]);
|
||||
if ($this->_users) {
|
||||
foreach ($this->_users as $us) {
|
||||
$m2 = new UserCardAccesses();
|
||||
$m2->user_card_id = $us;
|
||||
$m2->accesses_id = $this->id;
|
||||
$m2->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProjectAccesses()
|
||||
{
|
||||
return $this->hasMany(ProjectAccesses::className(), ['accesses_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getProjects()
|
||||
{
|
||||
return $this->hasMany(Project::className(), ['id' => 'project_id'])
|
||||
->via('projectAccesses');
|
||||
}
|
||||
}
|
66
common/models/ProjectAccesses.php
Normal file
66
common/models/ProjectAccesses.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_accesses".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $accesses_id
|
||||
* @property int $project_id
|
||||
*
|
||||
* @property Accesses $accesses
|
||||
* @property Project $project
|
||||
*/
|
||||
class ProjectAccesses extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project_accesses';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['accesses_id', 'project_id'], 'integer'],
|
||||
[['accesses_id'], 'exist', 'skipOnError' => true, 'targetClass' => Accesses::className(), 'targetAttribute' => ['accesses_id' => 'id']],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'accesses_id' => 'Accesses ID',
|
||||
'project_id' => 'Project ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getAccesses()
|
||||
{
|
||||
return $this->hasOne(Accesses::className(), ['id' => 'accesses_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->hasOne(Project::className(), ['id' => 'project_id']);
|
||||
}
|
||||
}
|
66
common/models/UserCardAccesses.php
Normal file
66
common/models/UserCardAccesses.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_card_accesses".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $accesses_id
|
||||
* @property int $user_card_id
|
||||
*
|
||||
* @property Accesses $accesses
|
||||
* @property UserCard $userCard
|
||||
*/
|
||||
class UserCardAccesses extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'user_card_accesses';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['accesses_id', 'user_card_id'], 'integer'],
|
||||
[['accesses_id'], 'exist', 'skipOnError' => true, 'targetClass' => Accesses::className(), 'targetAttribute' => ['accesses_id' => 'id']],
|
||||
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'accesses_id' => 'Accesses ID',
|
||||
'user_card_id' => 'User Card ID',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getAccesses()
|
||||
{
|
||||
return $this->hasOne(Accesses::className(), ['id' => 'accesses_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUserCard()
|
||||
{
|
||||
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
|
||||
}
|
||||
}
|
1461
composer.lock
generated
1461
composer.lock
generated
File diff suppressed because it is too large
Load Diff
29
console/migrations/m191021_085640_create_accesses_table.php
Normal file
29
console/migrations/m191021_085640_create_accesses_table.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%accesses}}`.
|
||||
*/
|
||||
class m191021_085640_create_accesses_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%accesses}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'name' => $this->string(),
|
||||
'access' => $this->string(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropTable('{{%accesses}}');
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%project_accesses}}`.
|
||||
*/
|
||||
class m191021_131536_create_project_accesses_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%project_accesses}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'accesses_id' => $this->integer(),
|
||||
'project_id' => $this->integer(),
|
||||
]);
|
||||
$this->addForeignKey('project_accesses_acc','project_accesses','accesses_id','accesses','id');
|
||||
$this->addForeignKey('project_accesses_prj','project_accesses','project_id','project','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropForeignKey('project_accesses_acc','project_accesses');
|
||||
$this->dropForeignKey('project_accesses_prj','project_accesses');
|
||||
$this->dropTable('{{%project_accesses}}');
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%user_card_accesses}}`.
|
||||
*/
|
||||
class m191021_133036_create_user_card_accesses_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%user_card_accesses}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'accesses_id' => $this->integer(),
|
||||
'user_card_id' => $this->integer(),
|
||||
]);
|
||||
$this->addForeignKey('user_card_accesses_acc','user_card_accesses','accesses_id','accesses','id');
|
||||
$this->addForeignKey('user_card_accesses_uscr','user_card_accesses','user_card_id','user_card','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropForeignKey('user_card_accesses_acc','user_card_accesses');
|
||||
$this->dropForeignKey('user_card_accesses_uscr','user_card_accesses');
|
||||
$this->dropTable('{{%user_card_accesses}}');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user