<?php
namespace App\Entity\Gos\Uniqskills;
use App\Entity\Gos\ProductVariant;
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;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\Gos\Uniqskills\ModuleRepository")
* @ORM\HasLifecycleCallbacks
*/
class Module
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActive;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=191, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
*/
private $shortBody;
/**
* @ORM\Column(type="integer")
*/
private $itemOrder;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $share;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $shareDate;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity="Lesson", mappedBy="module")
*/
private $lesson;
/**
* @ORM\ManyToOne(targetEntity="Course", inversedBy="module")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $course;
/**
* @ORM\ManyToMany(targetEntity="Package", mappedBy="modules")
* @ORM\JoinColumn()
*/
private $package;
/**
* @ORM\ManyToMany(targetEntity="Author", inversedBy="module")
* @ORM\JoinTable(name="module_author")
*/
private $authors;
/**
* @ORM\OneToOne(targetEntity="Test", mappedBy="module")
*/
private $test;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Uniqskills\Certificate", mappedBy="module", cascade={"persist", "remove"})
*/
private $certificate;
/**
* @ORM\ManyToMany(targetEntity=ProductVariant::class)
*/
private $productVariants;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isUpgrade;
/**
* GOS-1835
* After how many days from the order should module be visible in customer panel
* default: 0 - visible immediately
* @ORM\Column(type="integer", options={"default": 0})
* @Assert\GreaterThanOrEqual(value=0)
*/
private $visibleAfterDays = 0;
/** @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;
}
/**
* Constructor
*/
public function __construct()
{
$this->lesson = new ArrayCollection();
$this->package = new ArrayCollection();
$this->authors = new ArrayCollection();
$this->certificate = new ArrayCollection();
$this->productVariants = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->updatedAt = null;
}
/* ****************************** GETTERS & SETTERS ****************************** */
public function getId(): ?int
{
return $this->id;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug($slug): self
{
$this->slug = $slug;
return $this;
}
public function getShortBody(): ?string
{
return $this->shortBody;
}
public function setShortBody(string $shortBody): self
{
$this->shortBody = $shortBody;
return $this;
}
public function getItemOrder(): ?int
{
return $this->itemOrder;
}
public function setItemOrder(int $itemOrder): self
{
$this->itemOrder = $itemOrder;
return $this;
}
public function getShare(): ?bool
{
return $this->share;
}
public function setShare(?bool $share): self
{
$this->share = $share;
return $this;
}
public function getShareDate(): ?\DateTimeInterface
{
return $this->shareDate;
}
public function setShareDate(?\DateTimeInterface $shareDate): self
{
$this->shareDate = $shareDate;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Lesson[]
*/
public function getLesson(): Collection
{
return $this->lesson;
}
public function addLesson(Lesson $lesson): self
{
if (!$this->lesson->contains($lesson)) {
$this->lesson[] = $lesson;
$lesson->setModule($this);
}
return $this;
}
public function removeLesson(Lesson $lesson): self
{
if ($this->lesson->contains($lesson)) {
$this->lesson->removeElement($lesson);
// set the owning side to null (unless already changed)
if ($lesson->getModule() === $this) {
$lesson->setModule(null);
}
}
return $this;
}
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(?Course $course): self
{
$this->course = $course;
return $this;
}
/**
* @return Collection|Package[]
*/
public function getPackage(): Collection
{
return $this->package;
}
public function addPackage(Package $package): self
{
if (!$this->package->contains($package)) {
$this->package[] = $package;
$package->addModule($this);
}
return $this;
}
public function removePackage(Package $package): self
{
if ($this->package->contains($package)) {
$this->package->removeElement($package);
$package->removeModule($this);
}
return $this;
}
public function getTest(): ?Test
{
return $this->test;
}
public function setTest(Test $test): self
{
$this->test = $test;
return $this;
}
/**
* @return Collection|Author[]
*/
public function getAuthors(): Collection
{
return $this->authors;
}
public function addAuthor(Author $author): self
{
if (!$this->authors->contains($author)) {
$this->authors[] = $author;
}
return $this;
}
public function removeAuthor(Author $author): self
{
if ($this->authors->contains($author)) {
$this->authors->removeElement($author);
}
return $this;
}
/**
* @return Collection|Certificate[]
*/
public function getCertificate(): Collection
{
return $this->certificate;
}
public function addCertificate(Certificate $certificate): self
{
if (!$this->certificate->contains($certificate)) {
$this->certificate[] = $certificate;
$certificate->setModule($this);
}
return $this;
}
public function removeCertificate(Certificate $certificate): self
{
if ($this->certificate->contains($certificate)) {
$this->certificate->removeElement($certificate);
// set the owning side to null (unless already changed)
if ($certificate->getModule() === $this) {
$certificate->setModule(null);
}
}
return $this;
}
public function isLastModule($placesFromEnd = 0): bool
{
$modulesAhead = 0;
foreach ($this->getCourse()->getModule() as $module)
{
if ($module->getItemOrder() > $this->getItemOrder())
{
if (++$modulesAhead > $placesFromEnd) return false;
}
}
return true;
}
/**
* @return Collection|ProductVariant[]
*/
public function getProductVariants(): Collection
{
return $this->productVariants;
}
public function addProductVariant(ProductVariant $productVariant): self
{
if (!$this->productVariants->contains($productVariant)) {
$this->productVariants[] = $productVariant;
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): self
{
if ($this->productVariants->contains($productVariant)) {
$this->productVariants->removeElement($productVariant);
}
return $this;
}
public function getIsUpgrade(): ?bool
{
return $this->isUpgrade;
}
public function setIsUpgrade(?bool $isUpgrade): self
{
$this->isUpgrade = $isUpgrade;
return $this;
}
public function getVisibleAfterDays(): ?int
{
return $this->visibleAfterDays;
}
public function setVisibleAfterDays(int $visibleAfterDays): self
{
$this->visibleAfterDays = $visibleAfterDays;
return $this;
}
}