Retrieve Search Query for a category

@param ContainerConfigurationInterface $containerConfigurationInterface Container Configuration
@param CategoryInterface               $category                        Category

@return QueryInterface
2444
public function getCategorySearchQuery(
        ContainerConfigurationInterface $containerConfigurationInterface,
        CategoryInterface $category
    ) {
        $filters = array_merge(
            ['category' => $this->categoryFilterProvider->getQueryFilter($category)],
            $containerConfigurationInterface->getFilters()
        );

        $filterQuery  = $this->queryBuilder->createFilterQuery($containerConfigurationInterface, $filters);

        return $this->queryFactory->create(QueryInterface::TYPE_FILTER, ['filter' => $filterQuery]);
    }
385409
public function retrieveFirstByCategorySlug($categorySlug)
    {
        $query = $this->createQueryBuilder('q')
            ->join('q.category', 'c')
            ->where('c.slug = :categorySlug')
            ->andWhere('q.isActive = :isActive')
            ->andWhere('q.publishAt <= :publishAt')
            ->andWhere('(q.expiresAt IS NULL OR q.expiresAt >= :expiresAt)')
            ->orderBy('q.rank', 'ASC')
            ->setMaxResults(1)
            ->getQuery();

        $query->setParameter('categorySlug', $categorySlug);
        $query->setParameter('isActive', true);
        $query->setParameter('publishAt', date('Y-m-d H:i:s'));
        $query->setParameter('expiresAt', date('Y-m-d H:i:s'));

        return $query->getOneOrNullResult();
    }
394834
public function getCategory(ConnectionInterface $con = null)
    {
        if ($this->aCategory === null && ($this->category_id != 0)) {
            $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aCategory->addC2Ms($this);
             */
        }

        return $this->aCategory;
    }
1000232
public function getCategoryActiveProductsQueryBuilder(CategoryInterface $category = null, $filter = null, $option = null)
    {
        $queryBuilder = $this->getCategoryProductsQueryBuilder($category);
        $queryBuilder->leftJoin('p.variations', 'pv')
            ->andWhere('p.parent IS NULL')      // Limit to master products or products without variations
            ->andWhere('p.enabled = :enabled')
            ->andWhere($queryBuilder->expr()->orX('pv.enabled = :enabled', 'pv.enabled IS NULL'))
            ->setParameter('enabled', true);

        if (null !== $filter) {
            // TODO manage various filter types
            $queryBuilder->andWhere(sprintf('p.%s %s :%s', $filter, '>', $filter))
                ->setParameter(sprintf(':%s', $filter), $option);
        }

        return $queryBuilder;
    }
635215
public function getAvailableParentCategoriesQueryBuilder($categoryId = null)
    {
        $queryBuilder = $this
            ->createQueryBuilder('c')
            ->where('c.root = 1');

        if (null !== $categoryId) {
            $queryBuilder
                ->andWhere('c.id <> :parent_category')
                ->setParameter('parent_category', $categoryId);
        }

        return $queryBuilder;
    }
417082
private function getCategoryFilterParam(\Magento\Catalog\Model\Category $category)
    {
        $filterParam = $category->getId();

        if ($category->getVirtualRule()) { // Implicit dependency to Virtual Categories module.
            $category->setIsActive(true);

            $filterParam = $category->getVirtualRule()->getCategorySearchQuery($category);
        }

        return $filterParam;
    }
849273
public function findByCategory($category)
    {
        return $this->createQueryBuilder('p')
            ->leftJoin('Ekino\WordpressBundle\Entity\TermRelationships', 'tr', 'WITH', 'p.id = tr.post')
            ->leftJoin('Ekino\WordpressBundle\Entity\Term', 't', 'WITH', 't.id = tr.taxonomy')
            ->where('t.name = :category')
            ->setParameter('category', $category)
            ->getQuery()->getResult();
    }
483393
public static function getByCategory($catId, $limit = false, $offset = false, $moreQuerySettings = [])
    {
        return self::getBy(Ajax::CATEGORY, $catId, $limit, $offset, $moreQuerySettings);
    }
980285
private function get_category_from_group($categories) {
        global $DB;

        if (empty($categories)) {
            $catid = $this->get_default_category_id();
        } else {
            $createnewcategories = $this->get_config('createnewcategories');
            $categoryseparator = trim($this->get_config('categoryseparator'));
            $nestedcategories = trim($this->get_config('nestedcategories'));
            $searchbyidnumber = trim($this->get_config('categoryidnumber'));

            if (!empty($categoryseparator)) {
                $sep = '{\\'.$categoryseparator.'}';
            }

            $catid = 0;
            $fullnestedcatname = '';

            foreach ($categories as $categoryinfo) {
                if ($searchbyidnumber) {
                    $values = preg_split($sep, $categoryinfo, -1, PREG_SPLIT_NO_EMPTY);
                    if (count($values) < 2) {
                        $this->log_line('Category ' . $categoryinfo . ' missing name or idnumber. Using default category instead.');
                        $catid = $this->get_default_category_id();
                        break;
                    }
                    $categoryname = $values[0];
                    $categoryidnumber = $values[1];
                } else {
                    $categoryname = $categoryinfo;
                    $categoryidnumber = null;
                    if (empty($categoryname)) {
                        $this->log_line('Category ' . $categoryinfo . ' missing name. Using default category instead.');
                        $catid = $this->get_default_category_id();
                        break;
                    }
                }

                if (!empty($fullnestedcatname)) {
                    $fullnestedcatname .= ' / ';
                }

                $fullnestedcatname .= $categoryname;
                $parentid = $catid;

                // Check if category exist.
                $params = array();
                if ($searchbyidnumber) {
                    $params['idnumber'] = $categoryidnumber;
                } else {
                    $params['name'] = $categoryname;
                }
                if ($nestedcategories) {
                    $params['parent'] = $parentid;
                }

                if ($catid = $DB->get_field('course_categories', 'id', $params)) {
                    continue; // This category already exists.
                }

                // If we're allowed to create new categories, let's create this one.
                if ($createnewcategories) {
                    $newcat = new stdClass();
                    $newcat->name = $categoryname;
                    $newcat->visible = 0;
                    $newcat->parent = $parentid;
                    $newcat->idnumber = $categoryidnumber;
                    $newcat = core_course_category::create($newcat);
                    $catid = $newcat->id;
                    $this->log_line("Created new (hidden) category '$fullnestedcatname'");
                } else {
                    // If not found and not allowed to create, stick with default.
                    $this->log_line('Category ' . $categoryinfo . ' not found in Moodle database. Using default category instead.');
                    $catid = $this->get_default_category_id();
                    break;
                }
            }
        }

        return $catid;
    }
1329085
protected function loadCategories(ContextInterface $context)
    {
        if (\array_key_exists($context->getId(), $this->categories)) {
            return;
        }

        $class = $this->getClass();

        $categories = $this->getObjectManager()->createQuery(sprintf('SELECT c FROM %s c WHERE c.context = :context ORDER BY c.parent ASC', $class))
            ->setParameter('context', $context->getId())
            ->execute();

        if (0 === \count($categories)) {
            // no category, create one for the provided context
            $category = $this->create();
            $category->setName($context->getName());
            $category->setEnabled(true);
            $category->setContext($context);
            $category->setDescription($context->getName());

            $this->save($category);

            $categories = [$category];
        }

        $rootCategories = [];
        foreach ($categories as $pos => $category) {
            if (null === $category->getParent()) {
                $rootCategories[] = $category;
            }

            $this->categories[$context->getId()][$category->getId()] = $category;

            $parent = $category->getParent();

            $category->disableChildrenLazyLoading();

            if ($parent) {
                $parent->addChild($category);
            }
        }

        $this->categories[$context->getId()] = $rootCategories;
    }
506822
private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
    {
        $keywordString = $keyword->getKeyword();
        $keywordLocale = $keyword->getLocale();

        // if keyword wont be deleted (because of multiple references)
        // refresh it to be sure hat changes wont be written to
        // database.
        $this->entityManager->refresh($keyword);

        // delete old keyword from category
        $this->delete($keyword, $category);

        // create new keyword
        $newEntity = $this->keywordRepository->createNew();
        $newEntity->setKeyword($keywordString);
        $newEntity->setLocale($keywordLocale);

        // add new keyword to category
        return $this->save($newEntity, $category);
    }
1310445
public function getSearchQueriesByChildren(CategoryInterface $rootCategory)
    {
        $queries     = [];
        $childrenIds = $rootCategory->getResource()->getChildren($rootCategory, false);

        if (!empty($childrenIds)) {
            $storeId            = $this->getStoreId();
            $categoryCollection = $this->categoryCollectionFactory->create()->setStoreId($storeId);

            $categoryCollection
                ->setStoreId($this->getStoreId())
                ->addIsActiveFilter()
                ->addIdFilter($childrenIds)
                ->addAttributeToSelect(['virtual_category_root', 'is_virtual_category', 'virtual_rule']);

            foreach ($categoryCollection as $category) {
                $childQuery = $this->getCategorySearchQuery($category);
                if ($childQuery !== null) {
                    $queries[$category->getId()] = $childQuery;
                }
            }
        }

        return $queries;
    }
611758
public function getQueryFilter(CategoryInterface $category)
    {
        $queryParams       = ['field' => 'category.category_id', 'value' => $category->getId()];
        $query             = $this->queryFactory->create(QueryInterface::TYPE_TERM, $queryParams);
        $nestedQueryParams = ['query' => $query, 'path' => 'category'];

        return $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams);
    }
369132
public function update(DocumentCategory $category)
    {
        $attributes = request()->validate(DocumentCategory::$rules, DocumentCategory::$messages);

        $category = $this->updateEntry($category, $attributes);

        return redirect_to_resource();
    }
241992
public function removeCategory(CategoryInterface $category)
    {
        if ($this->hasCategory($category)) {
            $this->categories->removeElement($category);
        }

        return $this;
    }
44398
public function getCategoryUrls(string $category, array $criteria = [], $siteId = null): array
    {
        return RouteMap::$plugin->routes->getCategoryUrls($category, $criteria, $siteId);
    }
999923
public function matchCategory($category)
    {
        $result = empty($this->categories);
        foreach ($this->categories as $allowedCategory) {
            if ($this->categoryContains($allowedCategory, $category)) {
                $result = true;
            }
        }
        foreach ($this->exceptions as $deniedCategory) {
            if ($this->categoryContains($deniedCategory, $category)) {
                $result = false;
            }
        }

        return $result;
    }