add db and fixtures

This commit is contained in:
Tykayn 2025-05-26 11:32:53 +02:00 committed by tykayn
parent 03f53f4688
commit 528ebb672a
20 changed files with 1655 additions and 116 deletions

View file

@ -2,6 +2,9 @@
namespace App\Controller;
use App\Entity\Stats;
use App\Entity\Place;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -13,6 +16,11 @@ class PublicController extends AbstractController
private $mapbox_token = 'BVM2NRJuzQunWvXbTnzg';
private $maptiler_token = 'BVM2NRJuzQunWvXbTnzg';
public function __construct(
private EntityManagerInterface $entityManager
) {
}
public function get_osm_object_data($osm_object_id = 12855459190)
{
@ -45,7 +53,7 @@ class PublicController extends AbstractController
];
// Récupérer les vraies données OSM
$client = new \GuzzleHttp\Client();
$client = new Client();
try {
$response = $client->get($object_id);
$xml = simplexml_load_string($response->getBody()->getContents());
@ -89,6 +97,19 @@ class PublicController extends AbstractController
]);
}
#[Route('/dashboard', name: 'app_public_dashboard')]
public function dashboard(): Response
{
// get stats
$stats = $this->entityManager->getRepository(Stats::class)->findAll();
$places = $this->entityManager->getRepository(Place::class)->findAll();
return $this->render('public/dashboard.html.twig', [
'controller_name' => 'PublicController',
'stats' => $stats,
'places' => $places,
]);
}
#[Route('/modify/{osm_object_id}/{version}/{changesetID}', name: 'app_public_submit')]
public function submit($osm_object_id, $version, $changesetID): Response
{

View file

@ -0,0 +1,17 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}

View file

@ -0,0 +1,62 @@
<?php
namespace App\DataFixtures;
use App\Entity\History;
use App\Entity\Place;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Faker\Factory;
use App\Entity\Stats;
class HistoryFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
$faker = Factory::create('fr_FR');
$places_list = [];
// Créer quelques places de test
for ($i = 0; $i < 15; $i++) {
$place = new Place();
$place->setName($faker->company)
->setUuidForUrl($faker->uuid)
->setOsmId((string)$faker->numberBetween(1000000, 9999999))
->setOsmKind($faker->randomElement(['node', 'way', 'relation']))
->setEmail($faker->email)
->setOptedOut($faker->boolean)
->setDead($faker->boolean)
->setNote($faker->text)
->setModifiedDate($faker->dateTimeBetween('-1 year', 'now'))
->setAskedHumainsSupport($faker->boolean)
->setLastContactAttemptDate($faker->dateTimeBetween('-1 year', 'now'))
->setZipCode($faker->numberBetween(10000, 99999));
$manager->persist($place);
$places_list[] = $place;
// Créer plusieurs historiques pour chaque place
for ($j = 0; $j < 3; $j++) {
$history = new History();
$history->setPlaceId($place);
$history->setCompletionPercent($faker->numberBetween(0, 100));
$history->setDateTime($faker->dateTimeBetween('-1 year', 'now'));
$manager->persist($history);
}
}
// Créer des statistiques de test
for ($i = 0; $i < 3; $i++) {
$stat = new Stats();
$stat->setZone($faker->city)
->setCompletionPercent($faker->numberBetween(0, 100))
->addPlace( $faker->randomElement($places_list))
->addPlace( $faker->randomElement($places_list))
->addPlace( $faker->randomElement($places_list))
->setPlacesCount($faker->numberBetween(100, 1000));
$manager->persist($stat);
}
$manager->flush();
}
}

71
src/Entity/History.php Normal file
View file

@ -0,0 +1,71 @@
<?php
namespace App\Entity;
use App\Repository\HistoryRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: HistoryRepository::class)]
class History
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
private ?int $completion_percent = null;
#[ORM\Column]
private ?\DateTime $date_time = null;
#[ORM\ManyToOne(inversedBy: 'histories')]
#[ORM\JoinColumn(nullable: false)]
private ?Place $place_id = null;
public function getId(): ?int
{
return $this->id;
}
public function getCompletionPercent(): ?int
{
return $this->completion_percent;
}
public function setCompletionPercent(?int $completion_percent): static
{
$this->completion_percent = $completion_percent;
return $this;
}
public function getDateTime(): ?\DateTime
{
return $this->date_time;
}
public function setDateTime(\DateTime $date_time): static
{
$this->date_time = $date_time;
return $this;
}
public function getPlaceId(): ?Place
{
return $this->place_id;
}
public function setPlaceId(?Place $place_id): static
{
$this->place_id = $place_id;
return $this;
}
}

259
src/Entity/Place.php Normal file
View file

@ -0,0 +1,259 @@
<?php
namespace App\Entity;
use App\Repository\PlaceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PlaceRepository::class)]
class Place
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 50)]
private ?string $uuid_for_url = null;
#[ORM\Column(length: 10)]
private ?string $osm_kind = null;
#[ORM\Column(length: 255)]
private ?string $email = null;
#[ORM\Column]
private ?bool $opted_out = null;
#[ORM\Column]
private ?bool $dead = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $note = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $modified_date = null;
#[ORM\Column(type: Types::INTEGER)]
private ?int $zip_code = null;
#[ORM\Column]
private ?bool $asked_humains_support = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $last_contact_attempt_date = null;
/**
* @var Collection<int, History>
*/
#[ORM\OneToMany(targetEntity: History::class, mappedBy: 'place_id', orphanRemoval: true)]
private Collection $histories;
#[ORM\ManyToOne(inversedBy: 'places')]
private ?Stats $stats = null;
#[ORM\Column(type: Types::BIGINT)]
private ?string $osmId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
public function __construct()
{
$this->histories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuidForUrl(): ?string
{
return $this->uuid_for_url;
}
public function setUuidForUrl(string $uuid_for_url): static
{
$this->uuid_for_url = $uuid_for_url;
return $this;
}
public function getOsmKind(): ?string
{
return $this->osm_kind;
}
public function setOsmKind(string $osm_kind): static
{
$this->osm_kind = $osm_kind;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function isOptedOut(): ?bool
{
return $this->opted_out;
}
public function setOptedOut(bool $opted_out): static
{
$this->opted_out = $opted_out;
return $this;
}
public function isDead(): ?bool
{
return $this->dead;
}
public function setDead(bool $dead): static
{
$this->dead = $dead;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): static
{
$this->note = $note;
return $this;
}
public function getModifiedDate(): ?\DateTime
{
return $this->modified_date;
}
public function setModifiedDate(?\DateTime $modified_date): static
{
$this->modified_date = $modified_date;
return $this;
}
public function getZipCode(): ?int
{
return $this->zip_code;
}
public function setZipCode(int $zip_code): static
{
$this->zip_code = $zip_code;
return $this;
}
public function isAskedHumainsSupport(): ?bool
{
return $this->asked_humains_support;
}
public function setAskedHumainsSupport(bool $asked_humains_support): static
{
$this->asked_humains_support = $asked_humains_support;
return $this;
}
public function getLastContactAttemptDate(): ?\DateTime
{
return $this->last_contact_attempt_date;
}
public function setLastContactAttemptDate(?\DateTime $last_contact_attempt_date): static
{
$this->last_contact_attempt_date = $last_contact_attempt_date;
return $this;
}
/**
* @return Collection<int, History>
*/
public function getHistories(): Collection
{
return $this->histories;
}
public function addHistory(History $history): static
{
if (!$this->histories->contains($history)) {
$this->histories->add($history);
$history->setPlaceId($this);
}
return $this;
}
public function removeHistory(History $history): static
{
if ($this->histories->removeElement($history)) {
// set the owning side to null (unless already changed)
if ($history->getPlaceId() === $this) {
$history->setPlaceId(null);
}
}
return $this;
}
public function getStats(): ?Stats
{
return $this->stats;
}
public function setStats(?Stats $stats): static
{
$this->stats = $stats;
return $this;
}
public function getOsmId(): ?string
{
return $this->osmId;
}
public function setOsmId(string $osmId): static
{
$this->osmId = $osmId;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
}

109
src/Entity/Stats.php Normal file
View file

@ -0,0 +1,109 @@
<?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;
#[ORM\Column(type: Types::SMALLINT)]
private ?int $places_count = null;
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;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\History;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<History>
*/
class HistoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, History::class);
}
// /**
// * @return History[] Returns an array of History objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('h')
// ->andWhere('h.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('h.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?History
// {
// return $this->createQueryBuilder('h')
// ->andWhere('h.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Place;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Place>
*/
class PlaceRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Place::class);
}
// /**
// * @return Place[] Returns an array of Place objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Place
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Placve;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Placve>
*/
class PlacveRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Placve::class);
}
// /**
// * @return Placve[] Returns an array of Placve objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Placve
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View file

@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Stats;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Stats>
*/
class StatsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Stats::class);
}
// /**
// * @return Stats[] Returns an array of Stats objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Stats
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}