CategoryModel::getRolePermissions PHP Method

getRolePermissions() public method

Get the role specific permissions for a category.
public getRolePermissions ( integer $categoryID ) : array
$categoryID integer The ID of the category to get the permissions for.
return array Returns an array of permissions.
    public function getRolePermissions($categoryID)
    {
        $permissions = Gdn::permissionModel()->getJunctionPermissions(['JunctionID' => $categoryID], 'Category');
        $result = [];
        foreach ($permissions as $perm) {
            $row = ['RoleID' => $perm['RoleID']];
            unset($perm['Name'], $perm['RoleID'], $perm['JunctionID'], $perm['JunctionTable'], $perm['JunctionColumn']);
            $row += $perm;
            $result[] = $row;
        }
        return $result;
    }

Usage Example

 /**
  * Get a single category for administration.
  *
  * This endpoint is intended for API access.
  *
  * @param int $categoryID The category to find.
  */
 public function getCategory($categoryID)
 {
     // Check permission
     $this->permission('Garden.Community.Manage');
     if (!$categoryID) {
         throw new Gdn_UserException(sprintf(t('ValidationRequired'), 'CategoryID'));
     }
     $categoryModel = new CategoryModel();
     $category = $categoryModel->getID($categoryID, DATASET_TYPE_ARRAY);
     //        $category = Gdn::sql()->getWhere('Category', ['CategoryID' => $categoryID])->firstRow(DATASET_TYPE_ARRAY);
     if (!$category) {
         throw notFoundException('Category');
     }
     // Add the permissions for the category.
     if ($category['PermissionCategoryID'] == $category['CategoryID']) {
         $category['Permissions'] = $categoryModel->getRolePermissions($categoryID);
     } else {
         $category['Permissions'] = null;
     }
     $this->setData('Category', $category);
     saveToConfig('Api.Clean', false, false);
     $this->render('blank', 'utility', 'dashboard');
 }