Get brands from their products relationship

@param Category     $category
@param integer|null $limit

@return ArrayCollection
779743
public function getBrands($category, $limit = null)
    {
        $qb = $this->getQueryBuilder()
            ->select('DISTINCT b.id, b.name')
            ->innerJoin('c.products', 'p')
            ->innerJoin('p.brand', 'b')
            ->where('p.active = TRUE')
            ->andWhere('b.available = TRUE');

        if ($category->getFamily()) {
            // this is a category
            $qb->andWhere('c.parentCategory = :category')
                ->setParameter('category', $category);
        } else {
            // this is a subcategory
            $qb->andWhere('c = :category')
                ->setParameter('category', $category);
        }

        if (!is_null($limit)) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()
            ->getResult();
    }
534238
public function getRelatedFAQs($limit = null)
    {
        $tags = $this->owner->Tags();

        if ($tags->count() == 0) {
            return null;
        }

        // find any FAQ that has one of the same tags
        $faqs = FAQ::get()
            ->innerJoin('FAQ_Tags', '"FAQ"."ID" = "FAQ_Tags"."FAQID"')
            ->where(sprintf('"FAQ_Tags"."TaxonomyTermID" IN (%s)', implode(',', $tags->column('ID'))))
            ->exclude('ID', $this->owner->ID);

        // limit the faqs if applicable
        if ($limit && is_int($limit)) {
            $faqs = $faqs->limit($limit);
        }

        return $faqs;
    }
1228283
public function getAllFromCategories(array $categories)
    {
        $queryBuilder = $this->createQueryBuilder('p');
        $this->addPerformanceJoinsToQueryBuilder($queryBuilder);

        return $queryBuilder
            ->innerJoin('p.categories', 'c')
            ->where('c.id IN (:categories)')
            ->setParameters([
                'categories' => $categories,
            ])
            ->getQuery()
            ->getResult();
    }
704947
public function getAllChildren(Category $categories = null)
    {
        // 第一次,初始化一个Collection对象
        if (!$categories) {
            $categories = $this()->beColl();
        }

        // 递归获取所有子分类
        $children = $this->getChildren()->findAll();
        foreach ($children as $category) {
            $categories[] = $category;
            $category->getAllChildren($categories);
        }

        // 返回所有分类
        return $categories;
    }
1129578
public function getComponentsWithCategory($category)
    {
        $components = array();
        foreach ($this->blockConfiguration as $blockComponent => $configuration) {
            if (isset($configuration['category']) && $category === $configuration['category']) {
                $components[] = $blockComponent;
            }
        }

        return $components;
    }
826936
public function getAll($category, $context)
    {
        $model = $this->getModel($category);

        return $model->getAll($context);
    }
293824
protected function getProviderFromCategory(CategoryInterface $category = null)
    {
        if (null === $category) {
            return null;
        }

        $product = $this->getProductSetManager()->findProductForCategory($category);

        return $product ? $this->getProductPool()->getProvider($product) : null;
    }
613502
public function getProductsCollectionBySku($productsSku, $limit = false)
    {
        $productCollection = [];

        if (! empty($productsSku)) {
            $productCollection = $this->productFactory->create()
                ->getCollection()
                ->addAttributeToSelect(
                    ['product_url', 'name', 'store_id', 'small_image', 'price', 'visibility']
                )->addFieldToFilter('sku', ['in' => $productsSku]);

            if ($limit) {
                $productCollection->getSelect()->limit($limit);
            }
        }

        return $productCollection;
    }
377732
public function findEntitiesByCategoryId($categoryId, $locale)
    {
        $products = $this->productRepository->findByCategoryId($categoryId, $locale);

        return $products;
    }
1130050
public function getAchievementsByCategory(Category $category)
    {
        $achievements = array();

        /** @var Achievement $achievement */
        foreach ($this->getAchievements() as $achievement) {
            if ($achievement->getCategory() == $category) {
                $achievements[] = $achievement;
            }
        }

        return $achievements;
    }
81190
public function findProductForCategory(CategoryInterface $category)
    {
        return $this->getCategoryProductsQueryBuilder($category)
            ->select('partial p.{id}')
            ->setMaxResults(1)
        ->getQuery()->getOneOrNullResult();
    }
880374
public function getProductAbstractCollectionByBrandId(int $idBrand): BrandProductAbstractRelationTransfer
    {
        /** @var \Orm\Zed\BrandProduct\Persistence\FosBrandProduct[] $brandProductEntities */
        $brandProductEntities = $this->getFactory()
            ->getBrandProductQuery()
            ->findByFkBrand($idBrand);

        $productAbstractIds = [];
        foreach ($brandProductEntities as $entity) {
            $productAbstractIds[] = $entity->getFkProductAbstract();
        }

        $brandCollectionTransfer = new BrandProductAbstractRelationTransfer();
        $brandCollectionTransfer->setIdBrand($idBrand);
        $brandCollectionTransfer->setProductAbstractIds($productAbstractIds);

        return $brandCollectionTransfer;
    }
289020
public static function getAllSubcategoriesIds($category)
    {
        $ids = Database::getInstance()->getChildRecords($category, static::$strTable, false, (array) $category, (!BE_USER_LOGGED_IN ? 'published=1' : ''));
        $ids = \array_map('intval', $ids);

        return $ids;
    }
649625
private function addSelectedProducts(CategoryInterface $category)
    {
        $selectedProducts = $this->getRequest()->getParam('selected_products', []);

        $addedProducts = isset($selectedProducts['added_products']) ? $selectedProducts['added_products'] : [];
        $category->setAddedProductIds($addedProducts);

        $deletedProducts = isset($selectedProducts['deleted_products']) ? $selectedProducts['deleted_products'] : [];
        $category->setDeletedProductIds($deletedProducts);

        return $this;
    }
1131878
public function childrenOf($category_id, int $limit = 50, $columns = 'id')
    {
        $key = md5(vsprintf('%s', ['children_of_category']));

        return Cache::remember($key, 25, function () use ($category_id, $limit, $columns) {
            return $this->next->childrenOf($category_id, $limit, $columns);
        });
    }
903970
public function get($category, $key = null, $default = null)
    {
        $this->load($category);

        if ($key === null) {
            return isset($this->items[$category]) && !empty($this->items[$category]) ? $this->items[$category] : $default;
        }

        if (is_string($key)) {
            return isset($this->items[$category][$key]) ? $this->items[$category][$key] : $default;
        }

        if (is_array($key)) {
            $result = [];
            foreach ($key as $val) {
                $result[$val] = isset($this->items[$category][$val]) ? $this->items[$category][$val] : (is_array($default) && isset($default[$val]) ? $default[$val] : null);
            }
            return $result;
        }

        return $default;
    }
1006900
public function getRandomQuestions($category, $limit, $questionsLevel = array(), $excludeQuestions = array())
    {
        $query = $this->createQueryBuilder('q')
            ->addSelect('RAND() as HIDDEN rand, q, c, a')
            ->leftJoin('q.category', 'c')
            ->leftJoin('q.answers', 'a')
            ->where('q.category = :category')
            ->andWhere('q.enabled = 1')
            ->setParameter('category', $category)
            ->orderBy('rand');

        if (!empty($questionsLevel)) {
            $query->andWhere('q.level IN(:level)')
                ->setParameter('level', $questionsLevel);
        }

        if (!empty($excludeQuestions)) {
            $query->andWhere('q.id NOT IN(:questions)')
                ->setParameter('questions', $excludeQuestions);
        }

        $questions = array_slice($query->getQuery()->getResult(), 0, $limit);

        return $questions;
    }