194 lines
9.6 KiB
PHP
194 lines
9.6 KiB
PHP
<?php
|
|
namespace Cadoles\CoreBundle\EventListener;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
use Symfony\Component\EventDispatcher\Event;
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
|
|
class sessionListener {
|
|
protected $container;
|
|
protected $em;
|
|
|
|
public function __construct($container, EntityManager $em, TokenStorageInterface $token_storage)
|
|
{
|
|
$this->container = $container;
|
|
$this->em = $em;
|
|
$this->token_storage = $token_storage;
|
|
}
|
|
|
|
public function haveRole($roles,$tohave) {
|
|
if($roles=="") {
|
|
if(empty($tohave)) return true;
|
|
}
|
|
else {
|
|
foreach($roles as $role) {
|
|
if(in_array($role,$tohave))
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function onDomainParse(Event $event) {
|
|
$session = new Session();
|
|
|
|
|
|
|
|
$configs = $this->em->getRepository("CadolesCoreBundle:Config")->findAll();
|
|
foreach($configs as $config) {
|
|
$session->set($config->getId(), strval($config->getValue()));
|
|
}
|
|
|
|
// Calcul des couleurs
|
|
$color = $this->container->get('cadoles.core.service.color');
|
|
$color->setColor();
|
|
|
|
// Utilisateur en cours
|
|
$curentuserid=0;
|
|
$token = $this->token_storage->getToken();
|
|
if(!$token) return;
|
|
$curentuser=$token->getUser();
|
|
|
|
// Roles actif
|
|
if($curentuser=="anon.") $roles="";
|
|
else $roles=$curentuser->getRoles();
|
|
|
|
// App activate
|
|
$portal_activate =$this->container->getParameter('portal_activate');
|
|
$cron_activate =$this->container->getParameter('cron_activate');
|
|
|
|
// Masteridentity
|
|
$masteridentity =$this->container->getParameter('masteridentity');
|
|
$session->set('masteridentity',$masteridentity);
|
|
|
|
// mode_auth
|
|
$mode_auth =$this->container->getParameter('mode_auth');
|
|
$session->set('mode_auth',$mode_auth);
|
|
|
|
// Chargement de la sidebar
|
|
$iconniveau01 =$this->container->getParameter('iconniveau01');
|
|
$labelsniveau01 =$this->container->getParameter('labelsniveau01');
|
|
$labelniveau01 =$this->container->getParameter('labelsniveau01');
|
|
$session->set('labelniveau01',$labelniveau01);
|
|
|
|
$viewniveau02 =$this->container->getParameter('viewniveau02');
|
|
$iconniveau02 =$this->container->getParameter('iconniveau02');
|
|
$labelsniveau02 =$this->container->getParameter('labelsniveau02');
|
|
$labelniveau02 =$this->container->getParameter('labelsniveau02');
|
|
$session->set('labelniveau02',$labelniveau02);
|
|
|
|
$moderegistration =$this->container->getParameter('moderegistration');
|
|
if($masteridentity!="SQL") $moderegistration="none";
|
|
|
|
$sidebar=array();
|
|
$nvs1 = $this->em->getRepository("CadolesCoreBundle:Sidebar")->findBy(array('parent'=> NULL), array('roworder' => 'ASC'));
|
|
foreach($nvs1 as $nv1) {
|
|
|
|
if($this->haveRole($roles,$nv1->getPermission())) {
|
|
$sidebar[$nv1->getRoworder()] = array(
|
|
"fonticon" => $nv1->getFonticon(),
|
|
"label" => $nv1->getLabel(),
|
|
"path" => $nv1->getPath(),
|
|
);
|
|
|
|
if($nv1->getAppactivate()=="portal_activate"&&!$portal_activate) {
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
continue;
|
|
}
|
|
|
|
if($nv1->getAppactivate()=="cron_activate"&&!$cron_activate) {
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
continue;
|
|
}
|
|
|
|
if($nv1->getPath()=="cadoles_core_config_niveau01") {
|
|
$sidebar[$nv1->getRoworder()]["label"]=$labelsniveau01;
|
|
$sidebar[$nv1->getRoworder()]["fonticon"]=$iconniveau01;
|
|
}
|
|
if($nv1->getPath()=="cadoles_core_config_niveau02") {
|
|
if(!$viewniveau02)
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
else {
|
|
$sidebar[$nv1->getRoworder()]["label"]=$labelsniveau02;
|
|
$sidebar[$nv1->getRoworder()]["fonticon"]=$iconniveau02;
|
|
}
|
|
}
|
|
if($nv1->getPath()=="cadoles_core_config_whitelist") {
|
|
if($moderegistration=="none")
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
}
|
|
|
|
foreach($nv1->getChilds() as $nv2) {
|
|
if($this->haveRole($roles,$nv2->getPermission())) {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()] = array (
|
|
"fonticon" => $nv2->getFonticon(),
|
|
"label" => $nv2->getLabel(),
|
|
"path" => $nv2->getPath(),
|
|
);
|
|
|
|
if($nv2->getPath()=="cadoles_core_config_niveau01") {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["label"]=$labelsniveau01;
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["fonticon"]=$iconniveau01;
|
|
}
|
|
if($nv2->getPath()=="cadoles_core_config_niveau02") {
|
|
if(!$viewniveau02)
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
else {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["label"]=$labelsniveau02;
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["fonticon"]=$iconniveau02;
|
|
}
|
|
}
|
|
if($nv2->getPath()=="cadoles_core_config_whitelist") {
|
|
if($moderegistration=="none")
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
}
|
|
if($nv2->getPath()=="cadoles_core_config_registration") {
|
|
if($moderegistration=="none")
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
}
|
|
|
|
foreach($nv2->getChilds() as $nv3) {
|
|
if($this->haveRole($roles,$nv3->getPermission())) {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()] = array (
|
|
"fonticon" => $nv3->getFonticon(),
|
|
"label" => $nv3->getLabel(),
|
|
"path" => $nv3->getPath(),
|
|
);
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_niveau01") {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["label"]=$labelsniveau01;
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["fonticon"]=$iconniveau01;
|
|
}
|
|
if($nv3->getPath()=="cadoles_core_config_niveau02") {
|
|
if(!$viewniveau02)
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
else {
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["label"]=$labelsniveau02;
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["fonticon"]=$iconniveau02;
|
|
}
|
|
}
|
|
if($nv3->getPath()=="cadoles_core_config_whitelist") {
|
|
if($moderegistration=="none"||$moderegistration=="byuser")
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
}
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_registration") {
|
|
if($moderegistration=="none")
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$session->set('sidebar', $sidebar);
|
|
}
|
|
}
|