|
@@ -26,16 +26,27 @@ class PrivateDiscussionsController extends AbstractController
|
|
|
->setAction($this->generateUrl('private_discussions'));
|
|
->setAction($this->generateUrl('private_discussions'));
|
|
|
$form = $formBuilder->getForm();
|
|
$form = $formBuilder->getForm();
|
|
|
|
|
|
|
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
|
|
+ $repo_user = $em->getRepository(User::class);
|
|
|
|
|
+ $user = $repo_user->findOneBy(array('username' => $session->get("user")));
|
|
|
|
|
+ $private_discussions = array();
|
|
|
|
|
+ foreach ($user->getPrivateDiscussions() as $pd) {
|
|
|
|
|
+ $participants = $pd->getParticipants();
|
|
|
|
|
+ if ($participants[0] == $user) {
|
|
|
|
|
+ $participant = $participants[1];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $participant = $participants[0];
|
|
|
|
|
+ }
|
|
|
|
|
+ array_push($private_discussions, array($pd->getId() => $participant->getUsername()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if ($request->getMethod() == 'POST') {
|
|
if ($request->getMethod() == 'POST') {
|
|
|
$form->handleRequest($request);
|
|
$form->handleRequest($request);
|
|
|
if ($form->isValid()) {
|
|
if ($form->isValid()) {
|
|
|
- $em = $this->getDoctrine()->getManager();
|
|
|
|
|
- $repo_user = $em->getRepository(User::class);
|
|
|
|
|
$recept = $repo_user->findOneBy(array('username' => $form->get('username')->getData()));
|
|
$recept = $repo_user->findOneBy(array('username' => $form->get('username')->getData()));
|
|
|
if (!$recept) {
|
|
if (!$recept) {
|
|
|
return new Response("Profil non existant");
|
|
return new Response("Profil non existant");
|
|
|
}
|
|
}
|
|
|
- $user = $repo_user->findOneBy(array('username' => $session->get("user")));
|
|
|
|
|
$disc_found = false;
|
|
$disc_found = false;
|
|
|
foreach ($user->getPrivateDiscussions() as $disc) {
|
|
foreach ($user->getPrivateDiscussions() as $disc) {
|
|
|
if(in_array($recept, $disc->getParticipants()->getValues())) {
|
|
if(in_array($recept, $disc->getParticipants()->getValues())) {
|
|
@@ -61,7 +72,8 @@ class PrivateDiscussionsController extends AbstractController
|
|
|
|
|
|
|
|
return $this->render('private_discussions/index.html.twig', [
|
|
return $this->render('private_discussions/index.html.twig', [
|
|
|
'controller_name' => 'PrivateDiscussionsController',
|
|
'controller_name' => 'PrivateDiscussionsController',
|
|
|
- 'form' => $form->createView()
|
|
|
|
|
|
|
+ 'form' => $form->createView(),
|
|
|
|
|
+ 'private_discussions' => $private_discussions
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|