<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\ConnexionUser;
use App\Entity\PayementMethod;
use App\Entity\Congre;
use App\Entity\PrixVariableCongre;
use App\Entity\PrixVariable;
use App\Entity\EvenementAVenir;
use App\Entity\Document;
class ProfileController extends AbstractController
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function index(ManagerRegistry $doctrine,Request $request)
{
$session = $this->requestStack->getSession();
if(!$session->has('email'))
{
return $this->redirectToRoute('connexion');
exit();
}else
{
$tab=[];
$email=$session->get('email');
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $email]
);
$repository = $doctrine->getRepository(PayementMethod::class);
$evenement = $repository->findBy(
['id_user' => $p[0]->getId()],
['id' => 'DESC']
);
foreach($evenement as $event)
{
if($event->getUrl()=="0" || $event->getUrl()=="00" )
{
$i_event= $event->getEvenementId();
$repository = $doctrine->getRepository(Congre::class);
$congre = $repository->findBy(
['id' => $i_event]
);
array_push($tab,['id_event'=>$i_event,'title'=>$congre[0]->getTitre(),'image'=>$congre[0]->getImagePrincipale(),'url'=>$event->getUrl(),'date_evenement'=>$congre[0]->getDateEvenement(),'montant'=>$event->getMontant(),'dateAd'=>$event->getdateAd(),'order'=>$event->getOrderNumber(),'pai'=>$event->getPai(),'total'=>$event->getTotal()]);
}
else
{
$i_event= $event->getEvenementautre();
$repository = $doctrine->getRepository(EvenementAVenir::class);
$congre = $repository->findBy(
['id' => $i_event]
);
array_push($tab,['id_event'=>$i_event,'title'=>$congre[0]->getTitre(),'image'=>$congre[0]->getImagePrincipale(),'url'=>$event->getUrl(),'date_evenement'=>$congre[0]->getDateEvenement(),'montant'=>$event->getMontant(),'dateAd'=>$event->getdateAd(),'order'=>$event->getOrderNumber(),'pai'=>$event->getPai(),'total'=>0]);
}
}
}
$email=$session->get('email');
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $email]
);
$tab3=[];
$id_user= $p[0]->getId();
$nb=0;
$payement=$doctrine->getRepository(PayementMethod::class)->findBy(array('id_user' =>$id_user));
foreach($payement as $a)
{
$document = $doctrine->getRepository(Document::class)->findAll();
if($a->getEvenementId()!=NULL)
{
$evenmentTitle=$a->getEvenementId();
}
else if($a->getEvenementautre()!=NULL)
{
$evenmentTitle=$a->getEvenementautre();
}
$evenement = $doctrine->getRepository(Document::class)->findAll();
$ret=false;
foreach($document as $b)
{
if($evenmentTitle == $b->getDocumentAutre() || $evenmentTitle == $b->getDocumentCongre())
array_push($tab3,['evenement'=>$evenmentTitle,'video'=>$b->getVideo(),'file'=>$b->getFileDocument()]);
}
}
$nb=count($tab3);
if($email!="document@astp.tn")
{
$nb=0;
}
$nom=$p[0]->getNom();
$nom.=" ".$p[0]->getPrenom();
return $this->render('profile/profile.html.twig',array(
'tab'=>$tab,'nbcount'=>$nb,'nom'=>$nom
));
}
public function document(ManagerRegistry $doctrine,Request $request)
{
$session = $this->requestStack->getSession();
if(!$session->has('email'))
{
return $this->redirectToRoute('connexion');
exit();
}else
{
$tab=[];
$email=$session->get('email');
$repository = $doctrine->getRepository(ConnexionUser::class);
$p = $repository->findBy(
['email' => $email]
);
}
$tab3=[];
$id_user= $p[0]->getId();
$nb=0;
$payement=$doctrine->getRepository(PayementMethod::class)->findBy(array('id_user' =>$id_user));
foreach($payement as $a)
{
$document = $doctrine->getRepository(Document::class)->findAll();
if($a->getEvenementId()!=NULL)
{
$evenmentTitle=$a->getEvenementId();
}
else if($a->getEvenementautre()!=NULL)
{
$evenmentTitle=$a->getEvenementautre();
}
$evenement = $doctrine->getRepository(Document::class)->findAll();
$ret=false;
for($i=0;$i<count($tab3);$i++)
{
if($tab3[$i]['evenement']==$evenmentTitle) $ret=true;
}
foreach($document as $b)
{
if($evenmentTitle == $b->getDocumentAutre() || $evenmentTitle == $b->getDocumentCongre() && !$ret)
array_push($tab3,['evenement'=>$evenmentTitle,'video'=>$b->getVideo(),'file'=>$b->getFileDocument()]);
}
}
/*
$event = $doctrine->getRepository(EvenementAVenir::class)->findAll();
$document = $doctrine->getRepository(Document::class)->findAll();
$congre = $doctrine->getRepository(Congre::class)->findBy(array('userId' =>$id_user));
foreach($document as $a)
{
$congre = $doctrine->getRepository(Congre::class)->findBy(array('userId' =>$id_user,'titre' =>$a->getEvenementSelect()));
if($congre !=Null)
{
$nb++;
}
}
echo $nb;*/
$nom=$p[0]->getNom();
$nom.=" ".$p[0]->getPrenom();
$email=$session->get('email');
if($email!="document@astp.tn")
{
$tab3=[];
}
return $this->render('profile/document.html.twig',array('tab'=>$tab3,'nbcount'=>$nb,'nom'=>$nom));
}
function deconnexion(ManagerRegistry $doctrine,Request $request)
{
$session = $this->requestStack->getSession();
$session->invalidate();
return $this->redirectToRoute('connexion');
}
}