Commit 70eafe75 by Julien Jorry

Fix presta + comptoir infos modifications

parent cf535c67
...@@ -5,6 +5,7 @@ namespace App\Controller; ...@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Adherent; use App\Entity\Adherent;
use App\Entity\ChangeAdherentComptoir; use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir; use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir;
use App\Entity\RetraitComptoirAdherent; use App\Entity\RetraitComptoirAdherent;
use App\Entity\RetraitComptoirPrestataire; use App\Entity\RetraitComptoirPrestataire;
use App\Entity\VenteComptoirAdherent; use App\Entity\VenteComptoirAdherent;
...@@ -13,6 +14,7 @@ use App\Entity\VenteEmlcComptoirAdherent; ...@@ -13,6 +14,7 @@ use App\Entity\VenteEmlcComptoirAdherent;
use App\Entity\VenteEmlcComptoirPrestataire; use App\Entity\VenteEmlcComptoirPrestataire;
use App\Form\Type\ChangeAdherentComptoirFormType; use App\Form\Type\ChangeAdherentComptoirFormType;
use App\Form\Type\ChangePrestataireComptoirFormType; use App\Form\Type\ChangePrestataireComptoirFormType;
use App\Form\Type\ComptoirInfosFormType;
use App\Form\Type\RetraitComptoirAdherentFormType; use App\Form\Type\RetraitComptoirAdherentFormType;
use App\Form\Type\RetraitComptoirPrestataireFormType; use App\Form\Type\RetraitComptoirPrestataireFormType;
use App\Form\Type\VenteComptoirAdherentFormType; use App\Form\Type\VenteComptoirAdherentFormType;
...@@ -30,19 +32,22 @@ class UserComptoirController extends FluxController ...@@ -30,19 +32,22 @@ class UserComptoirController extends FluxController
* @Route("/user/comptoir/infos", name="comptoir_infos") * @Route("/user/comptoir/infos", name="comptoir_infos")
* @IsGranted("ROLE_COMPTOIR") * @IsGranted("ROLE_COMPTOIR")
*/ */
public function groupeInfosAction(Request $request) public function comptoirInfosAction(Request $request)
{ {
$form = $this->createForm(ComptoirInfosFormType::class, $this->session->get('_comptoirgere')); $comptoir = $this->session->get('_comptoirgere');
$comptoir = $this->em->getRepository(Comptoir::class)->findOneById($comptoir->getId());
$form = $this->createForm(ComptoirInfosFormType::class, $comptoir);
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData(); $data = $form->getData();
$this->em->persist($data); $this->em->persist($form->getData());
$this->em->flush(); $this->em->flush();
$this->addFlash( $this->addFlash(
'success', 'success',
$this->translator->trans('Comptoir bien modifié !') $this->translator->trans('Informations du comptoir bien modifiées !')
); );
$this->session->set('_comptoirgere', $comptoir);
$referer = $request->headers->get('referer'); $referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) { if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer); return $this->redirect($referer);
......
...@@ -33,7 +33,7 @@ class UserPrestataireController extends FluxController ...@@ -33,7 +33,7 @@ class UserPrestataireController extends FluxController
public function prestataireInfosAction(Request $request) public function prestataireInfosAction(Request $request)
{ {
$presta = $this->session->get('_prestagere'); $presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta); $presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$originalAdresses = $presta->getGeolocs(); $originalAdresses = $presta->getGeolocs();
$originalCaissiers = $presta->getCaissiers(); $originalCaissiers = $presta->getCaissiers();
...@@ -147,7 +147,7 @@ class UserPrestataireController extends FluxController ...@@ -147,7 +147,7 @@ class UserPrestataireController extends FluxController
//#180: at this point, the Prestataire entity is detached from the EntityManager (because we get it from the session) //#180: at this point, the Prestataire entity is detached from the EntityManager (because we get it from the session)
$presta = $this->session->get('_prestagere'); $presta = $this->session->get('_prestagere');
//#180: $presta now refers to the fully managed copy returned by the merge operation. //#180: $presta now refers to the fully managed copy returned by the merge operation.
$presta = $this->em->merge($presta); $presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$originalGroupes = clone $presta->getGroupeprestataires(); $originalGroupes = clone $presta->getGroupeprestataires();
$form = $this->createForm(GroupePrestataireInscriptionFormType::class, $presta); $form = $this->createForm(GroupePrestataireInscriptionFormType::class, $presta);
......
...@@ -67,7 +67,8 @@ class Comptoir extends AccountableObject implements AccountableInterface ...@@ -67,7 +67,8 @@ class Comptoir extends AccountableObject implements AccountableInterface
/** /**
* @var \Application\Sonata\MediaBundle\Entity\Media * @var \Application\Sonata\MediaBundle\Entity\Media
* @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"}, fetch="LAZY") * @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"}, fetch="LAZY")
* @ORM\JoinColumn(name="media_id", referencedColumnName="id") * @ORM\JoinColumn(name="media_id", referencedColumnName="id", nullable=true)
* @Groups({"read", "write"})
*/ */
protected $media; protected $media;
...@@ -116,19 +117,20 @@ class Comptoir extends AccountableObject implements AccountableInterface ...@@ -116,19 +117,20 @@ class Comptoir extends AccountableObject implements AccountableInterface
} }
/** /**
* Get idmlc * Get idmlc.
* @return *
*/ * @return
*/
public function getIdmlc(): ?string public function getIdmlc(): ?string
{ {
return $this->idmlc; return $this->idmlc;
} }
/** /**
* Set idmlc * Set idmlc.
* *
* @return $this * @return $this
*/ */
public function setIdmlc(string $idmlc): self public function setIdmlc(string $idmlc): self
{ {
$this->idmlc = $idmlc; $this->idmlc = $idmlc;
...@@ -284,13 +286,13 @@ class Comptoir extends AccountableObject implements AccountableInterface ...@@ -284,13 +286,13 @@ class Comptoir extends AccountableObject implements AccountableInterface
public function getContactsString() public function getContactsString()
{ {
return join(' - ', array_map(function ($contact) { return join(' - ', array_map(function ($contact) {
$return = ucwords($contact->getName()) . ($contact->getEmail() == $contact->getName()?'':(':' . $contact->getEmail())); $return = ucwords($contact->getName()) . ($contact->getEmail() == $contact->getName() ? '' : (':' . $contact->getEmail()));
$return .= $contact->getTel() ? ','.$contact->getTel() : ''; $return .= $contact->getTel() ? ',' . $contact->getTel() : '';
return $return; return $return;
}, $this->contacts->getValues())); }, $this->contacts->getValues()));
} }
public function __toString(): string public function __toString(): string
{ {
return !empty($this->name) ? $this->name : 'Comptoir'; return !empty($this->name) ? $this->name : 'Comptoir';
......
...@@ -8,6 +8,8 @@ use App\Entity\AchatMonnaieAdherent; ...@@ -8,6 +8,8 @@ use App\Entity\AchatMonnaieAdherent;
use App\Entity\AchatMonnaiePrestataire; use App\Entity\AchatMonnaiePrestataire;
use App\Entity\ChangeAdherentComptoir; use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir; use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir;
use App\Entity\Groupe;
use App\Entity\Prestataire; use App\Entity\Prestataire;
use App\Entity\Reconversion; use App\Entity\Reconversion;
use App\Entity\Siege; use App\Entity\Siege;
...@@ -95,7 +97,7 @@ class FormFactory ...@@ -95,7 +97,7 @@ class FormFactory
throw new \Exception('[FORM 2] Opération impossible !'); throw new \Exception('[FORM 2] Opération impossible !');
} }
$groupe = $this->session->get('_groupegere'); $groupe = $this->session->get('_groupegere');
$groupe = $this->em->merge($groupe); $groupe = $this->em->getRepository(Groupe::class)->findOneById($groupe->getId());
$form = $this->ff->create(GroupeInfosFormType::class, $groupe, ['action' => $this->router->generate('groupe_infos')]); $form = $this->ff->create(GroupeInfosFormType::class, $groupe, ['action' => $this->router->generate('groupe_infos')]);
return $form->createView(); return $form->createView();
...@@ -107,7 +109,7 @@ class FormFactory ...@@ -107,7 +109,7 @@ class FormFactory
throw new \Exception('[FORM 3] Opération impossible !'); throw new \Exception('[FORM 3] Opération impossible !');
} }
$comptoir = $this->session->get('_comptoirgere'); $comptoir = $this->session->get('_comptoirgere');
$comptoir = $this->em->merge($comptoir); $comptoir = $this->em->getRepository(Comptoir::class)->findOneById($comptoir->getId());
$form = $this->ff->create(ComptoirInfosFormType::class, $comptoir, ['action' => $this->router->generate('comptoir_infos')]); $form = $this->ff->create(ComptoirInfosFormType::class, $comptoir, ['action' => $this->router->generate('comptoir_infos')]);
return $form->createView(); return $form->createView();
...@@ -119,9 +121,9 @@ class FormFactory ...@@ -119,9 +121,9 @@ class FormFactory
throw new \Exception('[FORM 4] Opération impossible !'); throw new \Exception('[FORM 4] Opération impossible !');
} }
$presta = $this->session->get('_prestagere'); $presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta); $presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
// Disable enabled_filter to display all adresses // Disable enabled_filter to display all adresses
if ($this->em->getFilters()->isEnabled('enabled_filter')) { if ($this->em->getFilters()->isEnabled('enabled_filter')) {
$this->em->getFilters()->disable('enabled_filter'); $this->em->getFilters()->disable('enabled_filter');
} }
$form = $this->ff->create(PrestataireInfosFormType::class, $presta, ['action' => $this->router->generate('prestataire_infos')]); $form = $this->ff->create(PrestataireInfosFormType::class, $presta, ['action' => $this->router->generate('prestataire_infos')]);
...@@ -148,7 +150,7 @@ class FormFactory ...@@ -148,7 +150,7 @@ class FormFactory
// At this point, the Prestataire entity is detached from the EntityManager (because we get it from the session) // At this point, the Prestataire entity is detached from the EntityManager (because we get it from the session)
$presta = $this->session->get('_prestagere'); $presta = $this->session->get('_prestagere');
// $presta now refers to the fully managed copy returned by the merge operation. // $presta now refers to the fully managed copy returned by the merge operation.
$presta = $this->em->merge($presta); $presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$form = $this->ff->create(GroupePrestataireInscriptionFormType::class, $presta, ['action' => $this->router->generate('groupeprestataire_inscription')]); $form = $this->ff->create(GroupePrestataireInscriptionFormType::class, $presta, ['action' => $this->router->generate('groupeprestataire_inscription')]);
......
...@@ -2,22 +2,16 @@ ...@@ -2,22 +2,16 @@
namespace App\Form\Type; namespace App\Form\Type;
use App\Application\Sonata\MediaBundle\Entity\Media;
use App\Entity\Comptoir; use App\Entity\Comptoir;
use App\Entity\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\MediaBundle\Form\Type\MediaType; use Sonata\MediaBundle\Form\Type\MediaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
class ComptoirInfosFormType extends AbstractType class ComptoirInfosFormType extends AbstractType
...@@ -33,21 +27,25 @@ class ComptoirInfosFormType extends AbstractType ...@@ -33,21 +27,25 @@ class ComptoirInfosFormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$comptoir = $options['data'];
if (null != $comptoir->getMedia()) {
$comptoirMedia = $this->em->getRepository(Media::class)->findOneById($comptoir->getMedia()->getId());
}
$builder $builder
->add('name', TextType::class, array( ->add('name', TextType::class, [
'label' => 'Nom :', 'label' => 'Nom :',
'required' => true 'required' => true,
)) ])
->add('content', CKEditorType::class, array( ->add('content', CKEditorType::class, [
'label' => 'Description :', 'label' => 'Description :',
'required' => false 'required' => false,
)) ])
->add('media', MediaType::class, array( ->add('media', MediaType::class, [
'provider' => 'sonata.media.provider.image', 'provider' => 'sonata.media.provider.image',
'context' => 'comptoir', 'context' => 'comptoir',
'label' => 'Image' 'label' => 'Image',
)) ])
->add('save', SubmitType::class, ['label' => "Modifier"]) ->add('save', SubmitType::class, ['label' => 'Valider les modifications'])
; ;
} }
...@@ -55,7 +53,7 @@ class ComptoirInfosFormType extends AbstractType ...@@ -55,7 +53,7 @@ class ComptoirInfosFormType extends AbstractType
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Comptoir::class, 'data_class' => Comptoir::class,
'cascade_validation' => true 'cascade_validation' => true,
]); ]);
} }
......
...@@ -45,7 +45,9 @@ class CotiserFormType extends AbstractType ...@@ -45,7 +45,9 @@ class CotiserFormType extends AbstractType
$canPayWithMlc = ($this->security->getUser()->getAdherent()->getEmlcAccount()->getBalance() >= $montant); $canPayWithMlc = ($this->security->getUser()->getAdherent()->getEmlcAccount()->getBalance() >= $montant);
} elseif ($this->security->isGranted('ROLE_PRESTATAIRE')) { } elseif ($this->security->isGranted('ROLE_PRESTATAIRE')) {
$montant = floatval($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::COTISATION_PRESTATAIRE)); $montant = floatval($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::COTISATION_PRESTATAIRE));
$canPayWithMlc = (($this->em->merge($this->session->get('_prestagere'))->getEmlcAccount())->getBalance() >= $montant); $presta = $this->session->get('_prestagere');
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$canPayWithMlc = (($presta->getEmlcAccount())->getBalance() >= $montant);
} }
$canPayWithCB = 'true' === $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::USE_PAYZEN) ? true : false; $canPayWithCB = 'true' === $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::USE_PAYZEN) ? true : false;
......
...@@ -166,17 +166,17 @@ class AppExtension extends AbstractExtension ...@@ -166,17 +166,17 @@ class AppExtension extends AbstractExtension
$user = $this->security->getUser(); $user = $this->security->getUser();
if (null != $this->session->get('_prestagere') && $user->isGranted('ROLE_PRESTATAIRE')) { if (null != $this->session->get('_prestagere') && $user->isGranted('ROLE_PRESTATAIRE')) {
$presta = $this->session->get('_prestagere'); $presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta); $presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$return .= '<br/>' . $presta->__toString(); $return .= '<br/>' . $presta->__toString();
} elseif (null != $user->getAdherent() && $user->isGranted('ROLE_ADHERENT')) { } elseif (null != $user->getAdherent() && $user->isGranted('ROLE_ADHERENT')) {
$return .= '<br/>' . $user->getAdherent()->__toString(); $return .= '<br/>' . $user->getAdherent()->__toString();
} elseif (null != $this->session->get('_comptoirgere') && $user->isGranted('ROLE_COMPTOIR')) { } elseif (null != $this->session->get('_comptoirgere') && $user->isGranted('ROLE_COMPTOIR')) {
$comptoir = $this->session->get('_comptoirgere'); $comptoir = $this->session->get('_comptoirgere');
$comptoir = $this->em->merge($comptoir); $comptoir = $this->em->getRepository(Comptoir::class)->findOneById($comptoir->getId());
$return .= '<br/>' . $comptoir->__toString(); $return .= '<br/>' . $comptoir->__toString();
} elseif (null != $this->session->get('_groupegere') && $user->isGranted('ROLE_GESTION_GROUPE')) { } elseif (null != $this->session->get('_groupegere') && $user->isGranted('ROLE_GESTION_GROUPE')) {
$groupe = $this->session->get('_groupegere'); $groupe = $this->session->get('_groupegere');
$groupe = $this->em->merge($groupe); $groupe = $this->em->getRepository(Groupe::class)->findOneById($groupe->getId());
$return .= '<br/>' . $groupe->__toString(); $return .= '<br/>' . $groupe->__toString();
} }
...@@ -211,9 +211,11 @@ class AppExtension extends AbstractExtension ...@@ -211,9 +211,11 @@ class AppExtension extends AbstractExtension
} }
/** /**
* isCotisationValid * isCotisationValid.
* @param UserInterface|null $user *
* @return boolean|date * @param UserInterface|null $user
*
* @return bool|date
*/ */
public function isCotisationValid(?UserInterface $user = null) public function isCotisationValid(?UserInterface $user = null)
{ {
...@@ -221,9 +223,11 @@ class AppExtension extends AbstractExtension ...@@ -221,9 +223,11 @@ class AppExtension extends AbstractExtension
} }
/** /**
* [isCotisationValidForPresta * [isCotisationValidForPresta.
* @param Prestataire|null $presta *
* @return boolean|date * @param Prestataire|null $presta
*
* @return bool|date
*/ */
public function isCotisationValidForPresta(?Prestataire $presta = null) public function isCotisationValidForPresta(?Prestataire $presta = null)
{ {
...@@ -231,9 +235,11 @@ class AppExtension extends AbstractExtension ...@@ -231,9 +235,11 @@ class AppExtension extends AbstractExtension
} }
/** /**
* [isCotisationValidForAdherent * [isCotisationValidForAdherent.
* @param Adherent|null $adherent *
* @return boolean|date * @param Adherent|null $adherent
*
* @return bool|date
*/ */
public function isCotisationValidForAdherent(?Adherent $adherent = null) public function isCotisationValidForAdherent(?Adherent $adherent = null)
{ {
......
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