<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CertificateTemplateRepository;
use App\Entity\Interfaces\ContainerMappedInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_OPERATOR')", "filters"={"translation.groups"}},
* normalizationContext={"groups"={"CertificateTemplate:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"CertificateTemplate:Write", "certificateTemplateTranslations"}},
* collectionOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('IS_CO_OPR', object)"},
* "put"={"security"="is_granted('IS_CO_OPR', object)"},
* "patch"={"security"="is_granted('IS_CO_OPR', object)"},
* "delete"={"security"="is_granted('IS_CO_OPR', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"container.id": "exact", "type": "exact", "name": "partial"})
* @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
* @ORM\Entity(repositoryClass=CertificateTemplateRepository::class)
*/
class CertificateTemplate extends AbstractTranslatable implements ContainerMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\OneToMany(targetEntity="CertificateTemplateTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
*
* @Groups({"CertificateTemplate:Write", "CertificateTemplateTranslationGroup"})
* @Assert\Valid()
*/
protected $translations;
/**
* @Groups({"CertificateTemplate:Read"})
*/
private $content;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"CertificateTemplate:Read", "Conference:Read", "ElCourse:Read", "Certificate:Read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=32)
* @Groups({"CertificateTemplate:Read", "CertificateTemplate:Write", "Certificate:Read"})
*/
private $type;
public const CTTYPE_CONFERENCE = 'CONFERENCE';
public const CTTYPE_COURSE = 'COURSE';
public const CTTYPEINFO_CONFERENCE = [
'DOMAIN_NAME' => '##DOMAIN_NAME##',
'PROJECT_NAME' => '##PROJECT_NAME##',
'LOGO_MAIN' => '##LOGO_MAIN##',
'LOGO_EXPETSHARE' => '##LOGO_EXPERTSHARE##',
'COLOR_PRIMARY' => '##COLOR_PRIMARY##',
'COLOR_SECONDARY' => '##COLOR_SECONDARY##',
'COLOR_PRIMARY_BTN_BG' => '##COLOR_PRIMARY_BTN_BG##',
'COLOR_PRIMARY_BTN_TEXT' => '##COLOR_PRIMARY_BTN_TEXT##',
'USER_FIRSTNAME' => '##USER_FIRSTNAME##',
'USER_LASTNAME' => '##USER_LASTNAME##',
'USER_ACADEMIC_TITLE' => '##USER_ACADEMIC_TITLE##',
'CONFERENCE_ID' => '##CONFERENCE_ID##',
'CONFERENCE_TITLE' => '##CONFERENCE_TITLE##',
'CONFERENCE_START' => '##CONFERENCE_START##',
'CONFERENCE_END' => '##CONFERENCE_END##',
'CONFERENCE_TIMEZONE' => '##CONFERENCE_TIMEZONE##',
'CONFERENCE_URL' => '##CONFERENCE_URL##',
'CONFERENCE_CREDITS' => '##CONFERENCE_CREDITS##',
'CONFERENCE_ALL_CREDITS' => '##CONFERENCE_ALL_CREDITS##',
'CONFERENCE_BULLET_POINTS' => '##CONFERENCE_BULLET_POINTS##',
'CERTIFICATE_DATE' => '##CERTIFICATE_DATE##',
];
public const CTTYPEINFO_COURSE = [
'DOMAIN_NAME' => '##DOMAIN_NAME##',
'PROJECT_NAME' => '##PROJECT_NAME##',
'LOGO_MAIN' => '##LOGO_MAIN##',
'LOGO_EXPETSHARE' => '##LOGO_EXPERTSHARE##',
'COLOR_PRIMARY' => '##COLOR_PRIMARY##',
'COLOR_SECONDARY' => '##COLOR_SECONDARY##',
'COLOR_PRIMARY_BTN_BG' => '##COLOR_PRIMARY_BTN_BG##',
'COLOR_PRIMARY_BTN_TEXT' => '##COLOR_PRIMARY_BTN_TEXT##',
'USER_FIRSTNAME' => '##USER_FIRSTNAME##',
'USER_LASTNAME' => '##USER_LASTNAME##',
'USER_ACADEMIC_TITLE' => '##USER_ACADEMIC_TITLE##',
'COURSE_ID' => '##COURSE_ID##',
'COURSE_NAME' => '##COURSE_NAME##',
'COURSE_START' => '##COURSE_START##',
'COURSE_END' => '##COURSE_END##',
'COURSE_URL' => '##COURSE_URL##',
'COURSE_CREDITS' => '##COURSE_CREDITS##',
'COURSE_ALL_CREDITS' => '##COURSE_ALL_CREDITS##',
'COURSE_BULLET_POINTS' => '##COURSE_BULLET_POINTS##',
'CERTIFICATE_DATE' => '##CERTIFICATE_DATE##',
];
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"CertificateTemplate:Write"})
*/
private $container;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"CertificateTemplate:Read", "CertificateTemplate:Write", "Conference:Read", "ElCourse:Read", "Certificate:Read"})
*
* @Assert\NotBlank(message="validation.certificateTemplate:name.notBlank")
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=Certificate::class, mappedBy="certificateTemplate", orphanRemoval=true)
*/
private $certificates;
public function __construct()
{
parent::__construct();
$this->certificates = new ArrayCollection();
}
protected function createTranslation(): TranslationInterface
{
return new CertificateTemplateTranslation();
}
public function getContent(): ?string
{
return $this->getTranslation()->getContent();
}
public function setContent(string $content): self
{
$this->getTranslation()->setContent($content);
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection<int, Certificate>
*/
public function getCertificates(): Collection
{
return $this->certificates;
}
public function addCertificate(Certificate $certificate): self
{
if (!$this->certificates->contains($certificate)) {
$this->certificates[] = $certificate;
$certificate->setCertificateTemplate($this);
}
return $this;
}
public function removeCertificate(Certificate $certificate): self
{
if ($this->certificates->removeElement($certificate)) {
// set the owning side to null (unless already changed)
if ($certificate->getCertificateTemplate() === $this) {
$certificate->setCertificateTemplate(null);
}
}
return $this;
}
}