src/Admin/Entity/StdTranslations.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * StdTranslations
  9.  */
  10. #[ORM\Table(name'std_translations')]
  11. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdTranslationsRepository')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class StdTranslations
  14. {
  15.     /**
  16.      * @var int
  17.      */
  18.     #[ORM\Column(name'id'type'integer'nullablefalseoptions: ['unsigned' => true'comment' => 'Unique identifier'])]
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  21.     private $id;
  22.     /**
  23.      * @var string
  24.      */
  25.     #[ORM\Column(name'label'type'string'length100nullablefalseoptions: ['comment' => 'ISO 639 Label'])]
  26.     private $label;
  27.     /**
  28.      * @var string
  29.      */
  30.     #[ORM\Column(name'domain'type'string'nullabletrueoptions: ['comment' => 'ISO 639 Translation'])]
  31.     private $domain;
  32.     /**
  33.      * @var \DateTime
  34.      */
  35.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['default' => 'CURRENT_TIMESTAMP''comment' => 'Date and time of the record creation'])]
  36.     private $createdDate 'CURRENT_TIMESTAMP';
  37.     /**
  38.      * @var \DateTime
  39.      */
  40.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['default' => 'CURRENT_TIMESTAMP''comment' => 'Date and time the record was last updated'])]
  41.     private $updatedDate 'CURRENT_TIMESTAMP';
  42.     /**
  43.      * @var StdUsers
  44.      */
  45.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  46.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  47.     private $createdBy;
  48.     /**
  49.      * @var StdUsers
  50.      */
  51.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  52.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  53.     private $updatedBy;
  54.     #[ORM\OneToMany(mappedBy'translation'targetEntityStdTranslationsContent::class, orphanRemovaltrue)]
  55.     private Collection $contents;
  56.     public function __construct()
  57.     {
  58.         $this->contents = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getLabel(): ?string
  65.     {
  66.         return $this->label;
  67.     }
  68.     public function setLabel(string $label): self
  69.     {
  70.         $this->label $label;
  71.         return $this;
  72.     }
  73.     public function getDomain(): ?string
  74.     {
  75.         return $this->domain;
  76.     }
  77.     public function setDomain(string $domain): self
  78.     {
  79.         $this->domain $domain;
  80.         return $this;
  81.     }
  82.     public function getCreatedDate(): ?\DateTimeInterface
  83.     {
  84.         return $this->createdDate;
  85.     }
  86.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  87.     {
  88.         $this->createdDate $createdDate;
  89.         return $this;
  90.     }
  91.     public function getUpdatedDate(): ?\DateTimeInterface
  92.     {
  93.         return $this->updatedDate;
  94.     }
  95.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  96.     {
  97.         $this->updatedDate $updatedDate;
  98.         return $this;
  99.     }
  100.     public function getCreatedBy(): ?StdUsers
  101.     {
  102.         return $this->createdBy;
  103.     }
  104.     public function setCreatedBy(?StdUsers $createdBy): self
  105.     {
  106.         $this->createdBy $createdBy;
  107.         return $this;
  108.     }
  109.     public function getUpdatedBy(): ?StdUsers
  110.     {
  111.         return $this->updatedBy;
  112.     }
  113.     public function setUpdatedBy(?StdUsers $updatedBy): self
  114.     {
  115.         $this->updatedBy $updatedBy;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, StdTranslationsContent>
  120.      */
  121.     public function getContents(): Collection
  122.     {
  123.         return $this->contents;
  124.     }
  125.     public function addContent(StdTranslationsContent $content): self
  126.     {
  127.         if (!$this->contents->contains($content)) {
  128.             $this->contents->add($content);
  129.             $content->setTranslation($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeContent(StdTranslationsContent $content): self
  134.     {
  135.         if ($this->contents->removeElement($content)) {
  136.             // set the owning side to null (unless already changed)
  137.             if ($content->getTranslation() === $this) {
  138.                 $content->setTranslation(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return StdTranslationsContent|null
  145.      */
  146.     public function getLocalizedContents(StdLanguages $locale): ?StdTranslationsContent
  147.     {
  148.         $criteria Criteria::create()->where(Criteria::expr()->eq("languageCode"$locale))->setMaxResults(1);
  149.         $content $this->getContents()?->matching($criteria)?->first();
  150.         return $content $content null;
  151.     }
  152.     #[ORM\PreUpdate]
  153.     public function setUpdated()
  154.     {
  155.         $this->setUpdatedDate(new \DateTime());
  156.     }
  157.     
  158.     #[ORM\PrePersist]
  159.     public function setCreated()
  160.     {
  161.         $this->setUpdatedDate(new \DateTime());
  162.         $this->setCreatedDate(new \DateTime());
  163.     }
  164. }