From: Raphaël Gertz Date: Fri, 10 Nov 2023 12:01:30 +0000 (+0100) Subject: Add user translation entity X-Git-Tag: 0.1~21 X-Git-Url: https://git.rapsys.eu/blogbundle/commitdiff_plain/3a830cf40fb7c91fcce62fbe466cf243be2a7e52?ds=sidebyside Add user translation entity --- diff --git a/Entity/UserTranslation.php b/Entity/UserTranslation.php new file mode 100644 index 0000000..0774ff5 --- /dev/null +++ b/Entity/UserTranslation.php @@ -0,0 +1,183 @@ + + * + * 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; + +/** + * UserTranslation + */ +class UserTranslation { + /** + * @var int + */ + private int $user_id; + + /** + * @var string + */ + private string $locale; + + /** + * @var string + */ + private ?string $description; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * @var \Rapsys\BlogBundle\Entity\User + */ + private User $user; + + /** + * Constructor + */ + public function __construct(User $user, string $locale, ?string $description = null) { + //Set defaults + $this->locale = $locale; + $this->description = $description; + $this->created = new \DateTime('now'); + $this->updated = new \DateTime('now'); + $this->setUser($user); + } + + /** + * Get locale + * + * @return string + */ + public function getLocale(): string { + return $this->locale; + } + + /** + * Set locale + * + * @param string $locale + * + * @return UserTranslation + */ + public function setLocale(string $locale): UserTranslation { + $this->locale = $locale; + + return $this; + } + + /** + * Get description + * + * @return ?string + */ + public function getDescription(): ?string { + return $this->description; + } + + /** + * Set description + * + * @param ?string $description + * + * @return UserTranslation + */ + public function setDescription(?string $description): UserTranslation { + $this->description = $description; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return UserTranslation + */ + public function setCreated(\DateTime $created): UserTranslation { + $this->created = $created; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return UserTranslation + */ + public function setUpdated(\DateTime $updated): UserTranslation { + $this->updated = $updated; + + return $this; + } + + /** + * Get user + * + * @return \Rapsys\BlogBundle\Entity\User + */ + public function getUser(): User { + return $this->user; + } + + /** + * Set user + * + * @param \Rapsys\BlogBundle\Entity\User $user + * + * @return UserTranslation + */ + public function setUser(User $user): UserTranslation { + $this->user = $user; + $this->user_id = $user->getId(); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?UserTranslation { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof UserTranslation) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } +}