vendor/shopware/core/Content/Property/Aggregate/PropertyGroupOption/PropertyGroupOptionCollection.php line 12

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Property\Aggregate\PropertyGroupOption;
  3. use Shopware\Core\Content\Property\PropertyGroupCollection;
  4. use Shopware\Core\Content\Property\PropertyGroupEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  6. use Shopware\Core\Framework\Log\Package;
  7. /**
  8.  * @extends EntityCollection<PropertyGroupOptionEntity>
  9.  */
  10. #[Package('inventory')]
  11. class PropertyGroupOptionCollection extends EntityCollection
  12. {
  13.     /**
  14.      * @return array<string>
  15.      */
  16.     public function getPropertyGroupIds(): array
  17.     {
  18.         return $this->fmap(fn (PropertyGroupOptionEntity $propertyGroupOption) => $propertyGroupOption->getGroupId());
  19.     }
  20.     public function filterByGroupId(string $id): self
  21.     {
  22.         return $this->filter(fn (PropertyGroupOptionEntity $propertyGroupOption) => $propertyGroupOption->getGroupId() === $id);
  23.     }
  24.     /**
  25.      * @return array<string>
  26.      */
  27.     public function getMediaIds(): array
  28.     {
  29.         return $this->fmap(fn (PropertyGroupOptionEntity $propertyGroupOption) => $propertyGroupOption->getMediaId());
  30.     }
  31.     public function filterByMediaId(string $id): self
  32.     {
  33.         return $this->filter(fn (PropertyGroupOptionEntity $propertyGroupOption) => $propertyGroupOption->getMediaId() === $id);
  34.     }
  35.     public function getGroups(): PropertyGroupCollection
  36.     {
  37.         return new PropertyGroupCollection(
  38.             $this->fmap(fn (PropertyGroupOptionEntity $propertyGroupOption) => $propertyGroupOption->getGroup())
  39.         );
  40.     }
  41.     public function groupByPropertyGroups(): PropertyGroupCollection
  42.     {
  43.         $groups = new PropertyGroupCollection();
  44.         foreach ($this->getIterator() as $element) {
  45.             if ($groups->has($element->getGroupId())) {
  46.                 $group $groups->get($element->getGroupId());
  47.             } else {
  48.                 $group PropertyGroupEntity::createFrom($element->getGroup() ?? new PropertyGroupEntity());
  49.                 $groups->add($group);
  50.                 $group->setOptions(new self());
  51.             }
  52.             if ($group->getOptions()) {
  53.                 $group->getOptions()->add($element);
  54.             }
  55.         }
  56.         return $groups;
  57.     }
  58.     public function getApiAlias(): string
  59.     {
  60.         return 'product_group_option_collection';
  61.     }
  62.     protected function getExpectedClass(): string
  63.     {
  64.         return PropertyGroupOptionEntity::class;
  65.     }
  66. }