Commit 4fb9e8da by Julien Jorry

Fix user group

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