<?php
namespace App\Entity\Tutoring;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\Tutoring\MeetingRepository;
use App\Traits\Actions;
use App\Entity\Tutoring\Month;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* Meeting
*/
#[ORM\Entity(repositoryClass: MeetingRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_meeting')]
#[ApiResource]
class Meeting
{
use Actions;
#[ORM\ManyToOne(targetEntity: Month::class, cascade: ['persist'], inversedBy: 'meetings')]
private ?Month $month = null;
#[ORM\OneToMany(mappedBy: 'meeting', targetEntity: Presence::class, cascade: ['persist'], orphanRemoval: true)]
private ?Collection $presences = null;
public function __construct()
{
$this->createAt=new \DateTime('now');
$this->published=true;
}
/**
* Set month
*
*
* @return Meeting
*/
public function setMonth(Month $month = null)
{
$this->month = $month;
return $this;
}
/**
* Get month
*
* @return \App\Entity\Tutoring\Month
*/
public function getMonth()
{
return $this->month;
}
public function getNameDay($format){
switch ($format){
case 'short':
$days=['','Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam','Di'];
return $days[$this->createAt->format('N')].' '.$this->createAt->format("d");
case 'long':
$days=['','Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi','Dimanche'];
return $days[$this->createAt->format('N')].' '.$this->createAt->format("d/m");
}
}
/**
* Add presence
*
*
* @return Meeting
*/
public function addPresence(Presence $presence)
{
$presence->setMeeting($this);
$this->presences[] = $presence;
return $this;
}
/**
* Remove presence
*/
public function removePresence(Presence $presence)
{
$this->presences->removeElement($presence);
}
/**
* Get presences
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPresences()
{
return $this->presences;
}
public function setCreateAt(\DateTime $createAt): void
{
$this->createAt = $createAt;
}
public function isPassed(): bool
{
$today=new \DateTime('now');
return $this->createAt< $today;
}
}