Check if a category has posts.

@param string $postType     slug of post type
@param string $categoriesID selected category ID

@return bool
971149
public static function hasPosts($postType, $categoriesID)
    {
        if(DB::table(categoriesRelationTable($postType))->where('categoryID', $categoriesID)->count()
        ) {
            return true;
        }else{
            return false;
        }
    }
520680
public function GetID($CategoryID, $DatasetType = DATASET_TYPE_OBJECT) {
      return $this->SQL->GetWhere('Category', array('CategoryID' => $CategoryID))->FirstRow($DatasetType);
   }
1134804
public function deleteChildren(int $parentID, int $postTypeID)
    {
        $this->categoryList = self::where("postTypeID", $postTypeID)->get();
        $this->getAllChildren($parentID);
        foreach($this->categoriesToBeDeleted as $cat){
            // Post type should not be able to be deleted if it has posts
            if(self::isInMenuLinks($cat->categoryID)) {
                return $this->response("You can't delete this Category because it is part of a menu.", 403);
            }

            $postType = PostType::findByID($postTypeID);
            // delete relations
            DB::table($postType->slug.'_categories')->where("categoryID", $cat->categoryID)->delete();
            // delete children
            $cat->delete();
        }
    }
810617
protected function load_category($categoryid) {
        global $DB;
        $category = $DB->get_record('course_categories', array('id' => $categoryid));
        if (!$category) {
            throw new moodle_exception('unknowncategory');
        }
        $this->_categories[$category->id] = $category;
        $parentcategoryids = explode('/', trim($category->path, '/'));
        array_pop($parentcategoryids);
        foreach (array_reverse($parentcategoryids) as $catid) {
            $this->_categories[$catid] = null;
        }
    }
1084590
public static function findByCategoryId( $categoryId ) {

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

		return self::find()->where( "$optionTable.categoryId=:id", [ ':id' => $categoryId ] )->all();
	}
1370563
public static function isInMenuLinks($postTypeID)
    {
        $menulinks = MenuLink::where('belongsToID', $postTypeID)->where('belongsTo', 'post_type')->count();
        if($menulinks) {
            return true;
        }
        return false;
    }
82713
public static function isExistByNameCategoryId( $name, $categoryId ) {

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

		return isset( $option );
	}
756641
private function isCategoryDeletable($intId)
  {
    $params = new \DmsLoaderParams();
    $params->rootCategoryId = $intId;
    $params->includeRootCategory = true;
    $params->loadRootCategory = true;
    $params->loadAccessRights = true;
    $params->loadDocuments = true;

    $dmsLoader = \DmsLoader::getInstance();
    $arrCategories = $dmsLoader->loadCategories($params);

    if (count($arrCategories) == 1)
    {
      $category = $arrCategories[0];
      if ($category != null && ($category->hasDocuments() || $category->hasDocumentsInSubCategories()))
      {
        return false;
      }
    }
    return true;
  }
352480
public static function hasPosts($tagID, $postTypeSlug = '')
    {
        $postTypeSlug($postTypeSlug ? $postTypeSlug : PostType::getSlug());
        $queryObject = DB::table(tagsRelationTable($postTypeSlug))->where('tagID', $tagID);

        if($queryObject->count() > 0) {
            return true;
        }

        return false;
    }
1288100
public function IsInCategoryPath($sCategoryId)
    {
        $oBreadCrumb = $this->GetBreadcrumb();
        $oMatchingNode = $oBreadCrumb->FindItemWithProperty('id', $sCategoryId);
        if ($oMatchingNode) {
            return true;
        } else {
            return false;
        }
    }
241320
public boolean contains(final String category, final String checkId) {
		return (rules.containsKey(getRuleKey(category, checkId)));
	}
119335
public function loadCategory($categoryId, \DmsLoaderParams $params)
  {
    $objCategory = $this->Database->prepare("SELECT * FROM tl_dms_categories WHERE id = ?")
                    ->limit(1)
                    ->execute($categoryId);
    
    $category = null;
    if ($objCategory->numRows)
    {
      $category = $this->buildCategory($objCategory);
      if ($params->loadAccessRights)
      {
        $category->accessRights = $this->getAccessRights($category, $params);
      }
      if ($params->loadDocuments)
      {
        $category->documents = $this->getDocuments($category, $params);
      }
      if ($params->loadRootCategory)
      {
        $category->parentCategory = $this->loadCategory($category->parentCategoryId, $params);
      }
    }

    return $category;
  }
1210219
public function deleteRelatedTagsAndCategory($postType)
    {
        $categories = Category::where("postTypeID", $postType->postTypeID);
        $categoryIDs = $categories->pluck('categoryID')->toArray();
        $categoriesRelations = (new CategoryRelation)->setTable($postType->slug."_categories")->whereIn("categoryID", $categoryIDs);

        $tags = Tag::where("postTypeID", $postType->postTypeID);
        $tagIDs = $tags->pluck('tagID')->toArray();
        $tagsRelations = (new TagRelation)->setTable($postType->slug."_tags")->whereIn("tagID", $tagIDs);

        // return false if any delete failed
        if(($tagsRelations->count() && !$tagsRelations->delete()) 
            || ($categoriesRelations->count() && !$categoriesRelations->delete()) 
            || ($tags->count() && !$tags->delete()) 
            || ($categories->count() && !$categories->delete())
        ) {
            return false;
        }else{
            Schema::drop($postType->slug."_media");
            if($postType->hasCategories) {
                Schema::drop($postType->slug."_categories");
            }
            if($postType->hasTags) {
                Schema::drop($postType->slug."_tags");
            }
        }
        return true;
    }
64232
public static function isChildPost($postOrPostId = null)
    {
        $post = self::getPost($postOrPostId);
        if (empty($post)) {
            return false;
        }

        return $post->post_parent > 0;
    }
491715
protected function isInCategories(array $category)
    {
        $url = ltrim(wei()->request->getPathInfo(), '/');
        foreach ($category['navs'] as $i => $subCategories) {
            foreach ($subCategories['navs'] as $nav) {
                if ($nav['url'] == $url) {
                    return true;
                }
            }
        }

        return false;
    }
1320351
public function checkUserViewedCategoryAndStop($categoryId = '', $countViewed = 0)
    {
        $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;
            }
        } else {
            $viewValue = 1;
        }
        $checkBundle         = $this->getSessionData(self::SESSION_ID_CURRENT_USER_INFO_BUNDLE);
        $checkBundleDuration = $this->getSessionData(self::SESSION_ID_CURRENT_USER_PACKAGE_BUNDLE_DURATION);
        $this->logger->debug(__FUNCTION__, 'Check Bundle => ' . json_encode($checkBundle));
        $this->logger->debug(__FUNCTION__, 'Session view Value => ' . json_encode($viewValue));
        $this->logger->debug(__FUNCTION__, 'Count Viewed => ' . json_encode($countViewed));
        $this->updateUserViewedCategory($categoryId);
        if ((isset($checkBundle) && $checkBundle == '2') && $countViewed >= self::USER_VIEW_MAX_POST_IF_BUNDLE_IS_2) {
            if (isset($checkBundleDuration) && $checkBundleDuration == 1) {
                $this->logger->debug(__FUNCTION__, 'Hết thời gian đọc tin bài!');

                return TRUE;
            } else {
                $this->logger->debug(__FUNCTION__, 'User đăng ký gói tuần trở lên, không cần limit thời gian!');

                return FALSE;
            }
        }
        $this->logger->debug(__FUNCTION__, 'Tiếp tục đọc tin bài!');

        return FALSE;
    }
44398
public function getCategoryUrls(string $category, array $criteria = [], $siteId = null): array
    {
        return RouteMap::$plugin->routes->getCategoryUrls($category, $criteria, $siteId);
    }