Commit 70eafe75 by Julien Jorry

Fix presta + comptoir infos modifications

parent cf535c67
......@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Adherent;
use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir;
use App\Entity\RetraitComptoirAdherent;
use App\Entity\RetraitComptoirPrestataire;
use App\Entity\VenteComptoirAdherent;
......@@ -13,6 +14,7 @@ use App\Entity\VenteEmlcComptoirAdherent;
use App\Entity\VenteEmlcComptoirPrestataire;
use App\Form\Type\ChangeAdherentComptoirFormType;
use App\Form\Type\ChangePrestataireComptoirFormType;
use App\Form\Type\ComptoirInfosFormType;
use App\Form\Type\RetraitComptoirAdherentFormType;
use App\Form\Type\RetraitComptoirPrestataireFormType;
use App\Form\Type\VenteComptoirAdherentFormType;
......@@ -30,19 +32,22 @@ class UserComptoirController extends FluxController
* @Route("/user/comptoir/infos", name="comptoir_infos")
* @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);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->em->persist($data);
$this->em->persist($form->getData());
$this->em->flush();
$this->addFlash(
'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');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
......
......@@ -33,7 +33,7 @@ class UserPrestataireController extends FluxController
public function prestataireInfosAction(Request $request)
{
$presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta);
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$originalAdresses = $presta->getGeolocs();
$originalCaissiers = $presta->getCaissiers();
......@@ -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)
$presta = $this->session->get('_prestagere');
//#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();
$form = $this->createForm(GroupePrestataireInscriptionFormType::class, $presta);
......
......@@ -67,7 +67,8 @@ class Comptoir extends AccountableObject implements AccountableInterface
/**
* @var \Application\Sonata\MediaBundle\Entity\Media
* @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;
......@@ -116,19 +117,20 @@ class Comptoir extends AccountableObject implements AccountableInterface
}
/**
* Get idmlc
* @return
*/
* Get idmlc.
*
* @return
*/
public function getIdmlc(): ?string
{
return $this->idmlc;
}
/**
* Set idmlc
*
* @return $this
*/
* Set idmlc.
*
* @return $this
*/
public function setIdmlc(string $idmlc): self
{
$this->idmlc = $idmlc;
......@@ -284,13 +286,13 @@ class Comptoir extends AccountableObject implements AccountableInterface
public function getContactsString()
{
return join(' - ', array_map(function ($contact) {
$return = ucwords($contact->getName()) . ($contact->getEmail() == $contact->getName()?'':(':' . $contact->getEmail()));
$return .= $contact->getTel() ? ','.$contact->getTel() : '';
$return = ucwords($contact->getName()) . ($contact->getEmail() == $contact->getName() ? '' : (':' . $contact->getEmail()));
$return .= $contact->getTel() ? ',' . $contact->getTel() : '';
return $return;
}, $this->contacts->getValues()));
}
public function __toString(): string
{
return !empty($this->name) ? $this->name : 'Comptoir';
......
......@@ -8,6 +8,8 @@ use App\Entity\AchatMonnaieAdherent;
use App\Entity\AchatMonnaiePrestataire;
use App\Entity\ChangeAdherentComptoir;
use App\Entity\ChangePrestataireComptoir;
use App\Entity\Comptoir;
use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\Reconversion;
use App\Entity\Siege;
......@@ -95,7 +97,7 @@ class FormFactory
throw new \Exception('[FORM 2] Opération impossible !');
}
$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')]);
return $form->createView();
......@@ -107,7 +109,7 @@ class FormFactory
throw new \Exception('[FORM 3] Opération impossible !');
}
$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')]);
return $form->createView();
......@@ -119,9 +121,9 @@ class FormFactory
throw new \Exception('[FORM 4] Opération impossible !');
}
$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
if ($this->em->getFilters()->isEnabled('enabled_filter')) {
if ($this->em->getFilters()->isEnabled('enabled_filter')) {
$this->em->getFilters()->disable('enabled_filter');
}
$form = $this->ff->create(PrestataireInfosFormType::class, $presta, ['action' => $this->router->generate('prestataire_infos')]);
......@@ -148,7 +150,7 @@ class FormFactory
// At this point, the Prestataire entity is detached from the EntityManager (because we get it from the session)
$presta = $this->session->get('_prestagere');
// $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')]);
......
......@@ -2,22 +2,16 @@
namespace App\Form\Type;
use App\Application\Sonata\MediaBundle\Entity\Media;
use App\Entity\Comptoir;
use App\Entity\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
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\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
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 ComptoirInfosFormType extends AbstractType
......@@ -33,21 +27,25 @@ class ComptoirInfosFormType extends AbstractType
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
->add('name', TextType::class, array(
->add('name', TextType::class, [
'label' => 'Nom :',
'required' => true
))
->add('content', CKEditorType::class, array(
'required' => true,
])
->add('content', CKEditorType::class, [
'label' => 'Description :',
'required' => false
))
->add('media', MediaType::class, array(
'required' => false,
])
->add('media', MediaType::class, [
'provider' => 'sonata.media.provider.image',
'context' => 'comptoir',
'label' => 'Image'
))
->add('save', SubmitType::class, ['label' => "Modifier"])
'label' => 'Image',
])
->add('save', SubmitType::class, ['label' => 'Valider les modifications'])
;
}
......@@ -55,7 +53,7 @@ class ComptoirInfosFormType extends AbstractType
{
$resolver->setDefaults([
'data_class' => Comptoir::class,
'cascade_validation' => true
'cascade_validation' => true,
]);
}
......
......@@ -45,7 +45,9 @@ class CotiserFormType extends AbstractType
$canPayWithMlc = ($this->security->getUser()->getAdherent()->getEmlcAccount()->getBalance() >= $montant);
} elseif ($this->security->isGranted('ROLE_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;
......
......@@ -166,17 +166,17 @@ class AppExtension extends AbstractExtension
$user = $this->security->getUser();
if (null != $this->session->get('_prestagere') && $user->isGranted('ROLE_PRESTATAIRE')) {
$presta = $this->session->get('_prestagere');
$presta = $this->em->merge($presta);
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$return .= '<br/>' . $presta->__toString();
} elseif (null != $user->getAdherent() && $user->isGranted('ROLE_ADHERENT')) {
$return .= '<br/>' . $user->getAdherent()->__toString();
} elseif (null != $this->session->get('_comptoirgere') && $user->isGranted('ROLE_COMPTOIR')) {
$comptoir = $this->session->get('_comptoirgere');
$comptoir = $this->em->merge($comptoir);
$comptoir = $this->em->getRepository(Comptoir::class)->findOneById($comptoir->getId());
$return .= '<br/>' . $comptoir->__toString();
} elseif (null != $this->session->get('_groupegere') && $user->isGranted('ROLE_GESTION_GROUPE')) {
$groupe = $this->session->get('_groupegere');
$groupe = $this->em->merge($groupe);
$groupe = $this->em->getRepository(Groupe::class)->findOneById($groupe->getId());
$return .= '<br/>' . $groupe->__toString();
}
......@@ -211,9 +211,11 @@ class AppExtension extends AbstractExtension
}
/**
* isCotisationValid
* @param UserInterface|null $user
* @return boolean|date
* isCotisationValid.
*
* @param UserInterface|null $user
*
* @return bool|date
*/
public function isCotisationValid(?UserInterface $user = null)
{
......@@ -221,9 +223,11 @@ class AppExtension extends AbstractExtension
}
/**
* [isCotisationValidForPresta
* @param Prestataire|null $presta
* @return boolean|date
* [isCotisationValidForPresta.
*
* @param Prestataire|null $presta
*
* @return bool|date
*/
public function isCotisationValidForPresta(?Prestataire $presta = null)
{
......@@ -231,9 +235,11 @@ class AppExtension extends AbstractExtension
}
/**
* [isCotisationValidForAdherent
* @param Adherent|null $adherent
* @return boolean|date
* [isCotisationValidForAdherent.
*
* @param Adherent|null $adherent
*
* @return bool|date
*/
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