src/Entity/Gos/Uniqskills/Module.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos\Uniqskills;
  3. use App\Entity\Gos\ProductVariant;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Table()
  11.  * @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\ModuleRepository")
  12.  * @ORM\HasLifecycleCallbacks
  13.  */
  14. class Module
  15. {
  16.     /**
  17.      * @ORM\Column(type="integer")
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="IDENTITY")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="boolean", nullable=true)
  24.      */
  25.     private $isActive;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      * @Assert\NotBlank()
  29.      */
  30.     private $name;
  31.     /**
  32.      * @Gedmo\Slug(fields={"name"})
  33.      * @ORM\Column(type="string", length=191, unique=true)
  34.      */
  35.     private $slug;
  36.     /**
  37.      * @ORM\Column(type="text")
  38.      * @Assert\NotBlank()
  39.      */
  40.     private $shortBody;
  41.     /**
  42.      * @ORM\Column(type="integer")
  43.      */
  44.     private $itemOrder;
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true)
  47.      */
  48.     private $share;
  49.     /**
  50.      * @ORM\Column(type="datetime", nullable=true)
  51.      */
  52.     private $shareDate;
  53.     /**
  54.      * @ORM\Column(type="datetime")
  55.      */
  56.     private $createdAt;
  57.     /**
  58.      * @ORM\Column(type="datetime", nullable=true)
  59.      */
  60.     private $updatedAt;
  61.     /**
  62.      * @ORM\OneToMany(targetEntity="Lesson", mappedBy="module")
  63.      */
  64.     private $lesson;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity="Course", inversedBy="module")
  67.      * @ORM\JoinColumn(onDelete="CASCADE")
  68.      */
  69.     private $course;
  70.     /**
  71.      * @ORM\ManyToMany(targetEntity="Package", mappedBy="modules")
  72.      * @ORM\JoinColumn()
  73.      */
  74.     private $package;
  75.     /**
  76.      * @ORM\ManyToMany(targetEntity="Author", inversedBy="module")
  77.      * @ORM\JoinTable(name="module_author")
  78.      */
  79.     private $authors;
  80.     /**
  81.      * @ORM\OneToOne(targetEntity="Test", mappedBy="module")
  82.      */
  83.     private $test;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\Certificate", mappedBy="module", cascade={"persist", "remove"})
  86.      */
  87.     private $certificate;
  88.     /**
  89.      * @ORM\ManyToMany(targetEntity=ProductVariant::class)
  90.      */
  91.     private $productVariants;
  92.     /**
  93.      * @ORM\Column(type="boolean", nullable=true)
  94.      */
  95.     private $isUpgrade;
  96.     /**
  97.      * GOS-1835
  98.      * After how many days from the order should module be visible in customer panel
  99.      * default: 0 - visible immediately
  100.      * @ORM\Column(type="integer", options={"default": 0})
  101.      * @Assert\GreaterThanOrEqual(value=0)
  102.      */
  103.     private $visibleAfterDays 0;
  104.     /** @ORM\PrePersist() */
  105.     public function prePersist()
  106.     {
  107.         $this->createdAt = new \DateTime();
  108.     }
  109.     /** @ORM\PreUpdate() */
  110.     public function preUpdate()
  111.     {
  112.         $this->updatedAt = new \DateTime();
  113.     }
  114.     public function __toString()
  115.     {
  116.         return (string)$this->name;
  117.     }
  118.     /**
  119.      * Constructor
  120.      */
  121.     public function __construct()
  122.     {
  123.         $this->lesson          = new ArrayCollection();
  124.         $this->package         = new ArrayCollection();
  125.         $this->authors         = new ArrayCollection();
  126.         $this->certificate     = new ArrayCollection();
  127.         $this->productVariants = new ArrayCollection();
  128.     }
  129.     public function __clone()
  130.     {
  131.         $this->id           null;
  132.         $this->updatedAt    null;
  133.     }
  134.     /* ****************************** GETTERS & SETTERS ******************************  */
  135.     public function getId(): ?int
  136.     {
  137.         return $this->id;
  138.     }
  139.     public function getIsActive(): ?bool
  140.     {
  141.         return $this->isActive;
  142.     }
  143.     public function setIsActive(?bool $isActive): self
  144.     {
  145.         $this->isActive $isActive;
  146.         return $this;
  147.     }
  148.     public function getName(): ?string
  149.     {
  150.         return $this->name;
  151.     }
  152.     public function setName(string $name): self
  153.     {
  154.         $this->name $name;
  155.         return $this;
  156.     }
  157.     public function getSlug(): ?string
  158.     {
  159.         return $this->slug;
  160.     }
  161.     public function setSlug($slug): self
  162.     {
  163.         $this->slug $slug;
  164.         return $this;
  165.     }
  166.     public function getShortBody(): ?string
  167.     {
  168.         return $this->shortBody;
  169.     }
  170.     public function setShortBody(string $shortBody): self
  171.     {
  172.         $this->shortBody $shortBody;
  173.         return $this;
  174.     }
  175.     public function getItemOrder(): ?int
  176.     {
  177.         return $this->itemOrder;
  178.     }
  179.     public function setItemOrder(int $itemOrder): self
  180.     {
  181.         $this->itemOrder $itemOrder;
  182.         return $this;
  183.     }
  184.     public function getShare(): ?bool
  185.     {
  186.         return $this->share;
  187.     }
  188.     public function setShare(?bool $share): self
  189.     {
  190.         $this->share $share;
  191.         return $this;
  192.     }
  193.     public function getShareDate(): ?\DateTimeInterface
  194.     {
  195.         return $this->shareDate;
  196.     }
  197.     public function setShareDate(?\DateTimeInterface $shareDate): self
  198.     {
  199.         $this->shareDate $shareDate;
  200.         return $this;
  201.     }
  202.     public function getCreatedAt(): ?\DateTimeInterface
  203.     {
  204.         return $this->createdAt;
  205.     }
  206.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  207.     {
  208.         $this->createdAt $createdAt;
  209.         return $this;
  210.     }
  211.     public function getUpdatedAt(): ?\DateTimeInterface
  212.     {
  213.         return $this->updatedAt;
  214.     }
  215.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  216.     {
  217.         $this->updatedAt $updatedAt;
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection|Lesson[]
  222.      */
  223.     public function getLesson(): Collection
  224.     {
  225.         return $this->lesson;
  226.     }
  227.     public function addLesson(Lesson $lesson): self
  228.     {
  229.         if (!$this->lesson->contains($lesson)) {
  230.             $this->lesson[] = $lesson;
  231.             $lesson->setModule($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeLesson(Lesson $lesson): self
  236.     {
  237.         if ($this->lesson->contains($lesson)) {
  238.             $this->lesson->removeElement($lesson);
  239.             // set the owning side to null (unless already changed)
  240.             if ($lesson->getModule() === $this) {
  241.                 $lesson->setModule(null);
  242.             }
  243.         }
  244.         return $this;
  245.     }
  246.     public function getCourse(): ?Course
  247.     {
  248.         return $this->course;
  249.     }
  250.     public function setCourse(?Course $course): self
  251.     {
  252.         $this->course $course;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return Collection|Package[]
  257.      */
  258.     public function getPackage(): Collection
  259.     {
  260.         return $this->package;
  261.     }
  262.     public function addPackage(Package $package): self
  263.     {
  264.         if (!$this->package->contains($package)) {
  265.             $this->package[] = $package;
  266.             $package->addModule($this);
  267.         }
  268.         return $this;
  269.     }
  270.     public function removePackage(Package $package): self
  271.     {
  272.         if ($this->package->contains($package)) {
  273.             $this->package->removeElement($package);
  274.             $package->removeModule($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function getTest(): ?Test
  279.     {
  280.         return $this->test;
  281.     }
  282.     public function setTest(Test $test): self
  283.     {
  284.         $this->test $test;
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return Collection|Author[]
  289.      */
  290.     public function getAuthors(): Collection
  291.     {
  292.         return $this->authors;
  293.     }
  294.     public function addAuthor(Author $author): self
  295.     {
  296.         if (!$this->authors->contains($author)) {
  297.             $this->authors[] = $author;
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeAuthor(Author $author): self
  302.     {
  303.         if ($this->authors->contains($author)) {
  304.             $this->authors->removeElement($author);
  305.         }
  306.         return $this;
  307.     }
  308.     /**
  309.      * @return Collection|Certificate[]
  310.      */
  311.     public function getCertificate(): Collection
  312.     {
  313.         return $this->certificate;
  314.     }
  315.     public function addCertificate(Certificate $certificate): self
  316.     {
  317.         if (!$this->certificate->contains($certificate)) {
  318.             $this->certificate[] = $certificate;
  319.             $certificate->setModule($this);
  320.         }
  321.         return $this;
  322.     }
  323.     public function removeCertificate(Certificate $certificate): self
  324.     {
  325.         if ($this->certificate->contains($certificate)) {
  326.             $this->certificate->removeElement($certificate);
  327.             // set the owning side to null (unless already changed)
  328.             if ($certificate->getModule() === $this) {
  329.                 $certificate->setModule(null);
  330.             }
  331.         }
  332.         return $this;
  333.     }
  334.     public function isLastModule($placesFromEnd 0): bool
  335.     {
  336.         $modulesAhead 0;
  337.         foreach ($this->getCourse()->getModule() as $module)
  338.         {
  339.             if ($module->getItemOrder() > $this->getItemOrder())
  340.             {
  341.                 if (++$modulesAhead $placesFromEnd) return false;
  342.             }
  343.         }
  344.         return true;
  345.     }
  346.     /**
  347.      * @return Collection|ProductVariant[]
  348.      */
  349.     public function getProductVariants(): Collection
  350.     {
  351.         return $this->productVariants;
  352.     }
  353.     public function addProductVariant(ProductVariant $productVariant): self
  354.     {
  355.         if (!$this->productVariants->contains($productVariant)) {
  356.             $this->productVariants[] = $productVariant;
  357.         }
  358.         return $this;
  359.     }
  360.     public function removeProductVariant(ProductVariant $productVariant): self
  361.     {
  362.         if ($this->productVariants->contains($productVariant)) {
  363.             $this->productVariants->removeElement($productVariant);
  364.         }
  365.         return $this;
  366.     }
  367.     public function getIsUpgrade(): ?bool
  368.     {
  369.         return $this->isUpgrade;
  370.     }
  371.     public function setIsUpgrade(?bool $isUpgrade): self
  372.     {
  373.         $this->isUpgrade $isUpgrade;
  374.         return $this;
  375.     }
  376.     public function getVisibleAfterDays(): ?int
  377.     {
  378.         return $this->visibleAfterDays;
  379.     }
  380.     public function setVisibleAfterDays(int $visibleAfterDays): self
  381.     {
  382.         $this->visibleAfterDays $visibleAfterDays;
  383.         return $this;
  384.     }
  385. }