コード例 #1
0
ファイル: User.php プロジェクト: pc-brainy/blitz
 public function can($role)
 {
     $userRole = \backend\models\Roles::find()->where(['user_id' => $this->id])->one()->role_type_id;
     $hierarchy = \yii\helpers\ArrayHelper::map(\backend\models\RoleTypes::find()->all(), 'name', 'id');
     $idRole = $hierarchy[$role];
     return $userRole >= $idRole;
 }
コード例 #2
0
ファイル: RoleTypesSearch.php プロジェクト: pc-brainy/blitz
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RoleTypes::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
コード例 #3
0
 /**
  * Finds the RoleTypes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RoleTypes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RoleTypes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Roles.php プロジェクト: pc-brainy/blitz
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRoleType()
 {
     return $this->hasOne(RoleTypes::className(), ['id' => 'role_type_id']);
 }
コード例 #5
0
ファイル: _form.php プロジェクト: pc-brainy/blitz
/* @var $this yii\web\View */
/* @var $model backend\models\Roles */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="roles-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'user_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(User::find()->orderby('username', 'ASC')->all(), 'id', 'username'), 'options' => ['placeholder' => Yii::t('app', 'Select an user') . '...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'role_type_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(\backend\models\RoleTypes::find()->orderby('id', 'ASC')->all(), 'id', 'name'), 'options' => ['placeholder' => Yii::t('app', 'Select a role') . '...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
コード例 #6
0
ファイル: index.php プロジェクト: pc-brainy/blitz
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\RoleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', 'Roles');
$this->params['breadcrumbs'][] = $this->title;
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create Roles'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>
    
<div class="roles-index" style="margin-top: 30px;">

    <!--<h1><?php 
echo Html::encode($this->title);
?>
</h1>-->
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>


    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'user_id', 'value' => 'user.username', 'filter' => yii\helpers\ArrayHelper::map(\dektrium\user\models\User::find()->orderBy('username', 'ASC')->all(), 'id', 'username')], ['attribute' => 'role_type_id', 'value' => 'roleType.name', 'filter' => yii\helpers\ArrayHelper::map(\backend\models\RoleTypes::find()->orderBy('name', 'ASC')->all(), 'id', 'name')], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>