getPublicUserRoles() public method

Optionally return all the role data or just one field name.
public getPublicUserRoles ( $userID, string $field = "Name" ) : array | null | void
$userID
$field string optionally the field name from the role table to return.
return array | null | void
Example #1
0
 /**
  * Adds 'Discussion' item to menu.
  *
  * 'base_render_before' will trigger before every pageload across apps.
  * If you abuse this hook, Tim will throw a Coke can at your head.
  *
  * @since 2.0.0
  * @package Vanilla
  *
  * @param Gdn_Controller $sender The sending controller object.
  */
 public function base_render_before($sender)
 {
     if ($sender->Menu) {
         $sender->Menu->addLink('Discussions', t('Discussions'), '/discussions', false, ['Standard' => true]);
     }
     if (!inSection('Dashboard')) {
         // Spoilers assets
         $sender->addJsFile('spoilers.js', 'vanilla');
         $sender->addCssFile('spoilers.css', 'vanilla');
         $sender->addDefinition('Spoiler', t('Spoiler'));
         $sender->addDefinition('show', t('show'));
         $sender->addDefinition('hide', t('hide'));
     }
     // Add user's viewable roles to gdn.meta if user is logged in.
     if (!$sender->addDefinition('Roles')) {
         if (Gdn::session()->isValid()) {
             $roleModel = new RoleModel();
             Gdn::controller()->addDefinition("Roles", $roleModel->getPublicUserRoles(Gdn::session()->UserID, "Name"));
         }
     }
 }
Example #2
0
 /**
  * Add user's viewable roles to gdn.meta if user is logged in.
  * @param $sender
  * @param $args
  */
 public function gdn_dispatcher_afterControllerCreate_handler($sender, $args)
 {
     // Function addDefinition returns the value of the definition if you pass only one argument.
     if (!gdn::controller()->addDefinition('Roles')) {
         if (Gdn::session()->isValid()) {
             $roleModel = new RoleModel();
             gdn::controller()->addDefinition("Roles", $roleModel->getPublicUserRoles(gdn::session()->UserID, "Name"));
         }
     }
 }