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

Open in your IDE?
  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 list<string>
  15.      */
  16.     public function getPropertyGroupIds(): array
  17.     {
  18.         return $this->fmap(function (PropertyGroupOptionEntity $propertyGroupOption) {
  19.             return $propertyGroupOption->getGroupId();
  20.         });
  21.     }
  22.     public function filterByGroupId(string $id): self
  23.     {
  24.         return $this->filter(function (PropertyGroupOptionEntity $propertyGroupOption) use ($id) {
  25.             return $propertyGroupOption->getGroupId() === $id;
  26.         });
  27.     }
  28.     /**
  29.      * @return list<string>
  30.      */
  31.     public function getMediaIds(): array
  32.     {
  33.         return $this->fmap(function (PropertyGroupOptionEntity $propertyGroupOption) {
  34.             return $propertyGroupOption->getMediaId();
  35.         });
  36.     }
  37.     public function filterByMediaId(string $id): self
  38.     {
  39.         return $this->filter(function (PropertyGroupOptionEntity $propertyGroupOption) use ($id) {
  40.             return $propertyGroupOption->getMediaId() === $id;
  41.         });
  42.     }
  43.     public function getGroups(): PropertyGroupCollection
  44.     {
  45.         return new PropertyGroupCollection(
  46.             $this->fmap(function (PropertyGroupOptionEntity $propertyGroupOption) {
  47.                 return $propertyGroupOption->getGroup();
  48.             })
  49.         );
  50.     }
  51.     public function groupByPropertyGroups(): PropertyGroupCollection
  52.     {
  53.         $groups = new PropertyGroupCollection();
  54.         foreach ($this->getIterator() as $element) {
  55.             if ($groups->has($element->getGroupId())) {
  56.                 $group $groups->get($element->getGroupId());
  57.             } else {
  58.                 $group PropertyGroupEntity::createFrom($element->getGroup());
  59.                 $groups->add($group);
  60.                 $group->setOptions(new self());
  61.             }
  62.             $group->getOptions()->add($element);
  63.         }
  64.         return $groups;
  65.     }
  66.     public function getApiAlias(): string
  67.     {
  68.         return 'product_group_option_collection';
  69.     }
  70.     protected function getExpectedClass(): string
  71.     {
  72.         return PropertyGroupOptionEntity::class;
  73.     }
  74. }