vendor/kunstmaan/translator-bundle/Entity/Translation.php line 29

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\TranslatorBundle\Entity;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Kunstmaan\TranslatorBundle\Model\Translation as TranslationModel;
  6. use Kunstmaan\TranslatorBundle\Repository\TranslationRepository;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="Kunstmaan\TranslatorBundle\Repository\TranslationRepository")
  10.  * @ORM\Table(
  11.  *     name="kuma_translation",
  12.  *     uniqueConstraints={
  13.  *         @ORM\UniqueConstraint(name="keyword_per_locale", columns={"keyword", "locale", "domain"}),
  14.  *         @ORM\UniqueConstraint(name="translation_id_per_locale", columns={"translation_id", "locale"}),
  15.  *     },
  16.  *     indexes={@ORM\Index(name="idx_translation_locale_domain", columns={"locale", "domain"})}
  17.  * )
  18.  * @ORM\HasLifecycleCallbacks
  19.  */
  20. #[ORM\Entity(repositoryClassTranslationRepository::class)]
  21. #[ORM\Table(name'kuma_translation')]
  22. #[ORM\UniqueConstraint(name'keyword_per_locale'columns: ['keyword''locale''domain'])]
  23. #[ORM\UniqueConstraint(name'translation_id_per_locale'columns: ['translation_id''locale'])]
  24. #[ORM\Index(name'idx_translation_locale_domain'columns: ['locale''domain'])]
  25. #[ORM\HasLifecycleCallbacks]
  26. class Translation
  27. {
  28.     const FLAG_NEW 'new';
  29.     const FLAG_UPDATED 'updated';
  30.     const STATUS_DEPRECATED 'deprecated';
  31.     const STATUS_DISABLED 'disabled';
  32.     const STATUS_ENABLED 'enabled';
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\Column(type="integer")
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      */
  38.     #[ORM\Id]
  39.     #[ORM\Column(name'id'type'integer')]
  40.     #[ORM\GeneratedValue('AUTO')]
  41.     protected $id;
  42.     /**
  43.      * @ORM\Column(type="integer", name="translation_id", nullable=true)
  44.      */
  45.     #[ORM\Column(name'translation_id'type'integer'nullabletrue)]
  46.     #[Assert\NotBlank]
  47.     protected $translationId;
  48.     /**
  49.      * The translations keyword to use in your template or call from the translator
  50.      *
  51.      * @ORM\Column(type="string", nullable=true)
  52.      */
  53.     #[ORM\Column(name'keyword'type'string'nullabletrue)]
  54.     #[Assert\NotBlank]
  55.     protected $keyword;
  56.     /**
  57.      * The translations keyword to use in your template or call from the translator
  58.      *
  59.      * @ORM\Column(type="string", length=5, nullable=true)
  60.      */
  61.     #[ORM\Column(name'locale'type'string'length5nullabletrue)]
  62.     #[Assert\NotBlank]
  63.     protected $locale;
  64.     /**
  65.      * @var string
  66.      *
  67.      * @ORM\column(type="string", length=10, options={"default" : "enabled"})
  68.      */
  69.     #[ORM\Column(name'status'type'string'length10options: ['default' => self::STATUS_ENABLED])]
  70.     protected $status self::STATUS_ENABLED;
  71.     /**
  72.      * Location where the translation comes from
  73.      *
  74.      * @ORM\Column(type="string", length=50, nullable=true)
  75.      */
  76.     #[ORM\Column(name'file'type'string'length50nullabletrue)]
  77.     protected $file;
  78.     /**
  79.      * Translation
  80.      *
  81.      * @var string
  82.      *
  83.      * @ORM\Column(type="text", nullable=true)
  84.      */
  85.     #[ORM\Column(name'text'type'text'nullabletrue)]
  86.     #[Assert\NotBlank]
  87.     protected $text;
  88.     /**
  89.      * @ORM\Column(type="string", length=60, nullable=true)
  90.      */
  91.     #[ORM\Column(name'domain'type'string'length60nullabletrue)]
  92.     #[Assert\NotBlank]
  93.     #[Assert\Length(max60)]
  94.     protected $domain;
  95.     /**
  96.      * @var \DateTime
  97.      *
  98.      * @ORM\Column(type="datetime", name="created_at", nullable=true)
  99.      */
  100.     #[ORM\Column(name'created_at'type'datetime'nullabletrue)]
  101.     protected $createdAt;
  102.     /**
  103.      * @var \DateTime
  104.      *
  105.      * @ORM\Column(type="datetime", name="updated_at", nullable=true)
  106.      */
  107.     #[ORM\Column(name'updated_at'type'datetime'nullabletrue)]
  108.     protected $updatedAt;
  109.     /**
  110.      * A flag which defines the status of a specific translations ('updated', 'new', ..)
  111.      *
  112.      * @var string
  113.      *
  114.      * @ORM\Column(type="string", length=20, nullable=true)
  115.      */
  116.     #[ORM\Column(name'flag'type'string'length20nullabletrue)]
  117.     protected $flag;
  118.     /**
  119.      * @ORM\PrePersist
  120.      */
  121.     #[ORM\PrePersist]
  122.     public function prePersist()
  123.     {
  124.         $this->createdAt = new \DateTime();
  125.         $this->updatedAt = new \DateTime();
  126.         $this->flag self::FLAG_NEW;
  127.         return $this->id;
  128.     }
  129.     /**
  130.      * @ORM\PreUpdate
  131.      */
  132.     #[ORM\PreUpdate]
  133.     public function preUpdate()
  134.     {
  135.         $this->updatedAt = new \DateTime();
  136.         if ($this->flag === null) {
  137.             $this->flag self::FLAG_UPDATED;
  138.         }
  139.     }
  140.     /**
  141.      * @return string
  142.      */
  143.     public function getId()
  144.     {
  145.         return $this->id;
  146.     }
  147.     /**
  148.      * @param string $id
  149.      *
  150.      * @return Translation
  151.      */
  152.     public function setId($id)
  153.     {
  154.         $this->id $id;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return string
  159.      */
  160.     public function getKeyword()
  161.     {
  162.         return $this->keyword;
  163.     }
  164.     /**
  165.      * @param string $keyword
  166.      *
  167.      * @return Translation
  168.      */
  169.     public function setKeyword($keyword)
  170.     {
  171.         $this->keyword $keyword;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return string
  176.      */
  177.     public function getLocale()
  178.     {
  179.         return $this->locale;
  180.     }
  181.     /**
  182.      * @param string $locale
  183.      *
  184.      * @return Translation
  185.      */
  186.     public function setLocale($locale)
  187.     {
  188.         $this->locale $locale;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return string
  193.      */
  194.     public function getFile()
  195.     {
  196.         return $this->file;
  197.     }
  198.     /**
  199.      * @param string $file
  200.      *
  201.      * @return Translation
  202.      */
  203.     public function setFile($file)
  204.     {
  205.         $this->file $file;
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return string
  210.      */
  211.     public function getText()
  212.     {
  213.         return $this->text;
  214.     }
  215.     /**
  216.      * @param string $text
  217.      *
  218.      * @return Translation
  219.      */
  220.     public function setText($text)
  221.     {
  222.         $this->text $text;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return string
  227.      */
  228.     public function getDomain()
  229.     {
  230.         return $this->domain;
  231.     }
  232.     /**
  233.      * @param string $domain
  234.      *
  235.      * @return Translation
  236.      */
  237.     public function setDomain($domain)
  238.     {
  239.         $this->domain $domain;
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return \DateTime
  244.      */
  245.     public function getCreatedAt()
  246.     {
  247.         return $this->createdAt;
  248.     }
  249.     /**
  250.      * @return Translation
  251.      */
  252.     public function setCreatedAt(\DateTime $createdAt)
  253.     {
  254.         $this->createdAt $createdAt;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return \DateTime
  259.      */
  260.     public function getUpdatedAt()
  261.     {
  262.         return $this->updatedAt;
  263.     }
  264.     /**
  265.      * @return Translation
  266.      */
  267.     public function setUpdatedAt(\DateTime $updatedAt)
  268.     {
  269.         $this->updatedAt $updatedAt;
  270.         return $this;
  271.     }
  272.     /**
  273.      * @return string
  274.      */
  275.     public function getFlag()
  276.     {
  277.         return $this->flag;
  278.     }
  279.     /**
  280.      * @param string $flag
  281.      *
  282.      * @return Translation
  283.      */
  284.     public function setFlag($flag)
  285.     {
  286.         $this->flag $flag;
  287.         return $this;
  288.     }
  289.     /**
  290.      * @param string $translationId
  291.      *
  292.      * @return Translation
  293.      */
  294.     public function setTranslationId($translationId)
  295.     {
  296.         $this->translationId $translationId;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return string
  301.      */
  302.     public function getTranslationId()
  303.     {
  304.         return $this->translationId;
  305.     }
  306.     /**
  307.      * @return string
  308.      */
  309.     public function getStatus()
  310.     {
  311.         return $this->status;
  312.     }
  313.     /**
  314.      * @param string $status
  315.      *
  316.      * @return Translation
  317.      */
  318.     public function setStatus($status)
  319.     {
  320.         $this->status $status;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return bool
  325.      */
  326.     public function isDisabled()
  327.     {
  328.         return $this->getStatus() === self::STATUS_DISABLED;
  329.     }
  330.     /**
  331.      * @return bool
  332.      */
  333.     public function isDeprecated()
  334.     {
  335.         return $this->getStatus() === self::STATUS_DEPRECATED;
  336.     }
  337.     /**
  338.      * @param int $id
  339.      *
  340.      * @return TranslationModel
  341.      */
  342.     public function getTranslationModel($id null)
  343.     {
  344.         $translationModel = new TranslationModel();
  345.         $translationModel->setKeyword($this->getKeyword());
  346.         $translationModel->setDomain($this->getDomain());
  347.         $translationModel->addText($this->getLocale(), $this->getText(), $id);
  348.         return $translationModel;
  349.     }
  350. }