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
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/printthread.php(287) : eval()'d code 2 errorHandler->error
/printthread.php 287 eval
/printthread.php 117 printthread_multipage



UserSpice
GetRoles - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: GetRoles (/showthread.php?tid=934)

Pages: 1 2


GetRoles - shoropio - 02-06-2018

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.




GetRoles - mudmin - 02-06-2018

I can test it again. Are you saying that it is showing every role for every user?



GetRoles - shoropio - 02-06-2018

Exactly, that the user shows that the role in the site is the user and the administrator administrator and moderator moderator etc.



GetRoles - mudmin - 02-06-2018

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:
}



GetRoles - mudmin - 02-06-2018

So do you only want it to show 1 role per user?


GetRoles - shoropio - 02-06-2018

Yes, the corresponding one.


GetRoles - shoropio - 02-06-2018

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.


GetRoles - shoropio - 02-06-2018

[Image: zy8z7a.png]


GetRoles - mudmin - 02-06-2018

Ok. So you have to do some logic. How many user roles do you have and what are they?



GetRoles - shoropio - 02-06-2018

Only the ordinary, user and administrator.