diff --git a/config/routes.yaml b/config/routes.yaml index b718fa5..1bc2ec8 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -158,20 +158,24 @@ app_group_info: defaults: { _controller: App\Controller\GroupController:info } #== Category ====================================================================================================== -app_category: - path: /admin/category +app_admin_category: + path: /admin/category/{by}/{userid} defaults: { _controller: App\Controller\CategoryController:list } +app_user_category: + path: /user/category + defaults: { _controller: App\Controller\CategoryController:listuser } + app_category_submit: - path: /admin/category/submit + path: /admin/category/submit/{by}/{userid} defaults: { _controller: App\Controller\CategoryController:submit } app_category_update: - path: /admin/category/update/{id} + path: /admin/category/update/{id}/{by} defaults: { _controller: App\Controller\CategoryController:update } app_category_delete: - path: /admin/category/delete/{id} + path: /admin/category/delete/{id}/{by} defaults: { _controller: App\Controller\CategoryController:delete } #== Illustration ================================================================================================== diff --git a/public/styles/css/style.css b/public/styles/css/style.css index dfe3e7f..8cef795 100644 --- a/public/styles/css/style.css +++ b/public/styles/css/style.css @@ -399,7 +399,7 @@ th.dt-center, td.dt-center { text-align: center; } } .foliomenu .logo { float:left; height:40px; margin-top:7px; border-radius: 100%; } -.foliomenu .avatar { height: 20px; margin: 3px 3px 0px 0px; width: 20px; } +.foliomenu .avatar { height: 20px; margin: 0px 3px 0px 0px; width: 20px; } .foliomenu div { padding: 10px; line-height:35px; float:left;} .foliomenu a { color: var(--colorftbodydark); @@ -434,7 +434,7 @@ th.dt-center, td.dt-center { text-align: center; } .herofloatmenu { padding: 5px; - background: #cdcdcd; + background: var(--colorbgbodydarkdarker); border-radius: 0px 0px 6px 6px } @@ -458,7 +458,7 @@ th.dt-center, td.dt-center { text-align: center; } .foliomenu .float-right img { height:35px; width:35px; - margin-top:0px; + margin-top:-10px; } .foliomenu .float-right .fa, .foliomenu .float-right .fas { font-size:30px!important; diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index 3a22ed1..31dbe72 100755 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -13,23 +13,47 @@ use App\Form\CategoryType as Form; class CategoryController extends AbstractController { private $data = "category"; - private $route = "app_category"; + private $route = "app_admin_category"; private $render = "Category/"; private $entity = "App:Category"; - 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',[ - $this->data."s" => $datas, - "useheader" => true, - "usesidebar" => true, - ]); + 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 submit(Request $request) + 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, + "by" => "profil", + "userid" => $this->getUser()->getId(), + ]); + } + + public function submit($by, $userid, Request $request) { // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); @@ -43,9 +67,17 @@ class CategoryController extends AbstractController $data->setAppthumbfilteropacity(100); $data->setAppthumbfiltersepia(0); + 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); @@ -60,7 +92,13 @@ class CategoryController extends AbstractController $em->flush(); // Retour à la liste - 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"); + } // Affichage du formulaire @@ -69,18 +107,30 @@ class CategoryController extends AbstractController 'usesidebar' => true, $this->data => $data, 'mode' => 'submit', - 'form' => $form->createView() + 'form' => $form->createView(), + 'by' => $by, + 'userid' => $userid, ]); } - public function update($id,Request $request) + public function update($id,$by,Request $request) { // 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"); + } // 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"=>$this->getUser())); // Récupération des data du formulaire $form->handleRequest($request); @@ -95,7 +145,13 @@ class CategoryController extends AbstractController $em->flush(); // Retour à la liste - 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"); + } // Affichage du formulaire @@ -104,15 +160,27 @@ class CategoryController extends AbstractController 'usesidebar' => true, $this->data => $data, 'mode' => 'update', - 'form' => $form->createView() + 'form' => $form->createView(), + 'by' => $by, + 'userid' => $data->getUser()->getId(), ]); } - public function delete($id,Request $request) + public function delete($id,$by,Request $request) { // 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->getCategory()->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) + return $this->redirectToRoute("app_home"); + } // Controle avant suppression $error=false; @@ -125,7 +193,12 @@ class CategoryController extends AbstractController $em->flush(); // Retour à la liste - 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"); } } diff --git a/src/Controller/IllustrationController.php b/src/Controller/IllustrationController.php index 08a97f1..57d758f 100755 --- a/src/Controller/IllustrationController.php +++ b/src/Controller/IllustrationController.php @@ -57,7 +57,12 @@ class IllustrationController extends AbstractController // Initialisation de l'enregistrement $em = $this->getDoctrine()->getManager(); $data = new Entity(); - + + // 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(Form::class,$data,array("mode"=>"submit","by"=>$by,"user"=>$em->getRepository("App:User")->find($userid))); @@ -107,7 +112,12 @@ class IllustrationController 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->getCategory()->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) return $this->redirectToRoute("app_home"); @@ -128,7 +138,6 @@ class IllustrationController extends AbstractController $em->persist($data); $em->flush(); - // Retour à l'illustration // Retour à la liste if($by=="admin") return $this->redirectToRoute($this->route,["by"=>$by,"userid"=>-1]); @@ -157,13 +166,17 @@ class IllustrationController 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->getCategory()->getUser()&&!$this->getUser()->hasRole("ROLE_ADMIN")) return $this->redirectToRoute("app_home"); } - - + // Controle avant suppression $error=false; if($id<0) $error=true; @@ -196,8 +209,8 @@ class IllustrationController extends AbstractController $em = $this->getDoctrine()->getManager(); $data=$em->getRepository($this->entity)->find($id); - $datanext=$this->getDataAllNext($idcat,$id); - $dataprev=$this->getDataAllPrev($idcat,$id); + $datanext=$this->getDataAllNext($idcat,$data->getSubmittime(),$by); + $dataprev=$this->getDataAllPrev($idcat,$data->getSubmittime(),$by); $pathinfo=pathinfo($data->getIllustration()); @@ -214,61 +227,55 @@ class IllustrationController extends AbstractController } - protected function getDataAllNext($idcat,$id) + protected function getDataAllNext($idcat,$submittime,$by) { $em = $this->getDoctrine()->getManager(); - $data = $em->createQueryBuilder() - ->select('e') - ->from($this->entity, 'e') - ->where('e.id>:id') - ->andWhere('e.category=:idcat') - ->getQuery() - ->setParameter("id", $id) - ->setParameter("idcat", $idcat) - ->setMaxResults(1) - ->getResult(); + $qb = $em->createQueryBuilder() + ->select('e') + ->from($this->entity, 'e') + ->where('e.submittime>:submittime') + ->setParameter("submittime", $submittime); + if($by!="home") { + $qb=$qb->andWhere('e.category=:idcat')->setParameter("idcat", $idcat); + } + $data = $qb->orderBy('e.submittime', 'ASC')->getQuery()->setMaxResults(1)->getResult(); // Si pas de suivant on recherche le premier if(!$data) { - $data = $em->createQueryBuilder() - ->select('e') - ->from($this->entity, 'e') - ->Where('e.category=:idcat') - ->getQuery() - ->setParameter("idcat", $idcat) - ->setMaxResults(1) - ->getResult(); + $qb = $em->createQueryBuilder() + ->select('e') + ->from($this->entity, 'e'); + if($by!="home") { + $qb=$qb->andWhere('e.category=:idcat')->setParameter("idcat", $idcat); + } + $data = $qb->orderBy('e.submittime', 'ASC')->getQuery()->setMaxResults(1)->getResult(); } return $data; } - protected function getDataAllPrev($idcat,$id) + protected function getDataAllPrev($idcat,$submittime,$by) { $em = $this->getDoctrine()->getManager(); - $data = $em->createQueryBuilder() - ->select('e') - ->from($this->entity, 'e') - ->where('e.id<:id') - ->andWhere('e.category=:idcat') - ->orderBy('e.id','DESC') - ->getQuery() - ->setParameter("id", $id) - ->setParameter("idcat", $idcat) - ->setMaxResults(1) - ->getResult(); + $qb = $em->createQueryBuilder() + ->select('e') + ->from($this->entity, 'e') + ->where('e.submittime<:submittime') + ->setParameter("submittime", $submittime); + if($by!="home") { + $qb=$qb->andWhere('e.category=:idcat')->setParameter("idcat", $idcat); + } + $data = $qb->orderBy('e.submittime', 'DESC')->getQuery()->setMaxResults(1)->getResult(); // Si pas de précedent on recherche le dernier if(!$data) { - $data = $em->createQueryBuilder() - ->select('e') - ->from($this->entity, 'e') - ->Where('e.category=:idcat') - ->orderBy('e.id','DESC') - ->getQuery() - ->setParameter("idcat", $idcat) - ->setMaxResults(1) - ->getResult(); + $qb = $em->createQueryBuilder() + ->select('e') + ->from($this->entity, 'e'); + if($by!="home") { + $qb=$qb->Where('e.category=:idcat')->setParameter("idcat", $idcat); + } + $data = $qb->orderBy('e.submittime', 'DESC')->getQuery()->setMaxResults(1)->getResult(); } return $data; diff --git a/src/Form/CategoryType.php b/src/Form/CategoryType.php index 91cd237..50f354f 100644 --- a/src/Form/CategoryType.php +++ b/src/Form/CategoryType.php @@ -9,6 +9,10 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; +use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\QueryBuilder; + class CategoryType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) @@ -36,6 +40,28 @@ class CategoryType 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('usecategoryconfig', ChoiceType::class, [ "label" =>"Utiliser une configuration de style spécifique", @@ -91,6 +117,8 @@ class CategoryType extends AbstractType $resolver->setDefaults(array( 'data_class' => 'App\Entity\Category', 'mode' => 'string', + 'by' => 'string', + 'user' => 'App\Entity\User' )); } } diff --git a/src/Form/IllustrationType.php b/src/Form/IllustrationType.php index 309b9cd..66f4507 100644 --- a/src/Form/IllustrationType.php +++ b/src/Form/IllustrationType.php @@ -7,9 +7,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use FOS\CKEditorBundle\Form\Type\CKEditorType; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; diff --git a/templates/Category/edit.html.twig b/templates/Category/edit.html.twig index df96322..65d7e0c 100755 --- a/templates/Category/edit.html.twig +++ b/templates/Category/edit.html.twig @@ -12,10 +12,16 @@ {{ form_widget(form.submit) }} - Annuler + {% if by=="admin" %} + Annuler + {% elseif by=="update" %} + Annuler + {% elseif by=="profil" %} + Annuler + {% endif %} {% if mode=="update" and category.id >= 0 %} - @@ -49,6 +55,7 @@
+ {{ form_row(form.user) }} {{ form_row(form.order) }} {{ form_row(form.name) }} diff --git a/templates/Category/list.html.twig b/templates/Category/list.html.twig index 3e12aac..2a983c5 100644 --- a/templates/Category/list.html.twig +++ b/templates/Category/list.html.twig @@ -5,7 +5,7 @@ CATEGORIES -

Ajouter

+

Ajouter

@@ -18,6 +18,7 @@ CATEGORIES Action + Utilisateur Ordre Nom @@ -26,11 +27,12 @@ CATEGORIES {% for category in categorys %} - + {% if category.id >=0 %} - + {% endif %} + {{category.user.username}} {{category.order}} {{category.name}} diff --git a/templates/Category/listrender.html.twig b/templates/Category/listrender.html.twig new file mode 100644 index 0000000..97b4a97 --- /dev/null +++ b/templates/Category/listrender.html.twig @@ -0,0 +1,38 @@ +

Ajouter

+ +
+ + + + + + + + + + {% for category in categorys %} + + + + + + {% endfor %} + +
ActionOrdreNom
+ + {% if category.id >=0 %} + + {% endif %} + {{category.order}}{{category.name}}
+
+ + \ No newline at end of file diff --git a/templates/Home/home.html.twig b/templates/Home/home.html.twig index c0b3e8f..d3ec650 100644 --- a/templates/Home/home.html.twig +++ b/templates/Home/home.html.twig @@ -60,13 +60,15 @@ - - - {% endif %} - - - + + + + + + + + {% else %} @@ -112,13 +114,16 @@ - - - {% endif %} - - - + + + + + + + + + {% else %} @@ -352,7 +357,26 @@
- + + +
{% endblock %} diff --git a/templates/Home/user.html.twig b/templates/Home/user.html.twig index c03ac75..c02e9a2 100644 --- a/templates/Home/user.html.twig +++ b/templates/Home/user.html.twig @@ -77,13 +77,15 @@ - - - {% endif %} - - - + + + + + + + + {% else %} @@ -129,13 +131,15 @@ - - - {% endif %} - - - + + + + + + + + {% else %} @@ -350,7 +354,25 @@
- + + {% endblock %} diff --git a/templates/Illustration/listrender.html.twig b/templates/Illustration/listrender.html.twig index f9d0107..ce8609d 100644 --- a/templates/Illustration/listrender.html.twig +++ b/templates/Illustration/listrender.html.twig @@ -1,7 +1,7 @@

Ajouter

-
- +
+
diff --git a/templates/Illustration/view.html.twig b/templates/Illustration/view.html.twig index a0c296e..47f9a65 100755 --- a/templates/Illustration/view.html.twig +++ b/templates/Illustration/view.html.twig @@ -62,10 +62,15 @@
Action