<?php
namespace App\Entity\Tutoring;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\Tutoring\PresenceRepository;
use App\Traits\Actions;
use App\Entity\Tutoring\Month;
use Doctrine\ORM\Mapping as ORM;
/**
* Presence
*/
#[ORM\Entity(repositoryClass: PresenceRepository::class)]
#[ORM\Table(name: 'hs_tc_tutoring_presence')]
#[ApiResource]
class Presence
{
use Actions;
#[ORM\ManyToOne(targetEntity: Rowscourse::class, inversedBy: 'presences')]
#[ORM\JoinColumn(nullable: false)]
private ?Rowscourse $rowscourse = null;
#[ORM\ManyToOne(targetEntity: Meeting::class, inversedBy: 'presences')]
#[ORM\JoinColumn(nullable: false)]
private ?Meeting $meeting = null;
public function __construct()
{
$this->createAt=new \DateTime('now');
$this->published=true;
}
/**
* @return Meeting
*/
public function getMeeting(): ?Meeting
{
return $this->meeting;
}
/**
* @param Meeting $meeting
*/
public function setMeeting(?Meeting $meeting): Presence
{
$this->meeting = $meeting;
return $this;
}
/**
* @return Rowscourse
*/
public function getRowscourse(): ?Rowscourse
{
return $this->rowscourse;
}
/**
* @param Rowscourse $rowscourse
*/
public function setRowscourse(?Rowscourse $rowscourse): Presence
{
$this->rowscourse = $rowscourse;
return $this;
}
public function isAbondand(){
if($this->meeting->getMonth()->getStartAt()>=$this->rowscourse->getEndAt()) return true;
if($this->meeting->getMonth()->getEndAt()<=$this->rowscourse->getStartAt()) return true;
return false;
}
public function isPublished()
{
if(!$this->isAbondand()) return $this->published;
else return false;
}
public function getNameDay(){
$days=['Lundi','Mardi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi','Dimanche'];
return $days[$this->createAt->format('N')].' '.$this->createAt->format("d/m");
}
}