use app\modules\admin\modules\rbac\models\AuthItem; use dektrium\user\models\User; use app\modules\admin\modules\rbac\models\AuthAssignment; /* @var $this yii\web\View */ /* @var $model app\modules\admin\modules\rbac\models\AuthAssignment */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="auth-assignment-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'item_name')->dropDownList(AuthItem::getAuthItemArray(), ['prompt' => 'Виберіть роль ...']); ?> <?php echo !empty($model->user_id) ? '<p><b>Користувач: ' . User::findOne($model->user_id)->username . '</b></p>' : ''; ?> <?php if (!empty($model->user_id)) { $user = AuthAssignment::find()->where(['user_id' => $model->user_id])->one(); $role = $user->item_name; echo '<p><b>Поточна роль: '; if (!empty($role) && $model->isNewRecord) { echo $role . '</b></p>'; echo 'Роль уже задано для цього користувача! краще змініть існуючу ' . Html::a('Редагувати роль', ['/rbac/auth-assignment/update', 'user_id' => $user->user_id, 'item_name' => $user->item_name], ['class' => 'btn btn-xl btn-danger']); } else { echo $role ? $role : 'Роль відсутня</b></p>';
/** * @return \yii\db\ActiveQuery */ public function getItemName() { return $this->hasOne(AuthItem::className(), ['name' => 'item_name']); }
/** * @return \yii\db\ActiveQuery */ public function getChild0() { return $this->hasOne(AuthItem::className(), ['name' => 'child']); }
/* @var $this yii\web\View */ /* @var $searchModel app\modules\admin\modules\rbac\models\AuthAssignmentSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Ролі користувачів'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="auth-assignment-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Задати роль користувача', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'user_id', 'format' => 'html', 'value' => function ($model) { $username = User::findOne($model->user_id); return Html::a($username->username, ['/user/profile/show', 'id' => $username->id, ['class' => 'btn btn-success']]); }], ['attribute' => 'item_name', 'format' => 'html', 'filter' => AuthItem::getAuthItemArray()], ['attribute' => 'created_at', 'format' => 'date'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>