<?php
namespace Roothirsch\CoreBundle\Translation\Entity;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ORM\Entity
* @ORM\Table(name="translation_unit")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
* @ApiResource(
* shortName="Translation/Unit",
* itemOperations={
* "get",
* "put",
* "delete",
* "translate"={
* "route_name": "api_translation_units_translate_item",
* "method"="put",
* "requirements"={"id"="[a-z0-9\-]+", "language"="[a-z]+"},
* "swagger_context" = {
* "parameters" = {
* {
* "name" = "id",
* "in" = "path",
* "required" = "true",
* "type" = "string"
* },
* {
* "name" = "language",
* "in" = "path",
* "required" = "true",
* "type" = "string"
* }
* }
* }
* }
* },
* collectionOperations={
* "get"
* },
* attributes={
* "pagination_enabled"=true
* }
* )
* @ApiFilter(SearchFilter::class, strategy="partial", properties={"scope.namespace": "exact", "language.languageKey": "exact", "translationKey": "partial"})
*/
class TranslationUnit
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
* @ORM\Column(name="translation_key",type="text",length=255)
* @Assert\NotBlank()
*/
private $key;
/**
* @ORM\Column(name="translation_value",type="text", nullable=true)
* @var string
*/
private $value;
/**
* @var string
* @ORM\Column(name="note",type="text", nullable=true)
*/
private $note;
/**
* @var string
* @ORM\Column(name="context",type="text", nullable=true)
*/
private $context;
/**
* The DateTime of the creation date
* @ORM\Column(type="datetime")
* @var \DateTime $created
* @Gedmo\Timestampable(on="create")
*/
private $created;
/**
* The DateTime of the creation date
* @ORM\Column(type="datetime",nullable=true)
* @var \DateTime $created
* @Gedmo\Timestampable(on="update")
*/
private $lastModified;
/**
* The DateTime of the deletion date
* @ORM\Column(type="datetime",nullable=true)
* @var \DateTime $created
*/
private $deletedAt;
/**
* @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationUnit", inversedBy="translations", cascade={"persist"}, fetch="EAGER")
* @var TranslationUnit
*/
private $source;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationUnit", mappedBy="source", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $translations;
/**
* @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationScope", inversedBy="translations", fetch="EAGER")
* @ApiSubresource
* @var Scope
*/
private $scope;
/**
* @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\Language", fetch="EAGER", cascade={"remove"})
* @ORM\JoinColumn(onDelete="CASCADE")
* @var Language
* @ApiSubresource
*/
private $language;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $complete = false;
public function __construct()
{
$this->translations = new ArrayCollection();
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @param string $key
*/
public function setKey($key)
{
$this->key = $key;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @param string $value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getNote()
{
return $this->note;
}
/**
* @param string $note
*/
public function setNote($note)
{
$this->note = $note;
}
/**
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* @param \DateTime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* @return \DateTime
*/
public function getLastModified()
{
return $this->lastModified;
}
/**
* @param \DateTime $lastModified
*/
public function setLastModified($lastModified)
{
$this->lastModified = $lastModified;
}
/**
* @return \DateTime
*/
public function getDeletedAt()
{
return $this->deletedAt;
}
/**
* @param \DateTime $deletedAt
*/
public function setDeletedAt($deletedAt)
{
$this->deletedAt = $deletedAt;
}
/**
* @return Scope
*/
public function getScope()
{
return $this->scope;
}
/**
* @param Scope $scope
*/
public function setScope($scope)
{
$this->scope = $scope;
}
/**
* @return Language
*/
public function getLanguage()
{
return $this->language;
}
/**
* @param Language $language
*/
public function setLanguage($language)
{
$this->language = $language;
}
/**
* @return TranslationUnit
*/
public function getSource()
{
return $this->source;
}
/**
* @param TranslationUnit $source
*/
public function setSource($source)
{
$this->source = $source;
$source->getTranslations()->add($this);
}
/**
* @return mixed
*/
public function getTranslations()
{
return $this->translations;
}
/**
* @return mixed
*/
public function getTranslationFor($language)
{
if ($this->getLanguage() == $language || $this->getLanguage()->getLanguageKey() == $language) {
return $this->getValue();
}
foreach ($this->translations as $translation) {
if ($translation->getLanguage() == $language || $translation->getLanguage()->getLanguageKey() == $language) {
return $translation->getValue();
}
}
}
/**
* @param mixed $translations
*/
public function setTranslations($translations)
{
$this->translations = $translations;
}
/**
* @param TranslationUnit $translationUnit
*/
public function addTranslation($translationUnit)
{
$this->translations->add($translationUnit);
}
/**
* @return string
*/
public function getContext()
{
return $this->context;
}
/**
* @param string $context
*/
public function setContext($context)
{
$this->context = $context;
}
/**
* @return bool
*/
public function isComplete(): bool
{
return $this->complete;
}
/**
* @param bool $complete
*/
public function setComplete(bool $complete): void
{
$this->complete = $complete;
}
}