From 44860455f36b13659a337a3f683ee83945793ae6 Mon Sep 17 00:00:00 2001 From: "Gerardo J. Montivero" Date: Mon, 31 May 2021 21:27:27 -0300 Subject: [PATCH] step 2 completo --- .gitignore | 1 + assets/js/select2.js | 2 +- src/Controller/AdminEntradaController.php | 62 ++++ src/Entity/Entrada.php | 20 ++ src/Form/EntradaType.php | 295 ++++++++++++-------- src/Form/Step/Entrada/StepOneType.php | 98 +++++++ src/Form/Step/Entrada/StepTwoType.php | 79 ++++++ src/Repository/UserRepository.php | 9 + templates/admin_entrada/list.html.twig | 3 + templates/admin_entrada/new_step1.html.twig | 51 ++++ templates/admin_entrada/new_step2.html.twig | 56 ++++ templates/section_admin/new_step1.html.twig | 4 +- templates/sections/franjagris.html.twig | 13 +- 13 files changed, 568 insertions(+), 125 deletions(-) create mode 100644 src/Form/Step/Entrada/StepOneType.php create mode 100644 src/Form/Step/Entrada/StepTwoType.php create mode 100644 templates/admin_entrada/new_step1.html.twig create mode 100644 templates/admin_entrada/new_step2.html.twig diff --git a/.gitignore b/.gitignore index 10d06ab6..3ebcec3e 100755 --- a/.gitignore +++ b/.gitignore @@ -111,3 +111,4 @@ yarn-error.log /public/images/base.jpg /public/images/logo-mail.png /public/images/logo.png +/migrations/ diff --git a/assets/js/select2.js b/assets/js/select2.js index b0b4ff1a..f51a17cf 100644 --- a/assets/js/select2.js +++ b/assets/js/select2.js @@ -4,7 +4,7 @@ import 'select2/dist/css/select2.css'; // optional if you have css loader $(function () { $('.select2-enable').select2({ - placeholder: 'Seleccione la página en donde se insertará la sección', + placeholder: 'Seleccione item de la lista', allowClear: true }); diff --git a/src/Controller/AdminEntradaController.php b/src/Controller/AdminEntradaController.php index aa793e8f..baf81132 100755 --- a/src/Controller/AdminEntradaController.php +++ b/src/Controller/AdminEntradaController.php @@ -3,8 +3,11 @@ namespace App\Controller; use App\Entity\Entrada; +use App\Entity\Section; use App\Form\EntradaComplexType; use App\Form\EntradaType; +use App\Form\Step\Entrada\StepOneType; +use App\Form\Step\Entrada\StepTwoType; use App\Repository\EntradaRepository; use App\Service\BoleanToDateHelper; use App\Service\LoggerClient; @@ -219,6 +222,65 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper 'entrada' => $entrada, ]); } + /** + * @Route("/admin/new/step1", name="admin_entrada_new_step1", methods={"GET","POST"}) + * @param Request $request + * @return Response + * @throws Exception + * @IsGranted("ROLE_ADMIN") + */ + public function newStepOne(Request $request): Response + { + $entrada = new Entrada(); + $form = $this->createForm(StepOneType::class, $entrada); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $section = $form['section']->getData(); + $entrada->addSection($section); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($entrada); + $entityManager->flush(); + + return $this->redirectToRoute('admin_entrada_new_step2', [ + 'id' => $entrada->getId() + ]); + } + + return $this->render('admin_entrada/new_step.html.twig', [ + 'entrada' => $entrada, + 'entradaForm' => $form->createView(), + ]); + } + + /** + * @Route("/admin/new/step2/{id}", name="admin_entrada_new_step2", methods={"GET","POST"}) + * @param Request $request + * @param Entrada $entrada + * @return Response + * @IsGranted("ROLE_ADMIN") + */ + public function newStepTwo(Request $request, Entrada $entrada): Response + { + + $form = $this->createForm(StepTwoType::class, $entrada); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('admin_entrada_new_step3', [ + 'id' => $entrada->getId() + ]); + } + + return $this->render('admin_entrada/new_step2.html.twig', [ + 'entrada' => $entrada, + 'entradaForm' => $form->createView(), + ]); + } + /** * @Route("/admin/entrada/{linkRoute}", name="entrada_admin_link") diff --git a/src/Entity/Entrada.php b/src/Entity/Entrada.php index 40619c78..7ccce77e 100755 --- a/src/Entity/Entrada.php +++ b/src/Entity/Entrada.php @@ -144,6 +144,11 @@ class Entrada */ private $button; + /** + * @ORM\Column(type="string", length=150, nullable=true, unique=true) + */ + private $identificador; + public function __construct() { $this->entradaReferences = new ArrayCollection(); @@ -519,4 +524,19 @@ public function removeButton(ButtonLink $button): self return $this; } + public function getIdentificador(): ?string + { + return $this->identificador; + } + + public function setIdentificador(?string $identificador): self + { + if(null === $identificador){ + $identificador = str_replace(' ', '-',strip_tags($this->titulo)); + } + $this->identificador = $identificador; + + return $this; + } + } diff --git a/src/Form/EntradaType.php b/src/Form/EntradaType.php index 678741bc..b416c238 100755 --- a/src/Form/EntradaType.php +++ b/src/Form/EntradaType.php @@ -21,105 +21,170 @@ class EntradaType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('titulo', CKEditorType::class, [ - 'required' => true, - 'config' => [ - 'uiColor' => '#ffffff', + // Con steps + ->add( + 'titulo', + CKEditorType::class, + [ + 'required' => true, + 'config' => [ + 'uiColor' => '#ffffff', // 'toolbar' => 'full', - 'language' => 'es', - 'input_sync' => true + 'language' => 'es', + 'input_sync' => true, ], - 'attr' => [ + 'attr' => [ + 'required' => false, + 'class' => 'form-control', + ], + ] + ) + ->add( + 'linkRoute', + TextType::class, + [ 'required' => false, - 'class' => 'form-control', - ], - ]) - ->add('linkRoute', TextType::class, [ - 'required' => false, - 'attr' => [ - 'class' => 'form-control', - ], - ]) - ->add('contenido', CKEditorType::class, [ - 'required' => false, - 'config' => [ - 'uiColor' => '#ffffff', -// 'toolbar' => 'full', - 'language' => 'es', - ], - 'attr' => [ + 'attr' => [ + 'class' => 'form-control', + ], + ] + ) + ->add( + 'contenido', + CKEditorType::class, + [ 'required' => false, - 'rows' => 10, + 'config' => [ + 'uiColor' => '#ffffff', +// 'toolbar' => 'full', + 'language' => 'es', + ], + 'attr' => [ + 'required' => false, + 'rows' => 10, // 'class' => 'form-control', - ], - ]) - ->add('autor', EntityType::class, [ - 'class'=>User::class, - 'choice_label' => function(User $user) { - return sprintf('(%s) %s', $user->getPrimerNombre(), $user->getEmail()); - }, - 'placeholder'=> 'Seleccione Autor', - 'invalid_message' => 'Por favor ingrese un autor' - ]) - ->add('imageFile', FileType::class, [ - 'mapped' => false, - 'required' => false, - 'constraints' => [ - new Image([ - 'maxSize' => '2M', - 'maxSizeMessage' => 'La imagen no debe superar los 2MB', - 'mimeTypesMessage' => 'El archivo no es considerada una imagen', - ]), - ], + ], + ] + ) + ->add( + 'autor', + EntityType::class, + [ + 'class' => User::class, + 'choice_label' => function (User $user) { + return sprintf('(%s) %s', $user->getPrimerNombre(), $user->getEmail()); + }, + 'placeholder' => 'Seleccione Autor', + 'invalid_message' => 'Por favor ingrese un autor', + ] + ) + ->add('linkPosting') + ->add( + 'isLinkExterno', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) + ->add( + 'footer', + TextType::class, + [ + 'label' => 'Pie de la entrada', + 'required' => false, + 'attr' => [ + 'class' => 'form-control', + ], + ] + ) + // Con steps hasta aquí - 'attr' => [ - 'placeholder' => 'Ingrese una imagen para esta entrada', - ], - ]) - ->add('publicar', CheckboxType::class, [ - 'mapped' => false, - 'label' => false, - 'required' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], + ->add( + 'imageFile', + FileType::class, + [ + 'mapped' => false, + 'required' => false, + 'constraints' => [ + new Image( + [ + 'maxSize' => '2M', + 'maxSizeMessage' => 'La imagen no debe superar los 2MB', + 'mimeTypesMessage' => 'El archivo no es considerada una imagen', + ] + ), + ], + + 'attr' => [ + 'placeholder' => 'Ingrese una imagen para esta entrada', + ], + ] + ) + ->add( + 'publicar', + CheckboxType::class, + [ + 'mapped' => false, + 'label' => false, + 'required' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], // 'help' => 'Disponible?', - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) ->add('disponibleAt') ->add('disponibleHastaAt') ->add('eventoAt') - ->add('linkPosting') + // ->add('section') ->add('orden') - ->add('encabezado', CheckboxType::class, [ - 'required' => false, - 'label' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], + ->add( + 'encabezado', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], // 'help' => 'Disponible?', - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) - ->add('destacado', CheckboxType::class, [ - 'required' => false, - 'label' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) + ->add( + 'destacado', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], // 'help' => 'Disponible?', - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) ->add('contacto') - ->add('isSinTitulo', CheckboxType::class, [ - 'required' => false, - 'label' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], + ->add( + 'isSinTitulo', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], // 'help' => 'Disponible?', - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) // ->add('sections',EntityType::class,[ // 'class'=>Section::class, // 'multiple'=>true, @@ -130,46 +195,42 @@ public function buildForm(FormBuilderInterface $builder, array $options) // // ] // ]) - ->add('isPermanente',CheckboxType::class, [ - 'required' => false, - 'label' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], + ->add( + 'isPermanente', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'label_attr' => ['class' => 'checkbox-custom text-dark'], // 'help' => 'Disponible?', - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) - ->add('isLinkExterno',CheckboxType::class, [ - 'required' => false, - 'label' => false, - 'label_attr' => ['class' => 'checkbox-custom text-dark'], - 'attr' => [ - 'class' => 'form-check-input ', - ], - ]) - ->add('footer', TextType::class, [ - 'label' => 'Pie de la entrada', - 'required' => false, - 'attr' => [ - 'class' => 'form-control', - ], - ]) - ->add('modelTemplate', EntityType::class, [ - 'class' => ModelTemplate::class, - 'query_builder' => function (ModelTemplateRepository $er) { - return $er->findByTypeEntrada(); - }, - 'help' => 'Opcional, llama a un template específico, debe estar en sections creado', - 'required' => false - ]) + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) + + ->add( + 'modelTemplate', + EntityType::class, + [ + 'class' => ModelTemplate::class, + 'query_builder' => function (ModelTemplateRepository $er) { + return $er->findByTypeEntrada(); + }, + 'help' => 'Opcional, llama a un template específico, debe estar en sections creado', + 'required' => false, + ] + ) ; // ; Final Builder } public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults([ - 'data_class' => Entrada::class, - ]); + $resolver->setDefaults( + [ + 'data_class' => Entrada::class, + ] + ); } } diff --git a/src/Form/Step/Entrada/StepOneType.php b/src/Form/Step/Entrada/StepOneType.php new file mode 100644 index 00000000..aee22263 --- /dev/null +++ b/src/Form/Step/Entrada/StepOneType.php @@ -0,0 +1,98 @@ +add( + 'titulo', + CKEditorType::class, [ + 'required' => true, + 'config' => [ + 'uiColor' => '#ffffff', +// 'toolbar' => 'full', + 'language' => 'es', + 'input_sync' => true + ], + 'attr' => [ + 'required' => false, + 'class' => 'form-control', + ], + ]) + ->add('contenido', CKEditorType::class, [ + 'required' => false, + 'config' => [ + 'uiColor' => '#ffffff', +// 'toolbar' => 'full', + 'language' => 'es', + ], + 'attr' => [ + 'required' => false, + 'rows' => 10, +// 'class' => 'form-control', + ], + ]) + ->add( + 'section', + EntityType::class, + [ + 'class' => Section::class, + 'mapped' => false, + 'label' => 'Sección?', + 'choice_label' => 'identificador', + 'placeholder' => 'Seleccione la sección donde se insertará la entrada', + 'required' => false, + 'help' => 'En qué sección estará esta entrada?', + 'attr' => [ + 'class' => 'select2-enable', + ], + ] + ) + ->add( + 'autor', + EntityType::class, + [ + 'class' => User::class, + 'query_builder' => function (UserRepository $ur) { + return $ur->findByRoleAutor(); + }, + 'label' => 'Autor?', + 'choice_label' => 'primerNombre', + 'placeholder' => 'Seleccione autor', + 'required' => false, + 'help' => 'Autor de la entrada entrada?', + 'attr' => [ + 'class' => 'select2-enable', + ], + ] + ) + ; // Fin del builder + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults( + [ + 'data_class' => Entrada::class, + ] + ); + } +} diff --git a/src/Form/Step/Entrada/StepTwoType.php b/src/Form/Step/Entrada/StepTwoType.php new file mode 100644 index 00000000..34932360 --- /dev/null +++ b/src/Form/Step/Entrada/StepTwoType.php @@ -0,0 +1,79 @@ +add('linkRoute', TextType::class, [ + 'required' => false, + 'help'=>'Tiene un link interno? No debe contener link externo', + 'attr' => [ + 'class' => 'form-control', + ], + ]) + ->add('linkPosting', TextType::class, [ + 'label'=>'Link Externo al sitio', + 'required' => false, + 'help'=>'Tiene un link externo? No debe contener linkRoute', + 'attr' => [ + 'class' => 'form-control', + ], + ]) + ->add( + 'isLinkExterno', + CheckboxType::class, + [ + 'help'=>'Debe abrirse el enlace en una ventana nueva?', + 'required' => false, + 'label' => 'Abre otra ventana o pestaña?', + 'label_attr' => ['class' => 'checkbox-custom text-dark'], + 'attr' => [ + 'class' => 'form-check-input ', + ], + ] + ) + ->add( + 'footer', + TextType::class, + [ + 'label' => 'Pie de la entrada', + 'help'=> 'Puede usarse cómo texto de un enlace o botón (depende de la plantilla', + 'required' => false, + 'attr' => [ + 'class' => 'form-control', + ], + ] + ) + + ; // Fin del builder + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults( + [ + 'data_class' => Entrada::class, + ] + ); + } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 87f76206..779ec80d 100755 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -40,6 +40,15 @@ public function findByRoleAndEmail($email, $role) ; } + public function findByRoleAutor() + { + return $this->createQueryBuilder('u') + ->andWhere('u.roles LIKE :roles') + ->setParameter('roles', '%ROLE_ESCRITOR%') + ->orderBy('u.primerNombre', 'ASC') + ; + } + public function findAllEmailsRoleAlfa(string $role = null, string $query, int $limit = 5) { $qb = $this->createQueryBuilder('u'); diff --git a/templates/admin_entrada/list.html.twig b/templates/admin_entrada/list.html.twig index b06b41a8..32eec1d5 100644 --- a/templates/admin_entrada/list.html.twig +++ b/templates/admin_entrada/list.html.twig @@ -15,6 +15,9 @@ Crear Entrada + + Asistente Crear Entrada + Ver Publicados diff --git a/templates/admin_entrada/new_step1.html.twig b/templates/admin_entrada/new_step1.html.twig new file mode 100644 index 00000000..5ee8bd0e --- /dev/null +++ b/templates/admin_entrada/new_step1.html.twig @@ -0,0 +1,51 @@ +{% extends 'base_admin_board.html.twig' %} +{% block title %} + Paso 1 - Entradas +{% endblock %} +{% block stylesheets %} +{#{{ parent() }}#} + + + + +{{ encore_entry_link_tags('select2') }} + +{% endblock %} + +{% block content %} + +

Asistente para crear nueva entrada - Paso 1

+ + +
+
+ {{ form_start(entradaForm) }} +
+
+ {{ form_row(entradaForm.titulo) }} +
+
+ {{ form_row(entradaForm.contenido) }} +
+
+ {{ form_row(entradaForm.section) }} +
+
+ {{ form_row(entradaForm.autor) }} +
+ + {{ form_widget(entradaForm._token) }} + + {{ form_end(entradaForm, {'render_rest': true}) }} + + +
+ +
+ Cancelar e ir al Listado + +{% endblock %} +{% block javascripts %} + {{ parent() }} + {{ encore_entry_script_tags('select2') }} +{% endblock %} diff --git a/templates/admin_entrada/new_step2.html.twig b/templates/admin_entrada/new_step2.html.twig new file mode 100644 index 00000000..570329bc --- /dev/null +++ b/templates/admin_entrada/new_step2.html.twig @@ -0,0 +1,56 @@ +{% extends 'base_admin_board.html.twig' %} +{% block title %} + Paso 2 - Entradas +{% endblock %} +{% block stylesheets %} + {# {{ parent() }} #} + + + + + {{ encore_entry_link_tags('select2') }} + +{% endblock %} + +{% block content %} + +

Asistente para crear nueva entrada - Paso 2 {{ entrada.titulo| replace({'

':'', '

':''}) | raw }}

+ + +
+ {{ form_start(entradaForm) }} +
+
+ {{ form_row(entradaForm.linkRoute) }} +
+
+ {{ form_row(entradaForm.linkPosting) }} +
+
+
+ +
+
+
+ {{ form_row(entradaForm.footer) }} +
+ + {{ form_widget(entradaForm._token) }} + + {{ form_end(entradaForm, {'render_rest': true}) }} +
+ + Cancelar e ir al Listado +
+ +
+ +
+{% endblock %} + {% block javascripts %} + {{ parent() }} + {{ encore_entry_script_tags('select2') }} + {% endblock %} diff --git a/templates/section_admin/new_step1.html.twig b/templates/section_admin/new_step1.html.twig index 76de9932..a2743169 100644 --- a/templates/section_admin/new_step1.html.twig +++ b/templates/section_admin/new_step1.html.twig @@ -28,11 +28,9 @@ {{ form_row(sectionForm.description) }}
- {{ form_row(sectionForm.principal ) }} + {{ form_row(sectionForm.principal) }}
- - {{ form_widget(sectionForm._token) }} diff --git a/templates/sections/franjagris.html.twig b/templates/sections/franjagris.html.twig index 0fcb195b..5372631e 100644 --- a/templates/sections/franjagris.html.twig +++ b/templates/sections/franjagris.html.twig @@ -3,13 +3,18 @@

+ class="text-black-75 ArialLight"> {{ section.title | replace({'

':'', '

':''}) | raw }}