modificatio rest pour afficher attribut item d'un bookmark
This commit is contained in:
parent
8414bd58b2
commit
8cc5f686ab
|
@ -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('');
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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', [
|
||||
|
|
|
@ -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,9 +20,11 @@ class ItemRepository extends EntityRepository
|
|||
|
||||
// Bookmark lié à un item
|
||||
$bookmarksitems=new ArrayCollection();
|
||||
if($withbookmark==0) {
|
||||
foreach($bookmarks as $bookmark) {
|
||||
if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem());
|
||||
}
|
||||
}
|
||||
|
||||
// Initialisation du calcul des items
|
||||
$items=new ArrayCollection();
|
||||
|
@ -114,5 +114,6 @@ class ItemRepository extends EntityRepository
|
|||
|
||||
}
|
||||
|
||||
return $itemsordered;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue