From ad60b9372c05cf4e776fc2d4d09c953ed7ddd562 Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 31 Oct 2024 11:48:30 +0100 Subject: [PATCH] svg --- config/routes.yaml | 20 ++- src/Controller/CategoryController.php | 7 +- src/Controller/HomeController.php | 2 +- src/Controller/IllustrationController.php | 4 +- src/Controller/WebzineController.php | 176 +++++++++++++++------- src/Form/WebzineType.php | 28 ++++ templates/Config/edit.html.twig | 24 +-- templates/Config/render.html.twig | 1 - templates/Home/home.html.twig | 39 ++--- templates/Home/user.html.twig | 43 +++--- templates/Include/sidebar.html.twig | 2 +- templates/User/edit.html.twig | 13 ++ templates/Webzine/edit.html.twig | 13 +- templates/Webzine/list.html.twig | 8 +- templates/Webzine/listrender.html.twig | 51 +++++++ templates/Webzine/view.html.twig | 21 ++- 16 files changed, 323 insertions(+), 129 deletions(-) create mode 100644 templates/Webzine/listrender.html.twig diff --git a/config/routes.yaml b/config/routes.yaml index 1bc2ec8..b60c243 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -212,12 +212,16 @@ app_illustration_view: defaults: { _controller: App\Controller\IllustrationController:view } #== Webzine ================================================================================================== -app_webzine: - path: /admin/webzine/list/{by} +app_admin_webzine: + path: /admin/webzine/list/{by}/{userid} defaults: { _controller: App\Controller\WebzineController:list } +app_user_webzine: + path: /user/webzine/list + defaults: { _controller: App\Controller\WebzineController:listuser } + app_webzine_submit: - path: /admin/webzine/submit/{by} + path: /user/webzine/submit/{by}/{userid} defaults: { _controller: App\Controller\WebzineController:submit } app_webzine_update: @@ -228,18 +232,18 @@ app_webzine_delete: path: /admin/webzine/delete/{id}/{by} defaults: { _controller: App\Controller\WebzineController:delete } -app_webzine_view: - path: /webzine/view/{idcat}/{id}/{by} - defaults: { _controller: App\Controller\WebzineController:view } - app_webzine_crop: - path: /admin/webzine/crop/{type}/{reportinput}/{by} + path: /admin/webzine/crop/{type}/{reportinput} defaults: { _controller: App\Controller\CropController:crop02 } app_webzine_upload: path: /admin/webzine/upload defaults: { _controller: App\Controller\WebzineController:upload } +app_webzine_view: + path: /webzine/view/{idcat}/{id}/{by} + defaults: { _controller: App\Controller\WebzineController:view } + #== Link =========================================================================================================== app_link: path: /admin/link diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index 31dbe72..c7592d3 100755 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -67,6 +67,7 @@ class CategoryController extends AbstractController $data->setAppthumbfilteropacity(100); $data->setAppthumbfiltersepia(0); + // Permissions if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { return $this->redirectToRoute("app_home"); } @@ -104,7 +105,7 @@ class CategoryController extends AbstractController // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => true, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'submit', 'form' => $form->createView(), @@ -130,7 +131,7 @@ class CategoryController extends AbstractController } // Création du formulaire - $form = $this->createForm(Form::class,$data,array("mode"=>"update","by"=>$by,"user"=>$this->getUser())); + $form = $this->createForm(Form::class,$data,array("mode"=>"update","by"=>$by,"user"=>$em->getRepository("App:User")->find($data->getUser()->getId()))); // Récupération des data du formulaire $form->handleRequest($request); @@ -157,7 +158,7 @@ class CategoryController extends AbstractController // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => true, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'update', 'form' => $form->createView(), diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 9dc2a31..8687d32 100755 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -16,7 +16,7 @@ class HomeController extends AbstractController $users = $em->getRepository("App:User")->findBy([],["pseudo"=>"ASC"]); $illustrations = $em->getRepository("App:Illustration")->findBy([],["submittime"=>"DESC"]); $links = $em->getRepository("App:Link")->findBy(["user"=>null]); - $webzines = $em->getRepository("App:Webzine")->findBy(["user"=>null], ['set' => 'ASC', 'order' => 'ASC']); + $webzines = $em->getRepository("App:Webzine")->findBy([],["submittime"=>"DESC"]); return $this->render('Home/home.html.twig',[ "useheader" => false, diff --git a/src/Controller/IllustrationController.php b/src/Controller/IllustrationController.php index 57d758f..df2a3c7 100755 --- a/src/Controller/IllustrationController.php +++ b/src/Controller/IllustrationController.php @@ -98,7 +98,7 @@ class IllustrationController extends AbstractController // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => false, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'submit', 'form' => $form->createView(), @@ -152,7 +152,7 @@ class IllustrationController extends AbstractController // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => false, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'update', 'form' => $form->createView(), diff --git a/src/Controller/WebzineController.php b/src/Controller/WebzineController.php index 3142b4e..0fe4b2b 100755 --- a/src/Controller/WebzineController.php +++ b/src/Controller/WebzineController.php @@ -14,56 +14,64 @@ use App\Entity\Webzinepage as Webzinepage; class WebzineController extends AbstractController { private $data = "webzine"; - private $route = "app_webzine"; + private $route = "app_admin_webzine"; private $render = "Webzine/"; private $entity = "App:Webzine"; - public function list(Request $request) + public function list($by,$userid) { $em = $this->getDoctrine()->getManager(); - $datas = $em->getRepository($this->entity)->findAll(); + if($by=="admin") { + $datas = $em->getRepository($this->entity)->findAll(); - return $this->render($this->render.'list.html.twig',[ + return $this->render($this->render.'list.html.twig',[ + $this->data."s" => $datas, + "useheader" => true, + "usesidebar" => true, + ]); + } + else { + $datas = $em->getRepository($this->entity)->findBy(["user"=>$em->getRepository("App:User")->find($userid)]); + + return $this->render($this->render.'listrender.html.twig',[ + $this->data."s" => $datas, + "by" => $by, + "userid" => $userid, + ]); + } + } + + public function listuser() + { + $em = $this->getDoctrine()->getManager(); + + $datas = $em->getRepository($this->entity)->findByUser($this->getUser()); + + return $this->render($this->render.'listrender.html.twig',[ $this->data."s" => $datas, - "useheader" => true, - "usesidebar" => true, - ]); - } - - public function view($idcat,$id,Request $request) - { - $em = $this->getDoctrine()->getManager(); - $webzine=$em->getRepository($this->entity)->find($idcat); - $page=$em->getRepository("App:Webzinepage")->find($id); - $sets=$em->getRepository($this->entity)->findBy(["set"=>$webzine->getSet()],["order"=>"ASC"]); - - $datanext=$this->getDataAllNext($idcat,$id,$webzine); - $dataprev=$this->getDataAllPrev($idcat,$id,$webzine); - - $pathinfo=pathinfo($page->getIllustration()); - - if(!$page) return $this->redirectToRoute('app_home'); - - return $this->render($this->render.'view.html.twig', array( - $this->data => $webzine, - "page" => $page, - "sets" => $sets, - "prev" => $dataprev, - "next" => $datanext, - "pathinfo" => $pathinfo, - "usemonocolor" => true, - )); + "by" => "profil", + "userid" => $this->getUser()->getId(), + ]); } - - public function submit($by, Request $request) + public function submit($by, $userid, Request $request) { // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); $data = new Entity(); + + // Permissions + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } // Création du formulaire - $form = $this->createForm(Form::class,$data,array("mode"=>"submit")); + if($by=="admin"||$by=="update") { + $form = $this->createForm(Form::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$em->getRepository("App:User")->find($userid))); + } else { + $userid=$this->getUser()->getId(); + $form = $this->createForm(Form::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$this->getUser())); + } // Récupération des data du formulaire $form->handleRequest($request); @@ -98,23 +106,31 @@ class WebzineController extends AbstractController $em->persist($page); $em->flush(); + if($order==1) $firstpage=$page; } - + $em->flush(); // Retour à la liste - if($by=="console") - return $this->redirectToRoute($this->route); + if($by=="admin") + return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]); + elseif($by=="update") + return $this->redirectToRoute("app_user_update",["id"=>$data->getUser()->getId()]); + elseif($by=="profil") + return $this->redirectToRoute("app_user_profil"); else - return $this->redirectToRoute("app_home"); + { + return $this->redirectToRoute("app_webzine_view",["by"=>"user","idcat"=>$data->getId(),"id"=>$page->getId()]); + } } // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => false, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'submit', 'form' => $form->createView(), 'by' => $by, + 'userid' => $userid, ]); } @@ -123,13 +139,24 @@ class WebzineController extends AbstractController // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); $data=$em->getRepository($this->entity)->find($id); + if(!$data) return $this->redirectToRoute("app_home"); + + // Permission + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } + if($by!="admin"&&$by!="update") { + if($this->getUser()!=$data->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) + return $this->redirectToRoute("app_home"); + } + $oldlstpages = array(); foreach($data->getWebzinepages() as $page){ $oldlstpages[] = $page->getIllustration(); } // Création du formulaire - $form = $this->createForm(Form::class,$data,array("mode"=>"update")); + $form = $this->createForm(Form::class,$data,array("mode"=>"update","by"=>$by,"user"=>$em->getRepository("App:User")->find($data->getUser()->getId()))); // Récupération des data du formulaire $form->handleRequest($request); @@ -184,21 +211,26 @@ class WebzineController extends AbstractController $em->flush(); - // Retour à l'webzine - if($by=="console") - return $this->redirectToRoute($this->route); - else - return $this->redirectToRoute($this->route.'_view',array("idcat"=>$data->getId(),"id"=> $data->getWebzinepages()[0]->getId())); + // Retour à la liste + if($by=="admin") + return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]); + elseif($by=="update") + return $this->redirectToRoute("app_user_update",["id"=>$data->getUser()->getId()]); + elseif($by=="profil") + return $this->redirectToRoute("app_user_profil"); + elseif($by=="illustration") + return $this->redirectToRoute("app_webzine_view",["by"=>"user","idcat"=>$data->getId(),"id"=>$data->getWebzinepages()[0]->getId()]); } // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => false, + 'usesidebar' => ($by=="admin" || $by=="update"), $this->data => $data, 'mode' => 'update', 'form' => $form->createView(), 'by' => $by, + 'userid' => $data->getUser()->getId(), ]); } @@ -207,6 +239,16 @@ class WebzineController extends AbstractController // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); $data=$em->getRepository($this->entity)->find($id); + if(!$data) return $this->redirectToRoute("app_home"); + + // Permission + if(!$this->getUser()->hasRole("ROLE_ADMIN")&&($by=="admin"||$by=="update")) { + return $this->redirectToRoute("app_home"); + } + if($by!="admin"&&$by!="update") { + if($this->getUser()!=$data->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) + return $this->redirectToRoute("app_home"); + } // Controle avant suppression $error=false; @@ -219,10 +261,14 @@ class WebzineController extends AbstractController $em->flush(); // Retour à la liste - if($by=="console") - return $this->redirectToRoute($this->route); - else - return $this->redirectToRoute("app_home"); + if($by=="admin") + return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]); + elseif($by=="update") + return $this->redirectToRoute("app_user_update",["id"=>$data->getUser()->getId()]); + elseif($by=="profil") + return $this->redirectToRoute("app_user_profil"); + elseif($by=="illustration") + return $this->redirectToRoute("app_home_user",["userpseudo"=>$data->getUser()->getSlug()]); } } @@ -231,7 +277,31 @@ class WebzineController extends AbstractController return $this->render($this->render.'upload.html.twig'); } + public function view($idcat,$id,$by,Request $request) + { + $em = $this->getDoctrine()->getManager(); + $webzine=$em->getRepository($this->entity)->find($idcat); + $page=$em->getRepository("App:Webzinepage")->find($id); + $sets=$em->getRepository($this->entity)->findBy(["set"=>$webzine->getSet()],["order"=>"ASC"]); + $datanext=$this->getDataAllNext($idcat,$id,$webzine); + $dataprev=$this->getDataAllPrev($idcat,$id,$webzine); + + $pathinfo=pathinfo($page->getIllustration()); + + if(!$page) return $this->redirectToRoute('app_home'); + + return $this->render($this->render.'view.html.twig', array( + $this->data => $webzine, + "page" => $page, + "sets" => $sets, + "prev" => $dataprev, + "next" => $datanext, + "pathinfo" => $pathinfo, + "usemonocolor" => true, + "by" => $by, + )); + } protected function getDataAllNext($idcat,$id,$webzine) @@ -342,6 +412,10 @@ class WebzineController extends AbstractController } if ($form->get('submit')->isClicked() && ($mode=="submit" || $mode=="update")) { + // On récupère les pages et on cacule ceux à ajouter ou à supprimer + $lstpages=array_filter(explode(",",$form->get("linkpages")->getData())); + if(empty($lstpages)) + $form->addError(new FormError('Un webzine doit avoir au moins une page')); } if ($form->get('submit')->isClicked() && !$form->isValid()) { diff --git a/src/Form/WebzineType.php b/src/Form/WebzineType.php index affe588..9fcf2af 100644 --- a/src/Form/WebzineType.php +++ b/src/Form/WebzineType.php @@ -11,6 +11,9 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use FOS\CKEditorBundle\Form\Type\CKEditorType; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; class WebzineType extends AbstractType { @@ -42,6 +45,28 @@ class WebzineType extends AbstractType ] ); + if($options["by"]=="admin") { + $builder->add('user', + EntityType::class, [ + "class" => "App:User", + "label" => "Utilisateur", + "choice_label"=> "username", + ] + ); + } + else { + $builder->add('user', + EntityType::class, [ + "class" => "App:User", + "label" => "Utilisateur", + "choice_label"=> "username", + 'query_builder' => function (EntityRepository $er) use ($options): QueryBuilder { + return $er->createQueryBuilder('u')->where('u.id=:user')->setParameter('user',$options['user']->getId()); + }, + ] + ); + } + $builder->add('mode', ChoiceType::class, [ "label" =>"Mode de visualisation des planches", @@ -62,6 +87,7 @@ class WebzineType extends AbstractType ] ); + $builder->add('linkpages',HiddenType::class, array("mapped" => false)); } @@ -70,6 +96,8 @@ class WebzineType extends AbstractType $resolver->setDefaults(array( 'data_class' => 'App\Entity\Webzine', 'mode' => 'string', + 'by' => 'string', + 'user' => 'App\Entity\User' )); } } diff --git a/templates/Config/edit.html.twig b/templates/Config/edit.html.twig index 39f8cf7..99f7692 100755 --- a/templates/Config/edit.html.twig +++ b/templates/Config/edit.html.twig @@ -46,25 +46,25 @@ {{ form_row(form.value) }} {% if config.type=="logo" %}
- {% set color = "" %} - {% if config.id=='logodark' %} - {% set color = app.session.get('colorbgbodydark') %} - {% elseif config.id=='logolight' %} - {% set color = app.session.get('colorbgbodylight') %} - {% endif %} + {% set color = "" %} + {% if config.id=='logodark' %} + {% set color = app.session.get('colorbgbodydark') %} + {% elseif config.id=='logolight' %} + {% set color = app.session.get('colorbgbodylight') %} + {% endif %} - - Modifier + Modifier +
{% elseif config.type=="hero" %}
- - Modifier + Modifier +
{% elseif config.type=="image" %}
- - Modifier + Modifier +
{% endif %} {{ form_row(form.help) }} diff --git a/templates/Config/render.html.twig b/templates/Config/render.html.twig index e5e94da..e239ade 100644 --- a/templates/Config/render.html.twig +++ b/templates/Config/render.html.twig @@ -77,7 +77,6 @@ {% endif %} {% elseif config.type=="hero" %} {%if not config.value is empty %} - qsdfqsdf {% endif %} {% elseif config.type=="image" %} diff --git a/templates/Home/home.html.twig b/templates/Home/home.html.twig index d3ec650..47e9fa4 100644 --- a/templates/Home/home.html.twig +++ b/templates/Home/home.html.twig @@ -329,7 +329,7 @@ {% set source="thumbori_"~page.illustration %} {% set class=" grid-item-size-2 grid-item-size-page" %} - +
@@ -359,25 +359,30 @@ - + +
+
+ Webzine +
+
+ {% if mode=="profil" %} + {{ render(path("app_user_webzine")) }} + {% else %} + {{ render(path("app_admin_webzine",{by:mode,userid:user.id})) }} + {% endif %} +
+
{% endif %} diff --git a/templates/Webzine/edit.html.twig b/templates/Webzine/edit.html.twig index 83c1181..f97b340 100755 --- a/templates/Webzine/edit.html.twig +++ b/templates/Webzine/edit.html.twig @@ -20,10 +20,16 @@ {{ form_widget(form.submit) }} - {% if by=="console" %} - Annuler + {% if by=="admin" %} + Annuler + {% elseif by=="update" %} + Annuler + {% elseif by=="profil" %} + Annuler + {% elseif by=="illustration" %} + Annuler {% else %} - Annuler + Annuler {% endif %} {% if mode=="update" %} @@ -63,6 +69,7 @@
+ {{ form_row(form.user) }} {{ form_row(form.name) }} {{ form_row(form.set) }} {{ form_row(form.order) }} diff --git a/templates/Webzine/list.html.twig b/templates/Webzine/list.html.twig index ea63fd9..5076952 100644 --- a/templates/Webzine/list.html.twig +++ b/templates/Webzine/list.html.twig @@ -5,7 +5,7 @@ WEBZINES -

Ajouter

+

Ajouter

@@ -19,6 +19,7 @@ WEBZINES Action Miniature + Utilisateur Serie Nom @@ -27,9 +28,9 @@ WEBZINES {% for webzine in webzines %} - + {% if webzine.id >=0 %} - + {% endif %} @@ -41,6 +42,7 @@ WEBZINES
{% endif %} + {{ webzine.user.username }} {{ webzine.set }} #{{ webzine.order| format_number({min_integer_digit:'2'})}} {{ webzine.name }} diff --git a/templates/Webzine/listrender.html.twig b/templates/Webzine/listrender.html.twig new file mode 100644 index 0000000..c150f3b --- /dev/null +++ b/templates/Webzine/listrender.html.twig @@ -0,0 +1,51 @@ + +

Ajouter

+ + +
+ + + + + + + + + + + {% for webzine in webzines %} + + + + + + + + {% endfor %} + +
ActionMiniatureSerieNom
+ + {% if webzine.id >=0 %} + + {% endif %} + + {% if not webzine.webzinepages is empty %} + {% set source="thumbori_"~webzine.webzinepages[0].illustration %} + {% set height=30*90/21 %} + +
+ {% endif %} +
{{ webzine.set }} #{{ webzine.order| format_number({min_integer_digit:'2'})}}{{ webzine.name }}
+
+ + + \ No newline at end of file diff --git a/templates/Webzine/view.html.twig b/templates/Webzine/view.html.twig index 444e5d6..21ee8f5 100755 --- a/templates/Webzine/view.html.twig +++ b/templates/Webzine/view.html.twig @@ -49,10 +49,10 @@ {% if not prev is empty %} - + {% endif %} {% if not next is empty %} - + {% endif %} @@ -60,12 +60,17 @@
@@ -76,7 +81,7 @@ {% for page in webzine.webzinepages %} {% set height=30*90/21 %} - +
{% endfor %} @@ -86,7 +91,7 @@

Dans la même série

{% for set in sets %} {% if not set.webzinepages is empty %} - +
{% endif %}