|
@@ -10,26 +10,56 @@ use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
|
|
|
class ProfileController extends AbstractController
|
|
class ProfileController extends AbstractController
|
|
|
{
|
|
{
|
|
|
|
|
+ private function cmp_array($a, $b): int
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($a == $b) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ return ($a > $b) ? -1 : 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
#[Route('/profile/{username}', name: 'profile')]
|
|
#[Route('/profile/{username}', name: 'profile')]
|
|
|
public function index($username): Response
|
|
public function index($username): Response
|
|
|
{
|
|
{
|
|
|
|
|
+ // Vérifie si le profil est celui de l'utilisateur connecté.
|
|
|
|
|
+ $sessionUser = $this->get('session')->get('user');
|
|
|
|
|
+ $me = $sessionUser == $username ? true : false;
|
|
|
|
|
+
|
|
|
|
|
+ // Connexion à la table User
|
|
|
$em = $this->getDoctrine()->getManager();
|
|
$em = $this->getDoctrine()->getManager();
|
|
|
$repository_profile = $em->getRepository(User::class);
|
|
$repository_profile = $em->getRepository(User::class);
|
|
|
|
|
+
|
|
|
|
|
+ // Recherche de l'utilisateur correspondant au profil de la route
|
|
|
$profile = $repository_profile->findOneBy(array('username' => $username));
|
|
$profile = $repository_profile->findOneBy(array('username' => $username));
|
|
|
- $sessionUser = $this->get('session')->get('user');
|
|
|
|
|
- $loginuserprofile = $repository_profile->findOneBy(array('username' => $sessionUser));
|
|
|
|
|
if ($profile === null) {
|
|
if ($profile === null) {
|
|
|
return new Response("Profil non existant");
|
|
return new Response("Profil non existant");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Recherche de l'utilisateur connecté à la session
|
|
|
|
|
+ $loginuserprofile = $repository_profile->findOneBy(array('username' => $sessionUser));
|
|
|
|
|
+
|
|
|
|
|
+ // Vérifie si l'utilisateur connecté est abonné au profil
|
|
|
|
|
+ $follow = $loginuserprofile->getSubscriptions()->contains($profile) ? true : false;
|
|
|
|
|
+
|
|
|
|
|
+ $subscriptionsList = $profile->getSubscriptions();
|
|
|
|
|
+ $followersList = $profile->getFollowers();
|
|
|
|
|
+
|
|
|
|
|
+ // Définition des variables du profil
|
|
|
$username = $profile->getUsername();
|
|
$username = $profile->getUsername();
|
|
|
$isPrivate = $profile->getIsPrivate();
|
|
$isPrivate = $profile->getIsPrivate();
|
|
|
$description = $profile->getDescription();
|
|
$description = $profile->getDescription();
|
|
|
$privateNotAllowed = false;
|
|
$privateNotAllowed = false;
|
|
|
- $me = $sessionUser == $username ? true : false;
|
|
|
|
|
- if (!$me and $isPrivate and !$profile->getSubscriptions()->contains($loginuserprofile)) {
|
|
|
|
|
|
|
+ if (!$me and $isPrivate and !$follow) {
|
|
|
$privateNotAllowed = true;
|
|
$privateNotAllowed = true;
|
|
|
}
|
|
}
|
|
|
- $follow = $loginuserprofile->getSubscriptions()->contains($profile) ? true : false;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Récupération des messages de l'utilisateur
|
|
|
|
|
+ $sub_msg = array();
|
|
|
|
|
+ foreach ($profile->getMessages() as $msg_u) {
|
|
|
|
|
+ array_push($sub_msg, $msg_u);
|
|
|
|
|
+ }
|
|
|
|
|
+ usort($sub_msg, array($this, "cmp_array"));
|
|
|
|
|
+
|
|
|
return $this->render('profile/index.html.twig', [
|
|
return $this->render('profile/index.html.twig', [
|
|
|
'controller_name' => 'ProfileController',
|
|
'controller_name' => 'ProfileController',
|
|
|
'privateNotAllowed' => $privateNotAllowed,
|
|
'privateNotAllowed' => $privateNotAllowed,
|
|
@@ -39,6 +69,9 @@ class ProfileController extends AbstractController
|
|
|
'me' => $me,
|
|
'me' => $me,
|
|
|
'sessionUser' => $sessionUser,
|
|
'sessionUser' => $sessionUser,
|
|
|
'follow' => $follow,
|
|
'follow' => $follow,
|
|
|
|
|
+ 'subscriptionsList' => $subscriptionsList,
|
|
|
|
|
+ 'followersList' => $followersList,
|
|
|
|
|
+ 'messages' => $sub_msg,
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|