diff --git a/docs/bitacora.md b/docs/bitacora.md index beb94c1a..31c88c76 100644 --- a/docs/bitacora.md +++ b/docs/bitacora.md @@ -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 diff --git a/src/Controller/ModelTemplateController.php b/src/Controller/ModelTemplateController.php index 81d2dd06..e1c644a8 100644 --- a/src/Controller/ModelTemplateController.php +++ b/src/Controller/ModelTemplateController.php @@ -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; @@ -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); @@ -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) )); - } } diff --git a/src/Controller/PrincipalController.php b/src/Controller/PrincipalController.php index 50b5ccda..a2f6063b 100755 --- a/src/Controller/PrincipalController.php +++ b/src/Controller/PrincipalController.php @@ -18,6 +18,7 @@ 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; /** @@ -25,6 +26,17 @@ */ 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 @@ -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()) { @@ -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(), ]); diff --git a/src/Controller/SectionController.php b/src/Controller/SectionController.php index c65899d5..e2b369b7 100644 --- a/src/Controller/SectionController.php +++ b/src/Controller/SectionController.php @@ -90,6 +90,16 @@ 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(); @@ -97,6 +107,7 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper return $this->redirectToRoute('admin_section_list'); } + return $this->render('section_admin/new.html.twig', [ 'sectionForm' => $form->createView() ]);