Select content based on its CategoryID

@param integer $CategoryID
@return boolean
496705
protected function SelectByCategory($CategoryID) {
      $CategoryID = GetValue('CategoryID', $Parameters, NULL);
      if (!$CategoryID) return FALSE;
      
      // Check cache
      $SelectorCategoryCacheKey = "modules.promotedcontent.category.{$CategoryID}";
      $Content = Gdn::Cache()->Get($SelectorCategoryCacheKey);
      
      if ($Content == Gdn_Cache::CACHEOP_FAILURE) {
      
         // Get matching Discussions
         $Discussions = Gdn::SQL()->Select('d.*')
            ->From('Discussion d')
            ->Where('d.CategoryID', $CategoryID)
            ->OrderBy('DateInserted', 'DESC')
            ->Limit($this->Limit)
            ->Get()->Result(DATASET_TYPE_ARRAY);

         // Get matching Comments
         $CommentDiscussionIDs = Gdn::SQL()->Select('d.DiscussionID')
            ->From('Discussion d')
            ->Where('d.CategoryID', $CategoryID)
            ->OrderBy('DateLastComment', 'DESC')
            ->Limit($this->Limit)
            ->Get()->Result(DATASET_TYPE_ARRAY);
         
         $Comments = Gdn::SQL()->Select('c.*')
            ->From('Comment c')
            ->WhereIn('DiscussionID', $CommentDiscussionIDs)
            ->OrderBy('DateInserted', 'DESC')
            ->Limit($this->Limit)
            ->Get()->Result(DATASET_TYPE_ARRAY);
         
         $this->JoinCategory($Comments);
         
         // Interleave
         $Content = $this->Union('DateInserted', array(
            'Discussion'   => $Discussions, 
            'Comment'      => $Comments
         ));
         $this->Prepare($Content);
         
         // Add result to cache
         Gdn::Cache()->Store($SelectorCategoryCacheKey, $Content, array(
            Gdn_Cache::FEATURE_EXPIRY  => $this->Expiry
         ));
      }
      
      $this->Security($Content);
      $this->Condense($Content, $this->Limit);
      return $Content;
   }
173878
public function addCategoryToAllowedRoots($categoryId)
    {
        if (null === ($roots = $this->getUserAllowedRoots())) {
            return;
        }

        $categoryId = (int) $categoryId;
        $user = $this->getUser();

        /** @var StringUtil $stringUtil */
        $stringUtil = $this->framework->getAdapter(StringUtil::class);

        // Add the permissions on group level
        if ('custom' !== $user->inherit) {
            $groups = $this->db->fetchAll('SELECT id, newscategories, newscategories_roots FROM tl_user_group WHERE id IN('.\implode(',', \array_map('intval', $user->groups)).')');

            foreach ($groups as $group) {
                $permissions = $stringUtil->deserialize($group['newscategories'], true);

                if (\in_array('manage', $permissions, true)) {
                    $categoryIds = $stringUtil->deserialize($group['newscategories_roots'], true);
                    $categoryIds[] = $categoryId;

                    $this->db->update('tl_user_group', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $group['id']]);
                }
            }
        }

        // Add the permissions on user level
        if ('group' !== $user->inherit) {
            $userData = $this->db->fetchAssoc('SELECT newscategories, newscategories_roots FROM tl_user WHERE id=?', [$user->id]);
            $permissions = $stringUtil->deserialize($userData['newscategories'], true);

            if (\in_array('manage', $permissions, true)) {
                $categoryIds = $stringUtil->deserialize($userData['newscategories_roots'], true);
                $categoryIds[] = $categoryId;

                $this->db->update('tl_user', ['newscategories_roots' => \serialize($categoryIds)], ['id' => $user->id]);
            }
        }

        // Add the new element to the user object
        $user->newscategories_roots = \array_merge($roots, [$categoryId]);
    }
905807
public function getCategoryById($categoryId)
    {
        //wyszukanie w płaskiej liście
        return isset($this->_flatCategories[$categoryId]) ? $this->_flatCategories[$categoryId] : null;
    }
971149
public static function hasPosts($postType, $categoriesID)
    {
        if(DB::table(categoriesRelationTable($postType))->where('categoryID', $categoriesID)->count()
        ) {
            return true;
        }else{
            return false;
        }
    }
731989
public function findTranslated($category, $languageId)
    {
        return CategoryTranslation::whereCategoryId($category->id)
            ->whereLanguageId($languageId)
            ->first();
    }
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;
  }
902301
public function actionSelectFilters(int $categoryId, int $languageId, $id = null)
    {
        $category = Category::findOne($categoryId);
        if (empty($category)) throw new NotFoundHttpException();
        $filters = Filter::find()->where(['category_id' => $category->id])->all();
        $filter = (!empty($id)) ? Filter::findOne($id) : new Filter();

        if (Yii::$app->request->isPost) {
            $filter->load(Yii::$app->request->post());

            if ($filter->validate()) {
                $filter->category_id = $category->id;
                $filter->save();

                $this->trigger(self::EVENT_AFTER_EDIT_CATEGORY,
                    new CategoryEvent(['id' => $category->id]));

                Yii::$app->getSession()->setFlash('success', 'Data were successfully modified.');
                return $this->redirect(Yii::$app->request->referrer);
            }
        }

        return $this->render('save', [
            'viewName' => 'select-filters',
            'params' => [
                'languages' => Language::findAll(['active' => true]),
                'category' => $category,
                'selectedLanguage' => Language::findOne($languageId),
                'filters' => $filters,
                'newFilter' => new Filter(),
            ],
        ]);
    }
632506
public function saveAttributesData(int $categoryId, array $data)
    {
        $rows = [];
        $this->deleteByCategoryId($categoryId);

        $fields = $this->getConnection()->describeTable($this->getMainTable());
        foreach ($data as $item) {
            $item[$this->getIdFieldName()] = $categoryId;
            $row                           = $this->buildRow($item, $fields);
            if ($this->isValid($row)) {
                $rows[] = $row;
            }
        }

        $result = true;
        if (!empty($rows)) {
            $result = (bool) $this->getConnection()->insertArray($this->getMainTable(), array_keys($fields), $rows);
        }

        return $result;
    }
700325
public static function findByNameCategoryId( $name, $categoryId ) {

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

		return self::find()->where( "$optionTable.name=:name AND $optionTable.categoryId=:id", [ ':name' => $name, ':id' => $categoryId ] )->one();
	}
930107
public function getSearchableCategories($storeId, $categoryIds = null, $fromId = 0, $limit = 100)
    {
        /**
         * @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection
         */
        $categoryCollection = $this->categoryCollectionFactory->create();
        $categoryCollection->addIsActiveFilter();
        $select = $categoryCollection->getSelect();

        $this->addIsVisibleInStoreFilter($select, $storeId);

        if ($categoryIds !== null) {
            $select->where('e.entity_id IN (?)', $categoryIds);
        }

        $select->where('e.entity_id > ?', $fromId)
            ->limit($limit)
            ->order('e.entity_id');

        return $this->connection->fetchAll($select);
    }
1135415
public static function delete_category($id) {
        $category = new category($id);
        if ($category->is_used()) {
            throw new \moodle_exception('Category with id ' . $id . ' can not be deleted because it is used.');
        }
        return $category->delete();
    }
988140
public function getProductBlacklist($categoryId, $storeId)
    {
        $select = $this->getBaseSelect()
            ->columns(['product_id'])
            ->where('category_id = ?', (int) $categoryId)
            ->where('store_id = ?', (int) $storeId)
            ->where('is_blacklisted = ?', (int) true);

        return $this->getConnection()->fetchCol($select);
    }
310389
protected function setCategory($category_id)
    {
        $this->data_category = array();

        if (is_numeric($category_id)) {

            //Set unexisting language code to get original titles.
            //Otherwise it will be translated to the current language
            $conditions = array(
                'language' => 'und',
                'category_id' => $category_id
            );

            $this->data_category = $this->category->get($conditions);

            if (empty($this->data_category)) {
                $this->outputHttpStatus(404);
            }

            $this->prepareCategory($this->data_category);
        }
    }
82713
public static function isExistByNameCategoryId( $name, $categoryId ) {

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

		return isset( $option );
	}
862599
public function childrenOf($category_id, int $limit = 50, $columns = '*')
    {
        return Category::select($columns)->with('childrenRecursive')
            ->where('category_id', $category_id)
            ->orderBy('updated_at', 'desc')
            ->take($limit)
            ->get();
    }
975230
function getCategory($id)
    {
        $result = $this->db->query('SELECT * FROM category WHERE id = :id', [':id'=>(0+$id)]);
        if (isset($result[0])) {
            return ['name'=>$result[0]->get('name'),
                'description'=>$result[0]->get('description')];
        }
        return false;
    }
453151
public function getProductsInCategoryByMetadata(int $categoryId, array $context) : array
    {
        Assert::that($categoryId)->greaterThan(0, 'The $categoryId has to be positive');
        Assert::that($context)->notEmpty();

        return (array)$this->master->doRequest(
            'POST',
            sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/Products/%d', $categoryId),
            $context
        );
    }