vendor/shopware/core/Content/Category/CategoryCollection.php line 17

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Category;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Util\AfterSort;
  5. /**
  6.  * @method void                add(CategoryEntity $entity)
  7.  * @method void                set(string $key, CategoryEntity $entity)
  8.  * @method CategoryEntity[]    getIterator()
  9.  * @method CategoryEntity[]    getElements()
  10.  * @method CategoryEntity|null get(string $key)
  11.  * @method CategoryEntity|null first()
  12.  * @method CategoryEntity|null last()
  13.  */
  14. class CategoryCollection extends EntityCollection
  15. {
  16.     public function getParentIds(): array
  17.     {
  18.         return $this->fmap(function (CategoryEntity $category) {
  19.             return $category->getParentId();
  20.         });
  21.     }
  22.     public function filterByParentId(string $id): self
  23.     {
  24.         return $this->filter(function (CategoryEntity $category) use ($id) {
  25.             return $category->getParentId() === $id;
  26.         });
  27.     }
  28.     public function getMediaIds(): array
  29.     {
  30.         return $this->fmap(function (CategoryEntity $category) {
  31.             return $category->getMediaId();
  32.         });
  33.     }
  34.     public function filterByMediaId(string $id): self
  35.     {
  36.         return $this->filter(function (CategoryEntity $category) use ($id) {
  37.             return $category->getMediaId() === $id;
  38.         });
  39.     }
  40.     public function sortByPosition(): self
  41.     {
  42.         $this->elements AfterSort::sort($this->elements'afterCategoryId');
  43.         return $this;
  44.     }
  45.     public function sortByName(): self
  46.     {
  47.         $this->sort(function (CategoryEntity $aCategoryEntity $b) {
  48.             return strnatcasecmp($a->getTranslated()['name'], $b->getTranslated()['name']);
  49.         });
  50.         return $this;
  51.     }
  52.     public function getApiAlias(): string
  53.     {
  54.         return 'category_collection';
  55.     }
  56.     protected function getExpectedClass(): string
  57.     {
  58.         return CategoryEntity::class;
  59.     }
  60. }