public function init() { parent::init(); $this->assignmentTable = Assignment::tableName(); $this->roleTable = Role::tableName(); $this->permissionTable = Permission::tableName(); $this->relationTable = Relation::tableName(); }
/** * Lists all Relation models. * @return mixed */ public function actionIndex($role) { if (\Yii::$app->request->isPost) { $selectedPermissions = LuLu::getPostValue('Permission'); Relation::AddBatchItems($role, $selectedPermissions); return $this->redirect(['index', 'role' => $role]); } $allPermissions = Permission::getAllPermissionsGroupedByCategory(); $rolePermissions = Relation::find()->select(['permission', 'value'])->where(['role' => $role])->indexBy('permission')->all(); $categories = Permission::getCategoryItems(); $role = Role::findOne(['id' => $role]); return $this->render('index', ['rolePermissions' => $rolePermissions, 'allPermissions' => $allPermissions, 'categories' => $categories, 'role' => $role]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Role::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public function actionRole($user) { $userRoles = Assignment::find()->select('role')->where(['user' => $user])->indexBy('role')->all(); if (\Yii::$app->request->isPost) { $selectedRoles = LuLu::getPostValue('roles', []); Assignment::deleteAll(['and', 'user=\'' . $user . '\'', ['not in', 'role', $selectedRoles]]); foreach ($selectedRoles as $selectedRole) { if ($userRoles != null && isset($userRoles[$selectedRole])) { continue; } $newAssignment = new Assignment(); $newAssignment->user = $user; $newAssignment->role = $selectedRole; $newAssignment->save(); } return $this->redirect(['role', 'user' => $user]); } $allRoles = Role::findAll(); return $this->render('role', ['userRoles' => $userRoles, 'allRoles' => $allRoles]); }
<?php echo $form->field($model, 'password')->passwordInput(); ?> <?php echo $form->field($model, 'repassword')->passwordInput(); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'status')->radioList(Constants::getStatusItems()); ?> <?php echo $form->field($model, 'role')->dropDownList(Role::getAdminItems(null, false)); ?> <?php $submitText = $model->isNewRecord ? "新建" : "修改"; $closeLink = Url::to(['/user/adminuser/index']); Html::SubmitButtons($submitText, $closeLink); ?> <?php ActiveForm::end(); ?> </div>
<?php use source\helpers\Html; use source\LsYii; use source\modules\rbac\models\Role; /* @var $this yii\web\View */ /* @var $model source\modules\rbac\models\Role */ $category = LsYii::getGetValue('category'); $this->title = "新建" . Role::getCategoryItems($category); echo source\libs\Message::getMessage(); ?> <div class="page-header"> <h3> <strong><?php echo Html::encode($this->title); ?> </strong> </h3> </div> <div class="role-create"> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
use source\models\User; use source\libs\Constants; use source\modules\rbac\models\Role; /* @var $this yii\web\View */ /* @var $searchModel source\models\search\UserSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = '注册会员'; echo source\libs\Message::getMessage(); ?> <div class="page-header"> <h3> <strong><?php echo Html::encode($this->title); ?> </strong> <div class="pull-right"> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . LsYii::gT('添加' . $this->title), ['/user/member/create'], ['class' => 'btn btn-primary']); ?> </div> </h3> </div> <div class="user-index"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'username', 'value' => 'username'], ['attribute' => 'email', 'value' => 'email'], ['attribute' => 'status', 'filter' => Constants::getStatusItems(), 'content' => function ($model, $key, $index, $gridView) { return Constants::getStatusItems($model->status); }], ['attribute' => 'role', 'value' => 'role', 'filter' => Role::getMemberItems()], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
use source\modules\rbac\models\Role; /* @var $this yii\web\View */ /* @var $model app\modules\rbac\models\Role */ /* @var $form yii\widgets\ActiveForm */ ?> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'id')->textInput(['maxlength' => 64, 'readonly' => $model->isNewRecord ? false : true]); ?> <?php echo $form->field($model, 'category')->dropDownList(Role::getCategoryItems()); ?> <?php echo $form->field($model, 'name')->textInput(); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 5]); ?> <?php if (!$model->is_system) { ?> <?php echo $form->field($model, 'status')->radioList(Constants::getStatusItems());
/** * Finds the Role model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Role the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Role::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\helpers\Html; use source\core\widgets\ActiveForm; use source\models\config\BasicConfig; use yii\helpers\ArrayHelper; use source\modules\rbac\models\Role; /* @var $this yii\web\View */ /* @var $model app\models\config\Basic */ /* @var $form ActiveForm */ $this->title = '注册与访问控制'; $this->addBreadcrumbs([$this->title]); ?> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'sys_allow_register', ['size' => 'small'])->checkbox([], false); ?> <?php echo $form->field($model, 'sys_default_role')->dropDownList(ArrayHelper::map(Role::buildOptions(), 'id', 'name', 'category')); ?> <?php echo $form->defaultButtons(); ActiveForm::end(); ?>
echo Html::encode($this->title); ?> </strong> <div class="pull-right"> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . LsYii::gT('添加' . $this->title), ['/user/adminuser/create'], ['class' => 'btn btn-primary']); ?> </div> </h3> </div> <div class="user-index"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'username', 'value' => 'username'], ['attribute' => 'email', 'value' => 'email'], ['attribute' => 'status', 'filter' => Constants::getStatusItems(), 'content' => function ($model, $key, $index, $gridView) { return Constants::getStatusItems($model->status); }], ['attribute' => 'role', 'filter' => Role::getAdminItems(), 'content' => function ($model, $key, $index, $gridView) { return Role::getAdminItems($model->role); }], ['class' => 'source\\core\\grid\\ActionColumn', 'buttons' => ['update' => function ($url, $model) { if ($model->role != 'administrator') { return Html::a('<span class="glyphicon glyphicon-edit"></span>', $url, []); } else { return ''; } }, 'delete' => function ($url, $model) { if ($model->role != 'administrator') { return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, []); } else { return ''; } }]]]]); ?>
public function getAllRoles() { return Role::buildOptions(); }
/** * 设置默认菜单 * @param type $category */ public static function setMenus($category = 'system') { if ($category == 'admin') { $sideMenu = 18; } else { if ($category == 'member') { $sideMenu = 17; } else { $sideMenu = 45; } } $item = Role::getCategoryItems($category); \source\LsYii::getApp()->controller->setMenus($sideMenu, $item); }