src/Entity/Gos/Uniqskills/Certificate.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos\Uniqskills;
  3. use App\Entity\Gos\CertificatePath;
  4. use App\Entity\Gos\Events;
  5. use App\Entity\Gos\ProductVariant;
  6. use App\Enum\CertificateTypes;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15.  * @ORM\Table()
  16.  * @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\CertificateRepository")
  17.  * @Vich\Uploadable
  18.  * @ORM\HasLifecycleCallbacks
  19.  */
  20. class Certificate
  21. {
  22.     /**
  23.      * @var integer
  24.      *
  25.      * @ORM\Column(type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="AUTO")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @ORM\Column(type="string")
  32.      */
  33.     private $name;
  34.     /**
  35.      * @Gedmo\Slug(fields={"name"})
  36.      * @ORM\Column(type="string", length=191, unique=true)
  37.      */
  38.     private $slug;
  39.     /**
  40.      * @ORM\Column(type="boolean", nullable=true)
  41.      */
  42.     private $pageOrientationLandscape;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity="CertificateElement", mappedBy="certificate", cascade={"persist", "remove"}, orphanRemoval=true)
  45.      */
  46.     private $certificateElement;
  47.     /**
  48.      * @var \DateTime
  49.      *
  50.      * @ORM\Column(type="datetime", nullable=true)
  51.      */
  52.     private $createdAt;
  53.     /**
  54.      * @var \DateTime
  55.      *
  56.      * @ORM\Column(type="datetime", nullable=true)
  57.      */
  58.     private $updatedAt;
  59.     /**
  60.      * @ORM\Column(type="string", length=255, nullable=true)
  61.      */
  62.     private $surveyUrl;
  63.     /** @ORM\PrePersist() */
  64.     public function prePersist()
  65.     {
  66.         $this->createdAt = new \DateTime();
  67.     }
  68.     /** @ORM\PreUpdate() */
  69.     public function preUpdate()
  70.     {
  71.         $this->updatedAt = new \DateTime();
  72.     }
  73.     public function __toString()
  74.     {
  75.         return (string) $this->name;
  76.     }
  77.     /**
  78.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  79.      *
  80.      * @Assert\File(
  81.      *     maxSize="5M",
  82.      *     mimeTypes={"application/pdf", "application/x-pdf"}
  83.      * )
  84.      *
  85.      * @Vich\UploadableField(mapping="product_image", fileNameProperty="pdfName")
  86.      *
  87.      * @var File
  88.      */
  89.     private $file;
  90.     /**
  91.      * @ORM\Column(type="string", length=255, nullable=true)
  92.      *
  93.      * @var string
  94.      */
  95.     private $pdfName;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Uniqskills\Module", inversedBy="certificate", cascade={"persist", "remove"})
  98.      */
  99.     private $module;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity="App\Entity\Gos\Uniqskills\Course", inversedBy="certificates")
  102.      */
  103.     private $course;
  104.     /**
  105.      * @ORM\Column(type="integer", nullable=true)
  106.      */
  107.     private $validForDays;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\UserCertificate", mappedBy="certificate")
  110.      */
  111.     private $userCertificates;
  112.     /**
  113.      * @ORM\ManyToOne(targetEntity=Events::class, inversedBy="certificates", cascade={"persist", "remove"})
  114.      */
  115.     private $event;
  116.     /**
  117.      * @ORM\Column(type="boolean", nullable=true)
  118.      */
  119.     private $omitConditionals;
  120.     /**
  121.      * @ORM\ManyToMany(targetEntity=ProductVariant::class, mappedBy="certificates")
  122.      */
  123.     private $productVariants;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true)
  126.      */
  127.     private $isFastCertificate;
  128.     /**
  129.      * @var \DateTime
  130.      *
  131.      * @ORM\Column(type="datetime", nullable=true)
  132.      */
  133.     private $availableFrom;
  134.     /**
  135.      * @ORM\OneToMany(targetEntity=CertificatePath::class, mappedBy="certificate")
  136.      */
  137.     private $certificatePaths;
  138.     /**
  139.      * @ORM\Column(type="integer", options={"default": 0})
  140.      */
  141.     private $type 0;
  142.     /**
  143.      * @ORM\Column(type="boolean", nullable=true)
  144.      */
  145.     private $accessForPaidOnly;
  146.     public function isFastCertificate(): bool
  147.     {
  148.         if ($this->getIsFastCertificate())
  149.         {
  150.             return true;
  151.         }
  152.         return $this->type === CertificateTypes::FAST;
  153.     }
  154.     public function isPaidCertificate(): bool
  155.     {
  156.         return $this->type === CertificateTypes::PAID;
  157.     }
  158.     public function isPortalCertificate(): bool
  159.     {
  160.         return $this->type === CertificateTypes::PORTAL;
  161.     }
  162.     /**
  163.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  164.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  165.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  166.      * must be able to accept an instance of 'File' as the bundle will inject one here
  167.      * during Doctrine hydration.
  168.      *
  169.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  170.      *
  171.      * @return Certificate
  172.      */
  173.     public function setFile(File $image null)
  174.     {
  175.         $this->file $image;
  176.         if ($image) {
  177.             // It is required that at least one field changes if you are using doctrine
  178.             // otherwise the event listeners won't be called and the file is lost
  179.             $this->updatedAt = new \DateTimeImmutable();
  180.         }
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return File|null
  185.      */
  186.     public function getFile()
  187.     {
  188.         return $this->file;
  189.     }
  190.     /**
  191.      * @param string $pdfName
  192.      *
  193.      * @return Certificate
  194.      */
  195.     public function setPdfName($pdfName)
  196.     {
  197.         $this->pdfName $pdfName;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return string|null
  202.      */
  203.     public function getPdfName()
  204.     {
  205.         return $this->pdfName;
  206.     }
  207.     /**
  208.      * Constructor
  209.      */
  210.     public function __construct()
  211.     {
  212.         $this->certificateElement = new ArrayCollection();
  213.         $this->userCertificates   = new ArrayCollection();
  214.         $this->productVariants    = new ArrayCollection();
  215.         $this->certificatePaths   = new ArrayCollection();
  216.     }
  217.     /**
  218.      * Get id
  219.      *
  220.      * @return integer 
  221.      */
  222.     public function getId()
  223.     {
  224.         return $this->id;
  225.     }
  226.     /**
  227.      * Set name
  228.      *
  229.      * @param string $name
  230.      * @return Certificate
  231.      */
  232.     public function setName($name)
  233.     {
  234.         $this->name $name;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get name
  239.      *
  240.      * @return string 
  241.      */
  242.     public function getName()
  243.     {
  244.         return $this->name;
  245.     }
  246.     /**
  247.      * Set slug
  248.      *
  249.      * @param string $slug
  250.      * @return Certificate
  251.      */
  252.     public function setSlug($slug)
  253.     {
  254.         $this->slug $slug;
  255.         return $this;
  256.     }
  257.     /**
  258.      * Get slug
  259.      *
  260.      * @return string 
  261.      */
  262.     public function getSlug()
  263.     {
  264.         return $this->slug;
  265.     }
  266.     /**
  267.      * Set pageOrientationLandscape
  268.      *
  269.      * @param boolean $pageOrientationLandscape
  270.      * @return Certificate
  271.      */
  272.     public function setPageOrientationLandscape($pageOrientationLandscape)
  273.     {
  274.         $this->pageOrientationLandscape $pageOrientationLandscape;
  275.         return $this;
  276.     }
  277.     /**
  278.      * Get pageOrientationLandscape
  279.      *
  280.      * @return boolean 
  281.      */
  282.     public function getPageOrientationLandscape()
  283.     {
  284.         return $this->pageOrientationLandscape;
  285.     }
  286.     /**
  287.      * Set createdAt
  288.      *
  289.      * @param \DateTime $createdAt
  290.      * @return Certificate
  291.      */
  292.     public function setCreatedAt($createdAt)
  293.     {
  294.         $this->createdAt $createdAt;
  295.         return $this;
  296.     }
  297.     /**
  298.      * Get createdAt
  299.      *
  300.      * @return \DateTime 
  301.      */
  302.     public function getCreatedAt()
  303.     {
  304.         return $this->createdAt;
  305.     }
  306.     /**
  307.      * Set updatedAt
  308.      *
  309.      * @param \DateTime $updatedAt
  310.      * @return Certificate
  311.      */
  312.     public function setUpdatedAt($updatedAt)
  313.     {
  314.         $this->updatedAt $updatedAt;
  315.         return $this;
  316.     }
  317.     /**
  318.      * Get updatedAt
  319.      *
  320.      * @return \DateTime 
  321.      */
  322.     public function getUpdatedAt()
  323.     {
  324.         return $this->updatedAt;
  325.     }
  326.     /**
  327.      * Set availableFrom
  328.      *
  329.      * @param \DateTime|null $availableFrom
  330.      * @return Certificate
  331.      */
  332.     public function setAvailableFrom(?\DateTime $availableFrom)
  333.     {
  334.         $this->availableFrom $availableFrom;
  335.         return $this;
  336.     }
  337.     /**
  338.      * Get availableFrom
  339.      *
  340.      * @return \DateTime
  341.      */
  342.     public function getAvailableFrom(): ?\DateTime
  343.     {
  344.         return $this->availableFrom;
  345.     }
  346.     public function getSurveyUrl(): ?string
  347.     {
  348.         return $this->surveyUrl;
  349.     }
  350.     public function setSurveyUrl(?string $surveyUrl): Certificate
  351.     {
  352.         $this->surveyUrl $surveyUrl;
  353.         return $this;
  354.     }
  355.     /**
  356.      * @return Collection|CertificateElement[]
  357.      */
  358.     public function getCertificateElement(): Collection
  359.     {
  360.         return $this->certificateElement;
  361.     }
  362.     public function addCertificateElement(CertificateElement $certificateElement): self
  363.     {
  364.         if (!$this->certificateElement->contains($certificateElement)) {
  365.             $this->certificateElement[] = $certificateElement;
  366.             $certificateElement->setCertificate($this);
  367.         }
  368.         return $this;
  369.     }
  370.     public function removeCertificateElement(CertificateElement $certificateElement): self
  371.     {
  372.         if ($this->certificateElement->contains($certificateElement)) {
  373.             $this->certificateElement->removeElement($certificateElement);
  374.             // set the owning side to null (unless already changed)
  375.             if ($certificateElement->getCertificate() === $this) {
  376.                 $certificateElement->setCertificate(null);
  377.             }
  378.         }
  379.         return $this;
  380.     }
  381.     public function getCourse(): ?Course
  382.     {
  383.         return $this->course;
  384.     }
  385.     public function setCourse(?Course $course): self
  386.     {
  387.         $this->course $course;
  388.         return $this;
  389.     }
  390.     public function getValidForDays(): ?int
  391.     {
  392.         return $this->validForDays;
  393.     }
  394.     public function setValidForDays(?int $validForDays): self
  395.     {
  396.         $this->validForDays $validForDays;
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection|UserCertificate[]
  401.      */
  402.     public function getUserCertificates(): Collection
  403.     {
  404.         return $this->userCertificates;
  405.     }
  406.     public function addUserCertificate(UserCertificate $userCertificate): self
  407.     {
  408.         if (!$this->userCertificates->contains($userCertificate)) {
  409.             $this->userCertificates[] = $userCertificate;
  410.             $userCertificate->setCertificate($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeUserCertificate(UserCertificate $userCertificate): self
  415.     {
  416.         if ($this->userCertificates->contains($userCertificate)) {
  417.             $this->userCertificates->removeElement($userCertificate);
  418.             // set the owning side to null (unless already changed)
  419.             if ($userCertificate->getCertificate() === $this) {
  420.                 $userCertificate->setCertificate(null);
  421.             }
  422.         }
  423.         return $this;
  424.     }
  425.     public function getModule(): ?Module
  426.     {
  427.         return $this->module;
  428.     }
  429.     public function setModule(?Module $module): self
  430.     {
  431.         $this->module $module;
  432.         return $this;
  433.     }
  434.     public function getEvent(): ?Events
  435.     {
  436.         return $this->event;
  437.     }
  438.     public function setEvent(?Events $event): self
  439.     {
  440.         $this->event $event;
  441.         return $this;
  442.     }
  443.     public function getOmitConditionals(): ?bool
  444.     {
  445.         return $this->omitConditionals;
  446.     }
  447.     public function setOmitConditionals(?bool $omitConditionals): self
  448.     {
  449.         $this->omitConditionals $omitConditionals;
  450.         return $this;
  451.     }
  452.     /**
  453.      * @return Collection|ProductVariant[]
  454.      */
  455.     public function getProductVariants(): Collection
  456.     {
  457.         return $this->productVariants;
  458.     }
  459.     public function addProductVariant(ProductVariant $productVariant): self
  460.     {
  461.         if (!$this->productVariants->contains($productVariant)) {
  462.             $this->productVariants[] = $productVariant;
  463.             $productVariant->addCertificate($this);
  464.         }
  465.         return $this;
  466.     }
  467.     public function removeProductVariant(ProductVariant $productVariant): self
  468.     {
  469.         if ($this->productVariants->contains($productVariant)) {
  470.             $this->productVariants->removeElement($productVariant);
  471.             // set the owning side to null (unless already changed)
  472.             if ($productVariant->getCertificates()->contains($this)) {
  473.                 $productVariant->removeCertificate($this);
  474.             }
  475.         }
  476.         return $this;
  477.     }
  478.     public function getIsFastCertificate(): ?bool
  479.     {
  480.         return $this->isFastCertificate;
  481.     }
  482.     public function setIsFastCertificate(?bool $isFastCertificate): self
  483.     {
  484.         $this->isFastCertificate $isFastCertificate;
  485.         return $this;
  486.     }
  487.     /**
  488.      * @return Collection|CertificatePath[]
  489.      */
  490.     public function getCertificatePaths(): Collection
  491.     {
  492.         return $this->certificatePaths;
  493.     }
  494.     public function addCertificatePath(CertificatePath $certificatePath): self
  495.     {
  496.         if (!$this->certificatePaths->contains($certificatePath)) {
  497.             $this->certificatePaths[] = $certificatePath;
  498.             $certificatePath->setCertificate($this);
  499.         }
  500.         return $this;
  501.     }
  502.     public function removeCertificatePath(CertificatePath $certificatePath): self
  503.     {
  504.         if ($this->certificatePaths->contains($certificatePath)) {
  505.             $this->certificatePaths->removeElement($certificatePath);
  506.             // set the owning side to null (unless already changed)
  507.             if ($certificatePath->getCertificate() === $this) {
  508.                 $certificatePath->setCertificate(null);
  509.             }
  510.         }
  511.         return $this;
  512.     }
  513.     public function getType(): ?int
  514.     {
  515.         return $this->type;
  516.     }
  517.     public function setType(int $type): self
  518.     {
  519.         $this->type $type;
  520.         return $this;
  521.     }
  522.     public function getAccessForPaidOnly(): ?bool
  523.     {
  524.         return $this->accessForPaidOnly;
  525.     }
  526.     public function setAccessForPaidOnly(?bool $accessForPaidOnly): self
  527.     {
  528.         $this->accessForPaidOnly $accessForPaidOnly;
  529.         return $this;
  530.     }
  531. }