finish postcontroller

pull/21/head
remrem 5 months ago
commit 787c1e92ab

@ -0,0 +1,10 @@
{
"sqltools.connections": [
{
"previewLimit": 50,
"driver": "SQLite",
"name": "dbapplication",
"database": "${workspaceFolder:Fukafukashita}/var/data.db"
}
]
}

@ -0,0 +1,7 @@
INSERT INTO profil (id, name, description, password)
VALUES (
7,
'name:VARCHAR(255)',
'description:VARCHAR(255)',
'password:VARCHAR(255)'
);

@ -0,0 +1,17 @@
// public/js/scripts.js
function openPopup() {
document.getElementById("followPopup").style.display = "block";
}
function closePopup() {
document.getElementById("followPopup").style.display = "none";
}
// Close the popup if the user clicks outside of it
window.onclick = function(event) {
var popup = document.getElementById("followPopup");
if (event.target == popup) {
popup.style.display = "none";
}
}

@ -1,3 +1,235 @@
body {
background-color: skyblue;
font-family: Arial, sans-serif;
/* background-color: #f0f0f0; */
color: #1a2c4c;
}
.profile-container {
background-color: #fff;
border: 1px solid #5c5d7f;
border-radius: 8px;
margin: 20px auto;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 70%;
}
.profile-header {
display: flex;
align-items: center;
border-bottom: 1px solid #5c5d7f;
padding-bottom: 10px;
margin-bottom: 20px;
}
.profile-image {
border-radius: 50%;
width: 100px;
height: 100px;
object-fit: cover;
margin-right: 20px;
}
.profile-info {
flex-grow: 1;
}
.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;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
text-align: center;
text-decoration: none;
margin: 4px;
}
.delete-button {
background-color: #970c2a;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
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 {
background-color: #5c5d7f;
}
/* public/css/styles.css */
/* Ajoutez les styles existants ici */
.popup {
display: none;
/* Hidden by default */
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
}
.popup-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 400px;
border-radius: 8px;
text-align: center;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
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);
}
header {
background-color: #bda3b6;
padding: 4px;
border-radius: 10px;
border-style: solid;
border-color: #1a2c4c;
border-width: 2px;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-logo {
text-decoration: none;
color: #333;
margin-left: 15px;
}
.nav-link {
text-decoration: none;
color: #333;
margin-right: 30px;
}
nav img {
height: 40px;
}
.nav-links {
display: flex;
align-items: center;
}
.floating-button {
position: fixed;
bottom: 20px;
right: 20px;
width: 60px;
height: 60px;
background-color: #bda3b6;
border: none;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
cursor: pointer;
transition: background-color 0.3s;
border-style: solid;
border-color: #1a2c4c;
border-width: 4px;
padding-bottom: 10px;
font-size: 50px;
color: #1a2c4c;
}
.nav-links a:hover {
color: #494949;
}
.floating-button:hover {
background-color: #72606d;
}

@ -21,10 +21,10 @@ security:
login_path: app_login
check_path: app_login
enable_csrf: true
default_target_path: all post
logout:
path: app_logout
# where to redirect after logout
# target: app_any_route
target: /login
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
@ -35,8 +35,9 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
#- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/logout, role: ROLE_USER}
when@test:
security:

@ -3,3 +3,6 @@ controllers:
path: ../src/Controller/
namespace: App\Controller
type: attribute
profile_follow:
path: /profil/{id}/follow
controller: App\Controller\ProfileController::follow

@ -25,3 +25,7 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\Controller\ProfilController:
arguments:
$mgr: '@doctrine.orm.entity_manager'

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240611131531 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__post AS SELECT id, profil_id, title, text, is_dream, up_vote, down_vote FROM post');
$this->addSql('DROP TABLE post');
$this->addSql('CREATE TABLE post (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, profil_id INTEGER NOT NULL, title VARCHAR(255) DEFAULT NULL, text VARCHAR(512) DEFAULT NULL, is_dream BOOLEAN NOT NULL, up_vote INTEGER DEFAULT 0 NOT NULL, down_vote INTEGER DEFAULT 0 NOT NULL, CONSTRAINT FK_5A8A6C8D275ED078 FOREIGN KEY (profil_id) REFERENCES profil (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO post (id, profil_id, title, text, is_dream, up_vote, down_vote) SELECT id, profil_id, title, text, is_dream, up_vote, down_vote FROM __temp__post');
$this->addSql('DROP TABLE __temp__post');
$this->addSql('CREATE INDEX IDX_5A8A6C8D275ED078 ON post (profil_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__post AS SELECT id, profil_id, title, text, is_dream, up_vote, down_vote FROM post');
$this->addSql('DROP TABLE post');
$this->addSql('CREATE TABLE post (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, profil_id INTEGER NOT NULL, title VARCHAR(255) DEFAULT NULL, text VARCHAR(512) DEFAULT NULL, is_dream BOOLEAN NOT NULL, up_vote INTEGER NOT NULL, down_vote INTEGER NOT NULL, CONSTRAINT FK_5A8A6C8D275ED078 FOREIGN KEY (profil_id) REFERENCES profil (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO post (id, profil_id, title, text, is_dream, up_vote, down_vote) SELECT id, profil_id, title, text, is_dream, up_vote, down_vote FROM __temp__post');
$this->addSql('DROP TABLE __temp__post');
$this->addSql('CREATE INDEX IDX_5A8A6C8D275ED078 ON post (profil_id)');
}
}

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240612095513 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240612095600 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}

@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240605095530 extends AbstractMigration
final class Version20240612225056 extends AbstractMigration
{
public function getDescription(): string
{
@ -23,12 +23,14 @@ final class Version20240605095530 extends AbstractMigration
$this->addSql('CREATE TABLE commentary (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, post_id INTEGER NOT NULL, profil_id INTEGER NOT NULL, text VARCHAR(255) DEFAULT NULL, CONSTRAINT FK_1CAC12CA4B89032C FOREIGN KEY (post_id) REFERENCES post (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1CAC12CA275ED078 FOREIGN KEY (profil_id) REFERENCES profil (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_1CAC12CA4B89032C ON commentary (post_id)');
$this->addSql('CREATE INDEX IDX_1CAC12CA275ED078 ON commentary (profil_id)');
$this->addSql('CREATE TABLE post (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, profil_id INTEGER NOT NULL, title VARCHAR(255) DEFAULT NULL, text VARCHAR(512) DEFAULT NULL, is_dream BOOLEAN NOT NULL, up_vote INTEGER NOT NULL, down_vote INTEGER NOT NULL, CONSTRAINT FK_5A8A6C8D275ED078 FOREIGN KEY (profil_id) REFERENCES profil (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE TABLE post (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, profil_id INTEGER NOT NULL, title VARCHAR(255) DEFAULT NULL, text VARCHAR(512) DEFAULT NULL, is_dream BOOLEAN NOT NULL, up_vote INTEGER DEFAULT 0 NOT NULL, down_vote INTEGER DEFAULT 0 NOT NULL, created_at DATETIME NOT NULL --(DC2Type:datetime_immutable)
, CONSTRAINT FK_5A8A6C8D275ED078 FOREIGN KEY (profil_id) REFERENCES profil (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_5A8A6C8D275ED078 ON post (profil_id)');
$this->addSql('CREATE TABLE post_tags (post_id INTEGER NOT NULL, tags_id INTEGER NOT NULL, PRIMARY KEY(post_id, tags_id), CONSTRAINT FK_A6E9F32D4B89032C FOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_A6E9F32D8D7B4FB4 FOREIGN KEY (tags_id) REFERENCES tags (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_A6E9F32D4B89032C ON post_tags (post_id)');
$this->addSql('CREATE INDEX IDX_A6E9F32D8D7B4FB4 ON post_tags (tags_id)');
$this->addSql('CREATE TABLE profil (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, password VARCHAR(255) DEFAULT NULL)');
$this->addSql('CREATE TABLE profil (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, roles CLOB DEFAULT NULL --(DC2Type:json)
, name VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, password VARCHAR(255) DEFAULT NULL)');
$this->addSql('CREATE TABLE profil_profil (profil_source INTEGER NOT NULL, profil_target INTEGER NOT NULL, PRIMARY KEY(profil_source, profil_target), CONSTRAINT FK_97293BC52E75F621 FOREIGN KEY (profil_source) REFERENCES profil (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_97293BC53790A6AE FOREIGN KEY (profil_target) REFERENCES profil (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('CREATE INDEX IDX_97293BC52E75F621 ON profil_profil (profil_source)');
$this->addSql('CREATE INDEX IDX_97293BC53790A6AE ON profil_profil (profil_target)');

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

@ -21,13 +21,14 @@ class PostController extends AbstractController
}
# DEBUG: Ne doit pas être laissé en production.
#[Route('/post/all', name: 'all post', methods: ['GET'])]
#[Route('/', name: 'all post', methods: ['GET'])]
public function getAllPost(): Response
{
$posts = $this->em->getRepository(Post::class)->findAll();
return $this->render('post/all.html.twig', [
"posts" => $posts
"posts" => $posts,
"title" => "Derniers Posts"
]);
}
@ -52,6 +53,8 @@ class PostController extends AbstractController
#[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])]
public function addPost(Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$post = new Post();
$form = $this->createForm(PostType::class, $post);

@ -2,17 +2,168 @@
namespace App\Controller;
use App\Entity\Profil;
use App\Form\ProfilType;
use App\Repository\PostRepository;
use Doctrine\ORM\EntityManager;
use SebastianBergmann\Environment\Console;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpFoundation\Request;
class ProfilController extends AbstractController
{
#[Route('/profil', name: 'app_profil')]
public function index(): Response
public function __construct(private EntityManager $mgr, private PostRepository $postRepository)
{
}
#[Route(path: "/profil", name: "profil_perso", methods: ["GET"])]
public function baseProfil(): Response
{
try {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
} catch (\Exception $e) {
return $this->redirectToRoute('app_login');
}
return $this->redirectToRoute('profil_show', ['id' => $this->getUser()->getId()]);
}
#[Route('/profil/{id}', name: 'profil_show', requirements: ['page' => '\d+'])]
public function profil(int $id): Response
{
$connected = $this->isGranted('ROLE_USER');
// $connected = $this->isGranted('ROLE_USER') != false;
$profil = $this->mgr->find(Profil::class, $id);
$posts = $profil->getPosts();
return $this->render('profil/index.html.twig', [
'controller_name' => 'ProfilController',
'profil' => $profil,
'posts' => $posts,
'followFlag' => $profil->getFollowers()->contains($this->getUser()),
'selfFlag' => $profil == $this->getUser(),
'connected' => $connected
]);
}
#[Route('/profil/post/follow', name: 'profil_post_follow')]
public function postProfilfollow(): Response
{
try{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->getUser();
$posts = $this->postRepository->getPostFromFollowed($profil);
return $this->render('post/all.html.twig', [
"posts" => $posts,
"title" => "Abonnements"
]);
}
#[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', []);
}
}
#[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')]
// public function new(): Response
// {
// $profil = new Profil();
// return $this->redirectToRoute('profil_show', ['id' => $profil->getId()]);
// }
#[Route('/profil/{id}/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
public function editProfil(int $id, Request $request): Response
{
$profil = $this->mgr->find(Profil::class, $id);
$form = $this->createForm(ProfilType::class, $profil);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$form->getData();
$this->mgr->persist($profil);
$this->mgr->flush();
return $this->redirectToRoute('profil_show', ['id' => $id]);
}
return $this->render('profil/edit.html.twig', [
'form' => $form,
'profil' => $profil,
]);
}
#[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])]
public function followProfil(int $id): Response
{
$profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) {
$profil->addFollower($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', []);
}
}
#[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])]
public function delete(int $id, Request $request): Response
{
$profil = $this->mgr->find(Profil::class, $id);
if (!$profil) {
throw $this->createNotFoundException('The profile does not exist');
}
if ($this->isCsrfTokenValid('delete' . $profil->getId(), $request->request->get('_token'))) {
$this->mgr->remove($profil);
$this->mgr->flush();
$this->addFlash('success', 'Profile deleted successfully');
}
return $this->redirectToRoute('app_login');
}
}

@ -28,8 +28,8 @@ class RegistrationController extends AbstractController
$user,
$form->get('plainPassword')->getData()
);
$user->setRoles(['ROLE_USER']);
$user->setPassword($hashedPassword);
$entityManager->persist($user);
$entityManager->flush();

@ -49,10 +49,14 @@ class Post
#[ORM\ManyToMany(targetEntity: Tags::class, inversedBy: 'posts')]
private Collection $tags;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
public function __construct()
{
$this->commentaries = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
@ -195,4 +199,16 @@ class Post
'maxMessage' => 'Your title cannot be longer than {{ limit }} characters',
]));
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
}

@ -19,6 +19,7 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'json', nullable: true)]
private array $roles = [];
#[ORM\Column(length: 255, nullable: true)]
@ -45,14 +46,23 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface
/**
* @var Collection<int, self>
*/
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'followers')]
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'following')]
private Collection $followers;
/**
* @var Collection<int, self>
*/
#[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 +171,33 @@ 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<int, self>
*/
@ -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<int, self>
*/
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;
}
}

@ -0,0 +1,29 @@
<?php
namespace App\Form;
use App\Entity\Profil;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ProfilType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('description')
// ->add('password')
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Profil::class,
]);
}
}

@ -3,6 +3,7 @@
namespace App\Repository;
use App\Entity\Post;
use App\Entity\Profil;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@ -16,20 +17,21 @@ class PostRepository extends ServiceEntityRepository
parent::__construct($registry, Post::class);
}
// /**
// * @return Post[] Returns an array of Post objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
/**
* @return Post[] Returns an array of Post objects
*/
public function getPostFromFollowed(Profil $profil): array
{
return $this->createQueryBuilder('p')
->innerJoin('p.profil', 'a')
->innerJoin('a.followers', 'f')
->where('f.id = :userId')
->setParameter('userId', $profil->getId())
->orderBy('p.createdAt', 'DESC')
->getQuery()
->getResult();
;
}
// public function findOneBySomeField($value): ?Post
// {

@ -9,7 +9,7 @@ use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Tags>
*/
class agsRepository extends ServiceEntityRepository
class TagsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{

@ -5,15 +5,32 @@
<title>{% block title %}Fukafukashita{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text><text y=%221.3em%22 x=%220.2em%22 font-size=%2276%22 fill=%22%23fff%22>sf</text></svg>">
<link rel="stylesheet" href="{{ asset('css/base.css') }}">
<link rel="stylesheet" href="{{ asset('styles/app.css')}}">
{% block stylesheets %}
{% endblock %}
{% block javascripts %}
{# {% block importmap %}{{ importmap('app') }}{% endblock %} #}
{% endblock %}
</head>
<body>
<header>
<nav>
<div class="nav-links">
<a class="nav-logo" href="/">
<img src="{{ asset('images/logo.jpg') }}" alt="Logo">
</a>
<a class="nav-link" href="/"><h1>FukaFukashita</h1></a>
</div>
<div class="nav-links">
<a href="/profil/post/follow" class="nav-link">Abonnements</a>
<a href="/profil" class="nav-link">Compte</a>
{% if is_granted('ROLE_USER') %}
<a href="/logout" class="nav-link">Se déconnecter</a>
{% endif %}
</div>
</nav>
</header>
{% block body %}{% endblock %}
</body>
<button class="floating-button" onclick="location.href='/post/new'">+</button>
</html>

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #1a2c4c; /* Big Stone */
color: #bda3b6; /* Lily */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.error-container {
text-align: center;
border: 1px solid #38476b; /* Rhino */
background-color: #5c5d7f; /* Comet */
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.error-container h1 {
font-size: 48px;
margin: 0;
color: #928ba2; /* Manatee */
}
.error-container p {
font-size: 18px;
margin: 10px 0 20px;
}
.error-container a {
text-decoration: none;
color: #1a2c4c; /* Big Stone */
font-weight: bold;
border: 1px solid #1a2c4c; /* Big Stone */
padding: 10px 20px;
border-radius: 5px;
background-color: #bda3b6; /* Lily */
}
.error-container a:hover {
background-color: #928ba2; /* Manatee */
}
</style>
</head>
<body>
<div class="error-container">
<h1>Something went wrong</h1>
<p>We're sorry, but something went wrong. Please try again later.</p>
{# <a href="{{ path('homepage') }}">Go to Homepage</a> #}
</div>
</body>
</html>

@ -1,6 +1,7 @@
{% extends 'base.html.twig' %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset ('styles/app.css')}}">
<link rel="stylesheet" href="{{ asset('css/components/post_mini.css') }}">
{% endblock %}
@ -8,7 +9,7 @@
{% block body%}
<div id="wrapper">
<h1>All posts</h1>
<h1>{{title}}</h1>
{% for post in posts %}
{% include 'post/post_mini.html.twig' with {'post' : post} %}

@ -1,6 +1,7 @@
{% extends 'base.html.twig' %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset ('styles/app.css')}}">
<link rel="stylesheet" href="{{ asset('css/components/form.css') }}">
<link rel="stylesheet" href="{{ asset('css/components/post.css') }}">
{% endblock %}

@ -1,3 +1,4 @@
{% block body %}
<a href="{{ path('display_post', {'id': post.id}) }}">
<div id="post-wrapper">
<div id="post">
@ -13,3 +14,4 @@
</div>
</div>
</a>
{% endblock %}

@ -0,0 +1,30 @@
{# templates/profil/edit.html.twig #}
{% extends 'base.html.twig' %}
{% block title %}Edit Profile{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
<link rel="stylesheet" href="{{ asset('public/css/components/profil.css') }}">
{% endblock %}
{% block body %}
<div class="profile-container">
<h1>Edit Profile</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<button type="submit" class="btn btn-primary follow-button">Save</button>
{{ form_end(form) }}
<form method="post" action="{{ path('profil_delete', {id: profil.id}) }}" onsubmit="return confirm('Are you sure you want to delete this profile?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ profil.id) }}">
<button class="btn btn-danger delete-button">Delete Profile</button>
</form>
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('scripts/scripts.js') }}"></script>
{% endblock %}

@ -0,0 +1,55 @@
{# templates/profil/list.html.twig #}
{% extends 'base.html.twig' %}
{% block title %}Liste des Profils{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
<link rel="stylesheet" href="{{ asset('public/css/components/profil.css') }}">
<style>
.profile-list {
display: flex;
flex-wrap: wrap;
}
.profile-card {
width: calc(100% / 5);
padding: 10px;
box-sizing: border-box;
text-align: center;
border: 1px solid #ddd;
margin: 5px;
}
.profile-card img {
width: 100px;
height: 100px;
object-fit: cover;
}
.profile-card a {
display: block;
margin-top: 10px;
text-decoration: none;
color: #333;
}
.profile-card a:hover {
text-decoration: underline;
}
</style>
{% endblock %}
{% block body %}
<h1> {{title }} : </h1>
<div class="profile-list">
{% for profil in profils %}
<div class="profile-card">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ profil.name }}" alt="Profile Image">
<a href="{{ path('profil_show', {id: profil.id}) }}">{{ profil.name }}</a>
</div>
{% endfor %}
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('scripts/scripts.js') }}"></script>
{% endblock %}

@ -1,20 +1,52 @@
{% extends 'base.html.twig' %}
{% block title %}Hello ProfilController!{% endblock %}
{% block title %}Profil - {{ profil.name }}{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
<link rel="stylesheet" href="{{ asset('css/components/post_mini.css')}}">
{% endblock %}
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
{% block body %}
<div class="profile-container">
<div class="profile-header">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ profil.name }}" alt="Profile Image" class="profile-image">
<div class="profile-info">
<h1>{{ profil.name }}</h1>
<br>
<p>{{ profil.description }}</p>
</div>
</div>
<div class="horizontal-layout">
{% if selfFlag %}
<a href="{{ path('profil_edit', {id: profil.id}) }}" class="follow-button">Edit</a>
{% elseif connected %}
{% if followFlag %}
<a href="{{ path('profil_unfollow', {id: profil.id}) }}" class="follow-button">Unfollow</a>
{% else %}
<a href="{{ path('profil_follow', {id: profil.id}) }}" class="follow-button">Follow</a>
{% endif %}
{% endif %}
{# <a href="{{ path('profil_follow', {id: profil.id}) }}" class="follow-button"></a> #}
<div class="count-container">
<a href="{{ path('profil_followers', {id: profil.id}) }}" class="count-button">{{ profil.followers.count() }} followers</a>
<a href="{{ path('profil_following', {id: profil.id}) }}" class="count-button">{{ profil.following.count() }} following</a>
</div>
</div>
This friendly message is coming from:
<ul>
<li>Your controller at <code>/home/aurian/3eme_annee/assassymfony/fukafukashita/src/Controller/ProfilController.php</code></li>
<li>Your template at <code>/home/aurian/3eme_annee/assassymfony/fukafukashita/templates/profil/index.html.twig</code></li>
</ul>
<div class="posts-container">
{% if posts|length > 0 %}
<ul>
{% for post in posts %}
{% include 'post/post_mini.html.twig' with {'post': post} %}
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('scripts/scripts.js') }}"></script>
{% endblock %}

@ -2,6 +2,10 @@
{% block title %}Register{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
{% endblock %}
{% block body %}
<h1>Register</h1>

@ -2,6 +2,10 @@
{% block title %}Log in!{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset ('styles/app.css')}}">
{% endblock %}
{% block body %}
<form method="post">
{% if error %}
@ -39,4 +43,6 @@
Sign in
</button>
</form>
<a href="/register">Or Register</a>
{% endblock %}

Binary file not shown.
Loading…
Cancel
Save