From b648fecb322bcac042299bcaba33e48aeb38ca38 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 6 Oct 2020 17:06:26 +0200 Subject: [PATCH] vue pagewidget list --- .../CoreBundle/Resources/public/css/style.css | 7 + .../Controller/PageController.php | 99 +- .../Controller/PagetemplateController.php | 4 +- .../Controller/PagewidgetController.php | 1248 ++++++++--------- .../Controller/SlideController.php | 4 +- .../src/Cadoles/PortalBundle/Entity/Flux.php | 3 +- .../Repository/FluxRepository.php | 47 + .../Repository/ItemRepository.php | 20 +- .../Resources/views/Page/viewwidget.html.twig | 56 +- .../views/Pagewidget/viewalert.html.twig | 98 +- .../Pagewidget/viewappexternal.html.twig | 138 +- .../views/Pagewidget/viewblog.html.twig | 146 +- .../views/Pagewidget/viewbookmark.html.twig | 158 ++- .../views/Pagewidget/viewcalendar.html.twig | 150 +- .../views/Pagewidget/viewchat.html.twig | 72 +- .../views/Pagewidget/vieweditor.html.twig | 65 +- .../views/Pagewidget/viewfile.html.twig | 62 +- .../views/Pagewidget/viewflux.html.twig | 154 +- .../views/Pagewidget/viewframe.html.twig | 67 +- .../views/Pagewidget/viewgalery.html.twig | 147 +- .../views/Pagewidget/viewgroup.html.twig | 160 ++- .../Pagewidget/viewgroupmessage.html.twig | 117 +- .../views/Pagewidget/viewinfo.html.twig | 148 +- .../views/Pagewidget/viewitem.html.twig | 478 ++++--- .../Pagewidget/viewitemessential.html.twig | 320 +++-- .../views/Pagewidget/viewlink.html.twig | 77 +- .../views/Pagewidget/viewonlydoc.html.twig | 68 +- .../views/Pagewidget/viewproject.html.twig | 204 +-- .../views/Pagewidget/viewseparator.html.twig | 2 + .../views/Pagewidget/viewslide.html.twig | 92 +- .../views/Pagewidget/viewurl.html.twig | 87 +- 31 files changed, 2475 insertions(+), 2023 deletions(-) create mode 100644 src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/FluxRepository.php diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css index 3c1583bd..76925c6d 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/public/css/style.css @@ -671,6 +671,13 @@ a.item-heart { margin-top:30px; } +.widget-mini { + display: inline-block; + height:50px; + width:50px; + margin-top:0px; +} + .widgetmenu { right: 20px; position: absolute; diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PageController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PageController.php index 181b47b8..e434de97 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PageController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PageController.php @@ -455,6 +455,8 @@ class PageController extends Controller // usage soit portal / user / group $usage=$request->query->get('usage'); $groupid=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -481,45 +483,7 @@ class PageController extends Controller ]); } } - - // On marque tt les messages comme lu par l'utilisateur - /* Se fait à présent sur le controleur message au moment meme où l'on affiche l'ensemble des messages - if($usage=="group") { - // On calcule le nombre de message non lu pour le groupe - $group=$em->getRepository("CadolesCoreBundle:Group")->find($groupid); - $qb = $em ->createQueryBuilder(); - $tm = $qb ->select($qb->expr()->count('m.id')) - ->from('CadolesWebsocketBundle:Message', 'm') - ->where('m.group = :group') - ->andWhere('m.user != :user') - ->setParameter('group', $group) - ->setParameter('user', $this->getUser()) - ->getQuery()->getSingleScalarResult(); - - $qb = $em ->createQueryBuilder(); - $tr = $qb ->select($qb->expr()->count('m.id')) - ->from('CadolesWebsocketBundle:Message', 'm') - ->where('m.group = :group') - ->andWhere('m.user != :user') - ->andWhere(':user MEMBER OF m.readers') - ->setParameter('group', $group) - ->setParameter('user', $this->getUser()) - ->getQuery()->getSingleScalarResult(); - - if($tm-$tr>0) { - $messages=$em->getRepository("CadolesWebsocketBundle:Message")->findBy(["group"=>$group]); - foreach($messages as $message) { - $readers=$message->getReaders(); - if ( !$readers->contains($this->getUser()) ) { - $message->addReader($this->getUser()); - } - $em->persist($message); - $em->flush(); - } - } - } - */ - + // Compteur de visite if($this->getUser()) { if($groupid) { @@ -587,6 +551,19 @@ class PageController extends Controller // Type Widgets if($entity->getPageCategory()->getId()==2) { + $user=$this->getUser(); + if($user) { + // Sauvegarder les préférences + if($look) $this->setPreference($user,"pagelook",$id,$look); + if($selwidget) $this->setPreference($user,"pageselwidget",$id,$selwidget); + + // Récupérer les préférences + $look=$this->getPreference($user,"pagelook",$id,"view"); + $selwidget=$this->getPreference($user,"pageselwidget",$id,null); + } + + if($look=="list") $entity->setMaxwidth(0); + return $this->render($this->labelentity.':viewwidget.html.twig', [ 'useheader' => ($access=="config"), 'usemenu' => false, @@ -595,6 +572,8 @@ class PageController extends Controller 'access' => $access, 'canupdate' => $canupdate, 'mode' => "view", + 'look' => $look, + 'selwidget' => $selwidget, 'widgets' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->getWidgetAccess($access,'config'), 'usage' => $usage, 'group' => $groupid @@ -643,7 +622,9 @@ class PageController extends Controller 'mode' => "view", 'widgets' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->getWidgetAccess($access,'config'), 'usage' => $usage, - 'group' => $group + 'group' => $group, + 'look' => 'view', + 'selwidget' => null, ]); } @@ -720,4 +701,42 @@ class PageController extends Controller } } } + + protected function getPreference($user,$key,$id,$default) { + $preference=$user->getPreference(); + $return=$default; + + if(is_array($preference)) { + if(array_key_exists($key,$preference)) { + if(array_key_exists($id,$preference[$key])) + $return=$preference[$key][$id]; + } + } + + return $return; + } + protected function setPreference($user,$key,$id,$value) { + $preference=$user->getPreference(); + $toupdate=false; + if(!array_key_exists($key,$preference)) { + $toupdate=true; + $preference[$key]=[]; + } + if((!array_key_exists($id,$preference[$key]))) { + $toupdate=true; + $preference[$key][$id]=$value; + } + if($value&&$preference[$key][$id]!=$value) { + $toupdate=true; + $preference[$key][$id]=$value; + } + + // Mise à jour des préferences + if($toupdate) { + $em = $this->getDoctrine()->getManager(); + $user->setPreference($preference); + $em->persist($this->getUser()); + $em->flush(); + } + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagetemplateController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagetemplateController.php index ebf979e5..727948f2 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagetemplateController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagetemplateController.php @@ -297,7 +297,9 @@ class PagetemplateController extends Controller 'mode' => "viewtemplate", 'widgets' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->getWidgetAccess($access), 'usage' => "config", - 'group' => "" + 'group' => "", + 'look' => "view", + 'selwidget' => null, ]); } 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 5eed0032..ab8f9148 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php @@ -24,6 +24,18 @@ class PagewidgetController extends Controller private $labelentity="CadolesPortalBundle:Pagewidget"; private $routeprimary="cadoles_portal_config_pagewidget"; + private $entity; + private $page; + private $id; + private $access; + private $look; + private $mini; + private $selwidget; + + private $cansee; + private $canudate; + private $canadd; + private function searchArray($array, $key, $value) { $results = array(); @@ -386,6 +398,36 @@ class PagewidgetController extends Controller } } + protected function setRequest($request,$id,$access) { + $this->em = $this->getDoctrine()->getManager(); + $this->user = $this->getUser(); + $this->id = $id; + $this->access = $access; + $this->look = $request->query->get('look'); + $this->selwidget = $request->query->get('selwidget'); + + // Le widget existe-t-il ? + $this->entity = $this->em->getRepository($this->labelentity)->find($this->id); + if (!$this->entity) throw $this->createNotFoundException('Unable to find entity.'); + + // Permissions + if($this->access=="config") { + $this->canupdate = true; + } + else { + // On s'assure que l'utilisateur à la permission de voir + $this->page=$this->entity->getPage(); + $this->em->getRepository("CadolesPortalBundle:Page")->getPermission($this->user,$this->page,$this->cansee,$this->canupdate); + if(!$this->cansee) throw $this->createNotFoundException('Permission denied'); + } + + // Affichage miniature ? + $this->mini = ($this->look=="list"&&$this->entity->getId()!=$this->selwidget); + + // Préference utilisateur + if(!$this->mini) $this->getPreference($this->entity); + } + protected function getPreference(&$entity) { $user=$this->getUser(); if($user) { @@ -393,466 +435,508 @@ class PagewidgetController extends Controller $id=$entity->getId(); // Preference widgetshowhide - if(is_array($preference)) { - if(array_key_exists("widgetshowhide",$preference)) { - if(array_key_exists($id,$preference["widgetshowhide"])) - $entity->setOpened(($preference["widgetshowhide"][$id]=="true")); + if($this->look=="list") { + $entity->setOpened(true); + $entity->setBorder(false); + } + else { + if(is_array($preference)) { + if(array_key_exists("widgetshowhide",$preference)) { + if(array_key_exists($id,$preference["widgetshowhide"])) + $entity->setOpened(($preference["widgetshowhide"][$id]=="true")); + } } } } } - public function viewurlAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + protected function getRender($view,$params) { + // Paramétres toujours présent dans un rendu de widget + $allways = [ + 'entity' => $this->entity, + 'canupdate' => $this->canupdate, + 'access' => $this->access, + 'look' => $this->look, + 'mini' => $this->mini, + ]; - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } + // Parametres spéficiques + $params=array_merge($allways,$params); - // Récupération des paramétres du widget + // Rendu + return $this->render($this->labelentity.':'.$view, $params); + } + + public function viewurlAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); + + // Valeur par défaut $url=""; - foreach($entity->getParameter()["fields"] as $parameter) { - if($parameter["id"]=="url") - $url=$parameter["value"]; - } - - // Préference utilisateur - $this->getPreference($entity); - - - // Gestion des url youtuve - $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); - $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); - - // Detecter le type de lien $imagemedia=false; - $pathinfo = pathinfo($url); - // Type image - if(array_key_exists("extension",$pathinfo)) { - if($pathinfo['extension']=="jpg"||$pathinfo['extension']=="gif"||$pathinfo['extension']=="png") { - $imagemedia=true; + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + foreach($this->entity->getParameter()["fields"] as $parameter) { + if($parameter["id"]=="url") + $url=$parameter["value"]; } - } - // Spécifique Deviant Art - if(strpos($url, "images-wixmp") !== false) $imagemedia=true; - - - return $this->render($this->labelentity.':viewurl.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, + // Gestion des url youtuve + $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); + $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); + + // Detecter le type de lien + $pathinfo = pathinfo($url); + + // Type image + if(array_key_exists("extension",$pathinfo)) { + if($pathinfo['extension']=="jpg"||$pathinfo['extension']=="gif"||$pathinfo['extension']=="png") { + $imagemedia=true; + } + } + + // Spécifique Deviant Art + if(strpos($url, "images-wixmp") !== false) $imagemedia=true; + } + + return $this->getRender('viewurl.html.twig', [ 'url' => $url, 'imagemedia' => $imagemedia, - 'access' => $access ]); } - public function viewurlfixeAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + public function viewurlfixeAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } - - // Récupération des paramétres du widget + // Valeur par défaut $url=""; - $widgettype= $entity->getWidget(); - $jsons=$widgettype->getParameter(); - $param=array(); - $param["fields"]=array(); - foreach($jsons->fields as $field) { - if($field->id=="url") - $url=$field->value; - } - - // Préference utilisateur - $this->getPreference($entity); - - // Gestion des url youtuve - $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); - $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); - - // Detecter le type de lien $imagemedia=false; - $pathinfo = pathinfo($url); - // Type image - if(array_key_exists("extension",$pathinfo)) { - if($pathinfo['extension']=="jpg"||$pathinfo['extension']=="gif"||$pathinfo['extension']=="png") { - $imagemedia=true; + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + $widgettype= $this->entity->getWidget(); + $jsons=$widgettype->getParameter(); + $param=array(); + $param["fields"]=array(); + foreach($jsons->fields as $field) { + if($field->id=="url") + $url=$field->value; } + + // Gestion des url youtuve + $url=str_replace("http://www.youtube.com","https://www.youtube.com",$url); + $url=str_replace("https://www.youtube.com/watch?v=","https://www.youtube.com/embed/",$url); + + // Detecter le type de lien + $pathinfo = pathinfo($url); + + // Type image + if(array_key_exists("extension",$pathinfo)) { + if($pathinfo['extension']=="jpg"||$pathinfo['extension']=="gif"||$pathinfo['extension']=="png") { + $imagemedia=true; + } + } + + // Spécifique Deviant Art + if(strpos($url, "images-wixmp") !== false) $imagemedia=true; } - // Spécifique Deviant Art - if(strpos($url, "images-wixmp") !== false) $imagemedia=true; - - - return $this->render($this->labelentity.':viewurl.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, + return $this->getRender('viewurl.html.twig', [ 'url' => $url, - 'imagemedia' => $imagemedia, - 'access' => $access + 'imagemedia' => $imagemedia, ]); } - public function viewitemAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + public function viewitemAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } - - // Récupération des paramétres du widget + // Valeur par défaut $modedesktop=0; - $iditemcategory=null; - $withbookmark=true; - $search=false; $menu=false; $menuall=true; - foreach($entity->getParameter()["fields"] as $parameter) { - switch($parameter["id"]) { - case "modedesktop": - $modedesktop=$parameter["value"]; - break; + $search=false; + $withbookmark=true; + $bookmarks=null; + $itemsordered=null; + $itemcategorys=null; - case "withbookmark": - $withbookmark=$parameter["value"]; - break; + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + $iditemcategory=null; + foreach($this->entity->getParameter()["fields"] as $parameter) { + switch($parameter["id"]) { + case "modedesktop": + $modedesktop=$parameter["value"]; + break; - case "itemcategory": - $iditemcategory=$parameter["value"]; - if($iditemcategory) $itemcategoryfilter=$em->getRepository("CadolesPortalBundle:Itemcategory")->findBy(["id"=>$iditemcategory]); - break; + case "withbookmark": + $withbookmark=$parameter["value"]; + break; - case "search": - $search=($parameter["value"]==1); - break; + case "itemcategory": + $iditemcategory=$parameter["value"]; + if($iditemcategory) $itemcategoryfilter=$this->em->getRepository("CadolesPortalBundle:Itemcategory")->findBy(["id"=>$iditemcategory]); + break; - case "menu": - $menu=($parameter["value"]==1); - break; + case "search": + $search=($parameter["value"]==1); + break; - case "menuall": - $menuall=($parameter["value"]==1); - break; + case "menu": + $menu=($parameter["value"]==1); + break; + case "menuall": + $menuall=($parameter["value"]==1); + break; + + } } + + // Profilage + $itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,$iditemcategory,$withbookmark,false); } - - // Préference utilisateur - $this->getPreference($entity); - - // Profilage - $user=$this->getUser(); - $itemsordered = $em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,$iditemcategory,$withbookmark); // Render - return $this->render($this->labelentity.':viewitem.html.twig', [ - 'entity' => $entity, - 'canadd' => ($user), - 'canupdate' => $canupdate, + return $this->getRender('viewitem.html.twig', [ + 'canadd' => ($this->user), 'modedesktop' => $modedesktop, - 'items' => $itemsordered, - 'itemcategorys' => $itemcategorys, - 'bookmarks' => $bookmarks, - 'access' => $access, 'search' => $search, 'menu' => $menu, 'menuall' => $menuall, 'withbookmark' => $withbookmark, + 'bookmarks' => $bookmarks, + 'items' => $itemsordered, + 'itemcategorys' => $itemcategorys, ]); } - public function viewitemessentialAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + public function viewitemessentialAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } - - // Récupération des paramétres du widget + // Valeur par défaut $modedesktop=0; - foreach($entity->getParameter()["fields"] as $parameter) { - switch($parameter["id"]) { - case "modedesktop": - $modedesktop=$parameter["value"]; - break; + $itemsordered=null; + $bookmarks=null; + + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + foreach($this->entity->getParameter()["fields"] as $parameter) { + switch($parameter["id"]) { + case "modedesktop": + $modedesktop=$parameter["value"]; + break; + } } - } - // Préference utilisateur - $this->getPreference($entity); - - // 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()); + // Profilage + $itemsordered = $this->em->getRepository("CadolesPortalBundle:Item")->getUserItems($this->user,$bookmarks,$items,$itemcategorys,null,true,true); } - // 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%"))) - ->andWhere("item.essential=:flag") - ->setParameter("flag",true); - - $itemsroles=$qb->getQuery()->getResult(); - foreach($itemsroles as $itemrole) { - 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") - ->andWhere("item.essential=:flag") - ->setParameter("flag",true) - ->setParameter("group",$group->getGroup()); - - $itemsgroups=$qb->getQuery()->getResult(); - foreach($itemsgroups as $itemgroup) { - 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") - ->andWhere("item.essential=:flag") - ->setParameter("flag",true) - ->setParameter("niveau01",$niveau01); - - $itemsniveau01s=$qb->getQuery()->getResult(); - foreach($itemsniveau01s as $itemniveau01) { - 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; - }); - // Render - return $this->render($this->labelentity.':viewitemessential.html.twig', [ - 'entity' => $entity, - 'canadd' => ($user), - 'canupdate' => $canupdate, + return $this->getRender('viewitemessential.html.twig', [ + 'canadd' => ($this->user), 'modedesktop' => $modedesktop, 'items' => $itemsordered, - 'bookmarks' => $bookmarks, - 'access' => $access, + 'bookmarks' => $bookmarks, ]); } - public function viewalertAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + public function viewalertAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } + // Valeur par défaut + $alertsordered=null; - // Récupération des paramétres du widget - $idalertcategory=null; - $alertcategoryfilter=null; - foreach($entity->getParameter()["fields"] as $parameter) { - switch($parameter["id"]) { - case "alertcategory": - $idalertcategory=$parameter["value"]; - if($idalertcategory) $alertcategoryfilter=$em->getRepository("CadolesPortalBundle:Alertcategory")->find($idalertcategory); - break; + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + $idalertcategory=null; + $alertcategoryfilter=null; + foreach($this->entity->getParameter()["fields"] as $parameter) { + switch($parameter["id"]) { + case "alertcategory": + $idalertcategory=$parameter["value"]; + if($idalertcategory) $alertcategoryfilter=$this->em->getRepository("CadolesPortalBundle:Alertcategory")->find($idalertcategory); + break; + } } - } - // Préference utilisateur - $this->getPreference($entity); - - // Profilage - $user=$this->getUser(); - $alertsordered=$em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($user,$idalertcategory,$alertcategoryfilter); + // Profilage + $alertsordered=$this->em->getRepository("CadolesPortalBundle:Alert")->getUserAlerts($this->user,$idalertcategory,$alertcategoryfilter); + } // Render - return $this->render($this->labelentity.':viewalert.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, + return $this->getRender('viewalert.html.twig', [ 'alerts' => $alertsordered, - 'access' => $access ]); } - public function viewfluxAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + public function viewfluxAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } - - // Récupération des paramétres du widget + // Valeur par défaut $modelist=0; - foreach($entity->getParameter()["fields"] as $parameter) { - switch($parameter["id"]) { - case "modelist": - $modelist=$parameter["value"]; - break; - } - } + $fluxsordered=null; + $feeds=null; - // Préference utilisateur - $this->getPreference($entity); - - // Profilage - $user=$this->getUser(); - $roles=($user?$user->getRoles():["ROLE_ANONYME"]); - $groups=($user?$user->getGroups():[]); - - // Initialisation du calcul des fluxs - $fluxs=new ArrayCollection(); - - // Récupération des fluxs par rôles - foreach($roles as $role) { - $qb = $em->createQueryBuilder(); - $qb->select('flux') - ->from("CadolesPortalBundle:Flux", 'flux') - ->where($qb->expr()->like('flux.roles', $qb->expr()->literal("%$role%"))); - - $fluxsroles=$qb->getQuery()->getResult(); - foreach($fluxsroles as $fluxrole) { - if(!$fluxs->contains($fluxrole)) $fluxs->add($fluxrole); - } - } - - // Récupération des fluxs par group - foreach($groups as $group) { - $qb = $em->createQueryBuilder(); - $qb->select('flux') - ->from("CadolesPortalBundle:Flux", 'flux') - ->where(":group MEMBER OF flux.groups") - ->setParameter("group",$group->getGroup()); - - $fluxsgroups=$qb->getQuery()->getResult(); - foreach($fluxsgroups as $fluxgroup) { - if(!$fluxs->contains($fluxgroup)) $fluxs->add($fluxgroup); - } - } - - - - $feeds=array(); - $filesystem = new Filesystem(); - - foreach($fluxs as $keyflux => $flux) { - // On regarde si le flux a été lu il y a peu - $toregen=true; - $url=$flux->getUrl(); - - // Feed lié à un user interne - $filecache='uploads/flux/flux-'.$flux->getId().'.txt'; - if(stripos($url,"##userid##")!==false) { - if($user) { - $url=str_replace("##userid##",$user->getId(),$url); - $filecache=$filecache='uploads/flux/flux-'.$user->getId()."-".$flux->getId().'.txt'; + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + foreach($this->entity->getParameter()["fields"] as $parameter) { + switch($parameter["id"]) { + case "modelist": + $modelist=$parameter["value"]; + break; } } - // Si le fichie cache existe + // Profilage + $fluxs=$this->em->getRepository("CadolesPortalBundle:Flux")->getUserFluxs($this->user); + + $feeds=array(); + $filesystem = new Filesystem(); + + // Généraltion du cache associés aux flux + foreach($fluxs as $keyflux => $flux) { + // On regarde si le flux a été lu il y a peu + $toregen=true; + $url=$flux->getUrl(); + + // Feed lié à un user interne + $filecache='uploads/flux/flux-'.$flux->getId().'.txt'; + if(stripos($url,"##userid##")!==false) { + if($user) { + $url=str_replace("##userid##",$user->getId(),$url); + $filecache=$filecache='uploads/flux/flux-'.$user->getId()."-".$flux->getId().'.txt'; + } + } + + // Si le fichie cache existe + if($filesystem->exists($filecache)) { + // On récupère la date de modification du fichier + $timestampfile = filemtime($filecache); + $datetimeFormat = 'Y-m-d H:i:s'; + $datefile = new \DateTime(); + $datefile->setTimestamp($timestampfile); + + // On ajoute 30mn + $datefile->add(new \DateInterval('PT30M')); + + // Si la date est inférieur à maintenant on regénère le flux + $now = new \DateTime(); + if($datefile>=$now) { + $toregen=false; + $backup = unserialize(file_get_contents($filecache)); + $feeds=array_merge($feeds,$backup); + if(empty($backup)) unset($fluxs[$keyflux]); + } + } + + // Si le fichier est trop ancien on relit le flus + if($toregen) { + $PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue(); + $weburl=$this->getParameter('weburl'); + + if(stripos($url,"/")==0) { + $url="https://".$weburl.$url; + $PROXYactivate=false; + } + if(stripos($url,"https://".$weburl)===0) $PROXYactivate=false; + if(stripos($url,"http://".$weburl)===0) $PROXYactivate=false; + + if($PROXYactivate) { + $PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue(); + $PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue(); + $clientguzzle = new \GuzzleHttp\Client(array('timeout' => 3,'verify'=>false,'proxy' => ['http' => 'http://'.$PROXYserver.':'.$PROXYport,'https' => 'http://'.$PROXYserver.':'.$PROXYport])); + } + else + $clientguzzle = new \GuzzleHttp\Client(['timeout' => 3,'verify'=>false]); + + try { + $clientguzzle->request('GET', $url); + } catch (RequestException $e) { + if ($e->hasResponse()) { + continue; + } + } + + // On lit le flux rss + $client = new \FeedIo\Adapter\Guzzle\Client($clientguzzle); + $logger = new \Psr\Log\NullLogger(); + $feedIo = new \FeedIo\FeedIo($client, $logger); + + try { + $result = $feedIo->read($url); + } + catch (\Exception $e) { + $result=null; + } + + if($result) { + $feedtitle = $result->getFeed()->getTitle(); + + + $backup=[]; + + // Pour chaque articles + $nbflux=0; + foreach ($result->getFeed() as $item) { + $title = $item->getTitle(); + $link = $item->getLink(); + $description = substr(strip_tags($item->getDescription()),0,250); + $description = str_replace("¶","",$description); + $date = $item->getLastModified(); + $dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):""); + $content = $item->getDescription(); + $media = $item->getMedias(); + $mediaurl = ""; + + foreach ($item->getMedias() as $itemMedia) { + if($itemMedia->getType()=="image/jpeg") + $mediaurl=$itemMedia->getUrl(); + } + + foreach ($item->getAllElements() as $element) { + + if($element->getName()=="content:encoded") + $content = $element->getValue(); + } + + if($mediaurl!="") { + $imgurl=$mediaurl; + } + else { + // Récupérer la première image du contenu + $imgcontent=""; + $imgurl=""; + $imgstart = stripos($content,"",$imgstart); + $imgcontent=substr($content,$imgstart,$imgend-$imgstart+1); + + $imgstart = stripos($imgcontent,"src="); + $imgurl=substr($imgcontent,$imgstart+5); + $imgend = stripos($imgurl,'"'); + + if($imgend===false) $imgend = stripos($imgurl,"'"); + $imgurl=substr($imgurl,0,$imgend); + } + } + + // Garder le flux + $tmp=array( + "feedtitle" => $feedtitle, + "title" => $title, + "link" => $link, + "description" => $description, + "date" => $date, + "dateformat" => $dateformat, + "content" => $content, + "image" => $imgurl, + "color" => $flux->getColor(), + "fluxid" => $flux->getId(), + "fluxtitle" => $flux->getTitle(), + ); + + array_push($feeds,$tmp); + array_push($backup,$tmp); + + $nbflux++; + if($nbflux>=$flux->getMaxread()&&$flux->getMaxread()>0) break; + } + + + if($nbflux==0) unset($fluxs[$keyflux]); + + // On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn + $filesystem->dumpFile($filecache, serialize($backup)); + } + } + } + + // Trie des fluxs + $fluxsordered = $fluxs->getIterator(); + $fluxsordered->uasort(function ($first, $second) { + return (int) $first->getRowOrder() > (int) $second->getRowOrder() ? 1 : -1; + }); + + // Trie des feeds + $libelle=array(); + foreach ($feeds as $key => $valeur) { + $libelle[$key] = $valeur["date"]; + } + array_multisort($libelle, SORT_DESC, $feeds); + } + + // Render + return $this->getRender('viewflux.html.twig', [ + 'modelist' => $modelist, + 'fluxs' => $fluxsordered, + 'feeds' => $feeds, + ]); + } + + + public function viewrssAction(Request $request,$id,$access="config") { + // Récupération de la requete + $this->setRequest($request,$id,$access); + + // Valeur par défaut + $modelist=0; + $fluxs=["id"=>0]; + $feeds=null; + + // Datas associées au widget + if(!$this->mini) { + // Récupération des paramétres du widget + $url=""; + $nbarticle="_blank"; + $modelist=0; + foreach($this->entity->getParameter()["fields"] as $parameter) { + switch($parameter["id"]) { + case "url": + $url=$parameter["value"]; + break; + case "nbarticle": + $nbarticle=$parameter["value"]; + break; + case "modelist": + $modelist=$parameter["value"]; + break; + } + } + + // On regarde si le flux a été lu il y a peu + $toregen=true; + $filecache=$filecache='uploads/flux/widget-'.$id.'.txt'; + $user=$this->getUser(); + if(stripos($url,"##userid##")!==false) { + if($user) { + $url=str_replace("##userid##",$user->getId(),$url); + $filecache=$filecache='uploads/flux/widget-'.$user->getId()."-".$id.'.txt'; + } + } + + $filesystem = new Filesystem(); if($filesystem->exists($filecache)) { // On récupère la date de modification du fichier $timestampfile = filemtime($filecache); $datetimeFormat = 'Y-m-d H:i:s'; $datefile = new \DateTime(); $datefile->setTimestamp($timestampfile); - + // On ajoute 30mn $datefile->add(new \DateInterval('PT30M')); @@ -860,58 +944,62 @@ class PagewidgetController extends Controller $now = new \DateTime(); if($datefile>=$now) { $toregen=false; - $backup = unserialize(file_get_contents($filecache)); - $feeds=array_merge($feeds,$backup); - if(empty($backup)) unset($fluxs[$keyflux]); + $feeds = unserialize(file_get_contents($filecache)); } } // Si le fichier est trop ancien on relit le flus if($toregen) { - $PROXYactivate = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue(); + // Connexion au client + $PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue(); $weburl=$this->getParameter('weburl'); - if(stripos($url,"/")==0) { $url="https://".$weburl.$url; $PROXYactivate=false; } if(stripos($url,"https://".$weburl)===0) $PROXYactivate=false; - if(stripos($url,"http://".$weburl)===0) $PROXYactivate=false; - + if(stripos($url,"http://".$weburl)===0) $PROXYactivate=false; + if($PROXYactivate) { - $PROXYserver = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue(); - $PROXYport = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue(); + $PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue(); + $PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue(); $clientguzzle = new \GuzzleHttp\Client(array('timeout' => 3,'verify'=>false,'proxy' => ['http' => 'http://'.$PROXYserver.':'.$PROXYport,'https' => 'http://'.$PROXYserver.':'.$PROXYport])); } else - $clientguzzle = new \GuzzleHttp\Client(['timeout' => 3,'verify'=>false]); - + $clientguzzle = new \GuzzleHttp\Client(array('timeout' => 3,'verify'=>false)); + try { $clientguzzle->request('GET', $url); } catch (RequestException $e) { if ($e->hasResponse()) { - continue; + // Render + $feeds=[]; + return $this->getRender('viewflux.html.twig', [ + 'fluxs' => $fluxs, + 'feeds' => $feeds, + 'modelist' => $modelist, + ]); } } - - // On lit le flux rss + $client = new \FeedIo\Adapter\Guzzle\Client($clientguzzle); $logger = new \Psr\Log\NullLogger(); $feedIo = new \FeedIo\FeedIo($client, $logger); + $feeds=array(); + + // On lit le flux rss try { $result = $feedIo->read($url); } catch (\Exception $e) { $result=null; } - + if($result) { $feedtitle = $result->getFeed()->getTitle(); - $backup=[]; - // Pour chaque articles $nbflux=0; foreach ($result->getFeed() as $item) { @@ -931,7 +1019,6 @@ class PagewidgetController extends Controller } foreach ($item->getAllElements() as $element) { - if($element->getName()=="content:encoded") $content = $element->getValue(); } @@ -947,7 +1034,7 @@ class PagewidgetController extends Controller if($imgstart!== false) { $imgend = stripos($content,">",$imgstart); $imgcontent=substr($content,$imgstart,$imgend-$imgstart+1); - + $imgstart = stripos($imgcontent,"src="); $imgurl=substr($imgcontent,$imgstart+5); $imgend = stripos($imgurl,'"'); @@ -956,10 +1043,9 @@ class PagewidgetController extends Controller $imgurl=substr($imgurl,0,$imgend); } } - - // Garder le flux - $tmp=array( + // Garder le flux + array_push($feeds,array( "feedtitle" => $feedtitle, "title" => $title, "link" => $link, @@ -968,260 +1054,40 @@ class PagewidgetController extends Controller "dateformat" => $dateformat, "content" => $content, "image" => $imgurl, - "color" => $flux->getColor(), - "fluxid" => $flux->getId(), - "fluxtitle" => $flux->getTitle(), - ); - - array_push($feeds,$tmp); - array_push($backup,$tmp); + // "color" => $flux->getColor(), + "fluxid" => 0, + "fluxtitle" => $this->entity->getName(), + )); $nbflux++; - if($nbflux>=$flux->getMaxread()&&$flux->getMaxread()>0) break; + if($nbflux>=$nbarticle&&$nbarticle>0) break; } - if($nbflux==0) unset($fluxs[$keyflux]); - + $libelle=array(); + foreach ($feeds as $key => $valeur) { + $libelle[$key] = $valeur["date"]; + } + array_multisort($libelle, SORT_DESC, $feeds); + // On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn - $filesystem->dumpFile($filecache, serialize($backup)); + $filesystem->dumpFile($filecache, serialize($feeds)); } } - } - - // Trie des fluxs - $fluxsordered = $fluxs->getIterator(); - $fluxsordered->uasort(function ($first, $second) { - return (int) $first->getRowOrder() > (int) $second->getRowOrder() ? 1 : -1; - }); - - // Trie des feeds - $libelle=array(); - foreach ($feeds as $key => $valeur) { - $libelle[$key] = $valeur["date"]; - } - array_multisort($libelle, SORT_DESC, $feeds); - - // Render - return $this->render($this->labelentity.':viewflux.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, - 'modelist' => $modelist, - 'fluxs' => $fluxsordered, - 'access' => $access, - 'feeds' => $feeds, - - ]); - } - - - public function viewrssAction($id,$access="config") { - $em = $this->getDoctrine()->getManager(); - $entity = $em->getRepository($this->labelentity)->find($id); - if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); - - // Permissions - if($access=="config") { - $canupdate = true; - } - else { - // On s'assure que l'utilisateur à la permission de voir - $page=$entity->getPage(); - $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); - if(!$cansee) throw $this->createNotFoundException('Permission denied'); - } - - // Récupération des paramétres du widget - $url=""; - $nbarticle="_blank"; - $modelist=0; - foreach($entity->getParameter()["fields"] as $parameter) { - switch($parameter["id"]) { - case "url": - $url=$parameter["value"]; - break; - case "nbarticle": - $nbarticle=$parameter["value"]; - break; - case "modelist": - $modelist=$parameter["value"]; - break; - } - } - - // Préference utilisateur - $this->getPreference($entity); - - // On regarde si le flux a été lu il y a peu - $toregen=true; - $filecache=$filecache='uploads/flux/widget-'.$id.'.txt'; - $user=$this->getUser(); - if(stripos($url,"##userid##")!==false) { - if($user) { - $url=str_replace("##userid##",$user->getId(),$url); - $filecache=$filecache='uploads/flux/widget-'.$user->getId()."-".$id.'.txt'; - } - } - - $filesystem = new Filesystem(); - if($filesystem->exists($filecache)) { - // On récupère la date de modification du fichier - $timestampfile = filemtime($filecache); - $datetimeFormat = 'Y-m-d H:i:s'; - $datefile = new \DateTime(); - $datefile->setTimestamp($timestampfile); - - // On ajoute 30mn - $datefile->add(new \DateInterval('PT30M')); - - // Si la date est inférieur à maintenant on regénère le flux - $now = new \DateTime(); - if($datefile>=$now) { - $toregen=false; - $feeds = unserialize(file_get_contents($filecache)); - } - } - - // Si le fichier est trop ancien on relit le flus - if($toregen) { - // Connexion au client - $PROXYactivate = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue(); - $weburl=$this->getParameter('weburl'); - if(stripos($url,"/")==0) { - $url="https://".$weburl.$url; - $PROXYactivate=false; - } - if(stripos($url,"https://".$weburl)===0) $PROXYactivate=false; - if(stripos($url,"http://".$weburl)===0) $PROXYactivate=false; - - if($PROXYactivate) { - $PROXYserver = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue(); - $PROXYport = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue(); - $clientguzzle = new \GuzzleHttp\Client(array('timeout' => 3,'verify'=>false,'proxy' => ['http' => 'http://'.$PROXYserver.':'.$PROXYport,'https' => 'http://'.$PROXYserver.':'.$PROXYport])); - } - else - $clientguzzle = new \GuzzleHttp\Client(array('timeout' => 3,'verify'=>false)); - - try { - $clientguzzle->request('GET', $url); - } catch (RequestException $e) { - if ($e->hasResponse()) { - // Render - $feeds=[]; - return $this->render($this->labelentity.':viewflux.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, - 'access' => $access, - 'feeds' => $feeds, - ]); - } - } - - $client = new \FeedIo\Adapter\Guzzle\Client($clientguzzle); - $logger = new \Psr\Log\NullLogger(); - $feedIo = new \FeedIo\FeedIo($client, $logger); - - $feeds=array(); - - // On lit le flux rss - try { - $result = $feedIo->read($url); - } - catch (\Exception $e) { - $result=null; - } - - if($result) { - $feedtitle = $result->getFeed()->getTitle(); - - - // Pour chaque articles - $nbflux=0; - foreach ($result->getFeed() as $item) { - $title = $item->getTitle(); - $link = $item->getLink(); - $description = substr(strip_tags($item->getDescription()),0,250); - $description = str_replace("¶","",$description); - $date = $item->getLastModified(); - $dateformat = ($date?$item->getLastModified()->format('d/m/Y H:i:s'):""); - $content = $item->getDescription(); - $media = $item->getMedias(); - $mediaurl = ""; - - foreach ($item->getMedias() as $itemMedia) { - if($itemMedia->getType()=="image/jpeg") - $mediaurl=$itemMedia->getUrl(); - } - - foreach ($item->getAllElements() as $element) { - if($element->getName()=="content:encoded") - $content = $element->getValue(); - } - - if($mediaurl!="") { - $imgurl=$mediaurl; - } - else { - // Récupérer la première image du contenu - $imgcontent=""; - $imgurl=""; - $imgstart = stripos($content,"",$imgstart); - $imgcontent=substr($content,$imgstart,$imgend-$imgstart+1); - - $imgstart = stripos($imgcontent,"src="); - $imgurl=substr($imgcontent,$imgstart+5); - $imgend = stripos($imgurl,'"'); - - if($imgend===false) $imgend = stripos($imgurl,"'"); - $imgurl=substr($imgurl,0,$imgend); - } - } - - // Garder le flux - array_push($feeds,array( - "feedtitle" => $feedtitle, - "title" => $title, - "link" => $link, - "description" => $description, - "date" => $date, - "dateformat" => $dateformat, - "content" => $content, - "image" => $imgurl, - // "color" => $flux->getColor(), - "fluxid" => 0, - "fluxtitle" => $entity->getName(), - )); - - $nbflux++; - if($nbflux>=$nbarticle&&$nbarticle>0) break; - } - - - $libelle=array(); - foreach ($feeds as $key => $valeur) { - $libelle[$key] = $valeur["date"]; - } - array_multisort($libelle, SORT_DESC, $feeds); - - // On sauvegarde le résultat en fichier on rechargera son contenu que s'il n'a pas été lu depuis 30mn - $filesystem->dumpFile($filecache, serialize($feeds)); - } } // Render - return $this->render($this->labelentity.':viewflux.html.twig', [ - 'entity' => $entity, - 'canupdate' => $canupdate, - 'fluxs' => ["id"=>0], - 'access' => $access, + return $this->getRender('viewflux.html.twig', [ + 'fluxs' => $fluxs, 'feeds' => $feeds, 'modelist' => $modelist, ]); } - public function viewbookmarkAction($id,$access="config") { + public function viewbookmarkAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1266,10 +1132,15 @@ class PagewidgetController extends Controller 'modedesktop' => $modedesktop, 'bookmarks' => $bookmarks, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewlinkAction($id,$access="config") { + public function viewlinkAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1310,10 +1181,15 @@ class PagewidgetController extends Controller 'url' => $url, 'target' => $target, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function vieweditorAction($id,$access="config") { + public function vieweditorAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1350,10 +1226,15 @@ class PagewidgetController extends Controller 'canupdate' => $canupdate, 'html' => $html, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewslideAction($id,$access="config") { + public function viewslideAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1393,10 +1274,15 @@ class PagewidgetController extends Controller 'slides' => $slides, 'interval' => $interval, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewfileAction($id,$access="config") { + public function viewfileAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1432,13 +1318,18 @@ class PagewidgetController extends Controller 'access' => $access, 'directory' => "widget-".$id, 'view' => $view, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewgaleryAction($id,$access="config") { + public function viewgaleryAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1491,12 +1382,16 @@ class PagewidgetController extends Controller 'canupdate' => $canupdate, 'files' => $files, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewcalendarAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -1541,13 +1436,17 @@ class PagewidgetController extends Controller 'nbday' => $nbday, 'access' => $access, 'firstcalendar' => $firstcalendar, - 'usage' => $usage + 'usage' => $usage, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewblogAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -1602,13 +1501,17 @@ class PagewidgetController extends Controller 'nbarticle' => $nbarticle, 'access' => $access, 'firstblog' => $firstblog, - 'usage' => $usage + 'usage' => $usage, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewprojectAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -1676,11 +1579,16 @@ class PagewidgetController extends Controller 'nbarticle' => $nbarticle, 'access' => $access, 'firstproject' => $firstproject, - 'usage' => $usage + 'usage' => $usage, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewseparatorAction($id,$access="config") { + public function viewseparatorAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1721,10 +1629,15 @@ class PagewidgetController extends Controller 'seetitle' => $seetitle, 'seeicon' => $seeicon, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewclockAction($id,$access="config") { + public function viewclockAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1754,17 +1667,22 @@ class PagewidgetController extends Controller $this->getPreference($entity); // Render - return $this->render($this->labelentity.':viewurl.html.twig', [ + return $this->render($this->labelentity.':viewframe.html.twig', [ 'entity' => $entity, 'canadd' => $canupdate, 'canupdate' => $canupdate, 'onheader' => true, 'tool' => ($clock==0?"cadoles_portal_user_tool_clockanalogique":"cadoles_portal_user_tool_clocknumerique"), 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewcalculatorAction($id,$access="config") { + public function viewcalculatorAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1791,10 +1709,15 @@ class PagewidgetController extends Controller 'onheader' => true, 'tool' => "cadoles_portal_user_tool_calculator", 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } - public function viewappexternalAction($id,$access="config") { + public function viewappexternalAction(Request $request,$id,$access="config") { + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); @@ -1892,12 +1815,16 @@ class PagewidgetController extends Controller 'items' => $items, 'itemcategorys' => $itemcategorys, 'access' => $access, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewinfoAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); - $group=$request->query->get('group'); + $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $user=$this->getUser(); $em = $this->getDoctrine()->getManager(); @@ -1960,12 +1887,16 @@ class PagewidgetController extends Controller 'members' => $members, 'id' => $id, 'idpage' => $page->getId(), + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewchatAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository($this->labelentity)->find($id); @@ -1999,6 +1930,8 @@ class PagewidgetController extends Controller 'access' => $access, 'usage' => $usage, 'group' => $group, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } @@ -2006,6 +1939,9 @@ class PagewidgetController extends Controller public function viewgroupAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $user=$this->getUser(); $em = $this->getDoctrine()->getManager(); @@ -2049,13 +1985,17 @@ class PagewidgetController extends Controller 'canupdate' => $canupdate, 'usage' => $usage, 'groups' => $mygroups, - + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewgroupmessageAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $user=$this->getUser(); $em = $this->getDoctrine()->getManager(); @@ -2135,13 +2075,17 @@ class PagewidgetController extends Controller 'modelist' => $modelist, 'messages' => $mymsg, 'nbarticle' => $nbarticle, - + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } public function viewOnlydocAction(Request $request,$id,$access="config") { $usage=$request->query->get('usage'); $group=$request->query->get('group'); + $look=$request->query->get('look'); + $selwidget=$request->query->get('selwidget'); + $user=$this->getUser(); $em = $this->getDoctrine()->getManager(); @@ -2185,6 +2129,8 @@ class PagewidgetController extends Controller 'access' => $access, 'directory' => $id, 'view' => $view, + 'look' => $look, + 'mini' => ($look=="list"&&$entity->getId()!=$selwidget), ]); } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/SlideController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/SlideController.php index 7b51e373..55066a3f 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/SlideController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/SlideController.php @@ -32,7 +32,7 @@ class SlideController extends Controller // Vérifier que l'on générer un slide if($access=="user") { if($usage=="user") { - $user=$data->getPagewidget()->getPage()->getUser(); + $user=$pagewidget->getPage()->getUser(); if($user!=$this->getUser()) throw $this->createNotFoundException('Permission denied'); } else { @@ -76,7 +76,7 @@ class SlideController extends Controller // Vérifier que l'on générer un slide if($access=="user") { if($usage=="user") { - $user=$data->getPagewidget()->getPage()->getUser(); + $user=$pagewidget->getPage()->getUser(); if($user!=$this->getUser()) throw $this->createNotFoundException('Permission denied'); } else { diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Flux.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Flux.php index 199e1cf9..efd8f436 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Flux.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Flux.php @@ -11,7 +11,8 @@ use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity * @ORM\Table(name="flux") - * @ORM\HasLifecycleCallbacks + * @ORM\HasLifecycleCallbacks. + * @ORM\Entity(repositoryClass="Cadoles\PortalBundle\Repository\FluxRepository") */ class Flux { diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/FluxRepository.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/FluxRepository.php new file mode 100644 index 00000000..7587ee84 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/FluxRepository.php @@ -0,0 +1,47 @@ +getRoles():["ROLE_ANONYME"]); + $groups=($user?$user->getGroups():[]); + + // Initialisation du calcul des alerts + $fluxs=new ArrayCollection(); + + // Récupération des fluxs par rôles + foreach($roles as $role) { + $qb = $this->createQueryBuilder('a'); + $qb->select('flux') + ->from("CadolesPortalBundle:Flux", 'flux') + ->where($qb->expr()->like('flux.roles', $qb->expr()->literal("%$role%"))); + + $fluxsroles=$qb->getQuery()->getResult(); + foreach($fluxsroles as $fluxrole) { + if(!$fluxs->contains($fluxrole)) $fluxs->add($fluxrole); + } + } + + // Récupération des fluxs par group + foreach($groups as $group) { + $qb = $this->createQueryBuilder('a'); + $qb->select('flux') + ->from("CadolesPortalBundle:Flux", 'flux') + ->where(":group MEMBER OF flux.groups") + ->setParameter("group",$group->getGroup()); + + $fluxsgroups=$qb->getQuery()->getResult(); + foreach($fluxsgroups as $fluxgroup) { + if(!$fluxs->contains($fluxgroup)) $fluxs->add($fluxgroup); + } + } + + return $fluxs; + } +} 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 45d08cdf..fc2ec2bb 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/ItemRepository.php @@ -7,7 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; class ItemRepository extends EntityRepository { - public function getUserItems($user,&$bookmarks,&$itemsordered,&$itemcategorys,$iditemcategory=null,$withbookmark=1) { + public function getUserItems($user,&$bookmarks,&$itemsordered,&$itemcategorys,$iditemcategory=null,$withbookmark=1,$fgessential=false) { // Profilage $roles=($user?$user->getRoles():["ROLE_ANONYME"]); $groups=($user?$user->getGroups():[]); @@ -40,6 +40,12 @@ class ItemRepository extends EntityRepository $qb->andWhere("item.itemcategory=:itemcategory") ->setParameter("itemcategory",$itemcategoryfilter); } + + if($fgessential) { + $qb->andWhere("item.essential=:flag") + ->setParameter("flag",true); + } + $itemsroles=$qb->getQuery()->getResult(); foreach($itemsroles as $itemrole) { if(!$bookmarksitems->contains($itemrole) && !$items->contains($itemrole)) $items->add($itemrole); @@ -58,6 +64,12 @@ class ItemRepository extends EntityRepository $qb->andWhere("item.itemcategory=:itemcategory") ->setParameter("itemcategory",$itemcategoryfilter); } + + if($fgessential) { + $qb->andWhere("item.essential=:flag") + ->setParameter("flag",true); + } + $itemsgroups=$qb->getQuery()->getResult(); foreach($itemsgroups as $itemgroup) { @@ -78,6 +90,12 @@ class ItemRepository extends EntityRepository $qb->andWhere("item.itemcategory=:itemcategory") ->setParameter("itemcategory",$itemcategoryfilter); } + + if($fgessential) { + $qb->andWhere("item.essential=:flag") + ->setParameter("flag",true); + } + $itemsniveau01s=$qb->getQuery()->getResult(); foreach($itemsniveau01s as $itemniveau01) { if(!$bookmarksitems->contains($itemniveau01) && !$items->contains($itemniveau01)) $items->add($itemniveau01); diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig index 2a037951..2c1f9006 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Page/viewwidget.html.twig @@ -1,6 +1,13 @@ {% extends '@CadolesCore/base.html.twig' %} +{% block localstyle %} + {% if look=="list" %} + #R1C1:first-child { + margin-top: 30px; + } + {% endif %} +{% endblock %} {% block pagewrapper %} {% if access=="config" %}