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.
 /**
  * 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');
 }
 /**
  * Editing a category.
  *
  * @since 2.0.0
  * @param int|string $CategoryID Unique ID of the category to be updated.
  * @throws Exception when category cannot be found.
  */
 public function editCategory($CategoryID = '')
 {
     // Check permission
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     // Set up models
     $RoleModel = new RoleModel();
     $PermissionModel = Gdn::permissionModel();
     $this->Form->setModel($this->CategoryModel);
     if (!$CategoryID && $this->Form->authenticatedPostBack()) {
         if ($ID = $this->Form->getFormValue('CategoryID')) {
             $CategoryID = $ID;
         }
     }
     // Get category data
     $this->Category = CategoryModel::categories($CategoryID);
     if (!$this->Category) {
         throw notFoundException('Category');
     }
     // Category data is expected to be in the form of an object.
     $this->Category = (object) $this->Category;
     $this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
     $displayAsOptions = categoryModel::getDisplayAsOptions();
     // Restrict "Display As" types based on parent.
     $parentCategory = $this->CategoryModel->getID($this->Category->ParentCategoryID);
     $parentDisplay = val('DisplayAs', $parentCategory);
     if ($parentDisplay === 'Flat') {
         unset($displayAsOptions['Heading']);
     }
     // Set up head
     $this->addJsFile('jquery.alphanumeric.js');
     $this->addJsFile('manage-categories.js');
     $this->addJsFile('jquery.gardencheckboxgrid.js');
     $this->title(t('Edit Category'));
     $this->setHighlightRoute('vanilla/settings/categories');
     // Make sure the form knows which item we are editing.
     $this->Form->addHidden('CategoryID', $CategoryID);
     $this->setData('CategoryID', $CategoryID);
     // Load all roles with editable permissions
     $this->RoleArray = $RoleModel->getArray();
     $this->fireAs('SettingsController');
     $this->fireEvent('AddEditCategory');
     if ($this->Form->authenticatedPostBack()) {
         $this->setupDiscussionTypes($this->Category);
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->validateUpload('PhotoUpload', false);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
             $this->Form->setFormValue('Photo', $Parts['SaveName']);
         }
         $this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
         // Enforces tinyint values on boolean fields to comply with strict mode
         $this->Form->setFormValue('HideAllDiscussions', forceBool($this->Form->getFormValue('HideAllDiscussions'), '0', '1', '0'));
         $this->Form->setFormValue('Archived', forceBool($this->Form->getFormValue('Archived'), '0', '1', '0'));
         $this->Form->setFormValue('AllowFileUploads', forceBool($this->Form->getFormValue('AllowFileUploads'), '0', '1', '0'));
         if ($parentDisplay === 'Flat' && $this->Form->getFormValue('DisplayAs') === 'Heading') {
             $this->Form->addError('Cannot display as a heading when your parent category is displayed flat.', 'DisplayAs');
         }
         if ($this->Form->save()) {
             $Category = CategoryModel::categories($CategoryID);
             $this->setData('Category', $Category);
             if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
                 $destination = $this->categoryPageByParent($parentCategory);
                 redirect($destination);
             } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA && method_exists($this, 'getCategory')) {
                 $this->Data = [];
                 $this->getCategory($CategoryID);
                 return;
             }
         }
     } else {
         $this->Form->setData($this->Category);
         $this->setupDiscussionTypes($this->Category);
         $this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
     }
     // Get all of the currently selected role/permission combinations for this junction.
     $Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
     $Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->setData('PermissionData', $Permissions, true);
     }
     // Render default view
     $this->setData('Operation', 'Edit');
     $this->setData('DisplayAsOptions', $displayAsOptions);
     $this->render();
 }