Commit 4fb9e8da by Julien Jorry

Fix user group

parent 051e9a34
......@@ -122,9 +122,14 @@ services:
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\HiddenType }
App\EventListener\GeolocListener:
app.listener.geoloc.preupdate:
class: App\EventListener\GeolocListener
tags:
- { name: doctrine.event_listener, event: preUpdate }
app.listener.geoloc.postPersist:
class: App\EventListener\GeolocListener
tags:
- { name: doctrine.event_listener, event: postPersist }
mlc.user.listener:
class: App\EventListener\UserListener
......
<?php
namespace App\Entity;
use FOS\UserBundle\Model\Group as BaseGroup;
use Sonata\UserBundle\Entity\BaseGroup as BaseGroup;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Entity()
* @ORM\Table(name="usergroup")
*/
class Usergroup extends BaseGroup
......
......@@ -6,19 +6,33 @@ use App\Entity\EntityTrait\GeolocEntityTrait;
use App\Entity\Geoloc;
use App\Entity\Prestataire;
use App\Entity\User;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Geocoder\Provider\Nominatim\Nominatim;
use Geocoder\Query\GeocodeQuery;
class GeolocListener
{
public function postPersist(LifecycleEventArgs $eventArgs)
{
$entity = $eventArgs->getObject();
$this->updateGeoLoc($entity);
}
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if (!($entity instanceof Geoloc) || ($entity instanceof Geoloc) && !($eventArgs->hasChangedField('adresse') || $eventArgs->hasChangedField('cpostal') || $eventArgs->hasChangedField('ville') || $eventArgs->hasChangedField('lat') || $eventArgs->hasChangedField('lon'))) {
return;
}
$this->updateGeoLoc($entity);
}
private function updateGeoLoc($entity)
{
if (!$entity instanceof Geoloc) {
return;
}
// GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'Mozilla/5.0');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment