From 8cc5f686ab634d809627b537b27ae34e25504cf9 Mon Sep 17 00:00:00 2001 From: afornerot Date: Thu, 1 Oct 2020 16:04:50 +0200 Subject: [PATCH] modificatio rest pour afficher attribut item d'un bookmark --- .../CoreBundle/Command/TestRestCommand.php | 2 +- .../CoreBundle/Controller/RestController.php | 3 +- .../Controller/PagewidgetController.php | 116 +----------------- .../Repository/ItemRepository.php | 9 +- 4 files changed, 9 insertions(+), 121 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/TestRestCommand.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/TestRestCommand.php index a96a182f..24dd4812 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/TestRestCommand.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/TestRestCommand.php @@ -61,7 +61,7 @@ class TestRestCommand extends Command // only = liste des informations désirés = user, items, bookmarks, groups, alerts, calendars $apiurl = $url."/rest/user/".$login; $this->writeln($apiurl); - $response = \Unirest\Request::post($apiurl,$headers,["key"=>$masterapikey,"only"=>"user,calendars"]); + $response = \Unirest\Request::post($apiurl,$headers,["key"=>$masterapikey,"only"=>"user,items,bookmarks"]); dump($response->body); $this->writeln(''); diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php index e0e693a3..aaabd516 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RestController.php @@ -73,7 +73,7 @@ class RestController extends Controller $itemcategorys=null; $weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/"; - $em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,3); + $em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,4); //$this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->getPagesUser($user,null,$entity,$pagesuser,$pagesadmin,$groupsshared); // Construction de la réponse @@ -95,6 +95,7 @@ class RestController extends Controller $tmp["title"] = $bookmark->getTitle(); $tmp["url"] = $bookmark->getUrl(); $tmp["target"] = $bookmark->getTarget(); + $tmp["item"] = ($bookmark->getItem()?$bookmark->getItem()->getId():null); $tmp["order"] = 0; $tmp["color"] = "#".($bookmark->getColor()?$bookmark->getColor():$this->get('session')->get('color')["main"]); $tmp["icon"] = $weburl.($bookmark->getIcon()?$bookmark->getIcon()->getLabel():"uploads/icon/icon_pin.png"); diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php index ef287842..5eed0032 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php @@ -573,121 +573,7 @@ class PagewidgetController extends Controller // Profilage $user=$this->getUser(); - $roles=($user?$user->getRoles():["ROLE_ANONYME"]); - $groups=($user?$user->getGroups():[]); - $niveau01=($user?$user->getNiveau01():[]); - - // Bookmark de l'utilisateur - $bookmarks = array(); - if($user) - $bookmarks=$em->getRepository("CadolesPortalBundle:Bookmark")->findBy(["user"=>$user]); - - // Bookmark lié à un item - $bookmarksitems=new ArrayCollection(); - foreach($bookmarks as $bookmark) { - if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem()); - } - - // Initialisation du calcul des items - $items=new ArrayCollection(); - - // Récupération des items par rôles - foreach($roles as $role) { - $qb = $em->createQueryBuilder(); - $qb->select('item') - ->from("CadolesPortalBundle:Item", 'item') - ->where($qb->expr()->like('item.roles', $qb->expr()->literal("%$role%"))); - - if($iditemcategory && $itemcategoryfilter) { - $qb->andWhere("item.itemcategory=:itemcategory") - ->setParameter("itemcategory",$itemcategoryfilter); - } - $itemsroles=$qb->getQuery()->getResult(); - foreach($itemsroles as $itemrole) { - if($withbookmark==1) { - if(!$items->contains($itemrole)) $items->add($itemrole); - } - else { - if(!$bookmarksitems->contains($itemrole) && !$items->contains($itemrole)) $items->add($itemrole); - } - } - } - - // Récupération des items par group - foreach($groups as $group) { - $qb = $em->createQueryBuilder(); - $qb->select('item') - ->from("CadolesPortalBundle:Item", 'item') - ->where(":group MEMBER OF item.groups") - ->setParameter("group",$group->getGroup()); - - if($iditemcategory && $itemcategoryfilter) { - $qb->andWhere("item.itemcategory=:itemcategory") - ->setParameter("itemcategory",$itemcategoryfilter); - } - $itemsgroups=$qb->getQuery()->getResult(); - foreach($itemsgroups as $itemgroup) { - if($withbookmark==1) { - if(!$items->contains($itemgroup)) $items->add($itemgroup); - } - else { - if(!$bookmarksitems->contains($itemgroup) && !$items->contains($itemgroup)) $items->add($itemgroup); - } - } - } - - // Récupération des items par niveau01 - if($niveau01) { - $qb = $em->createQueryBuilder(); - $qb->select('item') - ->from("CadolesPortalBundle:Item", 'item') - ->where(":niveau01 MEMBER OF item.niveau01s") - ->setParameter("niveau01",$niveau01); - - if($iditemcategory && $itemcategoryfilter) { - $qb->andWhere("item.itemcategory=:itemcategory") - ->setParameter("itemcategory",$itemcategoryfilter); - } - $itemsniveau01s=$qb->getQuery()->getResult(); - foreach($itemsniveau01s as $itemniveau01) { - if($withbookmark==1) { - if(!$items->contains($itemniveau01)) $items->add($itemniveau01); - } - else { - if(!$bookmarksitems->contains($itemniveau01) && !$items->contains($itemniveau01)) $items->add($itemniveau01); - } - } - } - - // Trie des items - $itemsordered = $items->getIterator(); - $itemsordered->uasort(function ($first, $second) { - if((int) $first->getRowOrder() > (int) $second->getRowOrder()) - $return=1; - elseif((int) $first->getRowOrder() == (int) $second->getRowOrder()) { - if($first->getTitle() > $second->getTitle()) - $return=1; - else - $return=-1; - } - else - $return=-1; - - return $return; - }); - - // Catégories affichées - $itemcategorys = $this->getDoctrine()->getRepository('CadolesPortalBundle:Itemcategory')->findBy([], ['rowOrder' => 'asc']); - if($iditemcategory && $itemcategoryfilter) $itemcategorys = $itemcategoryfilter; - - switch($withbookmark) { - // items uniquement - case 1: $bookmarks=null; break; - - // bookmarks uniquement - case 2: $itemsordered=null; break; - - } + $itemsordered = $em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,$iditemcategory,$withbookmark); // Render return $this->render($this->labelentity.':viewitem.html.twig', [ diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php index a916fd86..45d08cdf 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php @@ -13,8 +13,6 @@ class ItemRepository extends EntityRepository $groups=($user?$user->getGroups():[]); $niveau01=($user?$user->getNiveau01():[]); - - // Bookmark de l'utilisateur $bookmarks = array(); if($user) @@ -22,8 +20,10 @@ class ItemRepository extends EntityRepository // Bookmark lié à un item $bookmarksitems=new ArrayCollection(); - foreach($bookmarks as $bookmark) { - if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem()); + if($withbookmark==0) { + foreach($bookmarks as $bookmark) { + if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem()); + } } // Initialisation du calcul des items @@ -114,5 +114,6 @@ class ItemRepository extends EntityRepository } + return $itemsordered; } }