stats up
This commit is contained in:
parent
9ae7c0d3e4
commit
a1c5647b43
9 changed files with 172 additions and 83 deletions
|
@ -173,6 +173,13 @@ class PublicController extends AbstractController
|
|||
#[Route('/modify/{osm_object_id}/{version}/{changesetID}', name: 'app_public_submit')]
|
||||
public function submit($osm_object_id, $version, $changesetID): Response
|
||||
{
|
||||
|
||||
$place = $this->entityManager->getRepository(Place::class)->findOneBy(['osmId' => $osm_object_id]);
|
||||
if (!$place) {
|
||||
$this->addFlash('warning', 'Ce commerce n\'existe pas.');
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
|
||||
// Récupérer les données POST
|
||||
$request = Request::createFromGlobals();
|
||||
|
||||
|
@ -227,7 +234,7 @@ class PublicController extends AbstractController
|
|||
|
||||
$tag = $changeset->addChild('tag');
|
||||
$tag->addAttribute('k', 'comment');
|
||||
$tag->addAttribute('v', 'Modification des tags via l\'interface web #MonCommerceOSM');
|
||||
$tag->addAttribute('v', 'Modification dans #MonCommerceOSM');
|
||||
|
||||
$changesetResponse = $client->put('https://api.openstreetmap.org/api/0.6/changeset/create', [
|
||||
'body' => $changesetXml->asXML(),
|
||||
|
@ -305,7 +312,28 @@ class PublicController extends AbstractController
|
|||
// après envoi on récupère les données
|
||||
$commerce = $this->motocultrice->get_osm_object_data($osm_kind, $osm_object_id);
|
||||
|
||||
|
||||
$place->update_place_from_overpass_data($commerce);
|
||||
$this->entityManager->persist($place);
|
||||
$this->entityManager->flush();
|
||||
|
||||
|
||||
$stats = $place->getStats();
|
||||
if(!$stats) {
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zip_code' => $place->getZipCode()]);
|
||||
}
|
||||
if(!$stats) {
|
||||
$stats = new Stats();
|
||||
$stats->setZipCode($place->getZipCode());
|
||||
}
|
||||
|
||||
$stats->addPlace($place);
|
||||
$place->setStats($stats);
|
||||
|
||||
$stats->computeCompletionPercent();
|
||||
$this->entityManager->persist($stats);
|
||||
$this->entityManager->persist($place);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->render('public/view.html.twig', [
|
||||
'controller_name' => 'PublicController',
|
||||
|
|
|
@ -7,7 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
// use App\Service\Motocultrice;
|
||||
#[ORM\Entity(repositoryClass: PlaceRepository::class)]
|
||||
class Place
|
||||
{
|
||||
|
@ -76,6 +76,40 @@ class Place
|
|||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $has_note = null;
|
||||
|
||||
public function update_place_from_overpass_data(array $overpass_data) {
|
||||
$overpass_data = $overpass_data['tags_converted'] ;
|
||||
|
||||
// Remplir les clés attendues avec des valeurs par défaut si non définies
|
||||
$overpass_data = array_merge([
|
||||
'id' => '',
|
||||
'type' => '',
|
||||
'name' => '',
|
||||
'postcode' => '',
|
||||
'email' => '',
|
||||
'opening_hours' => '',
|
||||
'addr:housenumber' => '',
|
||||
'addr:street' => '',
|
||||
'website' => '',
|
||||
'wheelchair' => '',
|
||||
'note' => ''
|
||||
], $overpass_data);
|
||||
|
||||
$this
|
||||
// ->setOsmId($overpass_data['id'])
|
||||
// ->setOsmKind($overpass_data['type'])
|
||||
->setName($overpass_data['name'])
|
||||
->setZipCode(\intval($overpass_data['postcode']))
|
||||
->setEmail($overpass_data['email'])
|
||||
// ->setUuidForUrl( Motocultrice::uuid_create_static())
|
||||
// ->setOptedOut(false)
|
||||
// ->setDead(false)
|
||||
->setHasOpeningHours($overpass_data['opening_hours'] ? true : false)
|
||||
->setHasAddress($overpass_data['addr:housenumber'] && $overpass_data['addr:street'] ? true : false)
|
||||
->setHasWebsite($overpass_data['website'] ? true : false)
|
||||
->setHasWheelchair($overpass_data['wheelchair'] and $overpass_data['wheelchair'] != '' ? true : false)
|
||||
->setHasNote($overpass_data['note'] and $overpass_data['note'] != '' ? true : false);
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->histories = new ArrayCollection();
|
||||
|
|
|
@ -15,6 +15,8 @@ class Motocultrice
|
|||
'name',
|
||||
'wheelchair',
|
||||
'harassment_prevention',
|
||||
'image',
|
||||
'panoramax',
|
||||
];
|
||||
// les tags OSM que l'on estime nécessaires pour un commerce
|
||||
public $base_tags = [
|
||||
|
@ -279,6 +281,10 @@ QUERY;
|
|||
|
||||
|
||||
|
||||
public static function uuid_create_static() {
|
||||
return $this->uuid_create();
|
||||
}
|
||||
|
||||
public function uuid_create() {
|
||||
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
// 32 bits for "time_low"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue