2019-03-21 17:15:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cadoles\PortalBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
|
|
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-04-02 11:26:41 +02:00
|
|
|
use Symfony\Component\Finder\Finder;
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
2019-03-21 17:15:06 +01:00
|
|
|
|
|
|
|
use Cadoles\PortalBundle\Entity\Pagewidget;
|
|
|
|
use Cadoles\PortalBundle\Form\PagewidgetType;
|
|
|
|
|
|
|
|
class PagewidgetController extends Controller
|
|
|
|
{
|
|
|
|
private $labelentity="CadolesPortalBundle:Pagewidget";
|
|
|
|
private $routeprimary="cadoles_portal_config_pagewidget";
|
|
|
|
|
|
|
|
private function searchArray($array, $key, $value)
|
|
|
|
{
|
|
|
|
$results = array();
|
|
|
|
|
|
|
|
if (is_array($array))
|
|
|
|
{
|
|
|
|
if (isset($array[$key]) && $array[$key] == $value)
|
|
|
|
$results[] = $array;
|
|
|
|
|
|
|
|
foreach ($array as $subarray)
|
|
|
|
$results = array_merge($results, $this->searchArray($subarray, $key, $value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function entityForm(Pagewidget $entity,$idpage,$id,$access="config")
|
|
|
|
{
|
|
|
|
if ($this->getDoctrine()->getManager()->contains($entity)) {
|
|
|
|
$widgettype= $this->getDoctrine()->getManager()->getRepository("CadolesPortalBundle:Pagewidget")->find($id)->getWidget();
|
|
|
|
$params = $widgettype->getParameter();
|
|
|
|
$values = $entity->getParameter();
|
|
|
|
|
|
|
|
foreach($params->fields as $key => $param) {
|
|
|
|
$tmp = $this->searchArray($values,"id",$param->id);
|
|
|
|
if(is_array($tmp))
|
|
|
|
$params->fields[$key]->value=$tmp[0]["value"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->createForm(PagewidgetType::class, $entity, [
|
|
|
|
'param' => $params,
|
|
|
|
'mode' => "update",
|
|
|
|
'idicon' => $entity->getIcon()->getId(),
|
|
|
|
'method' => 'POST',
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$widgettype= $this->getDoctrine()->getManager()->getRepository("CadolesPortalBundle:Widget")->find($id);
|
|
|
|
$entity->setName($widgettype->getName());
|
|
|
|
$entity->setHeight($widgettype->getHeight());
|
|
|
|
$entity->setAutoajust($widgettype->getAutoajust());
|
|
|
|
$entity->setBorder($widgettype->getBorder());
|
|
|
|
$entity->setColorheaderback($widgettype->getColorheaderback());
|
|
|
|
$entity->setColorheaderfont($widgettype->getColorheaderfont());
|
|
|
|
$entity->setColorbodyback($widgettype->getColorbodyback());
|
|
|
|
$entity->setColorbodyfont($widgettype->getColorbodyfont());
|
|
|
|
$entity->setIcon($widgettype->getIcon());
|
|
|
|
|
|
|
|
$param = $widgettype->getParameter();
|
|
|
|
return $this->createForm(PagewidgetType::class, $entity, [
|
|
|
|
'param' => $param,
|
|
|
|
'mode' => "submit",
|
|
|
|
'idicon' => $widgettype->getIcon()->getId(),
|
|
|
|
'method' => 'POST',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submitAction(Request $request,$idpage,$idwidgettype,$access="config")
|
|
|
|
{
|
|
|
|
$entity = new Pagewidget();
|
|
|
|
$form = $this->entityForm($entity,$idpage,$idwidgettype,$access);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// On s'assure que la page où l'on souhaite insérer un widget est bien du bon type
|
|
|
|
$page=$this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->findoneby(["id"=>$idpage]);
|
|
|
|
if (!$page)
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
if($page->getPagecategory()->getId()!=2)
|
|
|
|
throw $this->createNotFoundException('Permission denied');
|
2019-03-21 17:15:06 +01:00
|
|
|
|
|
|
|
if ($form->isValid()) {
|
|
|
|
$idicon = $form->get('idicon')->getData();
|
|
|
|
$icon=$this->getDoctrine()->getRepository("CadolesPortalBundle:Icon")->findoneby(["id"=>$idicon]);
|
|
|
|
$widgettype=$this->getDoctrine()->getRepository("CadolesPortalBundle:Widget")->findoneby(["id"=>$idwidgettype]);
|
|
|
|
|
|
|
|
// Localisation par défaut en R1C1
|
|
|
|
$entity->setLoc("R1C1");
|
|
|
|
$entity->setRoworder("1");
|
|
|
|
|
|
|
|
// Rattachement icon / panel / widgettype
|
|
|
|
$entity->setIcon($icon);
|
2019-04-02 11:26:41 +02:00
|
|
|
$entity->setPage($page);
|
2019-03-21 17:15:06 +01:00
|
|
|
$entity->setWidget($widgettype);
|
|
|
|
|
|
|
|
// Récupération des paramétres
|
|
|
|
$jsons=$widgettype->getParameter();
|
|
|
|
$param=array();
|
|
|
|
$param["fields"]=array();
|
|
|
|
foreach($jsons->fields as $field) {
|
|
|
|
$tmp=array();
|
|
|
|
$tmp["id"]=$field->id;
|
|
|
|
$tmp["value"]=$form->get($field->id)->getData();
|
|
|
|
array_push($param["fields"],$tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
$entity->setParameter($param);
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entity);
|
|
|
|
$em->flush();
|
2019-04-02 11:26:41 +02:00
|
|
|
|
|
|
|
if($access=="config")
|
|
|
|
return $this->redirect($this->generateUrl('cadoles_portal_config_page_view',["id"=>$idpage]));
|
|
|
|
else
|
|
|
|
return $this->redirect($this->generateUrl('cadoles_core_home',["id"=>$idpage]));
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render($this->labelentity.':edit.html.twig', [
|
|
|
|
'useheader' => true,
|
|
|
|
'usemenu' => false,
|
|
|
|
'usesidebar' => ($access=="config"),
|
|
|
|
'entity' => $entity,
|
|
|
|
'icons' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Icon")->findAll(),
|
|
|
|
'mode' => "submit",
|
|
|
|
'access' => $access,
|
|
|
|
'idpage' => $idpage,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateAction(Request $request,$idpage,$idwidget,$access="config")
|
|
|
|
{
|
2019-04-02 11:26:41 +02:00
|
|
|
// Recherche du pagewidget
|
2019-03-21 17:15:06 +01:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($idwidget);
|
2019-04-02 11:26:41 +02:00
|
|
|
if (!$entity) throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
|
|
|
|
// On s'assure que l'utilisateur à la permission de modifier
|
|
|
|
if($access=="user") {
|
|
|
|
$em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$entity->getPage(),$cansee,$canupdate);
|
|
|
|
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// Création du formulaire
|
2019-03-21 17:15:06 +01:00
|
|
|
$form = $this->entityForm($entity,$idpage,$idwidget,$access);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// Validation
|
2019-03-21 17:15:06 +01:00
|
|
|
if ($form->isValid()) {
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
|
|
|
|
$idicon = $form->get('idicon')->getData();
|
|
|
|
$icon=$this->getDoctrine()->getRepository("CadolesPortalBundle:Icon")->findoneby(["id"=>$idicon]);
|
|
|
|
$entity->setIcon($icon);
|
|
|
|
|
|
|
|
// Récupération des paramétres
|
|
|
|
$widgettype= $entity->getWidget();
|
|
|
|
$jsons=$widgettype->getParameter();
|
|
|
|
$param=array();
|
|
|
|
$param["fields"]=array();
|
|
|
|
foreach($jsons->fields as $field) {
|
|
|
|
$tmp=array();
|
|
|
|
$tmp["id"]=$field->id;
|
|
|
|
|
|
|
|
$tmp["value"]=$form->get($field->id)->getData();
|
|
|
|
array_push($param["fields"],$tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
$entity->setParameter($param);
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$em->persist($entity);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('cadoles_portal_'.$access.'_page_view',["id"=>$idpage]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render($this->labelentity.':edit.html.twig', [
|
2019-04-02 11:26:41 +02:00
|
|
|
'useheader' => ($access=="config"),
|
2019-03-21 17:15:06 +01:00
|
|
|
'usemenu' => false,
|
|
|
|
'usesidebar' => ($access=="config"),
|
|
|
|
'entity' => $entity,
|
|
|
|
'icons' => $this->getDoctrine()->getRepository("CadolesPortalBundle:Icon")->findAll(),
|
|
|
|
'mode' => "update",
|
|
|
|
'access' => $access,
|
|
|
|
'idpage' => $idpage,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
public function deleteAction(Request $request,$access="config")
|
2019-03-21 17:15:06 +01:00
|
|
|
{
|
|
|
|
// S'assurer que c'est un appel ajax
|
2019-04-02 11:26:41 +02:00
|
|
|
if (!$request->isXmlHttpRequest()) return new JsonResponse(array('message' => 'Interdit'), 400);
|
2019-03-21 17:15:06 +01:00
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// Récupération des parametres
|
2019-03-21 17:15:06 +01:00
|
|
|
$output=array();
|
|
|
|
$idwidget=$request->request->get('idwidget');
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// Recherche du pagetwidget
|
2019-03-21 17:15:06 +01:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($idwidget);
|
2019-04-02 11:26:41 +02:00
|
|
|
if (!$entity) throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
|
|
|
|
// On s'assure que l'utilisateur à la permission de supprimer
|
|
|
|
if($access=="user") {
|
|
|
|
$em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$entity->getPage(),$cansee,$canupdate);
|
|
|
|
if(!$canupdate) throw $this->createNotFoundException('Permission denied');
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// Supression du pagewidget
|
2019-03-21 17:15:06 +01:00
|
|
|
$em->remove($entity);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
$response = new Response(json_encode($output));
|
|
|
|
$response->headers->set('Content-Type', 'application/json');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function orderAction(Request $request)
|
|
|
|
{
|
|
|
|
// S'assurer que c'est un appel ajax
|
2019-04-02 11:26:41 +02:00
|
|
|
if (!$request->isXmlHttpRequest()) return new JsonResponse(array('message' => 'Interdit'), 400);
|
2019-03-21 17:15:06 +01:00
|
|
|
|
|
|
|
$output=array();
|
|
|
|
$idwidget=$request->request->get('idwidget');
|
|
|
|
$order=$request->request->get('order');
|
|
|
|
$idloc=$request->request->get('idloc');
|
|
|
|
|
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($idwidget);
|
|
|
|
if (!$entity) {
|
|
|
|
throw $this->createNotFoundException('Unable to find entity.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$entity->setRoworder($order);
|
|
|
|
$entity->setLoc($idloc);
|
|
|
|
$em->persist($entity);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
$response = new Response(json_encode($output));
|
|
|
|
$response->headers->set('Content-Type', 'application/json');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
public function viewurlAction($id,$access="config") {
|
2019-03-21 17:15:06 +01:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($id);
|
2019-04-02 11:26:41 +02:00
|
|
|
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');
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$url="";
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
if($parameter["id"]=="url")
|
|
|
|
$url=$parameter["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
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spécifique Deviant Art
|
|
|
|
if(strpos($url, "images-wixmp") !== false) $imagemedia=true;
|
|
|
|
|
|
|
|
|
|
|
|
return $this->render($this->labelentity.':viewurl.html.twig', [
|
2019-04-02 11:26:41 +02:00
|
|
|
'entity' => $entity,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'url' => $url,
|
|
|
|
'imagemedia' => $imagemedia,
|
|
|
|
'access' => $access
|
2019-03-21 17:15:06 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
public function viewitemAction($id,$access="config") {
|
2019-03-21 17:15:06 +01:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($id);
|
2019-04-02 11:26:41 +02:00
|
|
|
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');
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Récupération des paramétres du widget
|
|
|
|
$modedesktop=0;
|
|
|
|
$iditemcategory=null;
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "modedesktop":
|
|
|
|
$modedesktop=$parameter["value"];
|
|
|
|
break;
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
case "withbookmark":
|
|
|
|
$withbookmark=$parameter["value"];
|
|
|
|
break;
|
|
|
|
|
2019-03-21 17:15:06 +01:00
|
|
|
case "itemcategory":
|
|
|
|
$iditemcategory=$parameter["value"];
|
|
|
|
if($iditemcategory) $itemcategoryfilter=$em->getRepository("CadolesPortalBundle:Itemcategory")->find($iditemcategory);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Profilage
|
|
|
|
$user=$this->getUser();
|
|
|
|
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
|
|
|
|
$groups=($user?$user->getGroups():[]);
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:15:06 +01:00
|
|
|
// 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) {
|
2019-04-02 11:26:41 +02:00
|
|
|
if(!$bookmarksitems->contains($itemrole) && !$items->contains($itemrole)) $items->add($itemrole);
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2019-04-02 11:26:41 +02:00
|
|
|
if(!$bookmarksitems->contains($itemgroup) && !$items->contains($itemgroup)) $items->add($itemgroup);
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trie des items
|
|
|
|
$itemsordered = $items->getIterator();
|
|
|
|
$itemsordered->uasort(function ($first, $second) {
|
|
|
|
return (int) $first->getRowOrder() > (int) $second->getRowOrder() ? 1 : -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Catégories affichées
|
|
|
|
$itemcategorys = $this->getDoctrine()->getRepository('CadolesPortalBundle:Itemcategory')->findBy([], ['rowOrder' => 'asc']);
|
|
|
|
if($iditemcategory && $itemcategoryfilter) $itemcategorys = $itemcategoryfilter;
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
switch($withbookmark) {
|
|
|
|
// items uniquement
|
|
|
|
case 1: $bookmarks=null; break;
|
|
|
|
|
|
|
|
// bookmarks uniquement
|
|
|
|
case 2: $itemsordered=null; break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:15:06 +01:00
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewitem.html.twig', [
|
2019-04-02 11:26:41 +02:00
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => ($user),
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'modedesktop' => $modedesktop,
|
|
|
|
'items' => $itemsordered,
|
|
|
|
'itemcategorys' => $itemcategorys,
|
|
|
|
'bookmarks' => $bookmarks,
|
|
|
|
'access' => $access,
|
2019-03-21 17:15:06 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:26:41 +02:00
|
|
|
public function viewalertAction($id,$access="config") {
|
2019-03-21 17:15:06 +01:00
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
|
$entity = $em->getRepository($this->labelentity)->find($id);
|
2019-04-02 11:26:41 +02:00
|
|
|
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');
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Récupération des paramétres du widget
|
|
|
|
$idalertcategory=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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Profilage
|
|
|
|
$user=$this->getUser();
|
|
|
|
$roles=($user?$user->getRoles():["ROLE_ANONYME"]);
|
|
|
|
$groups=($user?$user->getGroups():[]);
|
|
|
|
|
|
|
|
// Initialisation du calcul des alerts
|
|
|
|
$alerts=new ArrayCollection();
|
2019-04-02 11:26:41 +02:00
|
|
|
|
2019-03-21 17:15:06 +01:00
|
|
|
// Récupération des alerts par rôles
|
|
|
|
foreach($roles as $role) {
|
|
|
|
$qb = $em->createQueryBuilder();
|
|
|
|
$qb->select('alert')
|
|
|
|
->from("CadolesPortalBundle:Alert", 'alert')
|
|
|
|
->where($qb->expr()->like('alert.roles', $qb->expr()->literal("%$role%")));
|
|
|
|
|
|
|
|
if($idalertcategory && $alertcategoryfilter) {
|
|
|
|
$qb->andWhere("alert.alertcategory=:alertcategory")
|
|
|
|
->setParameter("alertcategory",$alertcategoryfilter);
|
|
|
|
}
|
|
|
|
$alertsroles=$qb->getQuery()->getResult();
|
|
|
|
foreach($alertsroles as $alertrole) {
|
|
|
|
if(!$alerts->contains($alertrole)) $alerts->add($alertrole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Récupération des alerts par group
|
|
|
|
foreach($groups as $group) {
|
|
|
|
$qb = $em->createQueryBuilder();
|
|
|
|
$qb->select('alert')
|
|
|
|
->from("CadolesPortalBundle:Alert", 'alert')
|
|
|
|
->where(":group MEMBER OF alert.groups")
|
|
|
|
->setParameter("group",$group->getGroup());
|
|
|
|
|
|
|
|
if($idalertcategory && $alertcategoryfilter) {
|
|
|
|
$qb->andWhere("alert.alertcategory=:alertcategory")
|
|
|
|
->setParameter("alertcategory",$alertcategoryfilter);
|
|
|
|
}
|
|
|
|
$alertsgroups=$qb->getQuery()->getResult();
|
|
|
|
foreach($alertsgroups as $alertgroup) {
|
|
|
|
if(!$alerts->contains($alertgroup)) $alerts->add($alertgroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trie des alerts
|
|
|
|
$alertsordered = $alerts->getIterator();
|
|
|
|
$alertsordered->uasort(function ($first, $second) {
|
|
|
|
return (int) $first->getRowOrder() > (int) $second->getRowOrder() ? 1 : -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewalert.html.twig', [
|
2019-04-02 11:26:41 +02:00
|
|
|
'entity' => $entity,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'alerts' => $alertsordered,
|
|
|
|
'access' => $access
|
2019-03-21 17:15:06 +01:00
|
|
|
]);
|
|
|
|
}
|
2019-04-02 11:26:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
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.');
|
|
|
|
|
|
|
|
// 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');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trie des fluxs
|
|
|
|
$fluxsordered = $fluxs->getIterator();
|
|
|
|
$fluxsordered->uasort(function ($first, $second) {
|
|
|
|
return (int) $first->getRowOrder() > (int) $second->getRowOrder() ? 1 : -1;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Connexion au client
|
|
|
|
$PROXYactivate = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue();
|
|
|
|
|
|
|
|
if($PROXYactivate) {
|
|
|
|
$PROXYserver = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue();
|
|
|
|
$PROXYport = $em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue();
|
|
|
|
$clientguzzle = new \GuzzleHttp\Client(array('proxy' => ['http' => 'tcp://'.$PROXYserver.':'.$PROXYport,'https' => 'tcp://'.$PROXYserver.':'.$PROXYport]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$clientguzzle = new \GuzzleHttp\Client();
|
|
|
|
|
|
|
|
$client = new \FeedIo\Adapter\Guzzle\Client($clientguzzle);
|
|
|
|
$logger = new \Psr\Log\NullLogger();
|
|
|
|
$feedIo = new \FeedIo\FeedIo($client, $logger);
|
|
|
|
|
|
|
|
$feeds=array();
|
|
|
|
|
|
|
|
|
|
|
|
foreach($fluxsordered as $flux) {
|
|
|
|
// On regarde si le flux a été lu il y a peu
|
|
|
|
|
|
|
|
// On lit le flux rss
|
|
|
|
$result = $feedIo->read($flux->getUrl());
|
|
|
|
$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 = $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,"<img");
|
|
|
|
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,'"');
|
|
|
|
|
|
|
|
if($imgend===false) $imgend = stripos($imgurl,"'");
|
|
|
|
$imgurl=substr($imgurl,0,$imgend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Garder le flux
|
|
|
|
if($nbflux<26) {
|
|
|
|
array_push($feeds,array(
|
|
|
|
"feedtitle" => $feedtitle,
|
|
|
|
"title" => $title,
|
|
|
|
"link" => $link,
|
|
|
|
"description" => $description,
|
|
|
|
"date" => $date,
|
|
|
|
"dateformat" => $dateformat,
|
|
|
|
"content" => $content,
|
|
|
|
"image" => $imgurl,
|
|
|
|
"color" => $flux->getColor(),
|
|
|
|
"fluxid" => $flux->getId(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$nbflux++;
|
|
|
|
if($nbflux>=$flux->getMaxread()) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$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,
|
|
|
|
'fluxs' => $fluxsordered,
|
|
|
|
'access' => $access,
|
|
|
|
'feeds' => $feeds,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function viewbookmarkAction($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
|
|
|
|
$modedesktop=0;
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "modedesktop":
|
|
|
|
$modedesktop=$parameter["value"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Profilage
|
|
|
|
$user=$this->getUser();
|
|
|
|
|
|
|
|
// Bookmark du widget
|
|
|
|
$bookmarks=$em->getRepository("CadolesPortalBundle:Bookmark")->findBy(["pagewidget"=>$entity]);
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewbookmark.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => ($user),
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'modedesktop' => $modedesktop,
|
|
|
|
'bookmarks' => $bookmarks,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewlinkAction($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="";
|
|
|
|
$target="_blank";
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "url":
|
|
|
|
$url=$parameter["value"];
|
|
|
|
break;
|
|
|
|
case "target":
|
|
|
|
$target=$parameter["value"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewlink.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => false,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'url' => $url,
|
|
|
|
'target' => $target,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function vieweditorAction($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
|
|
|
|
$html="";
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "html":
|
|
|
|
$html=$parameter["value"];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':vieweditor.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => false,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'html' => $html,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewslideAction($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parametres
|
|
|
|
$interval="2";
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "interval":
|
|
|
|
$interval=$parameter["value"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$slides=$em->getRepository("CadolesPortalBundle:Slide")->findBy(["pagewidget"=>$entity],['roworder'=>'ASC','title'=>'ASC']);
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewslide.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => $canupdate,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'slides' => $slides,
|
|
|
|
'interval' => $interval,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewfileAction($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
$directory=$this->get('kernel')->getRootDir()."/../uploads/file/widget-".$id;
|
|
|
|
$files=[];
|
|
|
|
$fs = new Filesystem();
|
|
|
|
|
|
|
|
if($fs->exists($directory)) {
|
|
|
|
$finder = new Finder();
|
|
|
|
$finder->sortByName()->in($directory)->exclude('thumb');
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($finder as $file) {
|
|
|
|
$tmp=[];
|
|
|
|
$tmp["name"]=$file->getRelativePathname();
|
|
|
|
$tmp["extension"]=$file->getExtension();
|
|
|
|
$fileinfo = new file($file->getPathname());
|
|
|
|
$tmp["minetype"]=$fileinfo->getMimeType();
|
|
|
|
$tmp["minefamily"]=explode("/",$tmp["minetype"])[0];
|
|
|
|
|
|
|
|
$tmp["thumb"]="";
|
|
|
|
if($fs->exists($directory."/thumb/".$tmp["name"])) {
|
|
|
|
$data = file_get_contents($directory."/thumb/".$tmp["name"]);
|
|
|
|
$tmp["thumb"]="data:image/" . $tmp["extension"] . ";base64," . base64_encode($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($files,$tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewfile.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => $canupdate,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'files' => $files,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewgaleryAction($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
$directory=$this->get('kernel')->getRootDir()."/../uploads/file/widget-".$id;
|
|
|
|
$files=[];
|
|
|
|
$fs = new Filesystem();
|
|
|
|
|
|
|
|
if($fs->exists($directory)) {
|
|
|
|
$finder = new Finder();
|
|
|
|
$finder->sortByName()->in($directory)->exclude('thumb');
|
|
|
|
|
|
|
|
foreach ($finder as $file) {
|
|
|
|
$tmp=[];
|
|
|
|
$tmp["name"]=$file->getRelativePathname();
|
|
|
|
$tmp["extension"]=$file->getExtension();
|
|
|
|
$fileinfo = new file($file->getPathname());
|
|
|
|
$tmp["minetype"]=$fileinfo->getMimeType();
|
|
|
|
$tmp["minefamily"]=explode("/",$tmp["minetype"])[0];
|
|
|
|
|
|
|
|
$tmp["thumb"]="";
|
|
|
|
if($fs->exists($directory."/thumb/".$tmp["name"])) {
|
|
|
|
$data = file_get_contents($directory."/thumb/".$tmp["name"]);
|
|
|
|
$tmp["thumb"]="data:image/" . $tmp["extension"] . ";base64," . base64_encode($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push($files,$tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewgalery.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => $canupdate,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'files' => $files,
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function viewclockAction($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parametres
|
|
|
|
$clock="0";
|
|
|
|
foreach($entity->getParameter()["fields"] as $parameter) {
|
|
|
|
switch($parameter["id"]) {
|
|
|
|
case "clock":
|
|
|
|
$clock=$parameter["value"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render
|
|
|
|
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,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewcalculatorAction($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Render
|
|
|
|
return $this->render($this->labelentity.':viewframe.html.twig', [
|
|
|
|
'entity' => $entity,
|
|
|
|
'canadd' => $canupdate,
|
|
|
|
'canupdate' => $canupdate,
|
|
|
|
'onheader' => true,
|
|
|
|
'tool' => "cadoles_portal_user_tool_calculator",
|
|
|
|
'access' => $access,
|
|
|
|
]);
|
|
|
|
}
|
2019-03-21 17:15:06 +01:00
|
|
|
}
|