@ -0,0 +1,41 @@
|
||||
<?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)');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
:root {
|
||||
font-family: "Helvetica", 'Courier New', Courier, monospace;
|
||||
}
|
||||
|
||||
#post-wrapper {
|
||||
width: 70%;
|
||||
background-color: #f2f2f7;
|
||||
margin: 0 auto;
|
||||
border: 3px solid black;
|
||||
border-radius: 1rem;
|
||||
padding: 20px;
|
||||
margin-top: 25vh;
|
||||
}
|
||||
|
||||
#post-info {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3em;
|
||||
}
|
||||
|
||||
p {
|
||||
white-space: pre-wrap;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
#comments {
|
||||
h2 {
|
||||
font-size: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
color: black;
|
||||
}
|
||||
|
||||
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,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Entity\Post;
|
||||
use App\Form\Type\PostType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class PostController extends AbstractController
|
||||
{
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
# DEBUG: Ne doit pas être laissé en production.
|
||||
#[Route('/post/all', 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
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/post/{id}',
|
||||
name: 'display post',
|
||||
methods: ['GET'],
|
||||
requirements: ['id' => '\d+']
|
||||
)]
|
||||
public function getPost(int $id): Response
|
||||
{
|
||||
$post = $this->em->getRepository(Post::class)->find($id);
|
||||
|
||||
if (!$post) {
|
||||
}
|
||||
|
||||
return $this->render('post/post.html.twig', [
|
||||
'post' => $post
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])]
|
||||
public function addPost(Request $request): Response
|
||||
{
|
||||
$post = new Post();
|
||||
|
||||
$form = $this->createForm(PostType::class, $post);
|
||||
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$form = $form->getData();
|
||||
$user = $this->getUser();
|
||||
$post->setProfil($user);
|
||||
|
||||
$this->em->persist($post);
|
||||
$this->em->flush();
|
||||
|
||||
return new Response($user->getUserIdentifier());
|
||||
}
|
||||
|
||||
return $this->render('post/new.html.twig', [
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/post/{id}', name: 'remove_post', methods: ['DELETE'])]
|
||||
public function removePost(int $id): Response
|
||||
{
|
||||
$post = $this->em->getRepository(Post::class)->find($id);
|
||||
$this->em->remove($post);
|
||||
$this->em->flush();
|
||||
|
||||
return new Response();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class PostType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('title', TextType::class)
|
||||
->add('text', TextareaType::class)
|
||||
->add('dream', CheckboxType::class)
|
||||
// ->add('tags', ChoiceType::class, [
|
||||
// "multiple" => true
|
||||
// ])
|
||||
->add('submit', SubmitType::class)
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<h1>All website posts</h1>
|
||||
|
||||
{% for post in posts %}
|
||||
<div>
|
||||
<span>Id: {{ post.id }}</span>
|
||||
<span>Title: {{ post.title }}</span>
|
||||
<span>Content: {{ post.text }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
@ -0,0 +1 @@
|
||||
{{ form(form) }}
|
@ -0,0 +1,25 @@
|
||||
<link rel="stylesheet" href="{{ asset('css/components/post.css') }}">
|
||||
|
||||
<title>{{ post.title }}</title>
|
||||
|
||||
{% block body %}
|
||||
<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="50px">
|
||||
<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 }}</p>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div id="comments">
|
||||
<h2>Comments</h2>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Binary file not shown.
Loading…
Reference in new issue