profilController #16

Merged
corentin.richard merged 15 commits from profilController into master 10 months ago

@ -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,162 @@
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;
max-width: 600px;
margin: 20px auto;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.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);
}

@ -43,6 +43,8 @@
"symfony/web-link": "7.0.7",
"symfony/yaml": "7.0.7",
"twig/extra-bundle": "^2.12|^3.0",
"twig/intl-extra": "^3.10",
"twig/string-extra": "^3.10",
"twig/twig": "^2.12|^3.0"
},
"config": {

133
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "23d2c64b5bd955feec6a3a3d7dd6a841",
"content-hash": "0428f7bdfb99fd81d09175f70a82db43",
"packages": [
{
"name": "composer/semver",
@ -7314,6 +7314,137 @@
],
"time": "2024-05-11T07:35:57+00:00"
},
{
"name": "twig/intl-extra",
"version": "v3.10.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/intl-extra.git",
"reference": "693f6beb8ca91fc6323e01b3addf983812f65c93"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/intl-extra/zipball/693f6beb8ca91fc6323e01b3addf983812f65c93",
"reference": "693f6beb8ca91fc6323e01b3addf983812f65c93",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/intl": "^5.4|^6.4|^7.0",
"twig/twig": "^3.10"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.4|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Twig\\Extra\\Intl\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "A Twig extension for Intl",
"homepage": "https://twig.symfony.com",
"keywords": [
"intl",
"twig"
],
"support": {
"source": "https://github.com/twigphp/intl-extra/tree/v3.10.0"
},
"funding": [
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
"type": "tidelift"
}
],
"time": "2024-05-11T07:35:57+00:00"
},
{
"name": "twig/string-extra",
"version": "v3.10.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/string-extra.git",
"reference": "cd76ed8ae081bcd4fddf549e92e20c5df76c358a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/string-extra/zipball/cd76ed8ae081bcd4fddf549e92e20c5df76c358a",
"reference": "cd76ed8ae081bcd4fddf549e92e20c5df76c358a",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/string": "^5.4|^6.4|^7.0",
"symfony/translation-contracts": "^1.1|^2|^3",
"twig/twig": "^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.4|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Twig\\Extra\\String\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "A Twig extension for Symfony String",
"homepage": "https://twig.symfony.com",
"keywords": [
"html",
"string",
"twig",
"unicode"
],
"support": {
"source": "https://github.com/twigphp/string-extra/tree/v3.10.0"
},
"funding": [
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/twig/twig",
"type": "tidelift"
}
],
"time": "2024-05-11T07:35:57+00:00"
},
{
"name": "twig/twig",
"version": "v3.10.3",

@ -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,35 +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 Version20240612112105 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('ALTER TABLE profil ADD COLUMN roles CLOB DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__profil AS SELECT id, name, description, password FROM profil');
$this->addSql('DROP TABLE profil');
$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('INSERT INTO profil (id, name, description, password) SELECT id, name, description, password FROM __temp__profil');
$this->addSql('DROP TABLE __temp__profil');
}
}

@ -1,35 +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 Version20240612121601 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('ALTER TABLE profil ADD COLUMN roles CLOB DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__profil AS SELECT id, name, description, password FROM profil');
$this->addSql('DROP TABLE profil');
$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('INSERT INTO profil (id, name, description, password) SELECT id, name, description, password FROM __temp__profil');
$this->addSql('DROP TABLE __temp__profil');
}
}

@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240605095530 extends AbstractMigration
final class Version20240612171415 extends AbstractMigration
{
public function getDescription(): string
{
@ -23,12 +23,13 @@ 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, 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)');

@ -0,0 +1,34 @@
:root {
font-family: "Helvetica", 'Courier New', Courier, monospace;
}
#wrapper {
display: flex;
flex-direction: column;
gap: 1rem;
margin: 2em auto;
width: 70%;
>h1 {
color: white;
font-size: 3em;
margin-top: 0;
}
}
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);
}

@ -0,0 +1,24 @@
#post-wrapper {
background-color: #f2f2f7;
border: 3px solid black;
border-radius: 1rem;
padding: 20px;
}
#post-info {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
#post {
h1 {
font-size: 1.5em;
}
p {
white-space: pre-wrap;
font-size: 1em;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

@ -55,12 +55,12 @@ class PostController extends AbstractController
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$post = new Post();
$form = $this->createForm(PostType::class, $post);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//$dateNow = new DateTime();
$form = $form->getData();
$user = $this->getUser();
$post->setProfil($user);

@ -2,17 +2,146 @@
namespace App\Controller;
use App\Entity\Profil;
use App\Form\ProfilType;
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)
{
}
#[Route(path:"/profil", name:"profil_perso", methods: ["GET"])]
public function baseProfil(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
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/{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}/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}/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');
}
}

@ -3,6 +3,7 @@
namespace App\Entity;
use App\Repository\PostRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -24,6 +25,9 @@ class Post
#[ORM\Column]
private ?bool $isDream = null;
// #[ORM\Column()]
// private ?DateTime $dateCreated = null;
#[ORM\Column(options: ["default" => 0])]
private int $upVote = 0;
@ -93,6 +97,18 @@ class Post
return $this;
}
public function getDateCreated(): ?DateTime
{
return $this->dateCreated;
}
public function setDateCreated(?DateTime $dateCreated): static
{
$this->dateCreated = $dateCreated;
return $this;
}
public function getUpVote(): ?int
{
return $this->upVote;

@ -46,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
@ -162,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>
*/
@ -172,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);
}
@ -186,28 +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 getUserIdentifier(): string
public function removeFollowing(self $following): static
{
return $this->name;
}
if ($this->following->removeElement($following)) {
$following->removeFollower($this);
}
public function eraseCredentials(): void
{
// TODO: Implement eraseCredentials() method.
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,
]);
}
}

@ -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,9 +1,11 @@
<h1>All website posts</h1>
<a href="{{ path('add_post') }}" class="btn btn-primary">Créer un nouveau post</a>
{% for post in posts %}
<div>
<span>Id: {{ post.id }}</span>
<span>Title: {{ post.title }}</span>
<span>Content: {{ post.text }}</span>
</div>
{% endfor %}
<link rel="stylesheet" href="{{ asset('css/components/post_mini.css') }}">
<link rel="stylesheet" href="{{ asset('css/components/post_all.css') }}">
<div id="wrapper">
<h1>All posts</h1>
{% for post in posts %}
{% include 'post/post_mini.html.twig' with {'post' : post} %}
{% endfor %}
</div>

@ -0,0 +1,13 @@
<div id="post-wrapper">
<div id="post">
<div id="post-info">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="40px">
<span>{{ post.profil.name }}</span>
{# <span>- {{ post.dateCreated }}</span> #}
<span>- Il y a 3 jours</span>
</div>
<h1 id="post-title">{{ post.title }}</h1>
<p>{{ post.text|u.truncate(150, true, '...') }}</p>
</div>
</div>

@ -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,55 @@
{# templates/profil/show.html.twig #}
{% extends 'base.html.twig' %}
{% block title %}Hello ProfilController!{% endblock %}
{% block title %}Profil - {{ profil.name }}{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('styles/app.css') }}">
<link rel="stylesheet" href="{{ asset('public/css/components/profil.css') }}">
{% 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>
<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>
</div>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
<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>
{% endblock %}
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>
{% block javascripts %}
<script src="{{ asset('scripts/scripts.js') }}"></script>
{% endblock %}

Binary file not shown.
Loading…
Cancel
Save