<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ProjetRepository;
#[ORM\Entity(repositoryClass: ProjetRepository::class)]
#[ORM\Table(name: '`projet`')]
class Projet
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: "projets_assignes")]
#[ORM\JoinTable(name: "projet_assignes")]
private $devAssignes;
#[ORM\ManyToOne(targetEntity: Client::class, inversedBy: "projets")]
private $client;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: "projets_crees")]
private $createur;
#[ORM\ManyToMany(targetEntity: Contact::class, inversedBy: "projets")]
#[ORM\JoinTable(name: "projet_contact")]
private $contacts;
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: "projets_suivi")]
#[ORM\JoinTable(name: "projet_user_suivi")]
private $suiviPar;
#[ORM\OneToMany(targetEntity: LiaisonProjetEtat::class, mappedBy: "projet", cascade: ["all"])]
private $etats;
#[ORM\OneToMany(targetEntity: Tache::class, mappedBy: "projet", cascade: ["remove"])]
private $taches;
#[ORM\Column(type: 'text', nullable:true)]
private $nom;
#[ORM\Column(type: 'boolean', nullable:true)]
private $isCache;
#[ORM\ManyToOne(targetEntity: EtatProjet::class)]
#[ORM\JoinColumn(name: "etatprojet_id", referencedColumnName: "id")]
private $lastEtat;
#[ORM\OneToMany(targetEntity: DossierTache::class, mappedBy: "projet", cascade: ['all'])]
private $dossiers;
#[ORM\OneToMany(targetEntity: EntreeWiki::class, mappedBy: "projet", cascade: ['remove'])]
private $entreesWiki;
#[ORM\Column]
private ?bool $hasWiki = null;
public function __construct() {
$this->etats = new ArrayCollection();
$this->taches = new ArrayCollection();
$this->contacts = new ArrayCollection;
$this->suiviPar = new ArrayCollection();
$this->devAssignes = new ArrayCollection();
$this->dossiers = new ArrayCollection();
$this->entreesWiki = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function getLastEtat(){
return $this->lastEtat;
}
public function setLastEtat(EtatProjet $lastEtat = null){
$this->lastEtat = $lastEtat;
}
public function getIsCache(){
return $this->isCache;
}
public function setIsCache($isCache){
$this->isCache = $isCache;
}
public function getCreateur(){
return $this->createur;
}
public function setCreateur(User $createur){
$this->createur = $createur;
}
public function setNom($nom)
{
$this->nom = $nom;
return $this;
}
public function getNom()
{
return $this->nom;
}
public function addDevAssignes(User $devAssignes)
{
$this->devAssignes = $devAssignes;
return $this;
}
public function getDevAssignes()
{
return $this->devAssignes;
}
public function addSuiviPar(User $suiviPar)
{
$this->suiviPar = $suiviPar;
$suiviPar->addProjetsSuivi($this);
return $this;
}
public function removeSuiviPar(User $suiviPar)
{
$this->suiviPar->remove($suiviPar);
$suiviPar->removeProjetsSuivi($this);
return $this;
}
public function getSuiviPar()
{
return $this->suiviPar;
}
public function setClient(Client $client)
{
$this->client = $client;
return $this;
}
public function getAllUsers(){
$resultat = array();
$assignes = $this->getDevAssignes()->toArray();
$suivi = $this->getSuiviPar()->toArray();
foreach($assignes as $u){
$resultat[] = $u;
}
if(!(empty($this->contacts))){
foreach($this->contacts as $contact){
$resultat[] = $contact->getUser();
}
}
foreach($suivi as $u){
$resultat[] = $u;
}
return $resultat;
}
public function getClient()
{
return $this->client;
}
public function getContacts()
{
return $this->contacts;
}
public function addContacts(Contact $contact)
{
$this->contacts->add($contact);
$contacts->addProjet($this);
return $this;
}
public function removeContact(Contact $contact)
{
return $this->contacts->removeElement($contact);
$contacts->removeProjet($this);
}
public function addEtat(LiaisonProjetEtat $etat)
{
$this->etats->add($etat);
return $this;
}
public function getEtats()
{
return $this->etats;
}
public function removeTache(Tache $taches)
{
$this->taches->remove($taches);
return $this;
}
public function addTache(Tache $taches)
{
$this->taches->add($taches);
return $this;
}
public function getTaches()
{
return $this->taches;
}
public function getTempsTotal(){
$tempsTotal = 0;
foreach ($this->getTaches() as $tache) {
foreach ($tache->getChronos() as $chrono) {
$tempsTotal += $chrono->getTemps();
}
}
$heures = floor(($tempsTotal)/3600);
$min = floor((($tempsTotal)- $heures *3600)/60);
$sec = floor( ((($tempsTotal)- $heures*3600)) - ($min*60) );
return $heures."H ".$min."min ".$sec." s";
}
public function getDossiers()
{
return $this->dossiers;
}
public function addDossier(DossierTache $dossier)
{
$this->dossiers->add($dossier);
$dossier->addProjet($this);
return $this;
}
public function removeDossier(DossierTache $dossier)
{
return $this->dossiers->remove($dossier);
$dossier->removeProjet($this);
}
public function displayName(){
if(!empty($this->getClient())){
return $this->getClient()->getNom()." - ".$this->getNom();
}else{
return $this->getNom();
}
}
public function getEntreesWiki()
{
return $this->entreesWiki;
}
public function addEntreeWiki(EntreeWiki $entreeWiki)
{
$this->entreesWiki->add($entreeWiki);
$entreeWiki->addProjet($this);
return $this;
}
public function removeEntreeWiki(DossierTache $entreeWiki)
{
return $this->entreesWiki->remove($entreeWiki);
$entreeWiki->removeProjet($this);
}
public function isHasWiki(): ?bool
{
return $this->hasWiki;
}
public function setHasWiki(bool $hasWiki): static
{
$this->hasWiki = $hasWiki;
return $this;
}
}