コード例 #1
0
ファイル: _view.php プロジェクト: insolita/yii2-simplerbac
?>
</span>
    <?php 
echo $model->name . '(' . $model->description . ') ';
?>
</h3>
<?php 
if ($model->type == \insolita\simplerbac\models\RbacModel::TYPE_ROLE) {
    ?>
    <div class="well well-transparent well-small">
        <h4><?php 
    echo \insolita\simplerbac\RbacModule::t('simplerbac', 'Rights available for this role');
    ?>
:</h4>
        <span class="label label-success"><?php 
    echo implode('</span><br/><span class="label label-success">', \insolita\simplerbac\models\RbacModel::getRoleperms($model->name));
    ?>
</span>
    </div>
<?php 
}
?>
<div class="row">
    <div class="col-lg-6">
        <div class="panel panel-primary">
            <div class="panel-heading"><?php 
echo RbacModule::t('simplerbac', 'Inherits the rights of:');
?>
</div>
            <div class="panel-body" style="overflow: auto; max-height: 650px;" id="parentlist">
                <?php 
コード例 #2
0
 public function actionAllUsers()
 {
     $nodes = $edges = [];
     $assignments = RbacModel::getAllAssignments();
     $uids = array_keys($assignments);
     $uClass = $this->module->userClass;
     if (count($uids) > $this->module->maxUsersForGraph) {
         \Yii::$app->session->setFlash('error', RbacModule::t('simplerbac', 'Too many users for show'));
         return $this->redirect(['index']);
     }
     $users = $uClass::find()->where([$this->module->userPk => $uids])->indexBy($this->module->userPk)->asArray()->all();
     foreach ($assignments as $uid => $data) {
         if (!isset($users[$uid])) {
             continue;
         }
         $nodes[] = ['data' => ['id' => "u{$uid}", 'username' => $users[$uid][$this->module->usernameAttribute], 'faveColor' => '#E13A69', 'faveShape' => 'ellipse', 'width' => mb_strlen($users[$uid][$this->module->usernameAttribute])]];
         $roles = \Yii::$app->authManager->getRolesByUser($uid);
         if (!empty($roles)) {
             foreach ($roles as $rol) {
                 $nodes[] = ['data' => ['id' => $rol->name, 'faveColor' => '#5F40B8', 'faveShape' => 'star', 'width' => mb_strlen($rol->name)]];
                 $edges[] = ['data' => ["id" => $rol->name . '_' . "{$uid}", 'source' => $rol->name, 'target' => "u{$uid}", 'faveColor' => '#5F40B8']];
                 $perms = \Yii::$app->authManager->getPermissionsByRole($rol->name);
                 if (!empty($perms)) {
                     foreach ($perms as $p) {
                         $nodes[] = ['data' => ['id' => $p->name, 'faveColor' => '#3AB5E1', 'faveShape' => 'rectangle', 'width' => mb_strlen($p->name)]];
                         $edges[] = ['data' => ["id" => $p->name . '_' . $rol->name, 'source' => $p->name, 'target' => $rol->name, 'faveColor' => '#3AB5E1']];
                     }
                 }
             }
         }
     }
     return $this->render('ugraph', ['elems' => Json::encode(['nodes' => $nodes, 'edges' => $edges])]);
 }