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

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