Commit 4b8c493b by Julien Jorry

Prestataire profil : add the possibility to add/remove caissiers + delete lat/lon + better look

parent 9b772f29
......@@ -51,7 +51,7 @@ var $collectionHolder;
// setup an "add a groupe presta (marché amap" link
var $addGroupeButton = $('<button type="button" class="btn btn-secondary add_groupe_link"><i class="fa fa-plus-circle" aria-hidden="true"></i> Ajouter AMAP / Marché</button>');
var $newLinkLi = $('<p class="row mx-2"></p>').append($addGroupeButton);
var $addGeolocButton = $('<button type="button" class="btn btn-secondary add_groupe_link"><i class="fa fa-plus-circle" aria-hidden="true"></i> Ajouter Adresse</button>');
var $addGeolocButton = $('<button type="button" class="btn btn-secondary add_groupe_link"><i class="fa fa-plus-circle" aria-hidden="true"></i> Ajouter une adresse</button>');
var $newLinkLiGeoloc = $('<p class="row mx-2"></p>').append($addGeolocButton);
/* */
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,7 @@
"app": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/app.536327c8.js"
"/build/app.498d6ed6.js"
],
"css": [
"/build/app.b8845846.css"
......
{
"build/app.css": "/build/app.b8845846.css",
"build/app.js": "/build/app.536327c8.js",
"build/app.js": "/build/app.498d6ed6.js",
"build/admin.css": "/build/admin.87a6bc21.css",
"build/admin.js": "/build/admin.7f86a232.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
......
......@@ -22,6 +22,7 @@ use App\Security\LoginAuthenticator;
use App\Utils\CustomEntityManager;
use App\Utils\OperationUtils;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface;
use Payum\Core\Payum;
use Payum\Core\Request\GetHumanStatus;
use Payum\Core\Request\Notify;
......@@ -43,6 +44,7 @@ use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Twig\Environment;
/**
......@@ -82,6 +84,8 @@ class FluxController extends AbstractController
protected $userManager;
protected $templating;
protected $operationUtils;
protected $tokenGenerator;
protected $validator;
public function __construct(
Security $security,
......@@ -94,7 +98,9 @@ class FluxController extends AbstractController
UserManagerInterface $userManager,
Payum $payum,
Environment $templating,
OperationUtils $operationUtils
OperationUtils $operationUtils,
TokenGeneratorInterface $tokenGenerator,
ValidatorInterface $validator
) {
$this->security = $security;
$this->em = $em;
......@@ -107,6 +113,8 @@ class FluxController extends AbstractController
$this->userManager = $userManager;
$this->templating = $templating;
$this->operationUtils = $operationUtils;
$this->tokenGenerator = $tokenGenerator;
$this->validator = $validator;
}
protected function manageFluxForm(Request $request, Form $form, $template = '@kohinos/flux/transaction.html.twig', $params = [])
......
......@@ -8,14 +8,22 @@ use App\Entity\Payment;
use App\Entity\Prestataire;
use App\Entity\Reconversion;
use App\Entity\TransactionPrestataireAdherent;
use App\Entity\User;
use App\Entity\Usergroup;
use App\Events\MLCEvents;
use App\Events\PrestataireEvent;
use App\Form\Type\AchatMonnaieAConfirmerPrestataireFormType;
use App\Form\Type\AchatMonnaiePrestataireFormType;
use App\Form\Type\GroupePrestataireInscriptionFormType;
use App\Form\Type\PrestataireInfosFormType;
use App\Form\Type\ReconversionFormType;
use FOS\UserBundle\Event\UserEvent;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class UserPrestataireController extends FluxController
{
......@@ -28,6 +36,7 @@ class UserPrestataireController extends FluxController
$presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta);
$originalAdresses = $presta->getGeolocs();
$originalCaissiers = $presta->getCaissiers();
$form = $this->createForm(PrestataireInfosFormType::class, $presta);
$form->handleRequest($request);
......@@ -39,12 +48,54 @@ class UserPrestataireController extends FluxController
}
$this->em->persist($adresse);
}
$this->em->persist($form->getData());
$this->em->flush();
$this->addFlash(
'success',
$this->translator->trans('Infos du prestataire modifiées !')
);
if (!empty($form->get('newcaissiers')->getData())) {
$caissiers = explode(';', $form->get('newcaissiers')->getData());
$errors = [];
foreach ($caissiers as $caissier) {
$emailConstraint = new Assert\Email();
$emailConstraint->message = "Courriel '".$caissier."' invalide!";
$errors[] = $this->validator->validate(
$caissier,
$emailConstraint
);
}
$errorText = '';
foreach ($errors as $error) {
if ($error->count()) {
$errorText .= $error[0]->getMessage();
}
}
if ('' !== $errorText) {
$form->get('newcaissiers')->addError(new FormError($errorText));
$this->addFlash(
'error',
$this->translator->trans($errorText)
);
} else {
// Remove caissier(s) if delete from the field
foreach ($originalCaissiers as $oldCaissier) {
if (!in_array($oldCaissier->getEmail(), $caissiers)) {
$groupePresta = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
$oldCaissier->removePossibleGroup($groupePresta);
$this->em->persist($oldCaissier);
$form->getData()->getCaissiers()->removeElement($oldCaissier);
}
}
// Add caissier(s)
foreach ($caissiers as $caissier) {
$this->addCaissers($caissier, $form->getData(), $request);
}
}
}
if ('' == $errorText) {
$this->em->persist($form->getData());
$this->em->flush();
$this->addFlash(
'success',
$this->translator->trans('Informations modifiées !')
);
}
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
......@@ -56,6 +107,38 @@ class UserPrestataireController extends FluxController
return $this->redirectToRoute('index');
}
private function addCaissers($email, Prestataire $prestataire, Request $request)
{
$return = [];
$newUser = false;
$user = $this->em->getRepository(User::class)->findOneBy(['email' => $email]);
if (null == $user) {
$newUser = true;
$user = new User(); // $this->userManager->createUser();
$user->setConfirmationToken($this->tokenGenerator->generateToken());
$user->setEnabled(true);
$user->setPassword(md5(random_bytes(10)));
$user->setEmail($email);
$user->setUsername($email);
}
$prestataire->addCaissier($user);
$groupePresta = $this->em->getRepository(Usergroup::class)->findOneByName('Caissier');
if ($newUser) {
$this->eventDispatcher->dispatch(MLCEvents::REGISTRATION_CAISSIER, new PrestataireEvent($user, $prestataire, $request));
}
$user->addPossiblegroup($groupePresta);
$this->userManager->updateUser($user);
$this->em->persist($user);
if ($newUser) {
$this->eventDispatcher->dispatch(MLCEvents::REGISTRATION_ADHERENT, new UserEvent($user, $request));
}
$this->em->persist($prestataire);
$this->em->flush();
return true;
}
/**
* @Route("/prestatairegroupes/inscription", name="groupeprestataire_inscription")
* @IsGranted("ROLE_PRESTATAIRE")
......
......@@ -4,6 +4,7 @@ namespace App\Form\Type;
use App\Entity\Geoloc;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\FormBuilderInterface;
......@@ -60,6 +61,17 @@ class GeolocFormType extends AbstractType
'required' => false
))
;
} else {
$builder
->add('lat', HiddenType::class, array(
'label' => 'Latitude :',
'required' => false
))
->add('lon', HiddenType::class, array(
'label' => 'Longitude :',
'required' => false
))
;
}
}
......
......@@ -38,7 +38,8 @@ class GeolocPrestataireFormType extends AbstractType
'label_attr' => array('class' => 'checkbox-inline')
))
->add('geoloc', GeolocFormType::class, array(
'label' => false
'label' => false,
'with_latlon' => $options['with_latlon'],
))
;
}
......@@ -47,7 +48,8 @@ class GeolocPrestataireFormType extends AbstractType
{
// $resolver->setRequired(['with_latlon']);
$resolver->setDefaults([
'data_class' => GeolocPrestataire::class
'data_class' => GeolocPrestataire::class,
'with_latlon' => true
]);
}
......
<?php
namespace App\Form\Type;
use App\Application\Sonata\MediaBundle\Entity\Media;
use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\MediaBundle\Form\Type\MediaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
......@@ -28,15 +32,24 @@ class PrestataireInfosFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$presta = $options['data'];
if (null != $presta->getMedia()) {
if ($presta->getMedia() != null) {
$prestaMedia = $this->em->getRepository(Media::class)->findOneById($presta->getMedia()->getId());
}
$caissiers = '';
if (count($presta->getCaissiers()) > 0) {
foreach ($presta->getCaissiers() as $caissier) {
if ('' !== $caissiers) {
$caissiers .= ';';
}
$caissiers .= $caissier->getEmail();
}
}
$builder
->add('media', MediaType::class, [
->add('media', MediaType::class, array(
'provider' => 'sonata.media.provider.image',
'context' => 'prestataire',
'label' => 'Image',
])
'label' => 'Image'
))
->add('raison', TextType::class, [
'label' => 'Raison :',
'required' => true,
......@@ -77,9 +90,16 @@ class PrestataireInfosFormType extends AbstractType
'label' => 'Accepter la monnaie locale électronique',
'required' => false,
])
->add('newcaissiers', TextType::class, [
'mapped' => false,
'required' => false,
'data' => $caissiers,
'label' => 'Caissier(s) :',
'help' => 'Ajouter par email séparé par un point virgule (email1;email2;...)'
])
->add('geolocs', CollectionType::class, [
'entry_type' => GeolocPrestataireFormType::class,
'entry_options' => ['label' => false],
'entry_options' => ['label' => false, 'with_latlon' => false],
'required' => false,
'allow_add' => true,
'allow_delete' => true,
......
......@@ -20,19 +20,26 @@
{{ form_row(form.statut) }}
{{ form_row(form.siret) }}
{{ form_row(form.iban) }}
{{ form_row(form.acceptemlc) }}
{{ form_row(form.responsable) }}
{{ form_row(form.metier) }}
{{ form_row(form.horaires) }}
{{ form_row(form.web) }}
<hr/>
{{ form_row(form.media) }}
{{ form_row(form.description) }}
<h2>Adresses</h2>
<div class="geolocs" data-prototype="{{ form_widget(form.geolocs.vars.prototype)|e('html_attr') }}">
<hr/>
<h3>Adresses</h3>
<div class="geolocs" data-prototype="<div class='card p-2 mb-2 border-primary'>{{ form_widget(form.geolocs.vars.prototype)|e('html_attr') }}</div>">
{% for geoloc in form.geolocs %}
{{ form_row(geoloc) }}
<div class='card p-2 mb-2 border-primary'>
{{ form_row(geoloc) }}
</div>
{% endfor %}
</div>
<hr/>
{{ form_row(form.newcaissiers) }}
<hr/>
{{ form_row(form.acceptemlc) }}
{{ form_row(form.save) }}
{{form_end(form)}}
{% endblock blockcontent %}
\ No newline at end of file
......@@ -1852,15 +1852,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001164:
version "1.0.30001165"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001165.tgz#32955490d2f60290bb186bb754f2981917fa744f"
integrity sha512-8cEsSMwXfx7lWSUMA2s08z9dIgsnR5NAqjXP23stdsU3AUWkCr/rr4s4OFtHXn5XXr6+7kam3QFVoYyXNPdJPA==
caniuse-lite@^1.0.30001286:
version "1.0.30001298"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001298.tgz#0e690039f62e91c3ea581673d716890512e7ec52"
integrity sha512-AcKqikjMLlvghZL/vfTHorlQsLDhGRalYf1+GmWCf5SCMziSGjRYQW/JEksj14NaYHIR6KIhrFAy0HV5C25UzQ==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001164, caniuse-lite@^1.0.30001286:
version "1.0.30001299"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001299.tgz"
integrity sha512-iujN4+x7QzqA2NCSrS5VUy+4gLmRd4xv6vbBBsmfVqTx8bLAD8097euLqQgKxSVLvxjSDcvF1T/i9ocgnUFexw==
chalk@^2.0.0, chalk@^2.3.2, chalk@^2.4.2:
version "2.4.2"
......
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