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) }} +