From d0e86b920191ab5d580a22f557ca2a2340a8062a Mon Sep 17 00:00:00 2001 From: Corentin R Date: Wed, 12 Jun 2024 01:13:03 +0200 Subject: [PATCH] follow adding, and list of followers --- assets/styles/app.css | 75 ++++++++++++++++++++----- dbapplication.session.sql | 3 - src/Controller/ProfilController.php | 54 ++++++++++++++---- src/Entity/Profil.php | 70 +++++++++++++++++------ templates/posts/post.detail.html.twig | 70 ----------------------- templates/profil/follow-list.html.twig | 55 ++++++++++++++++++ templates/profil/followed.html.twig | 0 templates/profil/index.html.twig | 47 ++++++++-------- var/data.db | Bin 98304 -> 98304 bytes 9 files changed, 239 insertions(+), 135 deletions(-) delete mode 100644 templates/posts/post.detail.html.twig create mode 100644 templates/profil/follow-list.html.twig delete mode 100644 templates/profil/followed.html.twig diff --git a/assets/styles/app.css b/assets/styles/app.css index 0238c29..ebdb11d 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -1,9 +1,10 @@ body { font-family: Arial, sans-serif; - background-color: #f0f0f0; + /* background-color: #f0f0f0; */ color: #1a2c4c; } + .profile-container { background-color: #fff; border: 1px solid #5c5d7f; @@ -12,18 +13,18 @@ body { margin: 20px auto; padding: 20px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); -} - -.profile-header { - display: flex; + } + + .profile-header { + display: flex; align-items: center; border-bottom: 1px solid #5c5d7f; padding-bottom: 10px; margin-bottom: 20px; -} + } -.profile-image { - border-radius: 50%; + .profile-image { + border-radius: 50%; width: 100px; height: 100px; object-fit: cover; @@ -32,19 +33,24 @@ body { .profile-info { flex-grow: 1; -} - -.profile-info h1 { - font-size: 24px; + } + + .profile-info h1 { + font-size: 24px; margin: 0; color: #1a2c4c; -} - + } + .profile-info p { margin: 5px 0; color: #38476b; } +.horizontal-layout { + display: flex; + align-items: center; +} + .follow-button { background-color: #38476b; color: #fff; @@ -54,6 +60,30 @@ body { cursor: pointer; text-align: center; text-decoration: none; + margin: 4px; +} + +.count-container { + display: flex; + margin-left: auto; /* Pushes the container to the right */ +} + +.count-button { + background-color: #38476b; + color: #fff; + padding: 10px 20px; + border: none; + border-radius: 4px; + cursor: pointer; + text-align: center; + text-decoration: none; + margin: 4px; +} + + + +.count-button:hover{ + background-color: #5c5d7f; } .follow-button:hover { @@ -102,3 +132,20 @@ body { text-decoration: none; cursor: pointer; } + +html { + --s: 257px; + /* control the size */ + --c1: #38476b; + --c2: #bda3b6; + + --_c: var(--c1) calc(100% - var(--s)/2) 99%, #0000; + --_g: var(--s), #0000 calc(99% - var(--s)/2), var(--_c); + background: + radial-gradient(var(--s) at 100% var(--_g)), + radial-gradient(calc(var(--s)/4) at 50% calc(100%/3), var(--_c)) var(--s) 0, + radial-gradient(var(--s) at 0% var(--_g)) 0 calc(3*var(--s)) var(--c2); + background-size: + calc(2*var(--s)) calc(9*var(--s)/4), + calc(2*var(--s)) calc(3*var(--s)/4); + } \ No newline at end of file diff --git a/dbapplication.session.sql b/dbapplication.session.sql index e52316d..e69de29 100644 --- a/dbapplication.session.sql +++ b/dbapplication.session.sql @@ -1,3 +0,0 @@ -SELECT * FROM profil; - -SELECT * FROM profil_profil; \ No newline at end of file diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index 5f1c295..05b482a 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -16,18 +16,20 @@ class ProfilController extends AbstractController { } - #[Route('/profil/{id}', requirements: ['page' => '\d+'])] + #[Route('/profil/{id}',name:'profil_show', requirements: ['page' => '\d+'])] public function profil(int $id): Response { $profil = $this->mgr->find(Profil::class, $id); $posts = $profil->getPosts(); return $this->render('profil/index.html.twig', [ 'profil' => $profil, - 'posts' => $posts + 'posts' => $posts, + 'followFlag' => $profil->getFollowers()->contains($this->getUser()), + 'selfFlag' => $profil != $this->getUser() ]); } - #[Route('/profil/{id}/follow', requirements: ['page' => '\d+'])] + #[Route('/profil/{id}/follow',name:'profil_follow', requirements: ['page' => '\d+'])] public function followProfil(int $id): Response { $profil = $this->mgr->find(Profil::class, $id); @@ -36,17 +38,49 @@ class ProfilController extends AbstractController $this->mgr->persist($profil); $this->mgr->flush(); $this->addFlash('success',''); - $posts = $profil->getPosts(); - return $this->render('profil/index.html.twig', [ - 'profil' => $profil, - 'posts' => $posts - ]); + return $this->redirectToRoute('profil_show', ['id' => $id]); + } else { + $this->addFlash('error',''); + return $this->render('error.html.twig', []); + } + } + + #[Route('/profil/{id}/unfollow',name:'profil_unfollow', requirements: ['page' => '\d+'])] + public function unfollowProfil(int $id): Response + { + $profil = $this->mgr->find(Profil::class, $id); + if ($profil instanceof Profil) { + $profil->removeFollower($this->getUser()); + $this->mgr->persist($profil); + $this->mgr->flush(); + $this->addFlash('success',''); + return $this->redirectToRoute('profil_show', ['id' => $id]); } else { $this->addFlash('error',''); return $this->render('error.html.twig', []); } - // $profil = $this->mgr->find(Profil::class,$id); - // 'profil' => $profil + } + + #[Route('/profil/{id}/followers',name:'profil_followers', requirements: ['page'=> '\d'])] + public function getFollowers(int $id): Response + { + $profil = $this->mgr->find(Profil::class, $id); + + return $this->render('profil/follow-list.html.twig', [ + 'title'=> 'Followers', + 'profils' => $profil->getFollowers() + ]); + } + + #[Route('/profil/{id}/following',name:'profil_following', requirements: ['page'=> '\d'])] + public function getFollowing(int $id): Response + { + $profil = $this->mgr->find(Profil::class, $id); + + return $this->render('profil/follow-list.html.twig', [ + 'title'=> 'Following', + 'profils' => $profil->getFollowing() + ]); } #[Route('/profil/new', name: 'profil_new')] diff --git a/src/Entity/Profil.php b/src/Entity/Profil.php index a14065f..1683e00 100644 --- a/src/Entity/Profil.php +++ b/src/Entity/Profil.php @@ -45,14 +45,23 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface /** * @var Collection */ - #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'followers')] + #[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'following')] private Collection $followers; + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'followers')] + private Collection $following; + + public function __construct() { $this->posts = new ArrayCollection(); $this->commentaries = new ArrayCollection(); $this->followers = new ArrayCollection(); + $this->following = new ArrayCollection(); + } public function getId(): ?int @@ -161,6 +170,34 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + + public function getRoles(): array + { + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + public function setRoles(array $roles): self + { + $this->roles = $roles; + + return $this; + } + + public function eraseCredentials(): void + { + // TODO: Implement eraseCredentials() method. + } + + public function getUserIdentifier(): string + { + return $this->name; + } + /** * @return Collection */ @@ -171,7 +208,7 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface public function addFollower(self $follower): static { - if (!$this->followers->contains($follower)) { + if (!$this->followers->contains($follower) && $follower!=$this) { $this->followers->add($follower); } @@ -185,29 +222,30 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - public function getRoles(): array + /** + * @return Collection + */ + public function getFollowing(): Collection { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); + return $this->following; } - public function setRoles(array $roles): self + public function addFollowing(self $following): static { - $this->roles = $roles; + if (!$this->following->contains($following) && $following!=$this) { + $this->following->add($following); + $following->addFollower($this); + } return $this; } - public function eraseCredentials(): void + public function removeFollowing(self $following): static { - // TODO: Implement eraseCredentials() method. - } + if ($this->following->removeElement($following)) { + $following->removeFollower($this); + } - public function getUserIdentifier(): string - { - return $this->name; + return $this; } } diff --git a/templates/posts/post.detail.html.twig b/templates/posts/post.detail.html.twig deleted file mode 100644 index 0e86f85..0000000 --- a/templates/posts/post.detail.html.twig +++ /dev/null @@ -1,70 +0,0 @@ -{# templates/post/show.html.twig #} - -{% extends 'base.html.twig' %} - -{% block title %}Post - {{ post.title }}{% endblock %} - -{% block stylesheets %} - -{% endblock %} - -{% block body %} -
-

{{ post.profil.name }}

-

{{ post.title }}

-

{{ post.text }}

-
- Up Votes: {{ post.upVote }} / Down Votes: {{ post.downVote }} -
-
-

Tags:

-
    - {% for tag in post.tags %} -
  • {{ tag.name }}
  • - {% endfor %} -
-
-
-

Commentaires:

- {% for commentary in post.commentaries %} -
-
{{ commentary.profil.name }}
-
{{ commentary.text }}
-
- {% endfor %} -
-
-{% endblock %} diff --git a/templates/profil/follow-list.html.twig b/templates/profil/follow-list.html.twig new file mode 100644 index 0000000..4ade7db --- /dev/null +++ b/templates/profil/follow-list.html.twig @@ -0,0 +1,55 @@ +{# templates/profil/list.html.twig #} + +{% extends 'base.html.twig' %} + +{% block title %}Liste des Profils{% endblock %} + +{% block stylesheets %} + + + +{% endblock %} + +{% block body %} + +

{{title }} :

+
+ {% for profil in profils %} + + {% endfor %} +
+{% endblock %} + +{% block javascripts %} + +{% endblock %} diff --git a/templates/profil/followed.html.twig b/templates/profil/followed.html.twig deleted file mode 100644 index e69de29..0000000 diff --git a/templates/profil/index.html.twig b/templates/profil/index.html.twig index 376aabb..3dc23d0 100644 --- a/templates/profil/index.html.twig +++ b/templates/profil/index.html.twig @@ -6,40 +6,43 @@ {% block stylesheets %} + {% endblock %} {% block body %}
- Profile Image + Profile Image

{{ profil.name }}

-

ID: {{ profil.id }}

-

Description: {{ profil.description }}

+
+

{{ profil.description }}

- +
+ {% if selfFlag %} + {% if followFlag %} + + {% else %} + + {% endif %} + {% endif %} + {# #} + +
-

Posts

- {% if posts|length > 0 %} -
    - {% for post in posts %} - {% include 'posts/post.detail.html.twig' with {'post': post} %} - {% endfor %} -
- {% endif %} -
- - - {% endblock %} diff --git a/var/data.db b/var/data.db index 89c9537fc222ef48f887a8a3dc73bd334bf65702..86fa5e519a8a140f3ee6a87e05cb29fbec13770f 100644 GIT binary patch delta 404 zcmYLF%}N4c6#af?WX5Q2Erg`N0flz`C{eAVq|k}bN(!GN^AV=)%1h&f&m0r&e>-YOb4E47YP(49!$y!~Kc~bP;r6*q&Z` zfOf_YSEHUHTg`>XbFP>n)MIbx?R>}t@tZRmyNn~H53R85q$m_>A?g~F(!mkQJie! z_?NGdnrfxEDK`Z_f({hG-!wg-M5qgS(KWw)Vc2Rl5Ud84LxG*}ikVC+mq!QdM)o|J zx7EY47E?}Fj}y6UWNj-PDTNO9%ta+=6%)ss*-SZ?U#J%z@0f>o1RwCu%6Ntuj!+R( z4zo*~LJ0I7w$Ion@VYn=V@i1T#6NoE1Q;>;1w5Ria{T`)2MES6XivZOz==jlXY9j# F>Kl!|Y-s=h delta 219 zcmZo@U~6b#n;^}|Hc`fzk!@qbB73f{3{3nF82BIXzu7EkaD{*J1AlH&CUz!fQO<(= z;t~c125uk*flUD{3T%x0d<^`28w*+ZC-c>R19JZ`@c#j7e9zATRKm>6$;rE!G2p-a zq6C3W39JI_{J9ML+xc@h7AEpf&b>b!sNoj_|1YoxK?W8^W==*XE}%vfVOADSMoy?O b+;~B#@etL&8TfyL4Pjzn*#29dku?DT)j2gn