Commit a33a83cb by Julien Jorry

API REST config + test fonctions transactions + UPDATE BO cotisation / groupe

parent 22cc7353
......@@ -3299,16 +3299,16 @@
},
{
"name": "nelmio/api-doc-bundle",
"version": "v3.3.0",
"version": "v3.3.1",
"source": {
"type": "git",
"url": "https://github.com/nelmio/NelmioApiDocBundle.git",
"reference": "99833189fd963ba75c5b6a99d91fe5485201c0f3"
"reference": "1b104bbf748f2af0496897c98d5ded3ac545ed43"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelmio/NelmioApiDocBundle/zipball/99833189fd963ba75c5b6a99d91fe5485201c0f3",
"reference": "99833189fd963ba75c5b6a99d91fe5485201c0f3",
"url": "https://api.github.com/repos/nelmio/NelmioApiDocBundle/zipball/1b104bbf748f2af0496897c98d5ded3ac545ed43",
"reference": "1b104bbf748f2af0496897c98d5ded3ac545ed43",
"shasum": ""
},
"require": {
......@@ -3378,7 +3378,7 @@
"documentation",
"rest"
],
"time": "2018-08-29T23:10:36+00:00"
"time": "2019-01-25T17:25:46+00:00"
},
{
"name": "ocramius/package-versions",
......@@ -3501,16 +3501,16 @@
},
{
"name": "php-http/discovery",
"version": "1.5.2",
"version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/php-http/discovery.git",
"reference": "ffef11d54171336d841a34816a35bc035fb8cef0"
"reference": "02b7ea21eafa0757af04140890a67d8ed45f83b2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-http/discovery/zipball/ffef11d54171336d841a34816a35bc035fb8cef0",
"reference": "ffef11d54171336d841a34816a35bc035fb8cef0",
"url": "https://api.github.com/repos/php-http/discovery/zipball/02b7ea21eafa0757af04140890a67d8ed45f83b2",
"reference": "02b7ea21eafa0757af04140890a67d8ed45f83b2",
"shasum": ""
},
"require": {
......@@ -3520,8 +3520,7 @@
"nyholm/psr7": "<1.0"
},
"require-dev": {
"henrikbjorn/phpspec-code-coverage": "^2.0.2",
"php-http/httplug": "^1.0|^2.0",
"php-http/httplug": "^1.0 || ^2.0",
"php-http/message-factory": "^1.0",
"phpspec/phpspec": "^2.4",
"puli/composer-plugin": "1.0.0-beta10"
......@@ -3562,7 +3561,7 @@
"message",
"psr7"
],
"time": "2018-12-31T07:31:26+00:00"
"time": "2019-01-23T12:41:22+00:00"
},
{
"name": "php-http/guzzle6-adapter",
......@@ -5086,16 +5085,16 @@
},
{
"name": "sonata-project/doctrine-orm-admin-bundle",
"version": "3.8.0",
"version": "3.8.1",
"source": {
"type": "git",
"url": "https://github.com/sonata-project/SonataDoctrineORMAdminBundle.git",
"reference": "276e0925d6824ddd5a791146df08f922197b9bd7"
"reference": "0d692dc627435348e37aaf3486f465ab4bc9ee8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/zipball/276e0925d6824ddd5a791146df08f922197b9bd7",
"reference": "276e0925d6824ddd5a791146df08f922197b9bd7",
"url": "https://api.github.com/repos/sonata-project/SonataDoctrineORMAdminBundle/zipball/0d692dc627435348e37aaf3486f465ab4bc9ee8c",
"reference": "0d692dc627435348e37aaf3486f465ab4bc9ee8c",
"shasum": ""
},
"require": {
......@@ -5166,7 +5165,7 @@
"generator",
"sonata"
],
"time": "2019-01-20T16:50:56+00:00"
"time": "2019-01-23T22:01:58+00:00"
},
{
"name": "sonata-project/easy-extends-bundle",
......
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest: ~
# # Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
# fos_rest:
# param_fetcher_listener: true
# allowed_methods_listener: true
# routing_loader: true
# view:
# view_response_listener: true
# exception:
# codes:
# App\Exception\MyException: 403
# messages:
# App\Exception\MyException: Forbidden area.
# format_listener:
# rules:
# - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] }
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: force
body_converter:
enabled: true
validate: true
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
'App\Exception\BadRequestDataException': HTTP_BAD_REQUEST
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
'App\Exception\BadRequestDataException': true
# exception_controller: 'fos_rest.exception.controller:showAction'
# format_listener: ~
# rules:
# - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] }
#- { path: '^/', priorities: ['json'], fallback_format: 'json', prefer_extension: true }
sensio_framework_extra:
# view: { annotations: true }
router: { annotations: true }
request: { converters: true }
twig:
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
# FROM https://www.sgalinski.de/typo3-agentur/technik/how-to-create-a-basic-rest-api-in-symfony/
# fos_rest:
# param_fetcher_listener: true
# view:
# view_response_listener: 'force'
# formats:
# xml: true
# json: true
# templating_formats:
# html: true
# format_listener:
# rules:
# - { path: ^/, priorities: [ json, xml, html ], fallback_format: ~, prefer_extension: true }
# exception:
# codes:
# 'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
# 'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
# 'SGalinski\TypoScriptBackendBundle\Exception\BadRequestDataException': HTTP_BAD_REQUEST
# messages:
# 'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
# 'SGalinski\TypoScriptBackendBundle\Exception\BadRequestDataException': true
# allowed_methods_listener: true
# access_denied_listener:
# json: true
# body_listener: true
# disable_csrf_role: ROLE_API
\ No newline at end of file
framework:
templating: { engines: ['twig'] }
secret: '%env(APP_SECRET)%'
#default_locale: en
#csrf_protection: true
......
......@@ -21,11 +21,21 @@
# - Bearer: []
nelmio_api_doc:
# models: { use_jms: true }
documentation:
info:
title: Ledellin
title: MLC
description: Application de gesiton de Monnaie Locale Complémentaire
version: 1.0.0
security_definitions:
api_key:
type: apiKey
name: api_key
in: header
security:
api_key: []
areas: # to filter documented areas
path_patterns:
- ^/api(?!/doc$) # Accepts routes under /api except /api/doc
\ No newline at end of file
path_patterns: # an array of regexps
- ^/api(?!/doc$)
# host_patterns:
# - ^api\.
\ No newline at end of file
......@@ -20,4 +20,19 @@ sonata_translation:
lexik_translation_edition:
resource: "@LexikTranslationBundle/Resources/config/routing.yml"
prefix: /admin
\ No newline at end of file
prefix: /admin
app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
# sonata_api_user:
# type: rest
# prefix: /api/user
# resource: "@SonataUserBundle/Resources/config/routing/api.xml"
# sonata_api_media:
# type: rest
# prefix: /api/media
# resource: "@SonataMediaBundle/Resources/config/routing/api.xml"
\ No newline at end of file
controllers:
resource: ../../src/Controller/
type: annotation
rest_controllers:
resource: ../../src/Controller/Rest/
type: annotation
prefix: /api
......@@ -37,6 +37,14 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
apikey_authenticator:
class: App\Security\ApiKeyAuthenticator
public: false
api_key_user_provider:
class: App\Security\ApiKeyUserProvider
arguments:
- '@doctrine.orm.entity_manager'
redirect.after.login:
class: App\Listener\AfterLoginRedirection
autowire: false
......
......@@ -82,9 +82,9 @@ App\Entity\Usergroup:
App\Entity\Adherent:
adherent{1..11}:
ecompte: '<randomFloat(2, 0, 50)>'
groupe: '@groupe<numberBetween(1, 10)>'
# user (unique): '@user<numberBetween(1,10)>'
App\Entity\Prestataire:
prestataire{1..21}:
raison: '<text(10)>'
......@@ -96,7 +96,7 @@ App\Entity\Prestataire:
geoloc (unique): '@geoloc<numberBetween(1,70)>'
# user (unique): '@user<numberBetween(11,30)>'
typeprestataire: '@typepresta_prestataire'
prestataireGroup: '@groupe<numberBetween(1, 10)>'
groupe: '@groupe<numberBetween(1, 10)>'
horaires: "<dayOfWeek()> de <time('H')>h à <time('H')>h"
prestataire{22..32}:
raison: <text(10)>
......@@ -109,7 +109,7 @@ App\Entity\Prestataire:
# user (unique): '@user<numberBetween(11,30)>'
typeprestataire: '@typepresta_prestataire'
groupeprestataires: '2x @grppresta<numberBetween(1, 4)>'
prestataireGroup: '@groupe<numberBetween(1, 4)>'
groupe: '@groupe<numberBetween(1, 4)>'
horaires: "<dayOfWeek()> de <time('H')>h à <time('H')>h"
App\Entity\Rubrique:
......@@ -119,6 +119,32 @@ App\Entity\Rubrique:
enabled: true
prestataires: '<numberBetween(1, 8)>x @prestataire<numberBetween(1, 32)>'
App\Entity\Cotisation:
cotisation1:
annee: '2019'
debut: '<dateTimeBetween("-1 days", "now")>'
fin: '<dateTimeBetween("+1 years", "+2 years")>'
montant: '10'
moyen: 'espece'
recu: 'true'
user: '@useradherent'
cotisation{2..11}:
annee: '2019'
debut: '<dateTimeBetween("-15 days", "now")>'
fin: '<dateTimeBetween("+1 years", "+2 years")>'
montant: '10'
moyen: 'cb'
recu: 'true'
user: '@usera<current()>'
cotisationp{2..32}:
annee: '2019'
debut: '<dateTimeBetween("-15 days", "now")>'
fin: '<dateTimeBetween("+1 years", "+2 years")>'
montant: '10'
moyen: 'cb'
recu: 'true'
user: '@userp<current()>'
App\Entity\User:
usersuperadmin:
username: 'adminuser'
......@@ -185,6 +211,9 @@ App\Entity\User:
roles: ['ROLE_PRESTATAIRE']
prestataire: '@prestataire1'
useradherent:
firstname: 'firstname adherent'
lastname: 'lastname adherent'
phone: '012345789'
username: 'user_adherent'
email: 'adherent@doume.test'
plainPassword: 'test'
......@@ -215,6 +244,7 @@ App\Entity\TransactionAdherentPrestataire:
operateur: '@usera<current()>'
type: 'adherent_prestataire'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@adherent<current()>'
destinataire: '@prestataire<current()>'
......@@ -225,6 +255,7 @@ App\Entity\TransactionPrestataireAdherent:
operateur: '@userp<current()>'
type: 'prestataire_adherent'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@prestataire<current()>'
destinataire: '@adherent<current()>'
......@@ -235,6 +266,7 @@ App\Entity\TransactionPrestatairePrestataire:
operateur: '@userp<current()>'
type: 'prestataire_prestataire'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@prestataire<numberBetween(1, 10)>'
destinataire: '@prestataire<numberBetween(11, 21)>'
......@@ -245,6 +277,7 @@ App\Entity\TransfertComptoirAdherent:
operateur: '@usercomptoir'
type: 'comptoir_adherent'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@comptoir<numberBetween(1,50)>'
destinataire: '@adherent<current()>'
......@@ -255,6 +288,7 @@ App\Entity\TransfertComptoirGroupe:
operateur: '@usercomptoir'
type: 'comptoir_groupe'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@comptoir<numberBetween(1,50)>'
destinataire: '@groupe<numberBetween(1,10)>'
......@@ -265,6 +299,7 @@ App\Entity\TransfertComptoirPrestataire:
operateur: '@usercomptoir'
type: 'comptoir_prestataire'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@comptoir<numberBetween(1,50)>'
destinataire: '@prestataire<numberBetween(1,32)>'
......@@ -275,6 +310,7 @@ App\Entity\TransfertGroupeComptoir:
operateur: '@usergestiongroupe'
type: 'groupe_comptoir'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@groupe<numberBetween(1,10)>'
destinataire: '@comptoir<numberBetween(1,50)>'
......@@ -285,6 +321,7 @@ App\Entity\TransfertPrestataireComptoir:
operateur: '@userp<current()>'
type: 'prestataire_comptoir'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@prestataire<numberBetween(1,30)>'
destinataire: '@comptoir<numberBetween(1,50)>'
......@@ -295,6 +332,7 @@ App\Entity\TransfertSiegeGroupe:
operateur: '@useradminsiege'
type: 'siege_groupe'
reference: 'test'
moyen: 'cb'
montant: '<numberBetween(1,50)>'
expediteur: '@siege_1'
destinataire: '@groupe<numberBetween(1,10)>'
......
......@@ -5,6 +5,7 @@ namespace App\Admin;
use App\Entity\Adherent;
use App\Entity\Cotisation;
use App\Entity\Geoloc;
use App\Entity\Groupe;
use App\Entity\User;
use App\Entity\Usergroup;
use App\Enum\MoyenEnum;
......@@ -35,9 +36,9 @@ class AdherentAdmin extends AbstractAdmin
protected $datagridValues = [
// reverse order (default = 'ASC')
'_sort_order' => 'ASC',
'_sort_order' => 'DESC',
// name of the ordered field (default = the model's id field, if any)
'_sort_by' => 'createdAt',
'_sort_by' => 'updatedAt',
// '_page' => 1,
// '_per_page' => 32
];
......@@ -71,20 +72,26 @@ class AdherentAdmin extends AbstractAdmin
{
// Initialize adherent
$adherent = $this->getSubject();
$user = $this->userManager->createUser();
$groupe = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Usergroup::class)->findOneByName('Adherent');
$user->setEnabled(true);
$user->addGroup($groupe);
$user->addRole('ROLE_ADHERENT');
$adherent->setGeoloc(new Geoloc());
$adherent->setEcompte('0');
$now = new \DateTime();
$cotisation = new Cotisation();
$cotisation->setDebut($now);
$cotisation->setFin(new \DateTime('+ 1 year'));
$user->addCotisation($cotisation);
$user->setAdherent($adherent);
$adherent->setUser($user);
if ($this->isCurrentRoute('create')) {
$user = $this->userManager->createUser();
$groupe = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Usergroup::class)->findOneByName('Adherent');
$user->setEnabled(true);
$user->addGroup($groupe);
$user->addRole('ROLE_ADHERENT');
$adherent->setEcompte('0');
$user->setAdherent($adherent);
$adherent->setUser($user);
}
if (count($adherent->getUser()->getCotisations()) <= 0) {
$cotisation = new Cotisation();
$cotisation->setDebut($now);
$cotisation->setFin(new \DateTime('+ 1 year'));
$adherent->getUser()->addCotisation($cotisation);
}
if ($adherent->getGeoloc() == null) {
$adherent->setGeoloc(new Geoloc());
}
//nom, prénom, adresse, tel, mail et cotisation en une seule fois et générer un mdp
$formMapper
->tab('General')
......@@ -96,12 +103,16 @@ class AdherentAdmin extends AbstractAdmin
->add('user.lastname', TextType::class, array(
'label' => 'Nom :',
'required' => true
))
// ->add('user.username', TextType::class, array(
// 'label' => 'Username :',
// 'required' => true,
// 'disabled' => true
// ))
));
if (!$this->isCurrentRoute('create')) {
$formMapper
->add('user.username', TextType::class, array(
'label' => 'Username :',
'required' => true,
'disabled' => true
));
}
$formMapper
->add('user.phone', TextType::class, array(
'label' => 'Téléphone :',
'required' => true
......@@ -110,6 +121,13 @@ class AdherentAdmin extends AbstractAdmin
'label' => 'Email :',
'required' => true
))
->add('groupe', ChoiceType::class, array(
'required' => true,
'label' => 'Groupe local :',
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Groupe::class)->findAll(),
'choice_label' => 'name',
'placeholder' => 'Choisir un groupe',
))
->end()
->with('Cotisation', ['class' => 'col-md-5'])
->add('user.cotisations.first.annee', TextType::class, array('label' => 'Année', 'data' => $now->format('Y')))
......@@ -118,29 +136,32 @@ class AdherentAdmin extends AbstractAdmin
'required' => true,
'label' => 'Moyen :',
'choices' => MoyenEnum::getAvailableTypes(),
// 'choices_as_values' => true,
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
))
->add('user.cotisations.first.recu', CheckboxType::class, array('label' => 'Reçu'))
->end()
// ->with('Date', ['class' => 'col-md-5'])
// ->add('user.cotisations.first.debut', DateType::class, array(
// 'label' => 'Date de début',
// 'data' => new \DateTime(),
// 'widget' => 'single_text',
// 'html5' => false,
// 'attr' => ['class' => 'js-datepicker'],
// ))
// ->add('user.cotisations.first.fin', DateType::class, array(
// 'label' => 'Date de fin',
// 'data' => new \DateTime('+ 1 year'),
// 'widget' => 'single_text',
// 'html5' => false,
// 'attr' => ['class' => 'js-datepicker'],
// ))
// ->end()
->end();
if (!$this->isCurrentRoute('create')) {
$formMapper
->with('Date', ['class' => 'col-md-5'])
->add('user.cotisations.first.debut', DateType::class, array(
'label' => 'Date de début',
'data' => new \DateTime(),
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
))
->add('user.cotisations.first.fin', DateType::class, array(
'label' => 'Date de fin',
'data' => new \DateTime('+ 1 year'),
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker'],
))
->end();
}
$formMapper
->with('Addresse', ['class' => 'col-md-7'])
->add('geoloc.adresse', TextType::class, array(
'label' => 'Addresse :',
......@@ -239,16 +260,15 @@ class AdherentAdmin extends AbstractAdmin
->addIdentifier('user.username', null, array('label' => 'Login'))
->addIdentifier('user.email', null, array('label' => 'Email'))
->addIdentifier('ecompte', null, array('label' => 'Ecompte'))
->add('user.groups')
->addIdentifier('groupe', null, array(
'label' => 'Groupe',
'sortable' => true,
'sort_field_mapping' => array('fieldName' => 'name'),
'sort_parent_association_mappings' => array(array('fieldName' => 'groupe'))
))
->addIdentifier('user.enabled', null, array('label' => 'Activé', 'datatype' => 'App.User', 'template' => '@SonataAdmin/Boolean/editable_boolean.html.twig'))
->addIdentifier('user.createdAt')
->addIdentifier('user.updatedAt', null, array('label' => 'Mis à jour'))
;
// if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
// $listMapper
// ->addIdentifier('impersonating', 'string', ['template' => '@SonataUser/Admin/Field/impersonating.html.twig'])
// ;
// }
}
protected function configureRoutes(RouteCollection $collection)
......
......@@ -2,6 +2,7 @@
namespace App\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -18,11 +19,9 @@ class CotisationAdherentAdmin extends CotisationAdmin
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
// $query->leftJoin($query->getRootAliases()[0] . '.user', 'u')
// ->andWhere(
// $query->expr()->eq($query->getRootAliases()[0] . '.my_field', ':my_param')
// );
// $query->setParameter('my_param', 'my_value');
$query->leftJoin($query->getRootAliases()[0] . '.user', 'u')
->andWhere('u.adherent IS NOT NULL')
;
return $query;
}
......@@ -37,6 +36,14 @@ class CotisationAdherentAdmin extends CotisationAdmin
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
parent::configureDatagridFilters($datagridMapper);
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
......@@ -61,6 +68,10 @@ class CotisationAdherentAdmin extends CotisationAdmin
*/
protected function configureListFields(ListMapper $listMapper): void
{
unset($this->listModes['mosaic']);
$listMapper
->addIdentifier('user.username', null, array('label' => 'Login'))
->addIdentifier('user.email', null, array('label' => 'Email'));
parent::configureListFields($listMapper);
}
}
......@@ -4,6 +4,7 @@ namespace App\Admin;
use App\Enum\MoyenEnum;
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;
......@@ -26,6 +27,20 @@ class CotisationAdmin extends AbstractAdmin
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
$datagridMapper
->add('annee', null, array('label' => 'Année'))
->add('montant', null, array('label' => 'Montant'))
->add('recu', null, array('label' => 'Recu ?'))
->add('user.username', null, array('label' => 'Login'))
->add('user.email', null, array('label' => 'Email'))
;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$cotisation = $this->getSubject();
......@@ -37,7 +52,6 @@ class CotisationAdmin extends AbstractAdmin
->add('moyen', ChoiceType::class, array(
'required' => true,
'choices' => MoyenEnum::getAvailableTypes(),
// 'choices_as_values' => true,
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
......
......@@ -2,6 +2,7 @@
namespace App\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
......@@ -12,13 +13,15 @@ class CotisationPrestataireAdmin extends CotisationAdmin
protected $baseRouteName = 'cotisation_prestataire';
protected $baseRoutePattern = 'cotisation_prestataire';
/**
* {@inheritdoc}
*/
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
// $query->andWhere(
// $query->expr()->eq($query->getRootAliases()[0] . '.my_field', ':my_param')
// );
// $query->setParameter('my_param', 'my_value');
$query->leftJoin($query->getRootAliases()[0] . '.user', 'u')
->andWhere('u.prestataire IS NOT NULL')
;
return $query;
}
......@@ -33,6 +36,14 @@ class CotisationPrestataireAdmin extends CotisationAdmin
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
{
parent::configureDatagridFilters($datagridMapper);
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper): void
{
$formMapper
......@@ -56,6 +67,10 @@ class CotisationPrestataireAdmin extends CotisationAdmin
*/
protected function configureListFields(ListMapper $listMapper): void
{
unset($this->listModes['mosaic']);
$listMapper
->addIdentifier('user.username', null, array('label' => 'Login'))
->addIdentifier('user.email', null, array('label' => 'Email'));
parent::configureListFields($listMapper);
}
}
......@@ -109,6 +109,15 @@ class GroupeAdmin extends AbstractAdmin
'sort_field_mapping' => ['fieldName' => 'id'],
'sort_parent_association_mappings' => [],
]
)->add(
'getAdherentsCount',
null,
[
'label' => 'Nb adherents',
'sortable' => true,
'sort_field_mapping' => ['fieldName' => 'id'],
'sort_parent_association_mappings' => [],
]
)
->add(
'getComptoirsCount',
......
......@@ -5,6 +5,7 @@ namespace App\Admin;
use App\Admin\UserAdmin;
use App\Entity\Cotisation;
use App\Entity\Geoloc;
use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\User;
use App\Entity\Usergroup;
......@@ -109,14 +110,21 @@ class PrestataireAdmin extends AbstractAdmin
'label' => 'Email :',
'required' => true
))
->add('groupe', ChoiceType::class, array(
'required' => true,
'label' => 'Groupe local :',
'choices' => $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Groupe::class)->findAll(),
'choice_label' => 'name',
'placeholder' => 'Choisir un groupe',
))
->end()
->with('Cotisation', ['class' => 'col-md-5'])
->add('user.cotisations.first.annee', TextType::class, array('label' => 'Année', 'data' => $now->format('Y')))
->add('user.cotisations.first.montant', TextType::class, array('label' => 'Montant'))
->add('user.cotisations.first.moyen', ChoiceType::class, array(
'required' => true,
'label' => 'Moyen :',
'choices' => MoyenEnum::getAvailableTypes(),
// 'choices_as_values' => true,
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
......@@ -248,6 +256,12 @@ class PrestataireAdmin extends AbstractAdmin
->addIdentifier('user.username')
->addIdentifier('user.email')
->addIdentifier('raison')
->addIdentifier('groupe', null, array(
'label' => 'Groupe',
'sortable' => true,
'sort_field_mapping' => array('fieldName' => 'name'),
'sort_parent_association_mappings' => array(array('fieldName' => 'groupe'))
))
->addIdentifier('user.enabled', null, array('label' => 'Activé', 'datatype' => 'App.User', 'template' => '@SonataAdmin/Boolean/editable_boolean.html.twig'))
->addIdentifier('user.createdAt')
;
......
......@@ -50,6 +50,12 @@ class UserAdmin extends SonataUserAdmin
{
parent::configureListFields($listMapper);
unset($this->listModes['mosaic']);
if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
$listMapper
->addIdentifier('impersonating', 'string', ['template' => '@SonataUser/Admin/Field/impersonating.html.twig'])
;
}
// $listMapper
// ->addIdentifier('username', null, array('label' => 'Username'))
// ->addIdentifier('email', null, array('label' => 'Email'));
......
<?php
namespace App\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use App\Exception\BadRequestDataException;
/**
* Class ExceptionFOSRestController passes the error messages to FOSRest-registered exception.
*
* @package SGalinski\TypoScriptBackendBundle\Controller
*/
abstract class ExceptionFOSRestController extends FOSRestController
{
/**
* Makes response from given exception.
*
* @param \Exception $exception
* @throws BadRequestDataException
*/
protected function throwFosrestSupportedException(\Exception $exception)
{
throw new BadRequestDataException($exception->getMessage());
}
}
<?php
namespace App\Controller;
use App\Entity\TransactionAdherentPrestataire;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use Nelmio\ApiDocBundle\Annotation\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
*
* Types de transfert : (Les transferts dans la structure sont les flux de billets détenus par les opérateurs.)
*
* - SIEGE => GROUPES LOCAUX (Transfert du siège au groupe)
* - GROUPES LOCAUX => COMPTOIRS (Transfert du groupe au comptoir)
* - COMPTOIRS => GROUPES LOCAUX (Transfert du comptoir au groupe)
* - COMPTOIRS => ADHERENTS (Diffusion de monnaie papier auprès des adhérents)
* - COMPTOIRS => PRESTATAIRES (Diffusion de monnaie papier auprès des prestataires)
* - PRESTATAIRES => COMPTOIRS (Reconversion)
*
*
* Types de transaction :
*
* - PRESTATAIRES => ADHERENTS (Virement vers un adherent)
* - PRESTATAIRES => PRESTATAIRES (Virement entre prestataires)
* - ADHERENTS => PRESTATAIRES (Paiement numérique)
*
*/
class FluxController extends AbstractController
{
/**
* @Route("/flux/transaction/adherent/prestataire", name="transactionAdherentPrestataire")
*/
public function transactionAdherentPrestataireAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$entity = new TransactionAdherentPrestataire();
$entity->setOperateur($this->getUser());
$form = $this->createForm(TransactionAdherentPrestataireFormType::class, $entity);
$form->handleRequest($request);
$data = $form->getData();
dump($data);
if ($form->isSubmitted() && $form->isValid()) {
//TODO : terminer fonction ;)
$em->persist($data);
$em->flush();
}
return $this->render('flux/transactionAdherentPrestataire.html.twig', [
'form' => $form->createView(),
]);
}
}
......@@ -2,10 +2,16 @@
namespace App\Controller;
use App\Entity\User;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use Geocoder\Provider\Nominatim\Nominatim;
use Geocoder\Query\GeocodeQuery;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Geocoder\Query\GeocodeQuery;
use Geocoder\Provider\Nominatim\Nominatim;
class IndexController extends AbstractController
{
......@@ -13,7 +19,7 @@ class IndexController extends AbstractController
* @Route("/", name="index")
*/
// public function index(TranslatorInterface $translator)
public function index()
public function index(Request $request)
{
// Exemple pour la traduction :
// $translated = $translator->trans('Symfony is great');
......
<?php
namespace App\Controller\Rest;
use App\Controller\ExceptionFOSRestController;
use App\Entity\Groupe;
use App\Entity\User;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
/**
*
* Types de transfert : (Les transferts dans la structure sont les flux de billets détenus par les opérateurs.)
*
* - SIEGE => GROUPES LOCAUX (Transfert du siège au groupe)
* - GROUPES LOCAUX => COMPTOIRS (Transfert du groupe au comptoir)
* - COMPTOIRS => GROUPES LOCAUX (Transfert du comptoir au groupe)
* - COMPTOIRS => ADHERENTS (Diffusion de monnaie papier auprès des adhérents)
* - COMPTOIRS => PRESTATAIRES (Diffusion de monnaie papier auprès des prestataires)
* - PRESTATAIRES => COMPTOIRS (Reconversion)
*
*
* Types de transaction :
*
* - PRESTATAIRES => ADHERENTS (Virement vers un adherent)
* - PRESTATAIRES => PRESTATAIRES (Virement entre prestataires)
* - ADHERENTS => PRESTATAIRES (Paiement numérique)
*
*/
class FluxController extends ExceptionFOSRestController
{
/**
* Transfert du siège au groupe
*
* @Route("/api/tr_sie_grp/", methods={"GET"})
* @SWG\Response(
* response=200,
* description="Transfert du siège au groupe",
* @SWG\Schema(
* type="string"
* )
* )
* @SWG\Parameter(
* name="user",
* in="query",
* type="integer",
* description="The user"
* )
* @SWG\Tag(name="Utilisateurs")
* Security("is_granted('add_tr_sie_grp', user)")
*/
public function tranfertSiegeGroupeAction(User $user, Groupe $groupe)
{
try {
$view = $this->createView();
$view->setData('yes');
return $this->handleView($view);
//return new JsonResponse('yes');
} catch (\Exception $e) {
$this->throwFosrestSupportedException($exception);
}
}
protected function tranfert(User $operateur, $expediteur, $destinataire)
{
//TODO
}
}
<?php
namespace App\Controller\Rest;
use App\Controller\ExceptionFOSRestController;
use App\Entity\User;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class RestController extends ExceptionFOSRestController
{
/**
* Renvoi le type d'utilisateur
*
* @Route("/api/{user}/type", methods={"GET"})
* @SWG\Response(
* response=200,
* description="Returns the type of user",
* @SWG\Schema(
* type="string"
* )
* )
* @SWG\Parameter(
* name="order",
* in="query",
* type="string",
* description="The field used to order rewards"
* )
* @SWG\Tag(name="Utilisateurs")
*/
public function fetchUserTypeAction(User $user)
{
try {
return new JsonResponse('yes');
// return 'yes';
} catch (\Exception $e) {
$this->throwFosrestSupportedException($exception);
}
}
}
......@@ -6,6 +6,7 @@ use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\GeolocEntityTrait;
use App\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity(repositoryClass="App\Repository\AdherentRepository")
......@@ -13,6 +14,7 @@ use Doctrine\ORM\Mapping as ORM;
class Adherent
{
use EnablableEntityTrait,
TimestampableEntity,
GeolocEntityTrait;
/**
......@@ -34,6 +36,13 @@ class Adherent
*/
protected $user;
/**
* @var Groupe $groupe
*
* @ORM\ManyToOne(targetEntity="App\Entity\Groupe", inversedBy="adherents")
*/
private $groupe;
public function getId(): ?int
{
return $this->id;
......@@ -69,6 +78,25 @@ class Adherent
return $this;
}
/**
* @param null|Groupe $groupe
* @return $this
*/
public function setGroupe(?Groupe $groupe)
{
$this->groupe = $groupe;
return $this;
}
/**
* @return null|Groupe
*/
public function getGroupe(): ?Groupe
{
return $this->groupe;
}
public function isEnabled(): bool
{
return $this->getUser()->isEnabled();
......
......@@ -49,7 +49,7 @@ class EmailToken
{
return $this->token;
}
/**
* Set token
* @return $this
......@@ -68,7 +68,7 @@ class EmailToken
{
return $this->expiredAt;
}
/**
* Set expiredAt
* @return $this
......
......@@ -6,6 +6,7 @@ use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\Transaction;
use App\Entity\Transfert;
use App\Entity\User;
use App\Enum\MoyenEnum;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
......@@ -60,6 +61,13 @@ abstract class Flux
protected $montant;
/**
* @var string
*
* @ORM\Column(name="moyen", type="string", length=100)
*/
private $moyen;
/**
* @var null|string
*
* @ORM\Column(name="reference", type="string", length=255, nullable=true)
......@@ -71,6 +79,11 @@ abstract class Flux
abstract public function getParenttype();
public function __construct()
{
$this->parenttype = $this->getParenttype();
}
public function getId(): int
{
return $this->id;
......@@ -161,7 +174,7 @@ abstract class Flux
/**
* @return float
*/
public function getMontant(): float
public function getMontant(): ?float
{
return $this->montant;
}
......@@ -179,7 +192,7 @@ abstract class Flux
/**
* @return string
*/
public function getReference(): string
public function getReference(): ?string
{
return $this->reference;
}
......@@ -193,4 +206,22 @@ abstract class Flux
$this->reference = $reference;
return $this;
}
/**
* @return string
*/
public function getMoyen(): ?string
{
return $this->moyen;
}
public function setMoyen($moyen)
{
if (!in_array($moyen, MoyenEnum::getAvailableTypes())) {
throw new \InvalidArgumentException("Moyen de paiement invalide !");
}
$this->moyen = $moyen;
return $this;
}
}
......@@ -2,6 +2,7 @@
namespace App\Entity;
use App\Entity\Adherent;
use App\Entity\Comptoir;
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\HasCompteEntity;
......@@ -51,15 +52,23 @@ class Groupe
/**
* @var ArrayCollection|Prestataire[]
* @ORM\OneToMany(targetEntity="Prestataire", mappedBy="prestataireGroup", fetch="EXTRA_LAZY")
* @ORM\OneToMany(targetEntity="Prestataire", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"raison": "ASC"})
*/
private $prestataires;
/**
* @var ArrayCollection|Adherent[]
* @ORM\OneToMany(targetEntity="Adherent", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"updatedAt": "ASC"})
*/
private $adherents;
public function __construct()
{
$this->comptoirs = new ArrayCollection();
$this->prestataires = new ArrayCollection();
$this->adherents = new ArrayCollection();
}
/**
......@@ -149,7 +158,7 @@ class Groupe
{
if (!$this->prestataires->contains($prestataire)) {
$this->prestataires[] = $prestataire;
$prestataire->setPrestataireGroup($this);
$prestataire->setGroupe($this);
}
return $this;
}
......@@ -162,7 +171,41 @@ class Groupe
{
if ($this->prestataires->contains($prestataire)) {
$this->prestataires->removeElement($prestataire);
$prestataire->setPrestataireGroup(null);
$prestataire->setGroupe(null);
}
return $this;
}
/**
* @return Adherent[]|ArrayCollection
*/
public function getAdherents()
{
return $this->adherents;
}
/**
* @param Adherent $adherent
* @return $this
*/
public function addAdherent(Adherent $adherent)
{
if (!$this->adherents->contains($adherent)) {
$this->adherents[] = $adherent;
$adherent->setGroupe($this);
}
return $this;
}
/**
* @param Adherent $adherent
* @return $this
*/
public function removeAdherent(Adherent $adherent)
{
if ($this->adherents->contains($adherent)) {
$this->adherents->removeElement($adherent);
$adherent->setGroupe(null);
}
return $this;
}
......@@ -177,6 +220,11 @@ class Groupe
return $this->getPrestataires()->count();
}
public function getAdherentsCount()
{
return $this->getAdherents()->count();
}
public function __toString(): string
{
return (!empty($this->getName())?$this->getName():'Groupe');
......
......@@ -5,15 +5,16 @@ namespace App\Entity;
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\GeolocEntityTrait;
use App\Entity\EntityTrait\HasCompteEntity;
use App\Entity\Groupe;
use App\Entity\Groupeprestataire;
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;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
......@@ -23,6 +24,7 @@ use Symfony\Component\Validator\Constraints as Assert;
class Prestataire
{
use EnablableEntityTrait,
TimestampableEntity,
GeolocEntityTrait,
HasCompteEntity;
......@@ -135,11 +137,11 @@ class Prestataire
protected $user;
/**
* @var Groupe $prestataireGroup
* @var Groupe $groupe
*
* @ORM\ManyToOne(targetEntity="App\Entity\Groupe", inversedBy="prestataires")
*/
private $prestataireGroup;
private $groupe;
/**
* @var ArrayCollection|Amap/Marché[]
......@@ -345,21 +347,21 @@ class Prestataire
}
/**
* @param null|Groupe $prestataireGroup
* @param null|Groupe $groupe
* @return $this
*/
public function setPrestataireGroup(?Groupe $prestataireGroup)
public function setGroupe(?Groupe $groupe)
{
$this->prestataireGroup = $prestataireGroup;
$this->groupe = $groupe;
return $this;
}
/**
* @return null|Groupe
*/
public function getPrestataireGroup(): ?Groupe
public function getGroupe(): ?Groupe
{
return $this->prestataireGroup;
return $this->groupe;
}
/**
......
......@@ -90,14 +90,36 @@ class User extends BaseUser
*/
private $emailTokens;
/**
* @ORM\Column(name="apiKey", type="string", length=255, nullable=true)
*/
private $apiKey;
public function __construct()
{
parent::__construct();
$this->cotisations = new ArrayCollection();
$this->flux = new ArrayCollection();
$this->emailTokens = new ArrayCollection();
$this->createApiKey();
}
/**
* Get apiKey
* @return string
*/
public function getApiKey()
{
return $this->apiKey;
}
public function createApiKey()
{
$bytes = random_bytes(64);
$this->apiKey = rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=');
}
public function getCommonName(): ?string
{
return $this->getFirstname()." ".$this->getLastname();
......
......@@ -16,7 +16,7 @@ class GeolocListener
{
$entity = $eventArgs->getEntity();
if (!($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;
}
// GEOCODING ADDRESS :
......
<?php
namespace App\Exception;
/**
* Class BadRequestDataException has purpose to pass the error message through FOSRest bundle to the client.
* It should be used for error caused by client's bad input.
*
* @package SGalinski\TypoScriptBackendBundle\Exception
*/
class BadRequestDataException extends \Exception
{
}
<?php
namespace App\Form\Type;
use App\Entity\User;
use App\Enum\MoyenEnum;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class FluxFormType extends AbstractType
{
protected $em;
protected $tk;
public function __construct(EntityManagerInterface $em, TokenStorageInterface $tk)
{
$this->em = $em;
$this->tk = $tk;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('operateur', HiddenType::class, array(
'data' => $this->tk->getToken()->getUser()->getId(),
'data_class' => null,
'entity_class' => User::class,
'em' => $this->em
))
->add('montant', MoneyType::class, array(
'label' => 'Montant :',
'required' => true,
))
->add('moyen', ChoiceType::class, array(
'required' => true,
'choices' => MoyenEnum::getAvailableTypes(),
'choice_label' => function ($choice) {
return MoyenEnum::getTypeName($choice);
},
))
->add('reference', TextType::class, array(
'label' => 'Reference :',
'required' => true
))
;
}
public function getBlockPrefix()
{
return 'formFlux';
}
}
<?php
namespace App\Form\Type;
use App\Entity\Adherent;
use App\Entity\Prestataire;
use App\Entity\User;
use App\Enum\MoyenEnum;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TransactionAdherentPrestataireFormType extends TransactionFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('expediteur', HiddenType::class, array(
'data' => 1,//TODO : $this->tk->getToken()->getUser()->getAdherent()->getId(),
'data_class' => null,
'entity_class' => Adherent::class,
'em' => $this->em
))
->add('destinataire', EntityType::class, array(
'class' => Prestataire::class,
'choices' => $this->em->getRepository(Prestataire::class)->findBy(array('enabled' => true)),
'placeholder' => 'Prestataire',
'required' => true,
'label' => 'Prestataire :',
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'class' => '\App\Entity\TransactionAdherentPrestataire',
));
}
public function getParent()
{
return TransactionFormType::class;
}
public function getBlockPrefix()
{
return 'formTransactionAdherentPrestataire';
}
}
<?php
namespace App\Form\Type;
use App\Entity\User;
use App\Enum\MoyenEnum;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TransactionFormType extends FluxFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', HiddenType::class, array(
'data' => 'transaction',
'data_class' => null
))
;
}
public function getParent()
{
return FluxFormType::class;
}
public function getBlockPrefix()
{
return 'formTransaction';
}
}
<?php
namespace App\Form\Type;
use App\Entity\User;
use App\Enum\MoyenEnum;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TransfertFormType extends FluxFormType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', HiddenType::class, array(
'data' => 'transfert',
'data_class' => null
))
;
}
public function getParent()
{
return FluxFormType::class;
}
public function getBlockPrefix()
{
return 'formTransfert';
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190127125419 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE user ADD apiKey VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE document DROP text');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE document ADD text LONGTEXT DEFAULT NULL COLLATE utf8mb4_unicode_ci');
$this->addSql('ALTER TABLE user DROP apiKey');
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190127160239 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE flux ADD moyen VARCHAR(100) NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE flux DROP moyen');
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190206155738 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE adherent ADD groupe_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE adherent ADD CONSTRAINT FK_90D3F0607A45358C FOREIGN KEY (groupe_id) REFERENCES groupe (id)');
$this->addSql('CREATE INDEX IDX_90D3F0607A45358C ON adherent (groupe_id)');
$this->addSql('ALTER TABLE prestataire DROP FOREIGN KEY FK_60A264803AA0FF34');
$this->addSql('DROP INDEX IDX_60A264803AA0FF34 ON prestataire');
$this->addSql('ALTER TABLE prestataire CHANGE prestataire_group_id groupe_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A264807A45358C FOREIGN KEY (groupe_id) REFERENCES groupe (id)');
$this->addSql('CREATE INDEX IDX_60A264807A45358C ON prestataire (groupe_id)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE adherent DROP FOREIGN KEY FK_90D3F0607A45358C');
$this->addSql('DROP INDEX IDX_90D3F0607A45358C ON adherent');
$this->addSql('ALTER TABLE adherent DROP groupe_id');
$this->addSql('ALTER TABLE prestataire DROP FOREIGN KEY FK_60A264807A45358C');
$this->addSql('DROP INDEX IDX_60A264807A45358C ON prestataire');
$this->addSql('ALTER TABLE prestataire CHANGE groupe_id prestataire_group_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A264803AA0FF34 FOREIGN KEY (prestataire_group_id) REFERENCES groupe (id)');
$this->addSql('CREATE INDEX IDX_60A264803AA0FF34 ON prestataire (prestataire_group_id)');
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190206162237 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE adherent ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
$this->addSql('ALTER TABLE prestataire ADD created_at DATETIME NOT NULL, ADD updated_at DATETIME NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE adherent DROP created_at, DROP updated_at');
$this->addSql('ALTER TABLE prestataire DROP created_at, DROP updated_at');
}
}
<?php
namespace App\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface;
class ApiKeyAuthenticator implements SimplePreAuthenticatorInterface
{
public function createToken(Request $request, $providerKey)
{
// look for an apikey query parameter
$apiKey = $request->query->get('apikey');
if (!$apiKey) {
$apiKey = $request->get('apiKey');
}
// or if you want to use an "apikey" header, then do something like this:
if (!$apiKey) {
$apiKey = $request->headers->get('apikey');
}
if (!$apiKey) {
throw new BadCredentialsException('No API key found');
// or to just skip api key authentication
//return null;
}
return new PreAuthenticatedToken(
'anon.',
$apiKey,
$providerKey
);
}
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (!$userProvider instanceof ApiKeyUserProvider) {
throw new \InvalidArgumentException(
sprintf(
'The user provider must be an instance of ApiKeyUserProvider (%s was given).',
get_class($userProvider)
)
);
}
$apiKey = $token->getCredentials();
$username = $userProvider->getUsernameForApiKey($apiKey);
if (!$username) {
// CAUTION: this message will be returned to the client
// (so don't put any un-trusted messages / error strings here)
throw new \Exception(
sprintf('API Key "%s" does not exist.', $apiKey)
);
}
$user = $userProvider->loadUserByUsername($username);
return new PreAuthenticatedToken(
$user,
$apiKey,
$providerKey,
$user->getRoles()
);
}
public function supportsToken(TokenInterface $token, $providerKey)
{
return $token instanceof PreAuthenticatedToken && $token->getProviderKey() === $providerKey;
}
}
<?php
namespace App\Security;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
class ApiKeyUserProvider implements UserProviderInterface
{
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
public function getUsernameForApiKey($apiKey)
{
$user = $this->manager->getRepository('App\Entity\User')
->findOneByApiKey($apiKey);
if (!$user) {
return null;
}
return $user->getUsername();
}
public function loadUserByUsername($username)
{
return $this->manager->getRepository('App\Entity\User')
->findOneByUsername($username);
}
public function refreshUser(UserInterface $user)
{
// this is used for storing authentication in the session
// but in this example, the token is sent in each request,
// so authentication can be stateless. Throwing this exception
// is proper to make things stateless
throw new UnsupportedUserException();
}
public function supportsClass($class)
{
return 'Symfony\Component\Security\Core\User\User' === $class;
}
}
......@@ -40,6 +40,8 @@ class UserVoter extends AbstractVoter
}
switch ($attribute) {
case 'add_tr_sie_grp':
return true;
case self::LIST:
return $this->canList($subject, $user);
case self::VIEW:
......
{% extends 'base.html.twig' %}
{% block title %}Test page flux !{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
{{form_start(form)}}
<button class="btn btn-primary btn-sm btn-block" type="submit" id="_submit" name="_submit" >SUBMIT</button>
{{form_end(form)}}
</div>
{% endblock %}
......@@ -23,5 +23,6 @@
<li>Your controller at <code><a href="{{ 'src/Controller/IndexController.php'|file_link(0) }}">src/Controller/IndexController.php</a></code></li>
<li>Your template at <code><a href="{{ 'templates/index.html.twig'|file_link(0) }}">templates/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}
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