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
|
// only = liste des informations désirés = user, items, bookmarks, groups, alerts, calendars
|
||||||
$apiurl = $url."/rest/user/".$login;
|
$apiurl = $url."/rest/user/".$login;
|
||||||
$this->writeln($apiurl);
|
$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);
|
dump($response->body);
|
||||||
|
|
||||||
$this->writeln('');
|
$this->writeln('');
|
||||||
|
|
|
@ -73,7 +73,7 @@ class RestController extends Controller
|
||||||
$itemcategorys=null;
|
$itemcategorys=null;
|
||||||
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
|
$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);
|
//$this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->getPagesUser($user,null,$entity,$pagesuser,$pagesadmin,$groupsshared);
|
||||||
|
|
||||||
// Construction de la réponse
|
// Construction de la réponse
|
||||||
|
@ -95,6 +95,7 @@ class RestController extends Controller
|
||||||
$tmp["title"] = $bookmark->getTitle();
|
$tmp["title"] = $bookmark->getTitle();
|
||||||
$tmp["url"] = $bookmark->getUrl();
|
$tmp["url"] = $bookmark->getUrl();
|
||||||
$tmp["target"] = $bookmark->getTarget();
|
$tmp["target"] = $bookmark->getTarget();
|
||||||
|
$tmp["item"] = ($bookmark->getItem()?$bookmark->getItem()->getId():null);
|
||||||
$tmp["order"] = 0;
|
$tmp["order"] = 0;
|
||||||
$tmp["color"] = "#".($bookmark->getColor()?$bookmark->getColor():$this->get('session')->get('color')["main"]);
|
$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");
|
$tmp["icon"] = $weburl.($bookmark->getIcon()?$bookmark->getIcon()->getLabel():"uploads/icon/icon_pin.png");
|
||||||
|
|
|
@ -573,121 +573,7 @@ class PagewidgetController extends Controller
|
||||||
|
|
||||||
// Profilage
|
// Profilage
|
||||||
$user=$this->getUser();
|
$user=$this->getUser();
|
||||||
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
|
$itemsordered = $em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,$iditemcategory,$withbookmark);
|
||||||
$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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
return $this->render($this->labelentity.':viewitem.html.twig', [
|
return $this->render($this->labelentity.':viewitem.html.twig', [
|
||||||
|
|
|
@ -13,8 +13,6 @@ class ItemRepository extends EntityRepository
|
||||||
$groups=($user?$user->getGroups():[]);
|
$groups=($user?$user->getGroups():[]);
|
||||||
$niveau01=($user?$user->getNiveau01():[]);
|
$niveau01=($user?$user->getNiveau01():[]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Bookmark de l'utilisateur
|
// Bookmark de l'utilisateur
|
||||||
$bookmarks = array();
|
$bookmarks = array();
|
||||||
if($user)
|
if($user)
|
||||||
|
@ -22,8 +20,10 @@ class ItemRepository extends EntityRepository
|
||||||
|
|
||||||
// Bookmark lié à un item
|
// Bookmark lié à un item
|
||||||
$bookmarksitems=new ArrayCollection();
|
$bookmarksitems=new ArrayCollection();
|
||||||
foreach($bookmarks as $bookmark) {
|
if($withbookmark==0) {
|
||||||
if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem());
|
foreach($bookmarks as $bookmark) {
|
||||||
|
if($bookmark->getItem()) $bookmarksitems->add($bookmark->getItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialisation du calcul des items
|
// Initialisation du calcul des items
|
||||||
|
@ -114,5 +114,6 @@ class ItemRepository extends EntityRepository
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $itemsordered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue