Skip to content

Commit

Permalink
Merge pull request #47 from gerMdz/17-wizard-section
Browse files Browse the repository at this point in the history
Se mejora creación de nueva sección desde el block principal, agregan…
  • Loading branch information
gerMdz authored Oct 16, 2021
2 parents 77ffba8 + 90a0db7 commit 835341b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/bitacora.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#### Mejoras
- Cambio en section edit
- Bug de nueva section, no indicaba que principal era obligatoria
- Bug de nueva section, no indicaba que principal era obligatoria
- Se mejora creación de nueva sección desde el block principal, agregando la sección directamente al block

#### Nuevas Funciones

5 changes: 1 addition & 4 deletions src/Controller/ModelTemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Controller;

use App\Entity\ModelTemplate;
use App\Entity\TypeBlock;
use App\Form\ModelTemplateType;
use App\Repository\ModelTemplateRepository;
use App\Repository\TypeBlockRepository;
Expand Down Expand Up @@ -62,12 +61,11 @@ public function index(ModelTemplateRepository $modelTemplateRepository, Paginato
/**
* @Route("/{block}", name="model_template_index_block", methods={"GET"})
* @param ModelTemplateRepository $modelTemplateRepository
* @param TypeBlockRepository $typeBlockRepository
* @param Request $request
* @param PaginatorInterface $paginator
* @return Response
*/
public function indexBlock(ModelTemplateRepository $modelTemplateRepository, TypeBlockRepository $typeBlockRepository,Request $request, PaginatorInterface $paginator): Response
public function indexBlock(ModelTemplateRepository $modelTemplateRepository,Request $request, PaginatorInterface $paginator): Response
{
$block = $request->get('block');
$modelTemplate = $modelTemplateRepository->findModelTemplatesByBlock($block);
Expand Down Expand Up @@ -247,6 +245,5 @@ public function createBlockFromModelTemplate(ModelTemplate $modelTemplate): Redi
$this->session->set('model_template_id', $modelTemplate->getId());
$entity = $modelTemplate->getBlock()->getEntity();
return $this->redirectToRoute(sprintf('admin_%s_new_step1', strtolower($entity) ));

}
}
17 changes: 17 additions & 0 deletions src/Controller/PrincipalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/admin/principal")
*/
class PrincipalController extends BaseController
{

private $session;

/**
* @param SessionInterface $session
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
}

/**
* @Route("/", name="principal_index", methods={"GET"})
* @param PrincipalRepository $principalRepository
Expand Down Expand Up @@ -260,6 +272,7 @@ public function agregarSeccion(Request $request, Principal $principal, EntityMan
{
$form = $this->createForm(SectionAddType::class);
$form->handleRequest($request);
$this->session->set('principal_id', $principal->getId());

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

Expand All @@ -269,6 +282,10 @@ public function agregarSeccion(Request $request, Principal $principal, EntityMan
$entityManager->persist($principal);
$entityManager->flush();

if($this->session->get('principal_id')){
$this->session->remove('principal_id');
}

return $this->redirectToRoute('principal_show', [
'id' => $principal->getId(),
]);
Expand Down
11 changes: 11 additions & 0 deletions src/Controller/SectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper
$newFilename = $uploaderHelper->uploadEntradaImage($uploadedFile, false);
$section->setImageFilename($newFilename);
}

if($this->session->get('principal_id')){
$principal_id = $this->session->get('principal_id');
$principal = $em->getRepository(Principal::class)->find($principal_id);
if($principal){
$section->addPrincipale($principal);
}
$this->session->remove('principal_id');
}

$em->persist($section);
$em->flush();

$this->addFlash('success', 'Sección creada. Gracias por su contribución');

return $this->redirectToRoute('admin_section_list');
}

return $this->render('section_admin/new.html.twig', [
'sectionForm' => $form->createView()
]);
Expand Down

0 comments on commit 835341b

Please sign in to comment.