src/Entity/JournalNewsTranslation.php line 34
<?php
namespace App\Entity;
use App\Entity\Trait\JournalUniqueSlugTrait;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\Get;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslationTrait,
App\Entity\Trait\Media\ImageThumbableTrait,
App\Entity\Trait\SlugTrait,
App\Entity\Interface\TranslationInterface,
App\Entity\Interface\ThumbableInterface,
App\Repository\JournalNewsTranslationRepository;
use App\Util\ClassUtils,
App\Enum\Language;
#[ApiResource(
security: 'is_granted("' . Journal::class . '")',
operations: [ new Get() ],
extraProperties: ['standard_put' => false],
)]
#[ORM\Entity(repositoryClass: JournalNewsTranslationRepository::class)]
class JournalNewsTranslation implements TranslationInterface, ThumbableInterface
{
use IdTrait,
UuidTrait,
TimestampableTrait,
TranslationTrait,
ImageThumbableTrait,
JournalUniqueSlugTrait;
#[ApiProperty(description: 'Title')]
#[Groups(['read', 'write'])]
#[ORM\Column(type: Types::STRING, length: 511, nullable: true)]
private ?string $title = null;
#[ApiProperty(description: 'Subtitle')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 511, nullable: true)]
private ?string $subtitle = null;
#[ApiProperty(description: 'Short lead')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $shortLead = null;
#[ApiProperty(description: 'Alt')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 511, nullable: true)]
private ?string $alt = null;
public function __construct(JournalNews $parent, Language $lang)
{
$this->setUuid();
$this->parent = $parent;
$this->lang = $lang;
$this->uniqueKey = sprintf('%s_%s', $parent->getParent()->getId(), $lang->value);
$this->thumbs = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addTranslation($this);
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getSubtitle(): ?string
{
return $this->subtitle;
}
public function setSubtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
public function getShortLead(): ?string
{
return $this->shortLead;
}
public function setShortLead(?string $shortLead): self
{
$this->shortLead = $shortLead;
return $this;
}
public function getAlt(): ?string
{
return $this->alt;
}
public function setAlt(?string $alt): self
{
$this->alt = $alt;
return $this;
}
public function clone(JournalNews $parent): self
{
$clone = clone $this;
$clone->id = null;
$clone->setUuid();
if ($clone->media) {
$clone->media = $this->media->clone();
$clone->media->setRelated(self::class . ':' . $clone->uuid->toString());
}
$clone->slug = null;
$clone->parent = $parent;
$clone->parent->addTranslation($clone);
ClassUtils::cloneCollection($this, $clone, 'thumbs');
$clone->createdAt = new \DateTimeImmutable();
$clone->updatedAt = new \DateTimeImmutable();
return $clone;
}
}