Updates the CountDiscussions value on the category based on the CategoryID
being saved.

@since 2.0.0
@access public

@param int $CategoryID Unique ID of category we are updating.
974703
public function UpdateDiscussionCount($CategoryID, $Discussion = FALSE) {
      $DiscussionID = GetValue('DiscussionID', $Discussion, FALSE);
		if (strcasecmp($CategoryID, 'All') == 0) {
			$Exclude = (bool)Gdn::Config('Vanilla.Archive.Exclude');
			$ArchiveDate = Gdn::Config('Vanilla.Archive.Date');
			$Params = array();
			$Where = '';
			
			if($Exclude && $ArchiveDate) {
				$Where = 'where d.DateLastComment > :ArchiveDate';
				$Params[':ArchiveDate'] = $ArchiveDate;
			}
			
			// Update all categories.
			$Sql = "update :_Category c
            left join (
              select
                d.CategoryID,
                coalesce(count(d.DiscussionID), 0) as CountDiscussions,
                coalesce(sum(d.CountComments), 0) as CountComments
              from :_Discussion d
              $Where
              group by d.CategoryID
            ) d
              on c.CategoryID = d.CategoryID
            set 
               c.CountDiscussions = coalesce(d.CountDiscussions, 0),
               c.CountComments = coalesce(d.CountComments, 0)";
			$Sql = str_replace(':_', $this->Database->DatabasePrefix, $Sql);
			$this->Database->Query($Sql, $Params, 'DiscussionModel_UpdateDiscussionCount');
			
		} elseif (is_numeric($CategoryID)) {
         $this->SQL
            ->Select('d.DiscussionID', 'count', 'CountDiscussions')
            ->Select('d.CountComments', 'sum', 'CountComments')
            ->From('Discussion d')
            ->Where('d.CategoryID', $CategoryID);
         
			$this->AddArchiveWhere();
			
			$Data = $this->SQL->Get()->FirstRow();
         $CountDiscussions = (int)GetValue('CountDiscussions', $Data, 0);
         $CountComments = (int)GetValue('CountComments', $Data, 0);
         
         $CacheAmendment = array(
            'CountDiscussions'      => $CountDiscussions,
            'CountComments'         => $CountComments
         );
         
         if ($DiscussionID) {
            $CacheAmendment = array_merge($CacheAmendment, array(
               'LastDiscussionID'   => $DiscussionID,
               'LastCommentID'      => NULL,
               'LastDateInserted'   => GetValue('DateInserted', $Discussion)
            ));
         }
         
         $CategoryModel = new CategoryModel();
         $CategoryModel->SetField($CategoryID, $CacheAmendment);
         $CategoryModel->SetRecentPost($CategoryID);
      }
   }
903594
public function setCategory(array $category)
    {
        $categoryClassInstance = new Category();
        foreach ($category as $categoryInstance) {
            Validate::isInstanceOf(
                $categoryInstance,
                $categoryClassInstance,
                'category'
            );
        }
        $this->category = $category;
    }
407923
protected function reindexUpdatedCategories($categoryId)
    {
        /** @var $category \Magento\Catalog\Model\Category */
        $category = $this->defaultCategory->load($categoryId);
        //$categoryName = $category->getName();
        foreach ($category->getStoreIds() as $storeId) {
            if ($storeId == 0) {
                continue;
            }

            $category = $this->categoryRepository->get($categoryId, $storeId);

            $urlRewrites = $this->categoryUrlRewriteGenerator->generate($category, true);
            $this->urlPersist->replace($urlRewrites);
        }
        return $this;
    }
454250
public function SaveUserTree($CategoryID, $Set) {
      $Categories = $this->GetSubtree($CategoryID);
      foreach ($Categories as $Category) {
         $this->SQL->Replace(
            'UserCategory',
            $Set,
            array('UserID' => Gdn::Session()->UserID, 'CategoryID' => $Category['CategoryID']));
      }
      $Key = 'UserCategory_'.Gdn::Session()->UserID;
      Gdn::Cache()->Remove($Key);
   }
1143393
public function indexAction($categoryId)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var Category $entity */
        $entity = $em->getRepository('EcommerceBundle:Category')->find($categoryId);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Category entity.');
        }

        return array(
            'category' => $entity,
        );
    }
683163
public static function get_category_courses_visibility($categoryid) {
        global $DB;
        $sql = "SELECT c.id, c.visible
                  FROM {course} c
                 WHERE c.category = :category";
        $params = array('category' => (int)$categoryid);
        return $DB->get_records_sql($sql, $params);
    }
1314475
protected function updateCategoryGroup($category_group_id)
    {
        if (!$this->isError() && !$this->category_group->update($category_group_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
1089535
public function Delete($Category, $ReplacementCategoryID) {
      // Don't do anything if the required category object & properties are not defined.
      if (
         !is_object($Category)
         || !property_exists($Category, 'CategoryID')
         || !property_exists($Category, 'ParentCategoryID')
         || !property_exists($Category, 'AllowDiscussions')
         || !property_exists($Category, 'Name')
         || $Category->CategoryID <= 0
      ) {
         throw new Exception(T('Invalid category for deletion.'));
      } else {
         // Remove permissions related to category
         $PermissionModel = Gdn::PermissionModel();
         $PermissionModel->Delete(NULL, 'Category', 'CategoryID', $Category->CategoryID);
         
         // If there is a replacement category...
         if ($ReplacementCategoryID > 0) {
            // Update children categories
            $this->SQL
               ->Update('Category')
               ->Set('ParentCategoryID', $ReplacementCategoryID)
               ->Where('ParentCategoryID', $Category->CategoryID)
               ->Put();

            // Update permission categories.
            $this->SQL
               ->Update('Category')
               ->Set('PermissionCategoryID', $ReplacementCategoryID)
               ->Where('PermissionCategoryID', $Category->CategoryID)
               ->Where('CategoryID <>', $Category->CategoryID)
               ->Put();
               
            // Update discussions
            $this->SQL
               ->Update('Discussion')
               ->Set('CategoryID', $ReplacementCategoryID)
               ->Where('CategoryID', $Category->CategoryID)
               ->Put();
               
            // Update the discussion count
            $Count = $this->SQL
               ->Select('DiscussionID', 'count', 'DiscussionCount')
               ->From('Discussion')
               ->Where('CategoryID', $ReplacementCategoryID)
               ->Get()
               ->FirstRow()
               ->DiscussionCount;
               
            if (!is_numeric($Count))
               $Count = 0;
               
            $this->SQL
               ->Update('Category')->Set('CountDiscussions', $Count)
               ->Where('CategoryID', $ReplacementCategoryID)
               ->Put();
            
            // Update tags
            $this->SQL
               ->Update('Tag')
               ->Set('CategoryID', $ReplacementCategoryID)
               ->Where('CategoryID', $Category->CategoryID)
               ->Put();
            
            $this->SQL
               ->Update('TagDiscussion')
               ->Set('CategoryID', $ReplacementCategoryID)
               ->Where('CategoryID', $Category->CategoryID)
               ->Put();
         } else {
            // Delete comments in this category
            $this->SQL
               ->From('Comment c')
               ->Join('Discussion d', 'c.DiscussionID = d.DiscussionID')
               ->Where('d.CategoryID', $Category->CategoryID)
               ->Delete();
               
            // Delete discussions in this category
            $this->SQL->Delete('Discussion', array('CategoryID' => $Category->CategoryID));

            // Make inherited permission local permission
            $this->SQL
               ->Update('Category')
               ->Set('PermissionCategoryID', 0)
               ->Where('PermissionCategoryID', $Category->CategoryID)
               ->Where('CategoryID <>', $Category->CategoryID)
               ->Put();
            
            // Delete tags
            $this->SQL->Delete('Tag', array('CategoryID' => $Category->CategoryID));
            $this->SQL->Delete('TagDiscussion', array('CategoryID' => $Category->CategoryID));
         }
         
         // Delete the category
         $this->SQL->Delete('Category', array('CategoryID' => $Category->CategoryID));
      }
      // Make sure to reorganize the categories after deletes
      $this->RebuildTree();
   }
951963
public function insert_course_category($courseid) {
        $this->courseid    = $courseid;
        $this->fullname    = '?';
        $this->path        = null;
        $this->parent      = null;
        $this->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;

        $this->apply_default_settings();
        $this->apply_forced_settings();

        $this->timecreated = $this->timemodified = time();

        if (!parent::insert('system')) {
            debugging("Could not insert this category: " . print_r($this, true));
            return false;
        }

        // build path and depth
        $this->update('system');

        return $this->id;
    }
1372042
public function handleEdit(int $id)
    {
        if ($this->presenter->isAjax())
        {
            $this->categoryId = $id;
            $this->onOpen();
        }
    }
344203
public function addCategoryValues($values)
    {
        $this->_categoryValues = array_unique(array_merge($this->getCategoryValues(true), $this->filterCategoryValues($values)));
    }
1084590
public static function findByCategoryId( $categoryId ) {

		$optionTable = CoreTables::getTableName( CoreTables::TABLE_OPTION );

		return self::find()->where( "$optionTable.categoryId=:id", [ ':id' => $categoryId ] )->all();
	}
82713
public static function isExistByNameCategoryId( $name, $categoryId ) {

		$option = self::findByNameCategoryId( $name, $categoryId );

		return isset( $option );
	}
355900
public function postAction($categoryId, Request $request)
    {
        /** @var KeywordInterface $keyword */
        $keyword = $this->getKeywordRepository()->createNew();
        $category = $this->getCategoryRepository()->findCategoryById($categoryId);
        $keyword->setKeyword($request->get('keyword'));
        $keyword->setLocale($request->get('locale'));

        $keyword = $this->getKeywordManager()->save($keyword, $category);

        $this->getEntityManager()->persist($keyword);
        $this->getEntityManager()->flush();

        return $this->handleView($this->view($keyword));
    }
1099792
public function update($categoryKey)
    {
        $input = $this->validator->validate('update');
        $this->authorize('update', [Option::class, $categoryKey]);
        try {
            $this->optionRepo->updateOrCreateOption($categoryKey, $input['key'], $input['value']);
            return $this->respondWithSuccess($this->optionRepo->getOptions($categoryKey), new OptionTransformer);
        } catch (RepositoryValidationException $e) {
            return $this->respondWithError($e->getMessage());
        }
    }
1275771
public function deleteMediaCategoryAssignments(int $mediaId)
    {
        $this->sql = 'delete from media_category_map where media_id = ?';
        $this->bindValues[] = $mediaId;
        $this->execute();
    }
563946
public function updateUserViewedCategory($categoryId = '')
    {
        $sessionUserViewedCategoryId = self::SESSION_ID_USER_VIEW_TOTAL_POST_BY_CATEGORY_FROM_SESSION . $categoryId;
        $this->logger->debug(__FUNCTION__, '$sessionUserViewedCategoryId => ' . json_encode($sessionUserViewedCategoryId));
        $checkSessionUserViewedCategoryValue = $this->hasSessionData($sessionUserViewedCategoryId);
        $this->logger->debug(__FUNCTION__, '$checkSessionUserViewedCategoryValue => ' . json_encode($checkSessionUserViewedCategoryValue));
        if ($checkSessionUserViewedCategoryValue === TRUE) {
            $currentSessionUserViewedCategoryValue = $this->getSessionData($sessionUserViewedCategoryId);
            $this->logger->debug(__FUNCTION__, '$currentSessionUserViewedCategoryValue => ' . json_encode($currentSessionUserViewedCategoryValue));
            if (is_numeric($currentSessionUserViewedCategoryValue)) {
                $viewValue = $currentSessionUserViewedCategoryValue + 1;
            } else {
                $viewValue = 1;
            }
            $this->logger->debug(__FUNCTION__, 'Update Total View Value: ' . $viewValue);
            $this->saveSessionData($sessionUserViewedCategoryId, $viewValue);
        } else {
            $this->saveSessionData($sessionUserViewedCategoryId, 1);
        }
    }