diff --git a/config/routes.yaml b/config/routes.yaml index 8728143..5f9351e 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -196,6 +196,18 @@ app_illustration_submit: path: /user/illustration/submit/{by}/{userid} defaults: { _controller: App\Controller\IllustrationController:submit } +app_illustration_submits01: + path: /user/illustration/submits01/{by}/{userid} + defaults: { _controller: App\Controller\IllustrationController:submits01 } + +app_illustration_submits02: + path: /user/illustration/submits02/{by}/{userid}/{categoryid} + defaults: { _controller: App\Controller\IllustrationController:submits02 } + +app_illustration_submits03: + path: /user/illustration/submits03/{by}/{userid}/{categoryid} + defaults: { _controller: App\Controller\IllustrationController:submits03 } + app_illustration_update: path: /user/illustration/update/{id}/{by} defaults: { _controller: App\Controller\IllustrationController:update } diff --git a/src/Controller/IllustrationController.php b/src/Controller/IllustrationController.php index 88667d1..e24d4c1 100755 --- a/src/Controller/IllustrationController.php +++ b/src/Controller/IllustrationController.php @@ -2,13 +2,14 @@ namespace App\Controller; +use App\Entity\Category; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Form\FormError; +use Symfony\Component\HttpFoundation\JsonResponse; use App\Entity\Illustration as Entity; use App\Form\IllustrationType as Form; +use App\Form\IllustrationCategoryType as FormCategory; use DateTime; class IllustrationController extends AbstractController @@ -109,7 +110,117 @@ class IllustrationController extends AbstractController 'userid' => $userid, ]); } + + public function submits01($by, $userid, Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data = new Entity(); + $data->setSubmittime(new DateTime()); + + // Permission + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } + + // Création du formulaire + if($by=="admin"||$by=="update") { + $form = $this->createForm(FormCategory::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$em->getRepository("App:User")->find($userid))); + } else { + $form = $this->createForm(FormCategory::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$this->getUser())); + } + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur erreur + $this->getErrorForm(null,$form,$request,$data,"submit"); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $categoryid=$data->getCategory()->getId(); + + return $this->redirectToRoute('app_illustration_submits02',["by"=>$by,"userid"=>$userid,"categoryid"=>$categoryid]); + } + + // Affichage du formulaire + return $this->render($this->render.'submits01.html.twig', [ + 'useheader' => true, + 'usesidebar' => ($by=="admin" || $by=="update"), + $this->data => $data, + 'mode' => 'submit', + 'form' => $form->createView(), + 'by' => $by, + 'userid' => $userid, + ]); + } + + + public function submits02($by, $userid, $categoryid, Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data = new Entity(); + $data->setSubmittime(new DateTime()); + + // Permission + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } + if($by!="admin"&&$by!="update") { + if($this->getUser()!=$em->getRepository(Category::class)->find($categoryid)->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) + return $this->redirectToRoute("app_home"); + } + + // Affichage du formulaire + return $this->render($this->render.'submits02.html.twig', [ + 'useheader' => true, + 'usesidebar' => ($by=="admin" || $by=="update"), + $this->data => $data, + 'mode' => 'submit', + 'by' => $by, + 'userid' => $userid, + 'categoryid' => $categoryid, + ]); + } + + + public function submits03($by, $userid, $categoryid, Request $request) + { + // Initialisation de l'enregistrement + $em = $this->getDoctrine()->getManager(); + $data = new Entity(); + $data->setSubmittime(new \DateTime()); + $data->setUpdatetime(new \DateTime()); + $category=$em->getRepository(Category::class)->find($categoryid); + + // Permission + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } + if($by!="admin"&&$by!="update") { + if($this->getUser()!=$category->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) + return $this->redirectToRoute("app_home"); + } + + $illustration=$request->request->get('illustration'); + $width=$request->request->get('width'); + $height=$request->request->get('height'); + $name=$request->request->get('name'); + + $data->setName($name); + $data->setIllustration($illustration); + $data->setWidth($width); + $data->setHeight($height); + $data->setCategory($category); + $em->persist($data); + $em->flush(); + + return new JsonResponse(); + } + public function update($id,$by,Request $request) { // Initialisation de l'enregistrement diff --git a/src/Form/IllustrationCategoryType.php b/src/Form/IllustrationCategoryType.php new file mode 100644 index 0000000..e89650a --- /dev/null +++ b/src/Form/IllustrationCategoryType.php @@ -0,0 +1,65 @@ +add('submit', + SubmitType::class, [ + "label" => "Valider", + "attr" => ["class" => "btn btn-success no-print"], + ] + ); + + if($options["by"]=="admin") { + $builder->add('category', + EntityType::class, [ + "class" => "App:Category", + "label" => "Categorie", + "choice_label"=> function($category) { + return $category->getUser()->getUsername(). ' = ' . $category->getName(); + }, + "group_by" => function($category) { + return $category->getUser()->getUsername(); + }, + ] + ); + } + else { + $builder->add('category', + EntityType::class, [ + "class" => "App:Category", + "label" => "Categorie", + "choice_label"=> "name", + 'query_builder' => function (EntityRepository $er) use ($options): QueryBuilder { + return $er->createQueryBuilder('c')->where('c.user=:user')->setParameter('user',$options['user']->getId())->orderBy('c.order', 'ASC'); + }, + ] + ); + } + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'App\Entity\Illustration', + 'mode' => 'string', + 'by' => 'string', + 'user' => 'App\Entity\User' + )); + } +} diff --git a/src/Service/uploadListener.php b/src/Service/uploadListener.php index 561f881..f0bb997 100644 --- a/src/Service/uploadListener.php +++ b/src/Service/uploadListener.php @@ -55,6 +55,9 @@ class uploadListener case "image/x-png": $source=imagecreatefrompng($image); break; + case 'image/webp': + $source = imagecreatefromwebp($image); + break; } $newImage = imagecreatetruecolor( $newImageWidth, $newImageHeight ); @@ -75,6 +78,8 @@ class uploadListener case "image/x-png": imagepng($newImage,$image); break; + case 'image/webp': + imagewebp($newImage, $image, 90); } chmod($image, 0640); diff --git a/templates/Home/home.html.twig b/templates/Home/home.html.twig index 0640015..8a7b288 100644 --- a/templates/Home/home.html.twig +++ b/templates/Home/home.html.twig @@ -416,6 +416,10 @@ Ajouter une Illustration + + Ajouter des Illustrations en masse + + Ajouter un Webzine diff --git a/templates/Home/user.html.twig b/templates/Home/user.html.twig index 2d34e21..8a1c7f8 100644 --- a/templates/Home/user.html.twig +++ b/templates/Home/user.html.twig @@ -416,6 +416,11 @@ Ajouter une Illustration + + + Ajouter des Illustrations en masse + + Ajouter un Webzine diff --git a/templates/Illustration/submits01.html.twig b/templates/Illustration/submits01.html.twig new file mode 100755 index 0000000..1cd9fa3 --- /dev/null +++ b/templates/Illustration/submits01.html.twig @@ -0,0 +1,64 @@ +{% extends 'base.html.twig' %} + +{% block body %} +{{ form_start(form) }} +

+ Création ILLUSTRATIONS EN MASSE +

+ + {{ form_widget(form.submit) }} + {% if by=="admin" %} + Annuler + {% elseif by=="update" %} + Annuler + {% elseif by=="profil" %} + Annuler + {% elseif by=="illustration" %} + Annuler + {% else %} + Annuler + {% endif %} + +

+ + {% if app.session.flashbag.has('error') %} +
+ Erreur
+ {% for flashMessage in app.session.flashbag.get('error') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + + {% if app.session.flashbag.has('notice') %} +
+ Information
+ {% for flashMessage in app.session.flashbag.get('notice') %} + {{ flashMessage }}
+ {% endfor %} +
+ {% endif %} + +
+
+
+
+ Informations +
+ +
+ {{ form_row(form.category) }} +
+
+
+
+ +{{ form_end(form) }} + +{% endblock %} + +{% block localjavascript %} + $(document).ready(function() { + $("#illustration_category").focus(); + }); +{% endblock %} diff --git a/templates/Illustration/submits02.html.twig b/templates/Illustration/submits02.html.twig new file mode 100644 index 0000000..5fef67e --- /dev/null +++ b/templates/Illustration/submits02.html.twig @@ -0,0 +1,73 @@ +{% extends "base.html.twig" %} + +{% block encorelinktags %} + {{ encore_entry_link_tags('dropzone') }} +{% endblock encorelinktags %} + +{% block body %} +

+ Téléchargez vos Illustrations +

+ Annuler + +
+
+
+
+
+
+{% endblock %} + +{% block encorescripttags %} + {{ encore_entry_script_tags('dropzone') }} +{% endblock %} + +{% block localjavascript %} + function dropzoneinit( elt ) { + } + + function dropzonesuccess( file, response ) { + parent.$("#illustration_illustration").val(response["file"]); + parent.$("#illustration_width").val(response["width"]); + parent.$("#illustration_height").val(response["height"]); + parent.$("#illustration_name").val(response["originalname"]); + parent.$("#illustration_illustration_img").attr("src","/{{ appAlias }}/uploads/illustration/"+response["file"]); + + console.log('here'); + console.log(response["file"]); + + $.ajax({ + method: "POST", + url: "{{ path('app_illustration_submits03',{"by":by,"userid":userid,"categoryid":categoryid}) }}", + data: { + illustration:response["file"], + width:response["width"], + height:response["height"], + name:response["originalname"] + } + }); + + } + function dropzonequeuecomplete(file) { + {% if by=="admin" %} + url='{{ path('app_admin_illustration',{'by':by,'userid':-1}) }}'; + {% elseif by=="update" %} + url='{{ path('app_user_update',{id:userid}) }}'; + {% elseif by=="profil" %} + url='{{ path('app_user_profil') }}'; + {% elseif by=="illustration" %} + url='{{ path('app_illustration_view',{'by':"user","idcat":illustration.category.id,"id":illustration.id}) }}'; + {% else %} + url='{{ path('app_home_user',{'userpseudo':app.user.slug}) }}'; + {% endif %} + + window.location.href=url; + } +{% endblock %} +