Commit afd47d79 by Julien Jorry

Update BO dashboard + update presta / adherent add action (group + enabled auto)…

Update BO dashboard + update presta / adherent add action (group + enabled auto) + add geocoding on all address add to entity with geoloc
parent ccd72873
......@@ -4536,16 +4536,16 @@
},
{
"name": "sonata-project/admin-bundle",
"version": "3.45.0",
"version": "3.45.1",
"source": {
"type": "git",
"url": "https://github.com/sonata-project/SonataAdminBundle.git",
"reference": "96099052f2f1e114538f623d0d35ae7c0b6d3383"
"reference": "ba9c5dcbfe0412859d63f3319606ae006591ac85"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sonata-project/SonataAdminBundle/zipball/96099052f2f1e114538f623d0d35ae7c0b6d3383",
"reference": "96099052f2f1e114538f623d0d35ae7c0b6d3383",
"url": "https://api.github.com/repos/sonata-project/SonataAdminBundle/zipball/ba9c5dcbfe0412859d63f3319606ae006591ac85",
"reference": "ba9c5dcbfe0412859d63f3319606ae006591ac85",
"shasum": ""
},
"require": {
......@@ -4637,7 +4637,7 @@
"bootstrap",
"sonata"
],
"time": "2019-01-14T18:53:19+00:00"
"time": "2019-01-14T22:05:25+00:00"
},
{
"name": "sonata-project/block-bundle",
......
......@@ -55,14 +55,61 @@ sonata_admin:
# BOTTOM BOTTOM BOTTOM
blocks:
- { type: sonata.admin.block.admin_list, position: left }
-
type: sonata.block.service.text
position: right
settings:
content: >
<h2>Bienvenue sur l'administration de votre Monnaie Locale Complémentaire !</h2>
:
class: col-xs-12 col-md-6
position: center
type: sonata.admin.block.admin_list
# -
# class: col-xs-4 col-md-3
# position: top
# type: sonata.admin.block.stats
# settings:
# code: admin.adherent.gerer
# icon: fas fa-user-tie
# text: Adherents
# color: bg-info
# filters:
# enabled: { value: 1 }
# -
# class: col-xs-4 col-md-3
# position: top
# type: sonata.admin.block.stats
# settings:
# code: admin.prestataire.gerer
# icon: fas fa-user-ninja
# text: Prestataires
# color: bg-info
# filters:
# enabled: { value: 1 }
# -
# class: col-xs-4 col-md-3
# position: top
# type: sonata.admin.block.stats
# settings:
# code: admin.groupe.gerer
# icon: fas fa-user-ninja
# text: Groupes
# color: bg-info
# filters:
# enabled: { value: 1 }
# -
# class: col-xs-4 col-md-3
# position: top
# type: sonata.admin.block.stats
# settings:
# code: admin.comptoir.gerer
# icon: fas fa-user-ninja
# text: Comptoirs
# color: bg-info
# filters:
# enabled: { value: 1 }
# -
# type: sonata.block.service.text
# position: right
# settings:
# content: >
# <h2>Bienvenue sur l'administration de votre Monnaie Locale Complémentaire !</h2>
# :
# Exemple de block de stats
# -
# class: col-lg-3 col-xs-6 # twitter bootstrap responsive code
......@@ -177,5 +224,9 @@ sonata_admin:
# roles: [ ROLE_ONE, ROLE_TWO ]
sonata_block:
blocks:
sonata.admin.block.stats:
contexts: [admin]
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
......@@ -49,6 +49,10 @@ services:
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\HiddenType }
App\EventListener\GeolocListener:
tags:
- { name: doctrine.event_listener, event: preUpdate }
# Configuration de l'admin
admin.adherent.gerer:
class: App\Admin\AdherentAdmin
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -31,3 +31,7 @@
[Mon Jan 14 16:48:30.540076 2019] [php7:error] [pid 40571] [client 127.0.0.1:54761] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Model/UserAdmin.php on line 33
[Mon Jan 14 16:48:30.860332 2019] [php7:error] [pid 40571] [client 127.0.0.1:54761] PHP Fatal error: Class 'Sonata\\UserBundle\\Admin\\Model\\UserAdmin' not found in /Users/julien/Desktop/DOUME/ledellin/vendor/sonata-project/user-bundle/src/Admin/Entity/UserAdmin.php on line 18
[Mon Jan 14 16:50:00.697303 2019] [php7:error] [pid 40614] [client 127.0.0.1:54766] PHP Fatal error: Cannot declare class Sonata\\UserBundle\\Admin\\Model\\UserAdmin, because the name is already in use in /Users/julien/Desktop/DOUME/ledellin/src/Application/Sonata/UserBundle/Admin/UserAdmin.php on line 33
[Tue Jan 15 20:08:59.626105 2019] [php7:error] [pid 90073] [client 127.0.0.1:52195] PHP Fatal error: Declaration of App\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $datagridMapper) must be compatible with App\\Application\\Sonata\\UserBundle\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $filterMapper): void in /Users/julien/Desktop/DOUME/ledellin/src/Admin/UserAdmin.php on line 16, referer: http://www.doume.test/admin/adherent/create?_tab=tab_s76756ad69c_1
[Tue Jan 15 20:09:00.351222 2019] [php7:error] [pid 97869] [client 127.0.0.1:52196] PHP Fatal error: Declaration of App\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $datagridMapper) must be compatible with App\\Application\\Sonata\\UserBundle\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $filterMapper): void in /Users/julien/Desktop/DOUME/ledellin/src/Admin/UserAdmin.php on line 16, referer: http://www.doume.test/admin/dashboard
[Tue Jan 15 20:09:07.108980 2019] [php7:error] [pid 91422] [client 127.0.0.1:52197] PHP Fatal error: Declaration of App\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $datagridMapper) must be compatible with App\\Application\\Sonata\\UserBundle\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $filterMapper): void in /Users/julien/Desktop/DOUME/ledellin/src/Admin/UserAdmin.php on line 16, referer: http://www.doume.test/admin/adherent/create?_tab=tab_s76756ad69c_1
[Tue Jan 15 20:09:07.525042 2019] [php7:error] [pid 9159] [client 127.0.0.1:52198] PHP Fatal error: Declaration of App\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $datagridMapper) must be compatible with App\\Application\\Sonata\\UserBundle\\Admin\\UserAdmin::configureDatagridFilters(Sonata\\AdminBundle\\Datagrid\\DatagridMapper $filterMapper): void in /Users/julien/Desktop/DOUME/ledellin/src/Admin/UserAdmin.php on line 16, referer: http://www.doume.test/admin/dashboard
......@@ -2,9 +2,13 @@
namespace App\Admin;
use App\Entity\Adherent;
use App\Entity\Geoloc;
use App\Entity\Usergroup;
use Knp\Menu\ItemInterface;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -29,10 +33,29 @@ class AdherentAdmin extends UserAdmin
protected function configureFormFields(FormMapper $formMapper): void
{
parent::configureFormFields($formMapper);
// Initialize adherent
$user = $this->getSubject();
$groupe = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Usergroup::class)->findOneByName('Adherent');
$user->setEnabled(true);
$user->addGroup($groupe);
$user->addRole('ROLE_ADHERENT');
$adherent = new Adherent();
$user->setAdherent($adherent);
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
parent::configureDatagridFilters($datagridMapper);
$datagridMapper
->add('username')
->add('email')
;
}
protected function configureListFields(ListMapper $listMapper): void
{
unset($this->listModes['mosaic']);
......
......@@ -4,6 +4,7 @@ namespace App\Admin;
use App\Entity\Geoloc;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -34,10 +35,11 @@ class ComptoirAdmin extends AbstractAdmin
$comptoir->setGeoloc($geoloc);
$formMapper
->with('Comptoir', ['class' => 'col-md-8'])
->add('groupe')
->add('name')
->add('email')
->add('tel')
->add('groupe', null, array('label' => 'Groupe local'))
->add('name', null, array('label' => 'Nom'))
->add('email', null, array('label' => 'Email'))
->add('tel', null, array('label' => 'Téléphone'))
->add('enabled', null, array('label' => 'Activé ?'))
->end()
->with('Geoloc', ['class' => 'col-md-4'])
->add('geoloc.adresse', null, array('label' => 'Adresse'))
......@@ -49,6 +51,16 @@ class ComptoirAdmin extends AbstractAdmin
;
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('enabled')
;
}
protected function configureRoutes(RouteCollection $collection)
{
$collection->remove('delete');
......@@ -63,7 +75,7 @@ class ComptoirAdmin extends AbstractAdmin
$listMapper
->addIdentifier('name')
->addIdentifier('email')
->addIdentifier('geoloc.addresse')
->addIdentifier('geoloc.adresse')
->addIdentifier('tel')
->addIdentifier('updatedAt')
;
......
......@@ -5,6 +5,7 @@ namespace App\Admin;
use App\Entity\Comptoir;
use App\Entity\Siege;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -70,6 +71,16 @@ class GroupeAdmin extends AbstractAdmin
;
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('enabled')
;
}
protected function configureRoutes(RouteCollection $collection)
{
$collection->remove('delete');
......
......@@ -3,7 +3,11 @@
namespace App\Admin;
use App\Admin\UserAdmin;
use App\Entity\Geoloc;
use App\Entity\Prestataire;
use App\Entity\Usergroup;
use FOS\UserBundle\Model\UserManagerInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -18,6 +22,11 @@ class PrestataireAdmin extends UserAdmin
{
protected $baseRouteName = 'prestataire';
protected $baseRoutePattern = 'prestataire';
protected $datagridValues = [
'_page' => 1,
'_per_page' => 32,
];
public function configure()
{
......@@ -29,8 +38,17 @@ class PrestataireAdmin extends UserAdmin
*/
protected function configureFormFields(FormMapper $formMapper): void
{
// get the current Image instance
// Initialize prestataire
$user = $this->getSubject();
$groupe = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Usergroup::class)->findOneByName('Prestataire');
$user->setEnabled(true);
$user->addGroup($groupe);
$user->addRole('ROLE_PRESTATAIRE');
$presta = new Prestataire();
$presta->setGeoloc(new Geoloc());
$user->setPrestataire($presta);
// get the current Image instance
$imageHelp = null;
if (!empty($user->getPrestataire()) && !empty($user->getPrestataire()->getMedia())) {
$image = $user->getPrestataire()->getMedia();
......@@ -45,7 +63,7 @@ class PrestataireAdmin extends UserAdmin
$formMapper
->tab('Prestataire')
->with('General', ['class' => 'col-md-6'])
->with('General', ['class' => 'col-md-7'])
->add('prestataire.raison', TextType::class, array(
'label' => 'Raison :',
'required' => true
......@@ -63,7 +81,7 @@ class PrestataireAdmin extends UserAdmin
'required' => true
))
->end()
->with('Responsable', ['class' => 'col-md-6'])
->with('Responsable', ['class' => 'col-md-5'])
->add('prestataire.metier', TextType::class, array(
'label' => 'Métier :',
'required' => true
......@@ -73,7 +91,29 @@ class PrestataireAdmin extends UserAdmin
'required' => false
))
->end()
->with('Image', ['class' => 'col-md-6'])
->with('Addresse', ['class' => 'col-md-7'])
->add('prestataire.geoloc.adresse', TextType::class, array(
'label' => 'Addresse :',
'required' => false
))
->add('prestataire.geoloc.cpostal', TextType::class, array(
'label' => 'Code postal :',
'required' => false
))
->add('prestataire.geoloc.ville', TextType::class, array(
'label' => 'Ville :',
'required' => false
))
->add('prestataire.geoloc.lat', TextType::class, array(
'label' => 'Latitude :',
'required' => false
))
->add('prestataire.geoloc.lon', TextType::class, array(
'label' => 'Longitude :',
'required' => false
))
->end()
->with('Image', ['class' => 'col-md-5'])
->add('prestataire.media', MediaType::class, array(
'provider' => 'sonata.media.provider.image',
'context' => 'prestataire',
......@@ -86,6 +126,18 @@ class PrestataireAdmin extends UserAdmin
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
parent::configureDatagridFilters($datagridMapper);
$datagridMapper
->add('prestataire.raison')
->add('prestataire.statut')
;
}
/**
* @param UserManagerInterface $userManager
*/
public function setUserManager(UserManagerInterface $userManager): void
......
......@@ -61,15 +61,15 @@ class UserAdmin extends SonataUserAdmin
/**
* {@inheritdoc}
*/
// protected function configureDatagridFilters(DatagridMapper $datagridMapper)
// {
// $datagridMapper
// ->add('phone')
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('enabled')
// ->add('email', null, [
// 'show_filter' => true
// ])
// ;
// }
;
}
/**
* {@inheritdoc}
......
......@@ -16,7 +16,7 @@ trait GeolocEntityTrait
*/
private $geoloc;
public function getGeoloc(): Geoloc
public function getGeoloc(): ?Geoloc
{
return $this->geoloc;
}
......
......@@ -52,7 +52,7 @@ class Groupe
/**
* @var ArrayCollection|Prestataire[]
* @ORM\OneToMany(targetEntity="Prestataire", mappedBy="prestataireGroup", cascade={"persist"}, fetch="EXTRA_LAZY")
* @ORM\OrderBy({"name": "ASC"})
* @ORM\OrderBy({"raison": "ASC"})
*/
private $prestataires;
......
......@@ -10,6 +10,7 @@ use App\Entity\Image;
use App\Entity\Rubrique;
use App\Entity\TypePrestataire;
use App\Entity\User;
use App\Entity\Groupe;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
......@@ -131,7 +132,7 @@ class Prestataire
/**
* @var Groupe $prestataireGroup
*
* @ORM\ManyToOne(targetEntity="Groupe", cascade={"persist", "remove"}, inversedBy="prestataires")
* @ORM\ManyToOne(targetEntity="App\Entity\Groupe", cascade={"persist", "remove"}, inversedBy="prestataires")
*/
private $prestataireGroup;
......@@ -160,7 +161,7 @@ class Prestataire
/**
* @return string
*/
public function getRaison(): string
public function getRaison(): ?string
{
return $this->raison;
}
......@@ -178,7 +179,7 @@ class Prestataire
/**
* @return string
*/
public function getMetier(): string
public function getMetier(): ?string
{
return $this->metier;
}
......@@ -232,7 +233,7 @@ class Prestataire
/**
* @return string
*/
public function getIban(): string
public function getIban(): ?string
{
return $this->iban;
}
......@@ -250,7 +251,7 @@ class Prestataire
/**
* @return string
*/
public function getSiret(): string
public function getSiret(): ?string
{
return $this->siret;
}
......
<?php
namespace App\EventListener;
use App\Entity\Adherent;
use App\Entity\EntityTrait\GeolocEntityTrait;
use App\Entity\Geoloc;
use App\Entity\Prestataire;
use App\Entity\User;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Geocoder\Provider\Nominatim\Nominatim;
use Geocoder\Query\GeocodeQuery;
class GeolocListener
{
public function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if ($entity instanceof Geoloc && !($eventArgs->hasChangedField('adresse') || $eventArgs->hasChangedField('cpostal') || $eventArgs->hasChangedField('ville') || $eventArgs->hasChangedField('lat') || $eventArgs->hasChangedField('lon'))) {
return;
}
// GEOCODING ADDRESS :
$httpClient = new \Http\Adapter\Guzzle6\Client();
$provider = Nominatim::withOpenStreetMapServer($httpClient, 'test');
$geocoder = new \Geocoder\StatefulGeocoder($provider, 'fr');
$fullAddress = $entity->getAdresse().' '.$entity->getCpostal().' '.$entity->getVille();
// Query geocoding from complete addresse
$result = $geocoder->geocodeQuery(GeocodeQuery::create($fullAddress));
if (count($result) > 0) {
$coords = $result->first()->getCoordinates();
$entity->setLat($coords->getLatitude());
$entity->setLon($coords->getLongitude());
}
}
}
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