src/Entity/Course.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\CourseOccurrence;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JMS\Serializer\Annotation as JMS;
  6. use Doctrine\Common\Collections\Collection;
  7. use Menke\UserBundle\Entity\Client;
  8. use Menke\CommonsBundle\Entity\GenericEntity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use EXSyst\Component\Swagger\Response;
  11. /**
  12.  * @ORM\Entity(repositoryClass="App\Repository\CourseRepository")
  13.  * @JMS\ExclusionPolicy("all")
  14.  */
  15. class Course extends GenericEntity
  16. {
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity="\Menke\UserBundle\Entity\Client")
  19.      * @ORM\JoinColumn(name="clientId", referencedColumnName="id")
  20.      */
  21.     protected $client;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      * @JMS\Expose
  25.      * @JMS\Groups({"public"})
  26.      */
  27.     protected $title;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, nullable=true)
  30.      * @JMS\Expose
  31.      * @JMS\Groups({"public"})
  32.      */
  33.     protected $subtitle;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, options={"default" : "Course"})
  36.      * @JMS\Expose
  37.      * @JMS\Groups({"public", "personal"})
  38.      */
  39.     protected $courseNature 'Course';
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\CourseSubscription")
  42.      * @JMS\Expose
  43.      * @JMS\Groups({"public"})
  44.      */
  45.     protected $subscription;
  46.     /**
  47.      * @ORM\Column(type="text", nullable=true)
  48.      * @JMS\Expose
  49.      * @JMS\Groups({"public"})
  50.      */
  51.     protected $description;
  52.     /**
  53.      * @ORM\Column(type="float")
  54.      * @JMS\Expose
  55.      * @JMS\Groups({"public"})
  56.      */
  57.     protected $price;
  58.     /**
  59.      * @ORM\Column(type="float", nullable=true)
  60.      */
  61.     protected $taxRate 0;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity="CourseOccurrence", mappedBy="course", cascade={"all"})
  64.      * @JMS\Expose
  65.      * @JMS\Groups({"public"})
  66.      */
  67.     protected $occurrences;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity="App\Entity\Category")
  70.      * @JMS\Expose
  71.      * @JMS\Groups({"public"})
  72.      */
  73.     protected $category;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity="App\Entity\CourseImage", mappedBy="course", orphanRemoval=true, cascade={"all"})
  76.      * @ORM\OrderBy({"orderId" = "ASC"})
  77.      * @JMS\Expose
  78.      * @JMS\Groups({"public"})
  79.      */
  80.     protected $images;
  81.     /**
  82.      * @ORM\Column(type="string", length=20, nullable=true)
  83.      * @JMS\Expose
  84.      * @JMS\Groups({"public"})
  85.      */
  86.     protected $number;
  87.     /**
  88.      * @ORM\Column(type="float", nullable=true)
  89.      * @JMS\Expose
  90.      * @JMS\Groups({"public"})
  91.      */
  92.     protected $materialCost 0.0;
  93.     /**
  94.      * @ORM\Column(type="integer", nullable=true)
  95.      * @JMS\Expose
  96.      * @JMS\Groups({"public"})
  97.      */
  98.     protected $targetAgeMin;
  99.     /**
  100.      * @ORM\Column(type="integer", nullable=true)
  101.      * @JMS\Expose
  102.      * @JMS\Groups({"public"})
  103.      */
  104.     protected $targetAgeMax;
  105.     /**
  106.      * @ORM\OneToMany(targetEntity="App\Entity\CourseText", mappedBy="course", orphanRemoval=true, cascade={"all"})
  107.      * @ORM\OrderBy({"orderId" = "ASC"})
  108.      * @JMS\Expose
  109.      * @JMS\Groups({"detail"})
  110.      */
  111.     protected $texts;
  112.     /**
  113.      * @ORM\ManyToOne(targetEntity="App\Entity\CourseSeries", inversedBy="courses")
  114.      * @JMS\Expose
  115.      * @JMS\Groups({"public"})
  116.      */
  117.     protected $series;
  118.     /**
  119.      * @ORM\ManyToOne(targetEntity="App\Entity\CourseType")
  120.      * @JMS\Expose
  121.      * @JMS\Groups({"public", "personal"})
  122.      */
  123.     protected $type;
  124.     /**
  125.      * @ORM\Column(type="text", nullable=true)
  126.      */
  127.     protected $invoiceUpperComment;
  128.     /**
  129.      * @ORM\Column(type="text", nullable=true)
  130.      */
  131.     protected $invoiceLowerComment;
  132.     /**
  133.      * @ORM\Column(type="text", nullable=true)
  134.      */
  135.     protected $invoiceLowerCommentDebit;
  136.     /**
  137.      * @JMS\Expose
  138.      * @JMS\Groups({"public"})
  139.      */
  140.     protected $fields;
  141.     public function __construct()
  142.     {
  143.         $this->occurrences = new ArrayCollection();
  144.         $this->images = new ArrayCollection();
  145.         $this->texts = new ArrayCollection();
  146.     }
  147.     /**
  148.      * @return Client
  149.      */
  150.     public function getClient(): ?Client
  151.     {
  152.         return $this->client;
  153.     }
  154.     /**
  155.      * @param Client $client
  156.      * @return Course
  157.      */
  158.     public function setClient($client): self
  159.     {
  160.         $this->client $client;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return null|string
  165.      */
  166.     public function getTitle(): ?string
  167.     {
  168.         // $title = str_replace('&shy;', '', $this->title);
  169.         //   return $title;
  170.         return $this->title;
  171.     }
  172.     /**
  173.      * @param string $title
  174.      * @return Course
  175.      */
  176.     public function setTitle(string $title): self
  177.     {
  178.         $this->title $title;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @return null|string
  183.      */
  184.     public function getSubtitle(): ?string
  185.     {
  186.         return $this->subtitle;
  187.     }
  188.     /**
  189.      * @param null|string $subtitle
  190.      * @return Course
  191.      */
  192.     public function setSubtitle(?string $subtitle): self
  193.     {
  194.         $this->subtitle $subtitle;
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return null|string
  199.      */
  200.     public function getDescription(): ?string
  201.     {
  202.         return $this->description;
  203.     }
  204.     /**
  205.      * @param null|string $description
  206.      * @return Course
  207.      */
  208.     public function setDescription(?string $description): self
  209.     {
  210.         $this->description $description;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return float|null
  215.      */
  216.     public function getPrice(): ?float
  217.     {
  218.         return $this->price;
  219.     }
  220.     /**
  221.      * @param float $price
  222.      * @return Course
  223.      */
  224.     public function setPrice(float $price): self
  225.     {
  226.         $this->price $price;
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return float
  231.      */
  232.     public function getTaxRate(): ?float
  233.     {
  234.         return $this->taxRate;
  235.     }
  236.     /**
  237.      * @param float $taxRate
  238.      * @return Course
  239.      */
  240.     public function setTaxRate(?float $taxRate)
  241.     {
  242.         $this->taxRate $taxRate;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @JMS\Expose
  247.      * @JMS\Groups({"detail"})
  248.      * @JMS\VirtualProperty()
  249.      * @JMS\Type("array<App\Entity\CourseOccurrence>")
  250.      * @param ArrayCollection<CourseOccurrence> $occurrences
  251.      * @return array<App\Entity\CourseOccurrence>
  252.      */
  253.     public function getOccurrences(bool $onlyPublished falsebool $isBookable false): ArrayCollection
  254.     {
  255.         $occurrences = new ArrayCollection;
  256.         foreach ($this->occurrences as $occurrence) {
  257.             if ($isBookable) {
  258.                 if ($occurrence->getEnd() > new \DateTime() && $occurrence->isBookable() && (!$onlyPublished || $occurrence->getPublished())) {
  259.                     $occurrences->add($occurrence);
  260.                 }  
  261.             }else{
  262.                 $occurrences->add($occurrence);
  263.             } 
  264.         }
  265.         return $occurrences;
  266.     }
  267.     public function getAllOccurrences(bool $onlyPublished falsebool $isBookable false): ArrayCollection
  268.     {
  269.         $occurrences = new ArrayCollection();
  270.         foreach ($this->occurrences as $occurrence) {
  271.             if ($onlyPublished && !$occurrence->getPublished()) {
  272.                 continue;
  273.             }
  274.             if ($isBookable && !$occurrence->isBookable()) {
  275.                 continue;
  276.             }
  277.             // Beispiel für zusätzliche Berechnungen
  278.             // $freeSlots = $occurrence->getSlots() - $occurrence->getBookedSlots();
  279.             //$occurrence->setFreeSlots($freeSlots); // Beispielmethodenaufruf
  280.             $occurrences->add($occurrence);
  281.         }
  282.         return $occurrences;
  283.     }
  284.     /**
  285.      * @param ArrayCollection<CourseOccurrence> $occurrences
  286.      * @return Course
  287.      */
  288.     public function setOccurrences($occurrences): self
  289.     {
  290.         $this->occurrences $occurrences;
  291.         return $this;
  292.     }
  293.     /**
  294.      * @param CourseOccurrence $occurrence
  295.      * @return Course
  296.      */
  297.     public function addOccurrence(CourseOccurrence $occurrence): self
  298.     {
  299.         $occurrence->setCourse($this);
  300.         $this->occurrences->add($occurrence);
  301.         return $this;
  302.     }
  303.     /**
  304.      * @param CourseOccurrence $occurrence
  305.      * @return Course
  306.      */
  307.     public function removeOccurrence(CourseOccurrence $occurrence)
  308.     {
  309.         if ($this->occurrences->contains($occurrence)) {
  310.             $this->occurrences->removeElement($occurrence);
  311.             if ($occurrence->getCourse() === $this) {
  312.                 $occurrence->setCourse(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Category|null
  319.      */
  320.     public function getCategory(): ?Category
  321.     {
  322.         return $this->category;
  323.     }
  324.     /**
  325.      * @param Category|null $category
  326.      * @return Course
  327.      */
  328.     public function setCategory(?Category $category): self
  329.     {
  330.         $this->category $category;
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return string
  335.      */
  336.     public function getCourseNature(): string
  337.     {
  338.         return $this->courseNature;
  339.     }
  340.     /**
  341.      *
  342.      */
  343.     public function setCourseNature($courseNature)
  344.     {
  345.         $this->courseNature $courseNature;
  346.     }
  347.     /**
  348.      * @return Collection|CourseImage[]
  349.      */
  350.     public function getImages(): Collection
  351.     {
  352.         return $this->images;
  353.     }
  354.     /**
  355.      * @param CourseImage $image
  356.      * @return Course
  357.      */
  358.     public function addImage(CourseImage $image): self
  359.     {
  360.         if (!$this->images->contains($image)) {
  361.             $this->images[] = $image;
  362.             $image->setCourse($this);
  363.         }
  364.         return $this;
  365.     }
  366.     /**
  367.      * @param CourseImage $image
  368.      * @return Course
  369.      */
  370.     public function removeImage(CourseImage $image): self
  371.     {
  372.         if ($this->images->contains($image)) {
  373.             $this->images->removeElement($image);
  374.             // set the owning side to null (unless already changed)
  375.             if ($image->getCourse() === $this) {
  376.                 $image->setCourse(null);
  377.             }
  378.         }
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return null|string
  383.      */
  384.     public function getNumber(): ?string
  385.     {
  386.         return $this->number;
  387.     }
  388.     /**
  389.      * @param null|string $number
  390.      * @return Course
  391.      */
  392.     public function setNumber(?string $number): self
  393.     {
  394.         $this->number $number;
  395.         return $this;
  396.     }
  397.     public function getMaterialCost(): ?float
  398.     {
  399.         return $this->materialCost;
  400.     }
  401.     public function setMaterialCost(?float $materialCost): self
  402.     {
  403.         $this->materialCost $materialCost;
  404.         return $this;
  405.     }
  406.     public function getTargetAgeMin(): ?int
  407.     {
  408.         return $this->targetAgeMin;
  409.     }
  410.     public function setTargetAgeMin(?int $targetAgeMin): self
  411.     {
  412.         $this->targetAgeMin $targetAgeMin;
  413.         return $this;
  414.     }
  415.     public function getTargetAgeMax(): ?int
  416.     {
  417.         return $this->targetAgeMax;
  418.     }
  419.     public function setTargetAgeMax(?int $targetAgeMax): self
  420.     {
  421.         $this->targetAgeMax $targetAgeMax;
  422.         return $this;
  423.     }
  424.     /**
  425.      * @return Collection|CourseText[]
  426.      */
  427.     public function getTexts(): Collection
  428.     {
  429.         return $this->texts;
  430.     }
  431.     public function addText(CourseText $text): self
  432.     {
  433.         if (!$this->texts->contains($text)) {
  434.             $this->texts[] = $text;
  435.             $text->setCourse($this);
  436.         }
  437.         return $this;
  438.     }
  439.     public function removeText(CourseText $text): self
  440.     {
  441.         if ($this->texts->contains($text)) {
  442.             $this->texts->removeElement($text);
  443.             // set the owning side to null (unless already changed)
  444.             if ($text->getCourse() === $this) {
  445.                 $text->setCourse(null);
  446.             }
  447.         }
  448.         return $this;
  449.     }
  450.     public function getSeries(): ?CourseSeries
  451.     {
  452.         return $this->series;
  453.     }
  454.     public function setSeries(?CourseSeries $series): self
  455.     {
  456.         $this->series $series;
  457.         return $this;
  458.     }
  459.     public function getSubscription(): ?CourseSubscription
  460.     {
  461.         return $this->subscription;
  462.     }
  463.     public function setSubscription(?CourseSubscription $subscription): self
  464.     {
  465.         $this->subscription $subscription;
  466.         return $this;
  467.     }
  468.     /**
  469.      * @JMS\Expose
  470.      * @JMS\Groups({"public", "personal"})
  471.      * @JMS\VirtualProperty()
  472.      * @JMS\Type("int")
  473.      * @return int
  474.      */
  475.     public function getId(): ?int
  476.     {
  477.         return parent::getId();
  478.     }
  479.     /**
  480.      * @return CourseType|null
  481.      */
  482.     public function getType(): ?CourseType
  483.     {
  484.         return $this->type;
  485.     }
  486.     /**
  487.      * @param Type|null $CourseType
  488.      * @return CourseType
  489.      */
  490.     public function setType(?CourseType $type): self
  491.     {
  492.         $this->type $type;
  493.         return $this;
  494.     }
  495.     /**
  496.      * @return string|null
  497.      */
  498.     public function getInvoiceUpperComment(): ?string
  499.     {
  500.         return $this->invoiceUpperComment;
  501.     }
  502.     /**
  503.      * @param string|null $invoiceUpperComment
  504.      * @return self
  505.      */
  506.     public function setInvoiceUpperComment(?string $invoiceUpperComment): self
  507.     {
  508.         $this->invoiceUpperComment $invoiceUpperComment;
  509.         return $this;
  510.     }
  511.     /**
  512.      * @return string|null
  513.      */
  514.     public function getInvoiceLowerComment(): ?string
  515.     {
  516.         return $this->invoiceLowerComment;
  517.     }
  518.     /**
  519.      * @param string|null $invoiceLowerComment
  520.      * @return self
  521.      */
  522.     public function setInvoiceLowerComment(?string $invoiceLowerComment): self
  523.     {
  524.         $this->invoiceLowerComment $invoiceLowerComment;
  525.         return $this;
  526.     }
  527.     /**
  528.      * @return string|null
  529.      */
  530.     public function getInvoiceLowerCommentDebit(): ?string
  531.     {
  532.         return $this->invoiceLowerCommentDebit;
  533.     }
  534.     /**
  535.      * @param string|null $invoiceLowerCommentDebit
  536.      * @return self
  537.      */
  538.     public function setInvoiceLowerCommentDebit(?string $invoiceLowerCommentDebit): self
  539.     {
  540.         $this->invoiceLowerCommentDebit $invoiceLowerCommentDebit;
  541.         return $this;
  542.     }
  543.     /**
  544.      * @JMS\Expose
  545.      * @JMS\Groups({"public"})
  546.      * @JMS\VirtualProperty()
  547.      * @JMS\SerializedName("type")
  548.      * @JMS\Type("string")
  549.      * @return int
  550.      */
  551.     public function getTypeSlug()
  552.     {
  553.         return $this->getType() ? $this->getType()->getSlug() : null;
  554.     }
  555.     /**
  556.      * @return bool|null
  557.      */
  558.     public function isArchive(): ?bool
  559.     {
  560.         $onlyPublished true;
  561.         $isBookable false;
  562.         if (count($this->getAllOccurrences($onlyPublished$isBookable)) < 1) {
  563.             return true;
  564.         }
  565.         $now = new \DateTime();
  566.         foreach ($this->getAllOccurrences($onlyPublished$isBookable) as $occurrence) {
  567.             $diff $now->diff($occurrence->getEnd());
  568.             if ($diff->invert == || $diff->$_ENV['DAYS_TO_ARCHIVE']) {
  569.                 return false;
  570.             }
  571.         }
  572.         return true;
  573.     }
  574.     /**
  575.      * @return array|null
  576.      */
  577.     public function getFields(): ?array
  578.     {
  579.         return $this->fields;
  580.     }
  581.     /**
  582.      * @param array $fields
  583.      */
  584.     public function setFields(array $fields): void
  585.     {
  586.         $this->fields $fields;
  587.     }
  588. }