From 84ee76f74b3997142057a55ac0c2b6987285ebbf Mon Sep 17 00:00:00 2001 From: rem Date: Wed, 12 Jun 2024 17:22:50 +0200 Subject: [PATCH] add mini post css + twig --- composer.json | 2 + composer.lock | 133 +++++++++++++++++++++++++++- public/css/components/post_all.css | 34 +++++++ public/css/components/post_mini.css | 24 +++++ src/Controller/PostController.php | 4 +- src/Entity/Post.php | 16 ++++ templates/post/all.html.twig | 18 ++-- templates/post/post_mini.html.twig | 13 +++ var/data.db | Bin 102400 -> 102400 bytes 9 files changed, 233 insertions(+), 11 deletions(-) create mode 100644 public/css/components/post_all.css create mode 100644 public/css/components/post_mini.css create mode 100644 templates/post/post_mini.html.twig diff --git a/composer.json b/composer.json index 759ce3c..15798fa 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index d220368..d8c75dc 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/public/css/components/post_all.css b/public/css/components/post_all.css new file mode 100644 index 0000000..a2cdfa2 --- /dev/null +++ b/public/css/components/post_all.css @@ -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); +} \ No newline at end of file diff --git a/public/css/components/post_mini.css b/public/css/components/post_mini.css new file mode 100644 index 0000000..0ed7a8e --- /dev/null +++ b/public/css/components/post_mini.css @@ -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; + } +} diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index 7548d15..8ba7bf5 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -53,12 +53,12 @@ class PostController extends AbstractController public function addPost(Request $request): Response { $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); diff --git a/src/Entity/Post.php b/src/Entity/Post.php index 7d7a2db..26143f4 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -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; diff --git a/templates/post/all.html.twig b/templates/post/all.html.twig index 13180f2..159947c 100644 --- a/templates/post/all.html.twig +++ b/templates/post/all.html.twig @@ -1,9 +1,11 @@ -

All website posts

+ + -{% for post in posts %} -
- Id: {{ post.id }} - Title: {{ post.title }} - Content: {{ post.text }} -
-{% endfor %} + +
+

All posts

+ + {% for post in posts %} + {% include 'post/post_mini.html.twig' with {'post' : post} %} + {% endfor %} +
diff --git a/templates/post/post_mini.html.twig b/templates/post/post_mini.html.twig new file mode 100644 index 0000000..0081a38 --- /dev/null +++ b/templates/post/post_mini.html.twig @@ -0,0 +1,13 @@ +
+
+
+ + {{ post.profil.name }} + {# - {{ post.dateCreated }} #} + - Il y a 3 jours +
+ +

{{ post.title }}

+

{{ post.text|u.truncate(150, true, '...') }}

+
+
diff --git a/var/data.db b/var/data.db index 4747b9785c2c2404b9ff7663c4d25034de9e6509..0ab18af60dbd18c60ef554312137011474454495 100644 GIT binary patch delta 179 zcmZozz}B#UZGtqT+(a2?M!Ag%OZa(M_*KuRVrl277c;rC_W xzrw$qzlz^?W1}tqoe*m0046tE@}V( delta 70 zcmZozz}B#UZGtqT%tRSyMwyKXOZYjM_-h#W_wm