vendor/sylius/sylius/src/Sylius/Component/Core/Model/Taxon.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Component\Core\Model;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\Common\Comparable;
  15. use Sylius\Component\Resource\Model\TimestampableTrait;
  16. use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon;
  17. use Sylius\Component\Taxonomy\Model\TaxonTranslation;
  18. class Taxon extends BaseTaxon implements TaxonInterfaceComparable
  19. {
  20.     use TimestampableTrait;
  21.     /**
  22.      * @var Collection|ImageInterface[]
  23.      *
  24.      * @psalm-var Collection<array-key, ImageInterface>
  25.      */
  26.     protected $images;
  27.     public function __construct()
  28.     {
  29.         parent::__construct();
  30.         $this->createdAt = new \DateTime();
  31.         /** @var ArrayCollection<array-key, ImageInterface> $this->images */
  32.         $this->images = new ArrayCollection();
  33.     }
  34.     public function getImages(): Collection
  35.     {
  36.         return $this->images;
  37.     }
  38.     public function getImagesByType(string $type): Collection
  39.     {
  40.         return $this->images->filter(function (ImageInterface $image) use ($type): bool {
  41.             return $type === $image->getType();
  42.         });
  43.     }
  44.     public function hasImages(): bool
  45.     {
  46.         return !$this->images->isEmpty();
  47.     }
  48.     public function hasImage(ImageInterface $image): bool
  49.     {
  50.         return $this->images->contains($image);
  51.     }
  52.     public function addImage(ImageInterface $image): void
  53.     {
  54.         $image->setOwner($this);
  55.         $this->images->add($image);
  56.     }
  57.     public function removeImage(ImageInterface $image): void
  58.     {
  59.         if ($this->hasImage($image)) {
  60.             $image->setOwner(null);
  61.             $this->images->removeElement($image);
  62.         }
  63.     }
  64.     public static function getTranslationClass(): string
  65.     {
  66.         return TaxonTranslation::class;
  67.     }
  68.     public function compareTo($other): int
  69.     {
  70.         return $this->code === $other->getCode() ? 1;
  71.     }
  72. }