X-Git-Url: https://git.rapsys.eu/blogbundle/blobdiff_plain/9ad367710337f576ffa541975db98b0ace80bbce..b881ad790b1c50fdff160b5d1d51a72ab68c24d5:/Entity/Keyword.php?ds=inline diff --git a/Entity/Keyword.php b/Entity/Keyword.php index 228807d..bb92167 100644 --- a/Entity/Keyword.php +++ b/Entity/Keyword.php @@ -1,183 +1,186 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Rapsys\BlogBundle\Entity; +use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Event\PreUpdateEventArgs; + /** * Keyword */ -class Keyword -{ - /** - * @var integer - */ - private $id; - - /** - * @var \DateTime - */ - private $created; - - /** - * @var \DateTime - */ - private $updated; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - private $keyword_translations; - - /** - * @var \Doctrine\Common\Collections\Collection - */ - private $articles; - - /** - * Constructor - */ - public function __construct() - { - $this->keyword_translations = new \Doctrine\Common\Collections\ArrayCollection(); - $this->articles = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set created - * - * @param \DateTime $created - * - * @return Keyword - */ - public function setCreated($created) - { - $this->created = $created; - - return $this; - } - - /** - * Get created - * - * @return \DateTime - */ - public function getCreated() - { - return $this->created; - } - - /** - * Set updated - * - * @param \DateTime $updated - * - * @return Keyword - */ - public function setUpdated($updated) - { - $this->updated = $updated; - - return $this; - } - - /** - * Get updated - * - * @return \DateTime - */ - public function getUpdated() - { - return $this->updated; - } - - /** - * Add keywordTranslation - * - * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation - * - * @return Keyword - */ - public function addKeywordTranslation(\Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation) - { - $this->keyword_translations[] = $keywordTranslation; - - return $this; - } - - /** - * Remove keywordTranslation - * - * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation - */ - public function removeKeywordTranslation(\Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation) - { - $this->keyword_translations->removeElement($keywordTranslation); - } - - /** - * Get keywordTranslations - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getKeywordTranslations() - { - return $this->keyword_translations; - } - - /** - * Add article - * - * @param \Rapsys\BlogBundle\Entity\Article $article - * - * @return Keyword - */ - public function addArticle(\Rapsys\BlogBundle\Entity\Article $article) - { - $this->articles[] = $article; - - return $this; - } - - /** - * Remove article - * - * @param \Rapsys\BlogBundle\Entity\Article $article - */ - public function removeArticle(\Rapsys\BlogBundle\Entity\Article $article) - { - $this->articles->removeElement($article); - } - - /** - * Get articles - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getArticles() - { - return $this->articles; - } - - /** - * Set id - * - * @param integer $id - * - * @return Keyword - */ - public function setId($id) - { - $this->id = $id; - - return $this; - } +class Keyword { + /** + * @var int + */ + private ?int $id; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * @var \Doctrine\Common\Collections\Collection + */ + private Collection $keyword_translations; + + /** + * @var \Doctrine\Common\Collections\Collection + */ + private Collection $articles; + + /** + * Constructor + */ + public function __construct() { + $this->created = new \DateTime('now'); + $this->updated = new \DateTime('now'); + $this->keyword_translations = new ArrayCollection(); + $this->articles = new ArrayCollection(); + } + + /** + * Get id + * + * @return ?int + */ + public function getId(): ?int { + return $this->id; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return Keyword + */ + public function setCreated(\DateTime $created): Keyword { + $this->created = $created; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return Keyword + */ + public function setUpdated(\DateTime $updated): Keyword { + $this->updated = $updated; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * Add keywordTranslation + * + * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation + * + * @return Keyword + */ + public function addKeywordTranslation(KeywordTranslation $keywordTranslation): Keyword { + $this->keyword_translations[] = $keywordTranslation; + + return $this; + } + + /** + * Remove keywordTranslation + * + * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation + * + * @return \Doctrine\Common\Collections\Collection + */ + public function removeKeywordTranslation(KeywordTranslation $keywordTranslation): Collection { + return $this->keyword_translations->removeElement($keywordTranslation); + } + + /** + * Get keywordTranslations + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getKeywordTranslations(): Collection { + return $this->keyword_translations; + } + + /** + * Add article + * + * @param \Rapsys\BlogBundle\Entity\Article $article + * + * @return Keyword + */ + public function addArticle(Article $article): Keyword { + $this->articles[] = $article; + + return $this; + } + + /** + * Remove article + * + * @param \Rapsys\BlogBundle\Entity\Article $article + * + * @return \Doctrine\Common\Collections\Collection + */ + public function removeArticle(Article $article): Collection { + return $this->articles->removeElement($article); + } + + /** + * Get articles + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getArticles(): Collection { + return $this->articles; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?Keyword { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof Keyword) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } }