<?php
namespace App\Controller;
use App\Service\GlobalAdmin;
use App\Entity\ConfigMessenger ;
use App\Entity\Langue ;
use App\Entity\CommMedia ;
use App\Repository\SocialLinksRepository;
use DateTime;
use App\Repository\AdministrateursRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Repository\GroupeRestrictionRepository;
use App\Repository\GroupeRestrictionPageRepository;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Doctrine\ORM\EntityManagerInterface;
class ConfigMessengerController extends AbstractController
{
public function __construct(SessionInterface $session , Container $container , EntityManagerInterface $em )
{
$this->em = $em ;
$this->session = $session ;
}
/**
* @Route("/config_messenger", name="config_messenger", methods={"GET","POST"} , options={"expose"=true})
*/
public function config_messenger(Request $request,GroupeRestrictionRepository $groupeRestrictionRepository,AdministrateursRepository $AdministrateursRepository,
GroupeRestrictionPageRepository $grouprestrictionpageRepository): Response
{
$accessArray=[];
$niveauAcessPages = [];
$groupeRestrictions = [];
if( ($this->session->get('susrD3p9LjjY86') == 'gA64ya3G5N') && ($request->hasSession()) ){
$admin = $this->session->get('supAdT9m2XJzn4');
}else if(($this->session->get('supAdT9m2XJzn4') != null) && ($request->hasSession())){
$admin = $AdministrateursRepository->findOneBy(['email'=>$this->session->get('supAdT9m2XJzn4')['email']]);
$adminId = $admin->getId();
$groupeRestrictions = $groupeRestrictionRepository->findByAdminId($adminId);
$restrictionPages = $grouprestrictionpageRepository->findByRestriction($groupeRestrictions[0]->getId());
$accessArray = $restrictionPages[0]->getAccess();
$niveauAcessPagesCollection = $restrictionPages[0]->getNiveauAcessPages();
$niveauAcessPagesCollection->initialize();
$niveauAcessPages = $niveauAcessPagesCollection->toArray();
}else {
return $this->redirectToRoute('connexion');
}
return $this->render('config_messenger/index.html.twig', [
'admin' => $admin,
'groupeRestrictions' => $groupeRestrictions,
'pages' => $niveauAcessPages,
'access' => $accessArray,
]);
}
/**
* @Route("/loadConfig", name="loadConfig", methods={"GET","POST"} , options={"expose"=true})
*/
public function loadConfig(EntityManagerInterface $entityManager): JsonResponse {
$config = $entityManager->getRepository(ConfigMessenger::class)->find(1);
return new JsonResponse([
'proposition' => $config ? $config->getProposition() : null,
'preference' => $config ? $config->getPreference() : null,
'messenger' => $config ? $config->getMessenger() : null,
]);
}
/**
* @Route("/saveConfig", name="saveConfig", methods={"GET","POST"} , options={"expose"=true})
*/
public function saveConfig(Request $request, EntityManagerInterface $entityManager): JsonResponse {
$data = json_decode($request->getContent(), true);
$config = $entityManager->getRepository(ConfigMessenger::class)->find(1) ?? new ConfigMessenger();
$config->setProposition($data['proposition']);
$config->setPreference($data['preference']);
$config->setMessenger($data['messenger']);
$config->setDateUpdate(new \DateTime());
$entityManager->persist($config);
$entityManager->flush();
return new JsonResponse(['status' => 'success']);
}
}