<?php
namespace App\Entity;
use App\Repository\CourseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ORM\Entity(repositoryClass=CourseRepository::class)
*/
class Course extends Base
{
/**
* @ORM\ManyToOne(targetEntity=Organizer::class, inversedBy="courses")
* @ORM\JoinColumn(nullable=false)
*/
private $organizer;
/**
* @ORM\Column(type="boolean")
*/
private $isCreatedByAdmin;
/**
* @ORM\ManyToOne(targetEntity=Place::class, inversedBy="courses")
*/
private $place;
/**
* @ORM\Column(type="string", length=255)
*/
protected $name;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $price;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $priceDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $shortDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $requirements;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $publishedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $endAt;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $length;
/**
* @ORM\ManyToOne(targetEntity=CourseState::class)
* @ORM\JoinColumn(nullable=false)
*/
private $state;
/**
* @ORM\ManyToOne(targetEntity=CourseType::class, inversedBy="courses")
*/
private $type;
/**
* @ORM\Column(type="boolean")
*/
private $canCustomize;
/**
* @ORM\Column(type="boolean")
*/
private $isPreparationForCertification;
/**
* @ORM\Column(type="boolean")
*/
private $isWithCertificate;
/**
* @ORM\ManyToOne(targetEntity=Certification::class)
*/
private $certificate;
/**
* @ORM\ManyToOne(targetEntity=CourseFrequency::class)
*/
private $frequency;
/**
* @ORM\ManyToOne(targetEntity=CoursePlaceType::class)
* @ORM\JoinColumn(nullable=true)
*/
private $placeType;
/**
* @ORM\Column(type="boolean")
*/
private $canBuy;
/**
* @ORM\Column(type="boolean")
*/
private $canRegister;
/**
* @ORM\OneToMany(targetEntity=CourseReview::class, mappedBy="course", cascade={"persist", "remove"})
*/
private $reviews;
/**
* @ORM\OneToMany(targetEntity=CourseStats::class, mappedBy="course", cascade={"persist", "remove"})
*/
private $stats;
/**
* @ORM\ManyToMany(targetEntity=Attribute::class)
*/
private $attributes;
/**
* @ORM\ManyToMany(targetEntity=Lecturer::class, inversedBy="courses")
*/
private $lecturers;
/**
* @ORM\ManyToMany(targetEntity=Tag::class)
*/
private $tags;
/**
* @ORM\ManyToMany(targetEntity=Promoter::class, inversedBy="courses")
*/
private $promoters;
/**
* @ORM\ManyToOne(targetEntity=CourseTopic::class, inversedBy="courses")
* @ORM\JoinColumn(nullable=true)
*/
private $topic;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $canPaid;
/**
* @ORM\ManyToMany(targetEntity=DayInWeek::class)
*/
private $dayInWeeks;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $frequencyText;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $lessonStart;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $lessonEnd;
/**
* @ORM\ManyToOne(targetEntity=CourseLength::class)
*/
private $lengthType;
/**
* @ORM\ManyToOne(targetEntity=CourseProgressLevel::class)
*/
private $progressLevel;
/**
* @ORM\ManyToOne(targetEntity=LanguageLevel::class)
*/
private $languageLevelInput;
/**
* @ORM\ManyToOne(targetEntity=LanguageLevel::class)
*/
private $languageLevelOutput;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isConfirmationOfParticipation;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $certificationPriceNotIncluded;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $certificationPrice;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $confirmationName;
/**
* @ORM\ManyToOne(targetEntity=City::class)
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $url;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $code;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isRecommended;
/**
* @ORM\Column(type="float")
*/
private $rating;
/**
* @ORM\Column(type="boolean")
*/
private $isNativeSpeaker;
/**
* @ORM\Column(type="boolean")
*/
private $isCustomized;
/**
* @ORM\ManyToOne(targetEntity=TeachingType::class)
*/
private $teachingType;
/**
* @ORM\ManyToOne(targetEntity=RetrainingType::class)
*/
private $retrainingType;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $onlyForAdults;
/**
* @ORM\Column(type="integer")
*/
private $lastStep;
/**
* @ORM\OneToMany(targetEntity=CourseTerm::class, mappedBy="course", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $terms;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $placeDescription;
/**
* @ORM\Column(type="decimal", precision=10, scale=8, nullable=true)
*/
private $latitude;
/**
* @ORM\Column(type="decimal", precision=11, scale=8, nullable=true)
*/
private $longitude;
/**
* @ORM\ManyToOne(targetEntity=TargetGroup::class)
*/
private $targetGroup;
public function __construct()
{
parent::__construct();
$this->reviews = new ArrayCollection();
$this->stats = new ArrayCollection();
$this->attributes = new ArrayCollection();
$this->lecturers = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->promoters = new ArrayCollection();
$this->dayInWeeks = new ArrayCollection();
$this->isCreatedByAdmin = false;
$this->canCustomize = false;
$this->canBuy = false;
$this->isRecommended = false;
$this->rating = 0;
$this->lastStep = 1;
$this->isCustomized = false;
$this->isNativeSpeaker = false;
$this->terms = new ArrayCollection();
$endAt = new \DateTime();
$endAt->modify('+6 months');
$this->endAt = $endAt;
}
public function getOrganizer(): ?Organizer
{
return $this->organizer;
}
public function setOrganizer(?Organizer $organizer): self
{
$this->organizer = $organizer;
return $this;
}
public function getIsCreatedByAdmin(): ?bool
{
return $this->isCreatedByAdmin;
}
public function setIsCreatedByAdmin(bool $isCreatedByAdmin): self
{
$this->isCreatedByAdmin = $isCreatedByAdmin;
return $this;
}
public function getPlace(): ?Place
{
return $this->place;
}
public function setPlace(?Place $place): self
{
$this->place = $place;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(?string $price): self
{
$this->price = $price;
return $this;
}
public function getPriceDescription(): ?string
{
return $this->priceDescription;
}
public function setPriceDescription(?string $priceDescription): self
{
$this->priceDescription = $priceDescription;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(?string $shortDescription): self
{
$this->shortDescription = $shortDescription;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getRequirements(): ?string
{
return $this->requirements;
}
public function setRequirements(?string $requirements): self
{
$this->requirements = $requirements;
return $this;
}
public function getPublishedAt(): ?\DateTimeInterface
{
return $this->publishedAt;
}
public function setPublishedAt(?\DateTimeInterface $publishedAt): self
{
$this->publishedAt = $publishedAt;
return $this;
}
public function getLength(): ?int
{
return $this->length;
}
public function setLength(?int $length): self
{
$this->length = $length;
return $this;
}
public function getState(): ?CourseState
{
return $this->state;
}
public function setState(?CourseState $state): self
{
$this->state = $state;
return $this;
}
public function getType(): ?CourseType
{
return $this->type;
}
public function setType(?CourseType $type): self
{
$this->type = $type;
return $this;
}
public function getCanCustomize(): ?bool
{
return $this->canCustomize;
}
public function setCanCustomize(bool $canCustomize): self
{
$this->canCustomize = $canCustomize;
return $this;
}
public function getIsPreparationForCertification(): ?bool
{
return $this->isPreparationForCertification;
}
public function setIsPreparationForCertification(bool $isPreparationForCertification): self
{
$this->isPreparationForCertification = $isPreparationForCertification;
return $this;
}
public function getIsWithCertificate(): ?bool
{
return $this->isWithCertificate;
}
public function setIsWithCertificate(bool $isWithCertificate): self
{
$this->isWithCertificate = $isWithCertificate;
return $this;
}
public function getCertificate(): ?Certification
{
return $this->certificate;
}
public function setCertificate(?Certification $certificate): self
{
$this->certificate = $certificate;
return $this;
}
public function getFrequency(): ?CourseFrequency
{
return $this->frequency;
}
public function setFrequency(?CourseFrequency $frequency): self
{
$this->frequency = $frequency;
return $this;
}
public function getPlaceType(): ?CoursePlaceType
{
return $this->placeType;
}
public function setPlaceType(?CoursePlaceType $placeType): self
{
$this->placeType = $placeType;
return $this;
}
public function getCanBuy(): ?bool
{
return $this->canBuy;
}
public function setCanBuy(bool $canBuy): self
{
$this->canBuy = $canBuy;
return $this;
}
public function getCanRegister(): ?bool
{
return $this->canRegister;
}
public function setCanRegister(bool $canRegister): self
{
$this->canRegister = $canRegister;
return $this;
}
/**
* @return Collection|CourseReview[]
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(CourseReview $review): self
{
if (!$this->reviews->contains($review)) {
$this->reviews[] = $review;
$review->setCourse($this);
}
return $this;
}
public function removeReview(CourseReview $review): self
{
if ($this->reviews->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getCourse() === $this) {
$review->setCourse(null);
}
}
return $this;
}
/**
* @return Collection|CourseStats[]
*/
public function getStats(): Collection
{
return $this->stats;
}
public function addStat(CourseStats $stats): self
{
if (!$this->stats->contains($stats)) {
$this->stats[] = $stats;
$stats->setCourse($this);
}
return $this;
}
public function removeStat(CourseStats $review): self
{
if ($this->stats->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getCourse() === $this) {
$review->setCourse(null);
}
}
return $this;
}
/**
* @return Collection|Attribute[]
*/
public function getAttributes(): Collection
{
return $this->attributes;
}
public function addAttribute(Attribute $attribute): self
{
if (!$this->attributes->contains($attribute)) {
$this->attributes[] = $attribute;
}
return $this;
}
public function removeAttribute(Attribute $attribute): self
{
$this->attributes->removeElement($attribute);
return $this;
}
/**
* @return Collection|Lecturer[]
*/
public function getLecturers(): Collection
{
return $this->lecturers;
}
public function addLecturer(Lecturer $lecturer): self
{
if (!$this->lecturers->contains($lecturer)) {
$this->lecturers[] = $lecturer;
}
return $this;
}
public function removeLecturer(Lecturer $lecturer): self
{
$this->lecturers->removeElement($lecturer);
return $this;
}
/**
* @return Collection|Tag[]
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
}
return $this;
}
public function removeTag(Tag $tag): self
{
$this->tags->removeElement($tag);
return $this;
}
/**
* @return Collection|Promoter[]
*/
public function getPromoters(): Collection
{
return $this->promoters;
}
public function addPromoter(Promoter $promoter): self
{
if (!$this->promoters->contains($promoter)) {
$this->promoters[] = $promoter;
}
return $this;
}
public function removePromoter(Promoter $promoter): self
{
$this->promoters->removeElement($promoter);
return $this;
}
public function getTopic(): ?CourseTopic
{
return $this->topic;
}
public function setTopic(?CourseTopic $topic): self
{
$this->topic = $topic;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getCanPaid(): ?bool
{
return $this->canPaid;
}
public function setCanPaid(?bool $canPaid): self
{
$this->canPaid = $canPaid;
return $this;
}
/**
* @return Collection|DayInWeek[]
*/
public function getDayInWeeks(): Collection
{
return $this->dayInWeeks;
}
public function addDayInWeek(DayInWeek $dayInWeek): self
{
if (!$this->dayInWeeks->contains($dayInWeek)) {
$this->dayInWeeks[] = $dayInWeek;
}
return $this;
}
public function removeDayInWeek(DayInWeek $dayInWeek): self
{
$this->dayInWeeks->removeElement($dayInWeek);
return $this;
}
public function getFrequencyText(): ?string
{
return $this->frequencyText;
}
public function setFrequencyText(?string $frequencyText): self
{
$this->frequencyText = $frequencyText;
return $this;
}
public function getLessonStart(): ?\DateTimeInterface
{
return $this->lessonStart;
}
public function setLessonStart(?\DateTimeInterface $lessonStart): self
{
$this->lessonStart = $lessonStart;
return $this;
}
public function getLessonEnd(): ?\DateTimeInterface
{
return $this->lessonEnd;
}
public function setLessonEnd(?\DateTimeInterface $lessonEnd): self
{
$this->lessonEnd = $lessonEnd;
return $this;
}
public function getLengthType(): ?CourseLength
{
return $this->lengthType;
}
public function setLengthType(?CourseLength $lengthType): self
{
$this->lengthType = $lengthType;
return $this;
}
public function getProgressLevel(): ?CourseProgressLevel
{
return $this->progressLevel;
}
public function setProgressLevel(?CourseProgressLevel $progressLevel): self
{
$this->progressLevel = $progressLevel;
return $this;
}
public function getLanguageLevelInput(): ?LanguageLevel
{
return $this->languageLevelInput;
}
public function setLanguageLevelInput(?LanguageLevel $languageLevel): self
{
$this->languageLevelInput = $languageLevel;
return $this;
}
public function getLanguageLevelOutput(): ?LanguageLevel
{
return $this->languageLevelOutput;
}
public function setLanguageLevelOutput(?LanguageLevel $languageLevel): self
{
$this->languageLevelOutput = $languageLevel;
return $this;
}
public function getIsConfirmationOfParticipation(): ?bool
{
return $this->isConfirmationOfParticipation;
}
public function setIsConfirmationOfParticipation(?bool $isConfirmationOfParticipation): self
{
$this->isConfirmationOfParticipation = $isConfirmationOfParticipation;
return $this;
}
public function getCertificationPriceNotIncluded(): ?bool
{
return $this->certificationPriceNotIncluded;
}
public function setCertificationPriceNotIncluded(?bool $certificationPriceNotIncluded): self
{
$this->certificationPriceNotIncluded = $certificationPriceNotIncluded;
return $this;
}
public function getCertificationPrice(): ?string
{
return $this->certificationPrice;
}
public function setCertificationPrice(?string $certificationPrice): self
{
$this->certificationPrice = $certificationPrice;
return $this;
}
public function getConfirmationName(): ?string
{
return $this->confirmationName;
}
public function setConfirmationName(?string $confirmationName): self
{
$this->confirmationName = $confirmationName;
return $this;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
// if (!empty($this->start) && $this->start < date_create_from_format('Y-m-d','2021-01-01')) {
// $context->buildViolation('Minimální datum zahájení je 1. 1. 2021')
// ->atPath('start')
// ->addViolation();
// }
//
// if ($this->end > date_create_from_format('Y-m-d','2031-12-31')) {
// $context->buildViolation('Maximální datum ukončení je 31. 12. 2031')
// ->atPath('end')
// ->addViolation();
// }
//
// if ($this->registrationStart > $this->registrationEnd) {
// $context->buildViolation('Datum registrace musí být menší než konec registrace')
// ->atPath('registrationStart')
// ->addViolation();
// }
//
// if ($this->start > $this->end) {
// $context->buildViolation('Datum zahájení musí být menší než konec')
// ->atPath('start')
// ->addViolation();
// }
//
// if ($this->registrationEnd > $this->end) {
// $context->buildViolation('Datum ukončení registrace musí být před Datem ukončení kurzu.')
// ->atPath('registrationEnd')
// ->addViolation();
// }
//
// if ($this->publishedAt > $this->end) {
// $context->buildViolation('Datum publikování musí být před Datem ukončení kurzu.')
// ->atPath('publishedAt')
// ->addViolation();
// }
//
// if ($this->minimumNumberOfPersons > $this->maximumNumberOfPersons) {
// $context->buildViolation('Počet lidí minimální musí být menší počet lidí maximální.')
// ->atPath('minimumNumberOfPersons')
// ->addViolation();
// }
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
public function getIsRecommended(): ?bool
{
return $this->isRecommended;
}
public function setIsRecommended(?bool $isRecommended): self
{
$this->isRecommended = $isRecommended;
return $this;
}
public function getRating(): ?float
{
return $this->rating;
}
public function setRating(float $rating): self
{
$this->rating = $rating;
return $this;
}
public function getIsNativeSpeaker(): ?bool
{
return $this->isNativeSpeaker;
}
public function setIsNativeSpeaker(bool $isNativeSpeaker): self
{
$this->isNativeSpeaker = $isNativeSpeaker;
return $this;
}
/**
* @return false
*/
public function getIsCustomized(): bool
{
return $this->isCustomized;
}
/**
* @param false $isCustomized
*/
public function setIsCustomized(bool $isCustomized): void
{
$this->isCustomized = $isCustomized;
}
public function getTeachingType(): ?TeachingType
{
return $this->teachingType;
}
public function setTeachingType(?TeachingType $teachingType): self
{
$this->teachingType = $teachingType;
return $this;
}
public function getOnlyForAdults(): ?bool
{
return $this->onlyForAdults;
}
public function setOnlyForAdults(?bool $onlyForAdults): self
{
$this->onlyForAdults = $onlyForAdults;
return $this;
}
public function getLastStep(): ?int
{
return $this->lastStep;
}
public function setLastStep(int $lastStep): self
{
if ($lastStep > 7) {
$lastStep = 7;
}
$this->lastStep = $lastStep;
return $this;
}
/**
* @return Collection|CourseTerm[]
*/
public function getTerms(): Collection
{
return $this->terms;
}
public function addTerm(CourseTerm $term): self
{
if (!$this->terms->contains($term)) {
$this->terms[] = $term;
$term->setCourse($this);
}
return $this;
}
public function removeTerm(CourseTerm $term): self
{
if ($this->terms->removeElement($term)) {
// set the owning side to null (unless already changed)
if ($term->getCourse() === $this) {
$term->setCourse(null);
}
}
return $this;
}
public function getPlaceDescription(): ?string
{
return $this->placeDescription;
}
public function setPlaceDescription(?string $placeDescription): self
{
$this->placeDescription = $placeDescription;
return $this;
}
/**
* @return mixed
*/
public function getRetrainingType()
{
return $this->retrainingType;
}
/**
* @param mixed $retrainingType
*/
public function setRetrainingType($retrainingType): void
{
$this->retrainingType = $retrainingType;
}
/**
* @return mixed
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* @param mixed $latitude
*/
public function setLatitude($latitude): void
{
$this->latitude = $latitude;
}
/**
* @return mixed
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* @param mixed $longitude
*/
public function setLongitude($longitude): void
{
$this->longitude = $longitude;
}
/**
* @return mixed
*/
public function getCode()
{
return $this->code;
}
/**
* @param mixed $code
*/
public function setCode($code): void
{
$this->code = $code;
}
public function getExternalCode()
{
return str_replace($this->getOrganizer()->getId() . '_', '', $this->code);
}
public function getTargetGroup(): ?TargetGroup
{
return $this->targetGroup;
}
public function setTargetGroup(?TargetGroup $targetGroup): self
{
$this->targetGroup = $targetGroup;
return $this;
}
/**
* @return mixed
*/
public function getEndAt()
{
return $this->endAt;
}
/**
* @param mixed $endAt
*/
public function setEndAt($endAt): void
{
$this->endAt = $endAt;
}
public function getControlEndAt()
{
if($this->terms->isEmpty()) {
return $this->endAt;
}
$latestTerm = $this->getLatestTerm();
return $latestTerm->getEnd();
}
public function getLatestTerm()
{
// Vytvořte Criteria objekt pro řazení podle data sestupně
$criteria = Criteria::create()->orderBy(['end' => 'DESC'])->setMaxResults(1);
// Použijte Criteria na filtrování podřízených entit
$latestSubEntity = $this->terms->matching($criteria)->first();
return $latestSubEntity;
}
}