src/Entity/Calendar.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use ReflectionClass;
  8. #[ORM\Entity]
  9.  #[ORM\Table(name: "calendar")]
  10.  #[ORM\InheritanceType("SINGLE_TABLE")]
  11.  #[ORM\DiscriminatorColumn(name: "calendarType", type: "string")]
  12.  #[ORM\DiscriminatorMap(["activity" => Activity::class, "staffSchedule" => StaffSchedule::class])]
  13.  abstract class Calendar
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     protected ?int $id = null;
  19.     #[ORM\Column(length: 255)]
  20.     protected ?string $title = null;
  21.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  22.      public ?\DateTimeInterface $start = null;
  23.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  24.      protected ?\DateTimeInterface $end = null;
  25.   
  26.      /**
  27.      * @ORM\OneToMany(mappedBy="calendar", targetEntity="PurchaseItem", cascade={"remove"})
  28.      */
  29.     private Collection $purchaseItems;
  30.     /*
  31.     #[ORM\OneToMany(mappedBy: 'calendar', targetEntity: PurchaseItem::class)]
  32.      private Collection $purchaseItems;  */
  33.    
  34.      #[ORM\ManyToMany(targetEntity: Staff::class, inversedBy: 'calendars', cascade: ['remove'])]
  35.      #[ORM\JoinColumn(nullable: true)]
  36.      private $staffs;
  37.      
  38.     #[ORM\ManyToOne(inversedBy: 'calendars')]
  39.     #[ORM\JoinColumn(nullable: false)]
  40.     protected ?Category $category = null;
  41.     #[ORM\ManyToMany(targetEntity: Tide::class, inversedBy: 'calendars')]
  42.     protected Collection $tides;
  43.     #[ORM\Column]
  44.     private ?bool $visible = null;
  45.     #[ORM\Column(nullable: true)]
  46.     private ?bool $annulation = null;
  47.     
  48.   
  49.     public function __construct()
  50.     {
  51.         $this->staffs = new ArrayCollection();
  52.         $this->tides = new ArrayCollection();
  53.         $this->annulation = false;
  54.        
  55.     }
  56.    
  57.    // #[ORM\Column(nullable: true)]
  58.    // private ?int $price = null;
  59.    // #[ORM\Column(nullable: true)]
  60.    // private ?int $modifiedPrice = null;
  61.     /*#[Assert\NotBlank]  */
  62.   /*  #[ORM\Column(length: 255,nullable: true)]
  63.     private ?string $picture = null; */
  64.   
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getTitle(): ?string
  70.     {
  71.         return $this->title;
  72.     }
  73.     public function setTitle(string $title): static
  74.     {
  75.         $this->title = $title;
  76.         return $this;
  77.     }
  78.      public function getStart(): ?\DateTimeInterface
  79.      {
  80.          return $this->start;
  81.      }
  82.      public function setStart(\DateTimeInterface $start): self
  83.      {
  84.          $this->start = $start;
  85.          return $this;
  86.      }
  87.      public function getEnd(): ?\DateTimeInterface
  88.      {
  89.          return $this->end;
  90.      }
  91.      public function setEnd(\DateTimeInterface $end): self
  92.      {
  93.          $this->end = $end;
  94.          return $this;
  95.      }
  96.      protected function getDefaultPrice(): ?int
  97.      {
  98.          // Récupérer le prix par défaut de la catégorie associée à l'activité
  99.          $category = $this->getCategory();
  100.          if ($category) {
  101.              $categorySetting = $category->getCategorySetting();
  102.              if ($categorySetting) {
  103.                  return $categorySetting->getPrice();
  104.              }
  105.          }
  106.          return null;
  107.      }
  108.  
  109.      public function getPrice(): ?int
  110.      {
  111.          if ($this->modifiedPrice !== null) {
  112.              return $this->modifiedPrice;
  113.          } else {
  114.              return $this->getDefaultPrice();
  115.          }
  116.      }
  117.      
  118.      public function getModifiedPrice(): ?int
  119.      {
  120.          return $this->modifiedPrice;
  121.      }
  122.      
  123.      public function setModifiedPrice(?int $modifiedPrice): self
  124.      {
  125.          $this->modifiedPrice = $modifiedPrice;
  126.          // Si modifiedPrice est défini, on l'utilise à la place de price
  127.          $this->price = $modifiedPrice !== null ? $modifiedPrice : $this->price;
  128.          return $this;
  129.      }
  130.      
  131.     /**
  132.      * @return Collection<int, Staff>
  133.      */
  134.     public function getStaffs(): Collection
  135.     {
  136.         return $this->staffs ?? new ArrayCollection(); // Utilisez un opérateur de coalescence null pour retourner une nouvelle collection si $staffs est null
  137.     }
  138.     public function addStaff(Staff $staff): static
  139.     {
  140.         $this->staffs = $this->staffs ?? new ArrayCollection(); // Initialiser $this->staffs si elle est null
  141.         if (!$this->staffs->contains($staff)) {
  142.             $this->staffs->add($staff);
  143.             $staff->addCalendar($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeStaff(Staff $staff): static
  148.     {
  149.         if ($this->staffs->removeElement($staff)) {
  150.             $staff->removeCalendar($this);
  151.         }
  152.         return $this;
  153.     }
  154.      public function getClassName(){
  155.          $class = new ReflectionClass($this);
  156.          return $class->getShortName();
  157.      }
  158.      public function getCategory(): ?Category
  159.      {
  160.          return $this->category;
  161.      }
  162.  
  163.      public function setCategory(?Category $category): self
  164.      {
  165.          $this->category = $category;
  166.  
  167.          return $this;
  168.      }
  169.      /**
  170.       * @return Collection<int, Tide>
  171.       */
  172.      public function getTides(): Collection
  173.      {
  174.          return $this->tides;
  175.      }
  176.      public function addTide(Tide $tide): static
  177.      {
  178.          if (!$this->tides->contains($tide)) {
  179.              $this->tides->add($tide);
  180.          }
  181.          return $this;
  182.      }
  183.      public function removeTide(Tide $tide): static
  184.      {
  185.          $this->tides->removeElement($tide);
  186.          return $this;
  187.      }
  188.      public function isVisible(): ?bool
  189.      {
  190.          return $this->visible;
  191.      }
  192.      public function setVisible(bool $visible): static
  193.      {
  194.          $this->visible = $visible;
  195.          return $this;
  196.      }
  197.      
  198.      public function isAnnulation(): ?bool
  199.      {
  200.          return $this->annulation;
  201.      }
  202.      public function setAnnulation(?bool $annulation): static
  203.      {
  204.          $this->annulation = $annulation;
  205.          return $this;
  206.      }
  207.      
  208.      
  209. }