src/Entity/CertificateTemplate.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use ApiPlatform\Core\Annotation\ApiFilter;
  7. use App\Entity\Traits\TimestampableEntity;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use App\Repository\CertificateTemplateRepository;
  10. use App\Entity\Interfaces\ContainerMappedInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  15. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  16. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  17. /**
  18.  * @ApiResource(
  19.  *      attributes={"security"="is_granted('ROLE_OPERATOR')", "filters"={"translation.groups"}},
  20.  *      normalizationContext={"groups"={"CertificateTemplate:Read"}, "skip_null_values"=false},
  21.  *      denormalizationContext={"groups"={"CertificateTemplate:Write", "certificateTemplateTranslations"}},
  22.  *      collectionOperations={
  23.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  24.  *          "post"
  25.  *      },
  26.  *      itemOperations={
  27.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  28.  *          "put"={"security"="is_granted('IS_CO_OPR', object)"},
  29.  *          "patch"={"security"="is_granted('IS_CO_OPR', object)"},
  30.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"}
  31.  *     }
  32.  * )
  33.  * @ApiFilter(SearchFilter::class, properties={"container.id": "exact", "type": "exact", "name": "partial"})
  34.  * @ApiFilter(OrderFilter::class, properties={"id", "name": "ASC"})
  35.  * @ORM\Entity(repositoryClass=CertificateTemplateRepository::class)
  36.  */
  37. class CertificateTemplate extends AbstractTranslatable implements ContainerMappedInterface
  38. {
  39.     /**
  40.      * Hook timestampable behavior
  41.      * updates createdAt, updatedAt fields
  42.      */
  43.     use TimestampableEntity;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity="CertificateTemplateTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  46.      *
  47.      * @Groups({"CertificateTemplate:Write", "CertificateTemplateTranslationGroup"})
  48.      * @Assert\Valid()
  49.      */
  50.     protected $translations;
  51.     /**
  52.      * @Groups({"CertificateTemplate:Read"})
  53.      */
  54.     private $content;
  55.     /**
  56.      * @ORM\Id
  57.      * @ORM\GeneratedValue
  58.      * @ORM\Column(type="integer")
  59.      * @Groups({"CertificateTemplate:Read", "Conference:Read", "ElCourse:Read", "Certificate:Read"})
  60.      */
  61.     private $id;
  62.     /**
  63.      * @ORM\Column(type="string", length=32)
  64.      * @Groups({"CertificateTemplate:Read", "CertificateTemplate:Write", "Certificate:Read"})
  65.      */
  66.     private $type;
  67.     public const CTTYPE_CONFERENCE 'CONFERENCE';
  68.     public const CTTYPE_COURSE 'COURSE';
  69.     public const CTTYPEINFO_CONFERENCE = [
  70.         'DOMAIN_NAME' => '##DOMAIN_NAME##',
  71.         'PROJECT_NAME' => '##PROJECT_NAME##',
  72.         'LOGO_MAIN' => '##LOGO_MAIN##',
  73.         'LOGO_EXPETSHARE' => '##LOGO_EXPERTSHARE##',
  74.         'COLOR_PRIMARY' => '##COLOR_PRIMARY##',
  75.         'COLOR_SECONDARY' => '##COLOR_SECONDARY##',
  76.         'COLOR_PRIMARY_BTN_BG' => '##COLOR_PRIMARY_BTN_BG##',
  77.         'COLOR_PRIMARY_BTN_TEXT' => '##COLOR_PRIMARY_BTN_TEXT##',
  78.         'USER_FIRSTNAME' => '##USER_FIRSTNAME##',
  79.         'USER_LASTNAME' => '##USER_LASTNAME##',
  80.         'USER_ACADEMIC_TITLE' => '##USER_ACADEMIC_TITLE##',
  81.         'CONFERENCE_ID' => '##CONFERENCE_ID##',
  82.         'CONFERENCE_TITLE' => '##CONFERENCE_TITLE##',
  83.         'CONFERENCE_START' => '##CONFERENCE_START##',
  84.         'CONFERENCE_END' => '##CONFERENCE_END##',
  85.         'CONFERENCE_TIMEZONE' => '##CONFERENCE_TIMEZONE##',
  86.         'CONFERENCE_URL' => '##CONFERENCE_URL##',
  87.         'CONFERENCE_CREDITS' => '##CONFERENCE_CREDITS##',
  88.         'CONFERENCE_ALL_CREDITS' => '##CONFERENCE_ALL_CREDITS##',
  89.         'CONFERENCE_BULLET_POINTS' => '##CONFERENCE_BULLET_POINTS##',
  90.         'CERTIFICATE_DATE' => '##CERTIFICATE_DATE##',
  91.     ];
  92.     public const CTTYPEINFO_COURSE = [
  93.         'DOMAIN_NAME' => '##DOMAIN_NAME##',
  94.         'PROJECT_NAME' => '##PROJECT_NAME##',
  95.         'LOGO_MAIN' => '##LOGO_MAIN##',
  96.         'LOGO_EXPETSHARE' => '##LOGO_EXPERTSHARE##',
  97.         'COLOR_PRIMARY' => '##COLOR_PRIMARY##',
  98.         'COLOR_SECONDARY' => '##COLOR_SECONDARY##',
  99.         'COLOR_PRIMARY_BTN_BG' => '##COLOR_PRIMARY_BTN_BG##',
  100.         'COLOR_PRIMARY_BTN_TEXT' => '##COLOR_PRIMARY_BTN_TEXT##',
  101.         'USER_FIRSTNAME' => '##USER_FIRSTNAME##',
  102.         'USER_LASTNAME' => '##USER_LASTNAME##',
  103.         'USER_ACADEMIC_TITLE' => '##USER_ACADEMIC_TITLE##',
  104.         'COURSE_ID' => '##COURSE_ID##',
  105.         'COURSE_NAME' => '##COURSE_NAME##',
  106.         'COURSE_START' => '##COURSE_START##',
  107.         'COURSE_END' => '##COURSE_END##',
  108.         'COURSE_URL' => '##COURSE_URL##',
  109.         'COURSE_CREDITS' => '##COURSE_CREDITS##',
  110.         'COURSE_ALL_CREDITS' => '##COURSE_ALL_CREDITS##',
  111.         'COURSE_BULLET_POINTS' => '##COURSE_BULLET_POINTS##',
  112.         'CERTIFICATE_DATE' => '##CERTIFICATE_DATE##',
  113.     ];
  114.     /**
  115.      * @ORM\ManyToOne(targetEntity=Container::class)
  116.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  117.      *
  118.      * @Groups({"CertificateTemplate:Write"})
  119.      */
  120.     private $container;
  121.     /**
  122.      * @ORM\Column(type="string", length=255)
  123.      * @Groups({"CertificateTemplate:Read", "CertificateTemplate:Write", "Conference:Read", "ElCourse:Read", "Certificate:Read"})
  124.      *
  125.      * @Assert\NotBlank(message="validation.certificateTemplate:name.notBlank")
  126.      */
  127.     private $name;
  128.     /**
  129.      * @ORM\OneToMany(targetEntity=Certificate::class, mappedBy="certificateTemplate", orphanRemoval=true)
  130.      */
  131.     private $certificates;
  132.     public function __construct()
  133.     {
  134.         parent::__construct();
  135.         $this->certificates = new ArrayCollection();
  136.     }
  137.     protected function createTranslation(): TranslationInterface
  138.     {
  139.         return new CertificateTemplateTranslation();
  140.     }
  141.     public function getContent(): ?string
  142.     {
  143.         return $this->getTranslation()->getContent();
  144.     }
  145.     public function setContent(string $content): self
  146.     {
  147.         $this->getTranslation()->setContent($content);
  148.         return $this;
  149.     }
  150.     public function getId(): ?int
  151.     {
  152.         return $this->id;
  153.     }
  154.     public function getType(): ?string
  155.     {
  156.         return $this->type;
  157.     }
  158.     public function setType(string $type): self
  159.     {
  160.         $this->type $type;
  161.         return $this;
  162.     }
  163.     public function getContainer(): ?Container
  164.     {
  165.         return $this->container;
  166.     }
  167.     public function setContainer(?Container $container): self
  168.     {
  169.         $this->container $container;
  170.         return $this;
  171.     }
  172.     public function getName(): ?string
  173.     {
  174.         return $this->name;
  175.     }
  176.     public function setName(string $name): self
  177.     {
  178.         $this->name $name;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return Collection<int, Certificate>
  183.      */
  184.     public function getCertificates(): Collection
  185.     {
  186.         return $this->certificates;
  187.     }
  188.     public function addCertificate(Certificate $certificate): self
  189.     {
  190.         if (!$this->certificates->contains($certificate)) {
  191.             $this->certificates[] = $certificate;
  192.             $certificate->setCertificateTemplate($this);
  193.         }
  194.         return $this;
  195.     }
  196.     public function removeCertificate(Certificate $certificate): self
  197.     {
  198.         if ($this->certificates->removeElement($certificate)) {
  199.             // set the owning side to null (unless already changed)
  200.             if ($certificate->getCertificateTemplate() === $this) {
  201.                 $certificate->setCertificateTemplate(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206. }