<?php
namespace App\Entity\Gos\Uniqskills;
use App\Entity\Gos\CertificatePath;
use App\Entity\Gos\Events;
use App\Entity\Gos\ProductVariant;
use App\Enum\CertificateTypes;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\CertificateRepository")
* @Vich\Uploadable
* @ORM\HasLifecycleCallbacks
*/
class Certificate
{
/**
* @var integer
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string")
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=191, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $pageOrientationLandscape;
/**
* @ORM\OneToMany(targetEntity="CertificateElement", mappedBy="certificate", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $certificateElement;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $surveyUrl;
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __toString()
{
return (string) $this->name;
}
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Assert\File(
* maxSize="5M",
* mimeTypes={"application/pdf", "application/x-pdf"}
* )
*
* @Vich\UploadableField(mapping="product_image", fileNameProperty="pdfName")
*
* @var File
*/
private $file;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $pdfName;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\Uniqskills\Module", inversedBy="certificate", cascade={"persist", "remove"})
*/
private $module;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Gos\Uniqskills\Course", inversedBy="certificates")
*/
private $course;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $validForDays;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\UserCertificate", mappedBy="certificate")
*/
private $userCertificates;
/**
* @ORM\ManyToOne(targetEntity=Events::class, inversedBy="certificates", cascade={"persist", "remove"})
*/
private $event;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $omitConditionals;
/**
* @ORM\ManyToMany(targetEntity=ProductVariant::class, mappedBy="certificates")
*/
private $productVariants;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isFastCertificate;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $availableFrom;
/**
* @ORM\OneToMany(targetEntity=CertificatePath::class, mappedBy="certificate")
*/
private $certificatePaths;
/**
* @ORM\Column(type="integer", options={"default": 0})
*/
private $type = 0;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $accessForPaidOnly;
public function isFastCertificate(): bool
{
if ($this->getIsFastCertificate())
{
return true;
}
return $this->type === CertificateTypes::FAST;
}
public function isPaidCertificate(): bool
{
return $this->type === CertificateTypes::PAID;
}
public function isPortalCertificate(): bool
{
return $this->type === CertificateTypes::PORTAL;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @return Certificate
*/
public function setFile(File $image = null)
{
$this->file = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* @return File|null
*/
public function getFile()
{
return $this->file;
}
/**
* @param string $pdfName
*
* @return Certificate
*/
public function setPdfName($pdfName)
{
$this->pdfName = $pdfName;
return $this;
}
/**
* @return string|null
*/
public function getPdfName()
{
return $this->pdfName;
}
/**
* Constructor
*/
public function __construct()
{
$this->certificateElement = new ArrayCollection();
$this->userCertificates = new ArrayCollection();
$this->productVariants = new ArrayCollection();
$this->certificatePaths = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Certificate
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set slug
*
* @param string $slug
* @return Certificate
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set pageOrientationLandscape
*
* @param boolean $pageOrientationLandscape
* @return Certificate
*/
public function setPageOrientationLandscape($pageOrientationLandscape)
{
$this->pageOrientationLandscape = $pageOrientationLandscape;
return $this;
}
/**
* Get pageOrientationLandscape
*
* @return boolean
*/
public function getPageOrientationLandscape()
{
return $this->pageOrientationLandscape;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Certificate
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return Certificate
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set availableFrom
*
* @param \DateTime|null $availableFrom
* @return Certificate
*/
public function setAvailableFrom(?\DateTime $availableFrom)
{
$this->availableFrom = $availableFrom;
return $this;
}
/**
* Get availableFrom
*
* @return \DateTime
*/
public function getAvailableFrom(): ?\DateTime
{
return $this->availableFrom;
}
public function getSurveyUrl(): ?string
{
return $this->surveyUrl;
}
public function setSurveyUrl(?string $surveyUrl): Certificate
{
$this->surveyUrl = $surveyUrl;
return $this;
}
/**
* @return Collection|CertificateElement[]
*/
public function getCertificateElement(): Collection
{
return $this->certificateElement;
}
public function addCertificateElement(CertificateElement $certificateElement): self
{
if (!$this->certificateElement->contains($certificateElement)) {
$this->certificateElement[] = $certificateElement;
$certificateElement->setCertificate($this);
}
return $this;
}
public function removeCertificateElement(CertificateElement $certificateElement): self
{
if ($this->certificateElement->contains($certificateElement)) {
$this->certificateElement->removeElement($certificateElement);
// set the owning side to null (unless already changed)
if ($certificateElement->getCertificate() === $this) {
$certificateElement->setCertificate(null);
}
}
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(?Course $course): self
{
$this->course = $course;
return $this;
}
public function getValidForDays(): ?int
{
return $this->validForDays;
}
public function setValidForDays(?int $validForDays): self
{
$this->validForDays = $validForDays;
return $this;
}
/**
* @return Collection|UserCertificate[]
*/
public function getUserCertificates(): Collection
{
return $this->userCertificates;
}
public function addUserCertificate(UserCertificate $userCertificate): self
{
if (!$this->userCertificates->contains($userCertificate)) {
$this->userCertificates[] = $userCertificate;
$userCertificate->setCertificate($this);
}
return $this;
}
public function removeUserCertificate(UserCertificate $userCertificate): self
{
if ($this->userCertificates->contains($userCertificate)) {
$this->userCertificates->removeElement($userCertificate);
// set the owning side to null (unless already changed)
if ($userCertificate->getCertificate() === $this) {
$userCertificate->setCertificate(null);
}
}
return $this;
}
public function getModule(): ?Module
{
return $this->module;
}
public function setModule(?Module $module): self
{
$this->module = $module;
return $this;
}
public function getEvent(): ?Events
{
return $this->event;
}
public function setEvent(?Events $event): self
{
$this->event = $event;
return $this;
}
public function getOmitConditionals(): ?bool
{
return $this->omitConditionals;
}
public function setOmitConditionals(?bool $omitConditionals): self
{
$this->omitConditionals = $omitConditionals;
return $this;
}
/**
* @return Collection|ProductVariant[]
*/
public function getProductVariants(): Collection
{
return $this->productVariants;
}
public function addProductVariant(ProductVariant $productVariant): self
{
if (!$this->productVariants->contains($productVariant)) {
$this->productVariants[] = $productVariant;
$productVariant->addCertificate($this);
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): self
{
if ($this->productVariants->contains($productVariant)) {
$this->productVariants->removeElement($productVariant);
// set the owning side to null (unless already changed)
if ($productVariant->getCertificates()->contains($this)) {
$productVariant->removeCertificate($this);
}
}
return $this;
}
public function getIsFastCertificate(): ?bool
{
return $this->isFastCertificate;
}
public function setIsFastCertificate(?bool $isFastCertificate): self
{
$this->isFastCertificate = $isFastCertificate;
return $this;
}
/**
* @return Collection|CertificatePath[]
*/
public function getCertificatePaths(): Collection
{
return $this->certificatePaths;
}
public function addCertificatePath(CertificatePath $certificatePath): self
{
if (!$this->certificatePaths->contains($certificatePath)) {
$this->certificatePaths[] = $certificatePath;
$certificatePath->setCertificate($this);
}
return $this;
}
public function removeCertificatePath(CertificatePath $certificatePath): self
{
if ($this->certificatePaths->contains($certificatePath)) {
$this->certificatePaths->removeElement($certificatePath);
// set the owning side to null (unless already changed)
if ($certificatePath->getCertificate() === $this) {
$certificatePath->setCertificate(null);
}
}
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getAccessForPaidOnly(): ?bool
{
return $this->accessForPaidOnly;
}
public function setAccessForPaidOnly(?bool $accessForPaidOnly): self
{
$this->accessForPaidOnly = $accessForPaidOnly;
return $this;
}
}