Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 94 additions & 77 deletions src/AppBundle/Controller/AddMembreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
use Doctrine\ORM\EntityManager;


use AppBundle\Search\MembreSearch;
use AppBundle\Search\MembreSearchType;
use AppBundle\Search\MembreRepository;
use AppBundle\Search\Membre\MembreSearch;
use AppBundle\Search\Membre\MembreSearchType;
use AppBundle\Search\Membre\MembreRepository;

use AppBundle\Search\Mode;

Expand All @@ -46,7 +46,9 @@
*
* 2.b) aucune famille trouvée avec ce nom, on crée une nouvelle famille
*
* 3) forumaire du membre
* 3) redirection sur la page de nouveau membre
*
* 4) edition rapide du membre/famille possible va formulaire complet
*
*
*
Expand All @@ -62,6 +64,8 @@ class AddMembreController extends Controller
const FAMILLE_ID = 'membre_in_progress_famille_id';

/**
* Permet de repartir à zero dans le processus d'ajout de membre
*
* @Route("/reset", options={"expose"=true})
* @param Request $request
* @return Response
Expand Down Expand Up @@ -90,27 +94,48 @@ public function startAction(Request $request)

$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inverser les cas


$session = $request->getSession();

$nom = $form->get('nom')->getData();
$prenom = $form->get('prenom')->getData();

//save nom and prenom in session for futurer use.
$session->set(AddMembreController::MEMBRE_NOM, $nom);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faudrait créer un modèle simple qui contiendrait les différentes valeurs à transmettre entre état qui implémente \Serializable

$session->set(AddMembreController::MEMBRE_PRENOM, $prenom);
//reset familleId
$session->set(AddMembreController::FAMILLE_ID,null);

//search homonyme
$membreSearch = new MembreSearch();
$membreSearch->nom = $nom;
$membreSearch->prenom = $prenom;
$results = $this->get('app.search')->Membre($membreSearch);
if(!empty($results))
$resultsMembre = $this->get('app.search')->Membre($membreSearch);

//search famille with same name
$familleSearch = new FamilleSearch();
$familleSearch->nom = $nom;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$familleSearch->setNom($nom); utiliser le moins de propriétés publiques possible

$resultsFamille = $this->get('app.search')->Famille($familleSearch);

if(!empty($resultsMembre))
{
//then homonyme exists
return $this->redirect($this->generateUrl('app_addmembre_homonyme'));
}
return $this->redirect($this->generateUrl('app_addmembre_famillechoice'));

if(!empty($resultsFamille))
{
//then famille exists
return $this->redirect($this->generateUrl('app_addmembre_famillechoice'));
}

//create membre
return $this->redirect($this->generateUrl('app_addmembre_finish'));

}
return $this->render('AppBundle:Membre/AddForm:start.html.twig',

return $this->render('AppBundle:AddMembre:start.html.twig',
array('form' => $form->createView(), 'next' => $this->generateUrl('app_addmembre_start')));
}

Expand All @@ -121,11 +146,24 @@ public function startAction(Request $request)
*/
public function HomonymeAction(Request $request)
{

//get nom and prenom
$session = $request->getSession();
$nom = $session->get(AddMembreController::MEMBRE_NOM);
$prenom = $session->get(AddMembreController::MEMBRE_PRENOM);

//search homonyme
$membreSearch = new MembreSearch();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plutot que de créer plusieurs classes comme ca à la volée, ca vaudrait pas le coup de les réunir en un service ?

$membreSearch->nom = $nom;
$membreSearch->prenom = $prenom;
$resultsMembre = $this->get('app.search')->Membre($membreSearch);

$message = 'Un homonyme existe pour ce membre, voulez-vous continuer?';
return $this->render('AppBundle:Membre/AddForm:Homonyme.html.twig',
return $this->render('AppBundle:AddMembre:Homonyme.html.twig',
array(
'next' => $this->generateUrl('app_addmembre_famillechoice'),
'message' => $message
'message' => $message,
'homonymes'=>$resultsMembre
));
}

Expand All @@ -139,123 +177,102 @@ public function HomonymeAction(Request $request)
public function familleChoiceAction(Request $request) {

$session = $request->getSession();

$nom = $session->get(AddMembreController::MEMBRE_NOM,null);

if(is_null($nom))
{
//restart process
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faudrait qu'on prenne l'habitude à chaque fois qu'on fait une action de créer un flash message ($this->addFlash('success', "bravo!"); depuis le controller) histoire que lorsqu'on implémentera un système qui affiche ces alertes, elles soient fonctionnelles et pertinentes directement

return $this->redirect($this->generateUrl('app_addmembre_start'));
}

$familleSearch = new FamilleSearch();
$familleSearch->nom = $nom;
$matchedFamilles = $this->get('app.search')->Famille($familleSearch);
$searchResults = $this->get('app.search')->Famille($familleSearch);

if(empty($matchedFamilles))
if(empty($searchResults))
{
$session->set(AddMembreController::FAMILLE_ID, null);
//direct redirect to next step
return $this->redirect($this->generateUrl('app_addmembre_membre'));
return $this->redirect($this->generateUrl('app_addmembre_finish'));
}
else
{
$membre = new Membre();
//choix d'une famille
$form = $this->createForm(new MembreFamilleChoiceType($matchedFamilles),$membre);

$form->handleRequest($request);
$membre = new Membre();

if($form->isValid())
{
if($membre->getFamille() != null)
{
$familleId = $membre->getFamille()->getId();
}
else
{
$familleId = null;
}

$session->set(AddMembreController::FAMILLE_ID, $familleId);
//redirect to check famille
return $this->redirect($this->generateUrl('app_addmembre_membre'));
//cree un formulaire avec les résultats de la recherche en option
$form = $this->createForm(new MembreFamilleChoiceType($searchResults),$membre);

$form->handleRequest($request);

if($form->isValid())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inverser les cas

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$form->isSubmitted() && $form->isValid()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bien que ça n'ajoute rien à la fonctionnalité, c'est plus lisible

{
$familleId = null;
if($membre->getFamille() != null)
{
$familleId = $membre->getFamille()->getId();
}

/** @var ListStorage $sessionContainer */
$sessionContainer = $this->get('list_storage');
$sessionContainer->setRepository(ListKey::FAMILLE_SEARCH_RESULTS_ADD_MEMBRE,'AppBundle:Famille');
$sessionContainer->setObjects(ListKey::FAMILLE_SEARCH_RESULTS_ADD_MEMBRE,$matchedFamilles);

return $this->render('AppBundle:Membre/AddForm:FamilleChoice.html.twig',
array('form'=>$form->createView(),
'next'=>$this->generateUrl('app_addmembre_famillechoice'),
'list_key'=>ListKey::FAMILLE_SEARCH_RESULTS_ADD_MEMBRE,
'message'=>'Ce nom de famille existe déjà, ce membre fait-il partie d\'une des familles-ci dessous?'
));
$session->set(AddMembreController::FAMILLE_ID, $familleId);
//finish process
return $this->redirect($this->generateUrl('app_addmembre_finish'));

}


return $this->render('AppBundle:AddMembre:FamilleChoice.html.twig',
array('form'=>$form->createView(),
'next'=>$this->generateUrl('app_addmembre_famillechoice'),
'message'=>'Ce nom de famille existe déjà, ce membre fait-il partie d\'une des familles-ci dessous?'
));



}

/**
*
* @Route("/membre", options={"expose"=true})
* @Route("/finish", options={"expose"=true})
* @param Request $request
* @return Response
*/
public function membreAction(Request $request) {
public function finishAction(Request $request) {

$session = $request->getSession();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obtenir le service de session depuis le container, jamais depuis la request !

/** @var EntityManager $em */
$em = $this->getDoctrine()->getManager();

$nom = $session->get(AddMembreController::MEMBRE_NOM,null);
$prenom = $session->get(AddMembreController::MEMBRE_PRENOM,null);
$familleId = $session->get(AddMembreController::FAMILLE_ID,null);

if(is_null($nom) || is_null($prenom))
{
return $this->redirect($this->generateUrl('app_addmembre_start'));
}

$form = null;
$membre = new Membre();
$membre->setPrenom($prenom);

$famille = null;
$template = null;
if(!is_null($familleId))
{
$famille = $em->getRepository('AppBundle:Famille')->find($familleId);
$membre->setFamille($famille);
$form = $this->createForm(new MembreWithoutFamilleType(),$membre);
$template = 'AppBundle:Membre/AddForm:AddMembreWithoutFamille.html.twig';
}
else
if(is_null($familleId))
{
$famille = new Famille();
$famille->setNom($nom);
$membre->setFamille($famille);
$form = $this->createForm(new MembreWithFamilleType(),$membre);
$template = 'AppBundle:Membre/AddForm:AddMembre.html.twig';
}


$form->handleRequest($request);

if($form->isValid())
else
{
$em->persist($membre);
$em->flush();
return $this->render('AppBundle:Membre/AddForm:End.html.twig',array('membre'=>$membre));
$famille = $this->get('app.repository.famille')->findOneBy(array('id'=>$familleId));
}

return $this->render($template,
array('form'=>$form->createView(),
'famille'=>$famille,
'next'=> $this->generateUrl('app_addmembre_membre'),
));
$famille->addMembre($membre);

//presist new membre and his famille
$this->get('app.repository.membre')->save($membre);
$this->get('app.repository.famille')->save($famille);

/*
* Plustôt que de rediriger directement sur la page de membre on privilègie
* le rendu d'un nouveau template qui s'insere bien dans l'ajax qui gere
* cette page.
*/
return $this->render('AppBundle:AddMembre:finish.html.twig',
array('membre'=>$membre));

}

Expand Down
31 changes: 30 additions & 1 deletion src/AppBundle/Controller/FamilleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use AppBundle\Form\Famille\FamilleEditType;
use Symfony\Component\HttpFoundation\Request;

/**
* Class FamilleController
Expand All @@ -29,7 +31,7 @@ class FamilleController extends Controller {
*/
public function showAction(Famille $famille) {

$familleForm = $this->createForm(new FamilleType, $famille);
$familleForm = $this->createForm(FamilleType::class, $famille);

return array(
'listing' => $this->get('listing'),
Expand All @@ -38,6 +40,33 @@ public function showAction(Famille $famille) {
);
}

/**
* @param $famille Famille la famille
* @param Request $request,
* @return Response la vue
*
* @ParamConverter("famille", class="AppBundle:Famille")
* @Route("/edit/{famille}")
* @Template("AppBundle:Famille:page_edit.html.twig")
*/
public function editAction(Request $request,Famille $famille) {

$form = $this->createForm(FamilleEditType::class, $famille);

$form->handleRequest($request);

if($form->isSubmitted() && $form->isValid())
{
$this->get('app.repository.famille')->save($famille);
return $this->redirect($this->generateUrl('app_famille_show',array('famille'=>$famille->getId())));
}

return array(
'famille' => $famille,
'form' => $form->createView()
);
}

/**
* Cette fonction retourne une proprieté d'une famille donnés par son id. la proprieté doit être du type param1__param2...
* (getPere()->getAdresse())
Expand Down
4 changes: 1 addition & 3 deletions src/AppBundle/Controller/ListCallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public function Session($key, $call = self::CALL_BY_TWIG)
case ListKey::MEMBRES_SEARCH_RESULTS:
$list = ListModelsMembre::getDefault($this->getTwig(), $this->getRouter(), $items, $url)->render();
return $this->returnList($list, $call);
case ListKey::FAMILLE_SEARCH_RESULTS_ADD_MEMBRE:
$list = ListModelsFamille::getSearchResults($this->getTwig(), $this->getRouter(), $items, $url)->render();
return $this->returnList($list, $call);

case ListKey::PAYEMENTS_SEARCH_RESULTS:
$list = ListModelsPayement::getSearchResults($this->getTwig(), $this->getRouter(), $items, $url)->render();
return $this->returnList($list, $call);
Expand Down
Loading