CategoryModel::getID PHP Method

getID() public method

Get data for a single category selected by ID. Disregards permissions.
Since: 2.0.0
public getID ( integer $categoryID, string $datasetType = DATASET_TYPE_OBJECT, array $options = [] ) : object | array
$categoryID integer The unique ID of category we're getting data for.
$datasetType string Not used.
$options array Not used.
return object | array SQL results.
    public function getID($categoryID, $datasetType = DATASET_TYPE_OBJECT, $options = [])
    {
        $category = $this->SQL->getWhere('Category', array('CategoryID' => $categoryID))->firstRow($datasetType);
        if (val('AllowedDiscussionTypes', $category) && is_string(val('AllowedDiscussionTypes', $category))) {
            setValue('AllowedDiscussionTypes', $category, dbdecode(val('AllowedDiscussionTypes', $category)));
        }
        return $category;
    }

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');
 }
All Usage Examples Of CategoryModel::getID