]> Raphaël G. Git Repositories - blogbundle/commitdiff
Strict types
authorRaphaël Gertz <git@rapsys.eu>
Fri, 10 Nov 2023 11:58:01 +0000 (12:58 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Fri, 10 Nov 2023 11:58:01 +0000 (12:58 +0100)
Add preUpdate member function
Add constructor

Entity/KeywordTranslation.php

index 61bc1f75b10fe4eafedc4911ce42e1716f6b1c34..0c69ec70e7a08e2028eaf2b35ca10e705b618c9d 100644 (file)
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys BlogBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * 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\ORM\Event\PreUpdateEventArgs;
+
 /**
  * KeywordTranslation
  */
-class KeywordTranslation
-{
-    /**
-     * @var integer
-     */
-    private $keyword_id;
-
-    /**
-     * @var integer
-     */
-    private $language_id;
-
-    /**
-     * @var string
-     */
-    private $title;
-
-    /**
-     * @var \DateTime
-     */
-    private $created;
-
-    /**
-     * @var \DateTime
-     */
-    private $updated;
-
-    /**
-     * @var \Rapsys\BlogBundle\Entity\Keyword
-     */
-    private $keyword;
-
-    /**
-     * @var \Rapsys\BlogBundle\Entity\Language
-     */
-    private $language;
-
-
-    /**
-     * Set keywordId
-     *
-     * @param integer $keywordId
-     *
-     * @return KeywordTranslation
-     */
-    public function setKeywordId($keywordId)
-    {
-        $this->keyword_id = $keywordId;
-
-        return $this;
-    }
-
-    /**
-     * Get keywordId
-     *
-     * @return integer
-     */
-    public function getKeywordId()
-    {
-        return $this->keyword_id;
-    }
-
-    /**
-     * Set languageId
-     *
-     * @param integer $languageId
-     *
-     * @return KeywordTranslation
-     */
-    public function setLanguageId($languageId)
-    {
-        $this->language_id = $languageId;
-
-        return $this;
-    }
-
-    /**
-     * Get languageId
-     *
-     * @return integer
-     */
-    public function getLanguageId()
-    {
-        return $this->language_id;
-    }
-
-    /**
-     * Set title
-     *
-     * @param string $title
-     *
-     * @return KeywordTranslation
-     */
-    public function setTitle($title)
-    {
-        $this->title = $title;
-
-        return $this;
-    }
-
-    /**
-     * Get title
-     *
-     * @return string
-     */
-    public function getTitle()
-    {
-        return $this->title;
-    }
-
-    /**
-     * Set created
-     *
-     * @param \DateTime $created
-     *
-     * @return KeywordTranslation
-     */
-    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 KeywordTranslation
-     */
-    public function setUpdated($updated)
-    {
-        $this->updated = $updated;
-
-        return $this;
-    }
-
-    /**
-     * Get updated
-     *
-     * @return \DateTime
-     */
-    public function getUpdated()
-    {
-        return $this->updated;
-    }
-
-    /**
-     * Set keyword
-     *
-     * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
-     *
-     * @return KeywordTranslation
-     */
-    public function setKeyword(\Rapsys\BlogBundle\Entity\Keyword $keyword = null)
-    {
-        $this->keyword = $keyword;
-
-        return $this;
-    }
-
-    /**
-     * Get keyword
-     *
-     * @return \Rapsys\BlogBundle\Entity\Keyword
-     */
-    public function getKeyword()
-    {
-        return $this->keyword;
-    }
-
-    /**
-     * Set language
-     *
-     * @param \Rapsys\BlogBundle\Entity\Language $language
-     *
-     * @return KeywordTranslation
-     */
-    public function setLanguage(\Rapsys\BlogBundle\Entity\Language $language = null)
-    {
-        $this->language = $language;
-
-        return $this;
-    }
-
-    /**
-     * Get language
-     *
-     * @return \Rapsys\BlogBundle\Entity\Language
-     */
-    public function getLanguage()
-    {
-        return $this->language;
-    }
-    /**
-     * @var string
-     */
-    private $slug;
-
-
-    /**
-     * Set slug
-     *
-     * @param string $slug
-     *
-     * @return KeywordTranslation
-     */
-    public function setSlug($slug)
-    {
-        $this->slug = $slug;
-
-        return $this;
-    }
-
-    /**
-     * Get slug
-     *
-     * @return string
-     */
-    public function getSlug()
-    {
-        return $this->slug;
-    }
-    /**
-     * @var string
-     */
-    private $description;
-
-
-    /**
-     * Set description
-     *
-     * @param string $description
-     *
-     * @return KeywordTranslation
-     */
-    public function setDescription($description)
-    {
-        $this->description = $description;
-
-        return $this;
-    }
-
-    /**
-     * Get description
-     *
-     * @return string
-     */
-    public function getDescription()
-    {
-        return $this->description;
-    }
+class KeywordTranslation {
+       /**
+        * @var int
+        */
+       private int $keyword_id;
+
+       /**
+        * @var string
+        */
+       private string $locale;
+
+       /**
+        * @var ?string
+        */
+       private ?string $description;
+
+       /**
+        * @var ?string
+        */
+       private ?string $slug;
+
+       /**
+        * @var ?string
+        */
+       private ?string $title;
+
+       /**
+        * @var \DateTime
+        */
+       private \DateTime $created;
+
+       /**
+        * @var \DateTime
+        */
+       private \DateTime $updated;
+
+       /**
+        * @var \Rapsys\BlogBundle\Entity\Keyword
+        */
+       private Keyword $keyword;
+
+       /**
+        * Constructor
+        */
+       public function __construct(Keyword $keyword, string $locale, ?string $description = null, ?string $slug = null, ?string $title = null) {
+               //Set defaults
+               $this->locale = $locale;
+               $this->description = $description;
+               $this->slug = $slug;
+               $this->title = $title;
+               $this->created = new \DateTime('now');
+               $this->updated = new \DateTime('now');
+               $this->setKeyword($keyword);
+       }
+
+       /**
+        * Get locale
+        *
+        * @return string
+        */
+       public function getLocale(): string {
+               return $this->locale;
+       }
+
+       /**
+        * Set locale
+        *
+        * @param string $locale
+        *
+        * @return KeywordTranslation
+        */
+       public function setLocale(string $locale): KeywordTranslation {
+               $this->locale = $locale;
+
+               return $this;
+       }
+
+       /**
+        * Get description
+        *
+        * @return ?string
+        */
+       public function getDescription(): ?string {
+               return $this->description;
+       }
+
+       /**
+        * Set description
+        *
+        * @param ?string $description
+        *
+        * @return KeywordTranslation
+        */
+       public function setDescription(?string $description): KeywordTranslation {
+               $this->description = $description;
+
+               return $this;
+       }
+
+       /**
+        * Get slug
+        *
+        * @return ?string
+        */
+       public function getSlug(): ?string {
+               return $this->slug;
+       }
+
+       /**
+        * Set slug
+        *
+        * @param ?string $slug
+        *
+        * @return KeywordTranslation
+        */
+       public function setSlug(?string $slug): KeywordTranslation {
+               $this->slug = $slug;
+
+               return $this;
+       }
+
+       /**
+        * Get title
+        *
+        * @return ?string
+        */
+       public function getTitle(): ?string {
+               return $this->title;
+       }
+
+       /**
+        * Set title
+        *
+        * @param ?string $title
+        *
+        * @return KeywordTranslation
+        */
+       public function setTitle(?string $title): KeywordTranslation {
+               $this->title = $title;
+
+               return $this;
+       }
+
+       /**
+        * Get created
+        *
+        * @return \DateTime
+        */
+       public function getCreated(): \DateTime {
+               return $this->created;
+       }
+
+       /**
+        * Set created
+        *
+        * @param \DateTime $created
+        *
+        * @return KeywordTranslation
+        */
+       public function setCreated(\DateTime $created): KeywordTranslation {
+               $this->created = $created;
+
+               return $this;
+       }
+
+       /**
+        * Get updated
+        *
+        * @return \DateTime
+        */
+       public function getUpdated(): \DateTime {
+               return $this->updated;
+       }
+
+       /**
+        * Set updated
+        *
+        * @param \DateTime $updated
+        *
+        * @return KeywordTranslation
+        */
+       public function setUpdated(\DateTime $updated): KeywordTranslation {
+               $this->updated = $updated;
+
+               return $this;
+       }
+
+       /**
+        * Get keyword
+        *
+        * @return \Rapsys\BlogBundle\Entity\Keyword
+        */
+       public function getKeyword(): Keyword {
+               return $this->keyword;
+       }
+
+       /**
+        * Set keyword
+        *
+        * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
+        *
+        * @return KeywordTranslation
+        */
+       public function setKeyword(Keyword $keyword): KeywordTranslation {
+               $this->keyword = $keyword;
+               $this->keyword_id = $keyword->getId();
+
+               return $this;
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function preUpdate(PreUpdateEventArgs $eventArgs): ?KeywordTranslation {
+               //Check that we have an snippet instance
+               if (($entity = $eventArgs->getEntity()) instanceof KeywordTranslation) {
+                       //Set updated value
+                       return $entity->setUpdated(new \DateTime('now'));
+               }
+       }
 }