2025-05-26 11:32:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use App\Repository\StatsRepository;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: StatsRepository::class)]
|
|
|
|
class Stats
|
|
|
|
{
|
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\GeneratedValue]
|
|
|
|
#[ORM\Column]
|
|
|
|
private ?int $id = null;
|
|
|
|
|
|
|
|
#[ORM\Column(length: 255)]
|
|
|
|
private ?string $zone = null;
|
|
|
|
|
|
|
|
#[ORM\Column(type: Types::SMALLINT)]
|
|
|
|
private ?int $completion_percent = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Collection<int, Place>
|
|
|
|
*/
|
|
|
|
#[ORM\OneToMany(targetEntity: Place::class, mappedBy: 'stats')]
|
|
|
|
private Collection $places;
|
|
|
|
|
2025-05-26 23:51:46 +02:00
|
|
|
// nombre de commerces dans la zone
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
2025-05-26 11:32:53 +02:00
|
|
|
private ?int $places_count = null;
|
|
|
|
|
2025-05-26 23:51:46 +02:00
|
|
|
// nombre de commerces avec horaires
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
|
|
|
private ?int $avec_horaires = null;
|
|
|
|
|
|
|
|
// nombre de commerces avec adresse
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
|
|
|
private ?int $avec_adresse = null;
|
|
|
|
|
|
|
|
// nombre de commerces avec site
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
|
|
|
private ?int $avec_site = null;
|
|
|
|
|
|
|
|
// nombre de commerces avec accessibilité
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
|
|
|
private ?int $avec_accessibilite = null;
|
|
|
|
|
|
|
|
// nombre de commerces avec note
|
|
|
|
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
|
|
|
private ?int $avec_note = null;
|
|
|
|
|
|
|
|
// calcule le pourcentage de complétion de la zone
|
|
|
|
public function computeCompletionPercent(): ?int
|
|
|
|
{
|
|
|
|
// Si aucun commerce, on retourne 0
|
|
|
|
if ($this->places_count === 0 || $this->places_count === null) {
|
|
|
|
$this->setCompletionPercent(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// On prend le maximum entre les différents critères
|
|
|
|
$max = max(
|
|
|
|
$this->avec_horaires ?? 0,
|
|
|
|
$this->avec_adresse ?? 0,
|
|
|
|
$this->avec_site ?? 0,
|
|
|
|
$this->avec_accessibilite ?? 0,
|
|
|
|
$this->avec_note ?? 0
|
|
|
|
);
|
|
|
|
$computed = round(($max) / $this->places_count * 100);
|
|
|
|
$this->setCompletionPercent($computed);
|
|
|
|
return $this->completion_percent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-26 11:32:53 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->places = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId(): ?int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getZone(): ?string
|
|
|
|
{
|
|
|
|
return $this->zone;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setZone(string $zone): static
|
|
|
|
{
|
|
|
|
$this->zone = $zone;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCompletionPercent(): ?int
|
|
|
|
{
|
|
|
|
return $this->completion_percent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCompletionPercent(int $completion_percent): static
|
|
|
|
{
|
|
|
|
$this->completion_percent = $completion_percent;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection<int, Place>
|
|
|
|
*/
|
|
|
|
public function getPlaces(): Collection
|
|
|
|
{
|
|
|
|
return $this->places;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addPlace(Place $place): static
|
|
|
|
{
|
|
|
|
if (!$this->places->contains($place)) {
|
|
|
|
$this->places->add($place);
|
|
|
|
$place->setStats($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removePlace(Place $place): static
|
|
|
|
{
|
|
|
|
if ($this->places->removeElement($place)) {
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ($place->getStats() === $this) {
|
|
|
|
$place->setStats(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlacesCount(): ?int
|
|
|
|
{
|
|
|
|
return $this->places_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPlacesCount(int $places_count): static
|
|
|
|
{
|
|
|
|
$this->places_count = $places_count;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2025-05-26 23:51:46 +02:00
|
|
|
|
|
|
|
public function getAvecHoraires(): ?int
|
|
|
|
{
|
|
|
|
return $this->avec_horaires;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAvecHoraires(int $avec_horaires): static
|
|
|
|
{
|
|
|
|
$this->avec_horaires = $avec_horaires;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvecAdresse(): ?int
|
|
|
|
{
|
|
|
|
return $this->avec_adresse;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAvecAdresse(int $avec_adresse): static
|
|
|
|
{
|
|
|
|
$this->avec_adresse = $avec_adresse;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvecSite(): ?int
|
|
|
|
{
|
|
|
|
return $this->avec_site;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAvecSite(int $avec_site): static
|
|
|
|
{
|
|
|
|
$this->avec_site = $avec_site;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvecAccessibilite(): ?int
|
|
|
|
{
|
|
|
|
return $this->avec_accessibilite;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAvecAccessibilite(int $avec_accessibilite): static
|
|
|
|
{
|
|
|
|
$this->avec_accessibilite = $avec_accessibilite;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAvecNote(): ?int
|
|
|
|
{
|
|
|
|
return $this->avec_note;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAvecNote(int $avec_note): static
|
|
|
|
{
|
|
|
|
$this->avec_note = $avec_note;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|