vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Entity/CategoryTranslation.php line 21

  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\CategoryBundle\Entity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Sulu\Component\Security\Authentication\UserInterface;
  14. /**
  15.  * CategoryTranslation.
  16.  */
  17. class CategoryTranslation implements CategoryTranslationInterface
  18. {
  19.     /**
  20.      * @var string
  21.      */
  22.     protected $translation;
  23.     /**
  24.      * @var string|null
  25.      */
  26.     protected $description;
  27.     /**
  28.      * @var CategoryTranslationMedia[]
  29.      */
  30.     protected $medias;
  31.     /**
  32.      * @var string
  33.      */
  34.     protected $locale;
  35.     /**
  36.      * @var int
  37.      */
  38.     protected $id;
  39.     /**
  40.      * @var CategoryInterface
  41.      */
  42.     protected $category;
  43.     /**
  44.      * @var UserInterface|null
  45.      */
  46.     protected $creator;
  47.     /**
  48.      * @var UserInterface|null
  49.      */
  50.     protected $changer;
  51.     /**
  52.      * @var \DateTime
  53.      */
  54.     protected $created;
  55.     /**
  56.      * @var \DateTime
  57.      */
  58.     protected $changed;
  59.     /**
  60.      * @var Collection|KeywordInterface[]
  61.      */
  62.     protected $keywords;
  63.     public function __construct()
  64.     {
  65.         $this->keywords = new ArrayCollection();
  66.         $this->medias = new ArrayCollection();
  67.     }
  68.     public function setTranslation($translation)
  69.     {
  70.         $this->translation $translation;
  71.         return $this;
  72.     }
  73.     public function getTranslation()
  74.     {
  75.         return $this->translation;
  76.     }
  77.     /**
  78.      * @return string|null
  79.      */
  80.     public function getDescription()
  81.     {
  82.         return $this->description;
  83.     }
  84.     public function setDescription($description)
  85.     {
  86.         $this->description $description;
  87.         return $this;
  88.     }
  89.     public function getMedias()
  90.     {
  91.         $medias = [];
  92.         foreach ($this->medias as $media) {
  93.             $medias[] = $media->getMedia();
  94.         }
  95.         return $medias;
  96.     }
  97.     public function setMedias($medias)
  98.     {
  99.         $position 0;
  100.         foreach ($this->medias as $media) {
  101.             $mediaEntity $medias[$position] ?? null;
  102.             ++$position;
  103.             if (!$mediaEntity) {
  104.                 $this->medias->removeElement($media);
  105.                 continue;
  106.             }
  107.             $media->setMedia($mediaEntity);
  108.             $media->setPosition($position);
  109.         }
  110.         for (; $position \count($medias); ++$position) {
  111.             $media = new CategoryTranslationMedia($this$medias[$position], $position 1);
  112.             $this->medias->add($media);
  113.         }
  114.     }
  115.     public function setLocale($locale)
  116.     {
  117.         $this->locale $locale;
  118.         return $this;
  119.     }
  120.     public function getLocale()
  121.     {
  122.         return $this->locale;
  123.     }
  124.     public function getId()
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function setCategory(CategoryInterface $category)
  129.     {
  130.         $this->category $category;
  131.         return $this;
  132.     }
  133.     public function getCategory()
  134.     {
  135.         return $this->category;
  136.     }
  137.     public function getCreator()
  138.     {
  139.         return $this->creator;
  140.     }
  141.     public function setCreator($creator)
  142.     {
  143.         $this->creator $creator;
  144.     }
  145.     public function getChanger()
  146.     {
  147.         return $this->changer;
  148.     }
  149.     public function setChanger($changer)
  150.     {
  151.         $this->changer $changer;
  152.     }
  153.     public function getCreated()
  154.     {
  155.         return $this->created;
  156.     }
  157.     public function setCreated($created)
  158.     {
  159.         $this->created $created;
  160.     }
  161.     public function getChanged()
  162.     {
  163.         return $this->changed;
  164.     }
  165.     public function setChanged($changed)
  166.     {
  167.         $this->changed $changed;
  168.     }
  169.     public function addKeyword(KeywordInterface $keyword)
  170.     {
  171.         $this->keywords[] = $keyword;
  172.         return $this;
  173.     }
  174.     public function removeKeyword(KeywordInterface $keyword)
  175.     {
  176.         $this->keywords->removeElement($keyword);
  177.     }
  178.     public function getKeywords()
  179.     {
  180.         return $this->keywords;
  181.     }
  182.     public function hasKeyword(KeywordInterface $keyword)
  183.     {
  184.         return $this->getKeywords()->exists(
  185.             function($keyKeywordInterface $element) use ($keyword) {
  186.                 return $element->equals($keyword);
  187.             }
  188.         );
  189.     }
  190. }