The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetRoles
#1
Hi guys, @mudmin made this function for me,

Code:
<?php getRoles(1);?>

<pre>
Code:
function getRoles($id, $opts = []){
  $db = DB::getInstance();
  $userQ = $db->query("SELECT * FROM user_permission_matches WHERE user_id = ?",array($id));
  $c = $userQ->count();

  if($c > 0){
    $results = $userQ->results();

  foreach ($results as $u){
    echoPerm($u->permission_id);
    $c = $c-1;
    if($c > 0){
      echo ", ";
    }
  }
}
}

function echoPerm($id){
  $db = DB::getInstance();
  $p = $db->query("SELECT * FROM permissions WHERE id = ?",array($id))->first();
  echo $p->name;
}
</pre>


it's about calling the role the user has on the site. For example, I am the administrator and the user and administrator come out under the photo. but if I enter as a user the same thing comes out, what it means is that that function calls all the permissions not precisely to the specific permission. There will be a way to call the right permit.

  Reply
#2
I can test it again. Are you saying that it is showing every role for every user?
  Reply
#3
Exactly, that the user shows that the role in the site is the user and the administrator administrator and moderator moderator etc.
  Reply
#4
It works fine for me. I'm guessing you're not passing in the user id. If you pass in
Code:
getRoles(1);
It's always going to show you the roles for user 1.

What happens if you do
Code:
$u = $db->query("SELECT id FROM users")->results();
Code:
foreach($u as $v){
Code:
echouser($v->id);
Code:
echo "-";
Code:
getRoles($v->id);
Code:
echo "<br>";
Code:
}
  Reply
#5
So do you only want it to show 1 role per user?
  Reply
#6
Yes, the corresponding one.
  Reply
#7
Example, if you register on my site you would have user permissions. under the profile picture your name would appear and below this user as a role.
  Reply
#8
[Image: zy8z7a.png]
  Reply
#9
Ok. So you have to do some logic. How many user roles do you have and what are they?
  Reply
#10
Only the ordinary, user and administrator.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)