<?php
namespace App\Admin\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
/**
* StdTranslations
*/
#[ORM\Table(name: 'std_translations')]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdTranslationsRepository')]
#[ORM\HasLifecycleCallbacks]
class StdTranslations
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false, options: ['unsigned' => true, 'comment' => 'Unique identifier'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'label', type: 'string', length: 100, nullable: false, options: ['comment' => 'ISO 639 Label'])]
private $label;
/**
* @var string
*/
#[ORM\Column(name: 'domain', type: 'string', nullable: true, options: ['comment' => 'ISO 639 Translation'])]
private $domain;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP', 'comment' => 'Date and time of the record creation'])]
private $createdDate = 'CURRENT_TIMESTAMP';
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['default' => 'CURRENT_TIMESTAMP', 'comment' => 'Date and time the record was last updated'])]
private $updatedDate = 'CURRENT_TIMESTAMP';
/**
* @var StdUsers
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $createdBy;
/**
* @var StdUsers
*/
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $updatedBy;
#[ORM\OneToMany(mappedBy: 'translation', targetEntity: StdTranslationsContent::class, orphanRemoval: true)]
private Collection $contents;
public function __construct()
{
$this->contents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getDomain(): ?string
{
return $this->domain;
}
public function setDomain(string $domain): self
{
$this->domain = $domain;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
public function getCreatedBy(): ?StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?StdUsers $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?StdUsers
{
return $this->updatedBy;
}
public function setUpdatedBy(?StdUsers $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
/**
* @return Collection<int, StdTranslationsContent>
*/
public function getContents(): Collection
{
return $this->contents;
}
public function addContent(StdTranslationsContent $content): self
{
if (!$this->contents->contains($content)) {
$this->contents->add($content);
$content->setTranslation($this);
}
return $this;
}
public function removeContent(StdTranslationsContent $content): self
{
if ($this->contents->removeElement($content)) {
// set the owning side to null (unless already changed)
if ($content->getTranslation() === $this) {
$content->setTranslation(null);
}
}
return $this;
}
/**
* @return StdTranslationsContent|null
*/
public function getLocalizedContents(StdLanguages $locale): ?StdTranslationsContent
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("languageCode", $locale))->setMaxResults(1);
$content = $this->getContents()?->matching($criteria)?->first();
return $content ? $content : null;
}
#[ORM\PreUpdate]
public function setUpdated()
{
$this->setUpdatedDate(new \DateTime());
}
#[ORM\PrePersist]
public function setCreated()
{
$this->setUpdatedDate(new \DateTime());
$this->setCreatedDate(new \DateTime());
}
}