From 52b63aaec1f166a0a6b51e047043f6f3c88e2aa6 Mon Sep 17 00:00:00 2001 From: Corentin R Date: Fri, 7 Jun 2024 18:37:32 +0200 Subject: [PATCH 1/8] Ajout controleur Profil --- .env | 4 +- app.session.sql | 7 ++++ config/services.yaml | 4 ++ src/Controller/ProfilController.php | 36 ++++++++++++++++++ src/Entity/{Entity => }/Commentary.php | 0 src/Entity/Entity/.gitignore | 0 src/Entity/{Entity => }/Post.php | 0 src/Entity/{Entity => }/Profil.php | 0 src/Entity/{Entity => }/Tags.php | 0 .../{Repository => }/CommentaryRepository.php | 0 .../{Repository => }/PostRepository.php | 0 .../{Repository => }/ProfilRepository.php | 0 src/Repository/Repository/.gitignore | 0 .../{Repository => }/TagsRepository.php | 0 templates/profil/index.html.twig | 11 ++++++ var/data.db | Bin 98304 -> 98304 bytes 16 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 app.session.sql create mode 100644 src/Controller/ProfilController.php rename src/Entity/{Entity => }/Commentary.php (100%) delete mode 100644 src/Entity/Entity/.gitignore rename src/Entity/{Entity => }/Post.php (100%) rename src/Entity/{Entity => }/Profil.php (100%) rename src/Entity/{Entity => }/Tags.php (100%) rename src/Repository/{Repository => }/CommentaryRepository.php (100%) rename src/Repository/{Repository => }/PostRepository.php (100%) rename src/Repository/{Repository => }/ProfilRepository.php (100%) delete mode 100644 src/Repository/Repository/.gitignore rename src/Repository/{Repository => }/TagsRepository.php (100%) create mode 100644 templates/profil/index.html.twig diff --git a/.env b/.env index f81e782..6e5135c 100644 --- a/.env +++ b/.env @@ -23,10 +23,10 @@ APP_SECRET=5e7ed9de1fd633f917d0e87e2e05f923 # Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml # -# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" +DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" -DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" +# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" ###< doctrine/doctrine-bundle ### ###> symfony/messenger ### diff --git a/app.session.sql b/app.session.sql new file mode 100644 index 0000000..f25d5fa --- /dev/null +++ b/app.session.sql @@ -0,0 +1,7 @@ +INSERT INTO profil (id, name, description, password) +VALUES ( + 7, + 'name:VARCHAR(255)', + 'description:VARCHAR(255)', + 'password:VARCHAR(255)' + ); \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index 2d6a76f..00ecb09 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -22,3 +22,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' \ No newline at end of file diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php new file mode 100644 index 0000000..5b5250e --- /dev/null +++ b/src/Controller/ProfilController.php @@ -0,0 +1,36 @@ + '\d+'])] + public function profil(int $id): Response + { + $profil = $this->mgr->find(Profil::class,$id); + return $this->render('profil/index.html.twig', [ + 'profil' => $profil + ]); + } + + #[Route('/profil/{id}/follow',requirements: ['page' => '\d+'])] + public function followProfil(int $id): Response + { + // $profil = $this->mgr->find(Profil::class,$id); + return $this->render('profil/index.html.twig', [ + // 'profil' => $profil + ]); + } + + + +} diff --git a/src/Entity/Entity/Commentary.php b/src/Entity/Commentary.php similarity index 100% rename from src/Entity/Entity/Commentary.php rename to src/Entity/Commentary.php diff --git a/src/Entity/Entity/.gitignore b/src/Entity/Entity/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/Entity/Entity/Post.php b/src/Entity/Post.php similarity index 100% rename from src/Entity/Entity/Post.php rename to src/Entity/Post.php diff --git a/src/Entity/Entity/Profil.php b/src/Entity/Profil.php similarity index 100% rename from src/Entity/Entity/Profil.php rename to src/Entity/Profil.php diff --git a/src/Entity/Entity/Tags.php b/src/Entity/Tags.php similarity index 100% rename from src/Entity/Entity/Tags.php rename to src/Entity/Tags.php diff --git a/src/Repository/Repository/CommentaryRepository.php b/src/Repository/CommentaryRepository.php similarity index 100% rename from src/Repository/Repository/CommentaryRepository.php rename to src/Repository/CommentaryRepository.php diff --git a/src/Repository/Repository/PostRepository.php b/src/Repository/PostRepository.php similarity index 100% rename from src/Repository/Repository/PostRepository.php rename to src/Repository/PostRepository.php diff --git a/src/Repository/Repository/ProfilRepository.php b/src/Repository/ProfilRepository.php similarity index 100% rename from src/Repository/Repository/ProfilRepository.php rename to src/Repository/ProfilRepository.php diff --git a/src/Repository/Repository/.gitignore b/src/Repository/Repository/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/Repository/Repository/TagsRepository.php b/src/Repository/TagsRepository.php similarity index 100% rename from src/Repository/Repository/TagsRepository.php rename to src/Repository/TagsRepository.php diff --git a/templates/profil/index.html.twig b/templates/profil/index.html.twig new file mode 100644 index 0000000..9056ea7 --- /dev/null +++ b/templates/profil/index.html.twig @@ -0,0 +1,11 @@ +{# templates/profil/show.html.twig #} + +{% extends 'base.html.twig' %} + +{% block title %}Profil - {{ profil.name }}{% endblock %} + +{% block body %} +

Profil: {{ profil.name }}

+

ID: {{ profil.id }}

+

Description: {{ profil.description }}

+{% endblock %} \ No newline at end of file diff --git a/var/data.db b/var/data.db index 6237051ebba684d6509e08829d5e167c640f649f..70112b9c74125cec3dc127074c55dff3f22b2aec 100644 GIT binary patch delta 182 zcmZo@U~6b#n;^}|JWF0lOcG#Y+0DSed$XXzMt)akR#pamTl2ic z+*GSD#~^19#~=+OQ&Y{9)Z*l#%z~24{5%x#g2dwD^8BI{6hVl=iyQ Date: Tue, 11 Jun 2024 00:51:50 +0200 Subject: [PATCH 2/8] Ugly profile but fonctionnal --- src/Controller/ProfilController.php | 6 ++- templates/posts/post.detail.html.twig | 70 ++++++++++++++++++++++++++ templates/profil/index.html.twig | 11 ++++ var/data.db | Bin 98304 -> 98304 bytes 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 templates/posts/post.detail.html.twig diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index 2322baa..fbff2b5 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -20,8 +20,10 @@ class ProfilController extends AbstractController 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 + 'profil' => $profil, + 'posts' => $posts ]); } @@ -30,7 +32,7 @@ class ProfilController extends AbstractController { $profil = $this->mgr->find(Profil::class, $id); if ($profil instanceof Profil) { - $this->curentUser->addFollowing($profil); + $profil->addFollower($this->curentUser); return $this->render('profil/index.html.twig', [ ]); } else { diff --git a/templates/posts/post.detail.html.twig b/templates/posts/post.detail.html.twig new file mode 100644 index 0000000..0e86f85 --- /dev/null +++ b/templates/posts/post.detail.html.twig @@ -0,0 +1,70 @@ +{# 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/index.html.twig b/templates/profil/index.html.twig index 834c16f..376aabb 100644 --- a/templates/profil/index.html.twig +++ b/templates/profil/index.html.twig @@ -21,6 +21,17 @@ +
+

Posts

+ {% if posts|length > 0 %} +
    + {% for post in posts %} + {% include 'posts/post.detail.html.twig' with {'post': post} %} + {% endfor %} +
+ {% endif %} +
+
+ {% if selfFlag %} + + {% elseif connected %} {% if followFlag %} {% else %} From 0df65456c16ca3961229e631f75630a47b8d5406 Mon Sep 17 00:00:00 2001 From: Corentin R Date: Wed, 12 Jun 2024 19:08:57 +0200 Subject: [PATCH 7/8] Using mini --- templates/profil/index.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/profil/index.html.twig b/templates/profil/index.html.twig index 7e9aca1..a380683 100644 --- a/templates/profil/index.html.twig +++ b/templates/profil/index.html.twig @@ -43,7 +43,7 @@ {% if posts|length > 0 %}
    {% for post in posts %} - {% include 'post/post.html.twig' with {'post': post} %} + {% include 'post/post_mini.html.twig' with {'post': post} %} {% endfor %}
{% endif %} From 53cbd4bde864bbac2fbe3d81dccf38d97ff44bfc Mon Sep 17 00:00:00 2001 From: Corentin R Date: Wed, 12 Jun 2024 20:11:54 +0200 Subject: [PATCH 8/8] Merge et adding style --- assets/styles/app.css | 11 ++++++ migrations/Version20240612112105.php | 35 ------------------ migrations/Version20240612121601.php | 35 ------------------ ...11201839.php => Version20240612171415.php} | 5 ++- src/Controller/ProfilController.php | 9 ++++- src/Entity/Profil.php | 5 --- templates/profil/edit.html.twig | 2 +- var/data.db | Bin 98304 -> 102400 bytes 8 files changed, 22 insertions(+), 80 deletions(-) delete mode 100644 migrations/Version20240612112105.php delete mode 100644 migrations/Version20240612121601.php rename migrations/{Version20240611201839.php => Version20240612171415.php} (94%) diff --git a/assets/styles/app.css b/assets/styles/app.css index ebdb11d..08bac17 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -63,6 +63,17 @@ body { 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 */ diff --git a/migrations/Version20240612112105.php b/migrations/Version20240612112105.php deleted file mode 100644 index 451d975..0000000 --- a/migrations/Version20240612112105.php +++ /dev/null @@ -1,35 +0,0 @@ -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'); - } -} diff --git a/migrations/Version20240612121601.php b/migrations/Version20240612121601.php deleted file mode 100644 index f40fbff..0000000 --- a/migrations/Version20240612121601.php +++ /dev/null @@ -1,35 +0,0 @@ -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'); - } -} diff --git a/migrations/Version20240611201839.php b/migrations/Version20240612171415.php similarity index 94% rename from migrations/Version20240611201839.php rename to migrations/Version20240612171415.php index 8d30603..0fd4508 100644 --- a/migrations/Version20240611201839.php +++ b/migrations/Version20240612171415.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240611201839 extends AbstractMigration +final class Version20240612171415 extends AbstractMigration { public function getDescription(): string { @@ -28,7 +28,8 @@ final class Version20240611201839 extends AbstractMigration $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)'); diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index f2d69c7..0540944 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -13,12 +13,17 @@ use Symfony\Component\HttpFoundation\Request; class ProfilController extends AbstractController { - private Profil $currentProfil; + 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 { diff --git a/src/Entity/Profil.php b/src/Entity/Profil.php index ca45e7d..0909a5c 100644 --- a/src/Entity/Profil.php +++ b/src/Entity/Profil.php @@ -188,11 +188,6 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - public function getUserIdentifier(): string - { - return $this->name; - } - public function eraseCredentials(): void { // TODO: Implement eraseCredentials() method. diff --git a/templates/profil/edit.html.twig b/templates/profil/edit.html.twig index 997fd08..6806fec 100644 --- a/templates/profil/edit.html.twig +++ b/templates/profil/edit.html.twig @@ -20,7 +20,7 @@
- +
{% endblock %} diff --git a/var/data.db b/var/data.db index ac0e2523d0c553dfa6e69bf3b528000c409fdcc3..3346c7056132b9f0ce3ad102330854b453996a4d 100644 GIT binary patch delta 637 zcmY+B%TE(g6vpqR(|PoDix%skksCsSCe|?1D$0gPA2CweiWF)LLWOGvES*P(z7iF5 zBasEJW}^{JB-H4lG^TOkLi-Qs))gC9kYHj+j5NW)u;DDu$#>3|oZrb=SfCeH>6KGf z3IM=A$Nk4CaG|VNO$E`OnE{XXs_HUo@!B`sKT*3V^a=stqSzw_d_9+Zf{2AHeL|p5 zxLn)s_>0)Xxw8f*DK~?*0op~|wbq_Z)q)YoSu@1-l$-b#o8T`CwT6t@t{R? zJWFuqz^*kaSvlXR*#6(t1gL4^>>$>Z77NFjq>25GHzWQHXUyre)|`DH}`;}*d^9gRev!pr4vR~fhUca z0^7|pp+dg?Sb<@hD?1r4&%-Bi<69n%_G)s5#SZoSZ#p!-sJmXVY`UxKV(ojYt80_y@3ixAFi0 delta 1050 zcmYLIO>7%Q6rR~#Z@fDrZaTN0BCT_$bV`m(%yWZXG zU*cR6!zD-+P0PVY3S62VK&^$$1um9Q)v7m6T-r;ifFgv_AE|)KtZfNt^;Y}d`@Zk( z_hxo)io3hw{t3@X0Kl>9_}#&iAiS-6*cS-80UT=%2KUhoU2KZMN9cGo7KtX~=VOsr z;%wyH*=Q8UV&l=|cw)5q=G1HC?bZD)I0s?S_Y838F+h*e%jRI@Cxm^F4?*3~O0wc= z_&O56%kf8`u9+5hcTT`wF3<)j5NO}2w*t8-&I{nwyyW$A+0#VEB_dncRJ=3WiqKpai7&$MMg;-Z{E+(Kd)`;i{%$qkY?q-xb-8`3NX=Cj&B{Hj+n^J}{h4B!n5JxoajG}mfkR~lS6Ic+YOXrd(%4`d zHcOp$M`4yY29d+ApB#D#&_5l+e?$Eq9zu@ec}em&;oO^3U#cyfBf`;|ntzBiWd#=2lYWHKTGRoZ-4u3$)6f z9#wpKIii$G`p9M}Z)=fBCz;O4v#EI{Cz}!5w$s{du98~5xK7Oc*w!UubMlfxnOT|c z0qn%CwiX)^cp=!f3O4l3py@vyaagxvdDGaJ#_1b=yz6sf=-Bn1R>9P*h}g) zymIY-h5ljf{~*j0nl54 z@BMEN+#jI*|N3;_5$`A7rM|~JttFYy-z*|D&3k@ze JzE$C~{{WFhGw}cb