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" %}