/**
  * Show list of roles.
  *
  * @since 2.0.0
  * @access public
  */
 public function index($RoleID = null)
 {
     $this->_permission();
     $this->addSideMenu('dashboard/role');
     $this->addJsFile('jquery.tablednd.js');
     $this->addJsFile('jquery-ui.js');
     $this->title(t('Roles & Permissions'));
     if (!$RoleID) {
         $RoleData = $this->RoleModel->getWithRankPermissions()->resultArray();
         // Check to see which roles can be modified.
         foreach ($RoleData as &$Row) {
             $CanModify = true;
             if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) {
                 foreach ($this->RoleModel->RankPermissions as $Permission) {
                     if ($Row[$Permission] && !Gdn::session()->checkPermission($Permission)) {
                         $CanModify = false;
                         break;
                     }
                 }
             }
             $Row['CanModify'] = $CanModify;
         }
     } else {
         $Role = $this->RoleModel->getID($RoleID);
         $RoleData = array($Role);
     }
     $this->setData('Roles', $RoleData);
     $this->render();
 }
 /**
  * Show list of roles.
  *
  * @since 2.0.0
  * @access public
  */
 public function index($roleID = null)
 {
     $this->_permission();
     $this->setHighlightRoute('dashboard/role');
     $this->addJsFile('jquery.tablednd.js');
     $this->title(t('Roles & Permissions'));
     if (!$roleID) {
         $roles = $this->RoleModel->getWithRankPermissions()->resultArray();
         // Check to see which roles can be modified.
         foreach ($roles as &$row) {
             $canModify = true;
             if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) {
                 foreach ($this->RoleModel->RankPermissions as $permission) {
                     if ($row[$permission] && !Gdn::session()->checkPermission($permission)) {
                         $canModify = false;
                         break;
                     }
                 }
             }
             $row['CanModify'] = $canModify;
         }
         $this->setData('Roles', $roles);
     } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA) {
         // This is an API request. Get the role in a nicer format.
         $role = $this->RoleModel->getID($roleID, DATASET_TYPE_ARRAY);
         // Get the global permissions.
         $permissions = Gdn::permissionModel()->getGlobalPermissions($roleID);
         unset($permissions['PermissionID']);
         // Get the per-category permissions.
         $permissions['Category'] = $this->RoleModel->getCategoryPermissions($roleID);
         $role['Permissions'] = $permissions;
         $this->setData('Role', $role);
         saveToConfig('Api.Clean', false, false);
     } else {
         $Role = $this->RoleModel->getID($roleID);
         $this->setData('Roles', [$Role]);
     }
     // Grab the total users for each role.
     if (is_array($this->data('Roles'))) {
         $pastThreshold = Gdn::userModel()->pastUserMegaThreshold();
         $thresholdTypeExceptions = RoleModel::getDefaultTypes();
         unset($thresholdTypeExceptions[RoleModel::TYPE_MEMBER]);
         $roles = $this->data('Roles');
         foreach ($roles as &$role) {
             if ($pastThreshold && !in_array($role['Type'], $thresholdTypeExceptions)) {
                 $countUsers = t('View');
             } else {
                 $countUsers = $this->RoleModel->getUserCount($role['RoleID']);
             }
             $role['CountUsers'] = $countUsers;
         }
         $this->setData('Roles', $roles);
     }
     $this->render();
 }
 /**
  * Show list of roles.
  *
  * @since 2.0.0
  * @access public
  */
 public function index($roleID = null)
 {
     $this->_permission();
     $this->addSideMenu('dashboard/role');
     $this->addJsFile('jquery.tablednd.js');
     $this->addJsFile('jquery-ui.js');
     $this->title(t('Roles & Permissions'));
     if (!$roleID) {
         $roles = $this->RoleModel->getWithRankPermissions()->resultArray();
         // Check to see which roles can be modified.
         foreach ($roles as &$row) {
             $canModify = true;
             if (!Gdn::session()->checkPermission('Garden.Settings.Manage')) {
                 foreach ($this->RoleModel->RankPermissions as $permission) {
                     if ($row[$permission] && !Gdn::session()->checkPermission($permission)) {
                         $canModify = false;
                         break;
                     }
                 }
             }
             $row['CanModify'] = $canModify;
         }
         $this->setData('Roles', $roles);
     } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA) {
         // This is an API request. Get the role in a nicer format.
         $role = $this->RoleModel->getID($roleID, DATASET_TYPE_ARRAY);
         // Get the global permissions.
         $permissions = Gdn::permissionModel()->getGlobalPermissions($roleID);
         unset($permissions['PermissionID']);
         // Get the per-category permissions.
         $permissions['Category'] = $this->RoleModel->getCategoryPermissions($roleID);
         $role['Permissions'] = $permissions;
         $this->setData('Role', $role);
         saveToConfig('Api.Clean', false, false);
     } else {
         $Role = $this->RoleModel->getID($roleID);
         $this->setData('Roles', [$Role]);
     }
     $this->render();
 }