getByUserID() 공개 메소드

Get the roles for a user.
또한 보기: UserModel::getRoles()
public getByUserID ( integer $userID ) : Gdn_DataSet
$userID integer The user to get the roles for.
리턴 Gdn_DataSet Returns the roles as a dataset (with array values).
예제 #1
0
 /**
  * Test an individual condition.
  *
  * @param string $Type One of the types in this condition.
  * @param string $Field The field to test against.
  * @param string $Expr The expression to test with.
  * @return bool
  */
 public static function testOne($Type, $Field, $Expr = null)
 {
     switch (strtolower($Type)) {
         case PERMISSION:
             // Check to see if the user has the given permission.
             $Result = Gdn::session()->checkPermission($Field);
             if ($Expr === false) {
                 return !$Result;
             }
             return $Result;
         case REQUEST:
             // See if the field is a specific value.
             switch (strtolower($Field)) {
                 case 'path':
                     $Value = Gdn::request()->path();
                     break;
                 default:
                     // See if the field is targetting a specific part of the request.
                     $Fields = explode('.', $Field, 2);
                     if (count($Fields) >= 2) {
                         $Value = Gdn::request()->getValueFrom($Fields[0], $Fields[1], null);
                     } else {
                         $Value = Gdn::request()->getValue($Field, null);
                     }
                     break;
             }
             $Result = Gdn_Condition::testValue($Value, $Expr);
             return $Result;
         case ROLE:
             // See if the user is in the given role.
             $RoleModel = new RoleModel();
             $Roles = $RoleModel->getByUserID(Gdn::session()->UserID)->resultArray();
             foreach ($Roles as $Role) {
                 if (is_numeric($Expr)) {
                     $Result = $Expr == val('RoleID', $Role);
                 } else {
                     $Result = Gdn_Condition::testValue(val('Name', $Role), $Expr);
                 }
                 if ($Result) {
                     return true;
                 }
             }
             return false;
     }
     return false;
 }
예제 #2
0
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body id="<?php 
echo htmlspecialchars($BodyIdentifier);
?>
" class="<?php 
echo $this->CssClass;
?>
">
<?php 
$this->renderAsset('Symbols');
// TODO: Pull this asset out elsewhere
Gdn_Theme::assetBegin('DashboardUserDropDown');
$user = Gdn::session()->User;
$rm = new RoleModel();
$roles = $rm->getByUserID(val('UserID', $user))->resultArray();
$roleTitlesArray = [];
foreach ($roles as $role) {
    $roleTitlesArray[] = val('Name', $role);
}
$roleTitles = implode(', ', $roleTitlesArray);
/** var UserController $user */
?>
<div class="card card-user">
    <?php 
$userBlock = new MediaItemModule(val('Name', $user), userUrl($user), $roleTitles, '', ['class' => 'card-block']);
$userBlock->setView('media-sm')->setImage(userPhotoUrl($user))->addButton(t('My Profile') . ' ' . dashboardSymbol('external-link', 'icon-11 icon-text'), userUrl($user), ['class' => 'btn btn-sm-rounded btn-secondary padded-top']);
echo $userBlock;
?>
    <div class="list-group list-group-flush">
        <?php