当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getRol方法代码示例

本文整理汇总了PHP中common\models\User::getRol方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getRol方法的具体用法?PHP User::getRol怎么用?PHP User::getRol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\User的用法示例。


在下文中一共展示了User::getRol方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: search

 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find()->joinWith('authAssignment.authItem');
     $pageSize = isset($_GET['per-page']) ? $_GET['per-page'] : \Yii::$app->params['user.defaultPageSize'];
     // Aca se cocina lo que deberia ver el usuario segun su rol
     $rol = User::getRol(Yii::$app->user->getId());
     // el administrador no puede ver al usuario consejo, el consejo puede ver a todos,
     // el intendente no puede ver al consejo ni administrador
     switch ($rol->name) {
         case (string) "administrador":
             $query->andFilterWhere(['not in', 'item_name', ['consejo']]);
             break;
         case (string) "consejo":
             break;
         case (string) "intendente":
             $query->andFilterWhere(['not in', 'item_name', ['administrador', 'consejo']]);
             break;
         default:
             $query->andFilterWhere(['not in', 'item_name', ['intendente', 'administrador', 'consejo']]);
     }
     $query->andFilterWhere(['status' => User::STATUS_ACTIVE]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize], 'sort' => ['defaultOrder' => ['id' => SORT_DESC], 'enableMultiSort' => true]]);
     // Agregado a mano, para que incluya el ordenamiento por descCliente
     $dataProvider->sort->attributes['descRolUsuario'] = ['asc' => ['auth_item.description' => SORT_ASC], 'desc' => ['auth_item.description' => SORT_DESC]];
     $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, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'acceso_externo' => $this->acceso_externo]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_item.description', $this->descRolUsuario]);
     return $dataProvider;
 }
开发者ID:ibergonzi,项目名称:country,代码行数:41,代码来源:UserSearch.php

示例2: listaRoles

 public static function listaRoles()
 {
     // devuelve array de roles filtrado por el rol del usuario activo
     $rol = User::getRol(Yii::$app->user->getId());
     // se traen todos los roles
     $auth = Yii::$app->authManager;
     $roles = $auth->getRoles();
     // aca se filtran
     switch ($rol->name) {
         case (string) "intendente":
             unset($roles['administrador'], $roles['consejo']);
             break;
         case (string) "administrador":
             unset($roles['consejo']);
             break;
         case (string) "consejo":
             break;
         default:
             unset($roles['intendente'], $roles['administrador'], $roles['consejo']);
     }
     return $roles;
 }
开发者ID:ibergonzi,项目名称:country,代码行数:22,代码来源:AuthAssignment.php

示例3:

	<div class='row'>

		<div class="col-md-9">
			
			<div class="user-form">
				<?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'username']]);
?>
        
				<?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
				
				<div class="form-group">
				<?php 
$rol = User::getRol($model->id);
echo Html::label('Rol', 'rol', ['class' => 'control-label']);
//Yii::trace(ArrayHelper::map(AuthAssignment::listaRoles(), 'name', 'description'));
echo Html::dropDownList('rol', $rol->name, ArrayHelper::map(AuthAssignment::listaRoles(), 'name', 'description'), ['id' => 'rol', 'class' => 'form-control']);
?>
				<?php 
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>
				
				<?php 
echo $form->field($model, 'acceso_externo')->dropDownList(User::getSiNo());
?>
				<?php 
if ($model->isNewRecord) {
    echo $form->field($model, 'foto')->fileInput();
}
开发者ID:ibergonzi,项目名称:country,代码行数:31,代码来源:_form.php

示例4: isset

    /* Opcion de salir por defecto de yii2
       $menuItems[] = [
           'label' => 'Salir (' . Yii::$app->user->identity->username . ')',
           'url' => ['/site/logout'],
           'linkOptions' => ['data-method' => 'post']
       ];
       */
    $u = User::findOne(Yii::$app->user->getId());
    $sinImg = Yii::$app->urlManager->createUrl('images/sinfoto.png');
    if (!empty($u->foto)) {
        $imgFile = Yii::$app->urlManager->createUrl('images/usuarios/' . $u->foto);
        $contenido = Html::img($imgFile, ['class' => 'img-thumbnail', 'onerror' => "this.src='{$sinImg}'"]);
    } else {
        $contenido = Html::img($sinImg, ['class' => 'img-thumbnail']);
    }
    $headerPopover = '<p><i>Usuario: ' . Yii::$app->user->identity->username . '</i></p>' . '<p><i>' . User::getRol(Yii::$app->user->getId())->description . '</i></p>' . '<p><i>IP: ' . Yii::$app->request->userIp . '</i></p>';
    $userPopover = '<li class="dropdown"><div class="navbar-form">' . PopoverX::widget(['header' => $headerPopover, 'placement' => PopoverX::ALIGN_BOTTOM, 'type' => Popoverx::TYPE_WARNING, 'content' => $contenido, 'footer' => Html::a('Cerrar sesión &raquo;', ['/site/logout'], ['data-method' => 'post', 'class' => 'btn btn-sm btn-warning']), 'toggleButton' => ['label' => Html::tag('span', '', ['class' => 'glyphicon glyphicon-lock']), 'class' => 'btn btn-sm btn-default']]) . '</div></li>';
    $menuItems[] = $userPopover;
}
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $menuItems, 'encodeLabels' => false]);
NavBar::end();
?>

    <div class="container" >
        <?php 
echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]);
?>
		

        <?php 
// el alert se deberia aplicar en todas las paginas, excepto las que definen el parametro noAlerts,
开发者ID:ibergonzi,项目名称:country,代码行数:31,代码来源:main.php


注:本文中的common\models\User::getRol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。