diff --git a/assets/styles/app.scss b/assets/styles/app.scss index c6318ff2b63991bfa3dcefc4af7d1700605e9c13..6ee318459b56566ec50bd7fc1e01b30f926f00ce 100644 --- a/assets/styles/app.scss +++ b/assets/styles/app.scss @@ -15,4 +15,6 @@ @import 'lib/_sellingTable'; @import 'lib/_skills'; @import 'lib/_basicLightbox'; -@import 'lib/_pwgen'; \ No newline at end of file +@import 'lib/_pwgen'; +@import 'lib/_pagination'; +@import 'lib/_blogPage'; \ No newline at end of file diff --git a/assets/styles/lib/_blogPage.scss b/assets/styles/lib/_blogPage.scss new file mode 100644 index 0000000000000000000000000000000000000000..e0d31761f27db2fc52c328edfe1fd5cc21206eb8 --- /dev/null +++ b/assets/styles/lib/_blogPage.scss @@ -0,0 +1,6 @@ +.blogPage{ + article { + width: 100%; + margin-bottom: 10px; + } +} \ No newline at end of file diff --git a/assets/styles/lib/_pagination.scss b/assets/styles/lib/_pagination.scss new file mode 100644 index 0000000000000000000000000000000000000000..bcc9fd6a467dff572c512328de411f164843ea19 --- /dev/null +++ b/assets/styles/lib/_pagination.scss @@ -0,0 +1,19 @@ +.pagination { + display: inline-block; + a { + color: $text-color; + float: left; + padding: 8px 16px; + text-decoration: none; + + &.active { + background-color: $accent-color; + color: black; + } + + &:hover { + background-color: $accent-color-2; + color: black; + } + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index c14f702a3ba8cc7b4f9a9b51ad057148af725c1e..3d4fd08e1b315ce2465e29b43c5dfecb5fbf8649 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "ext-ctype": "*", "ext-iconv": "*", "aws/aws-sdk-php": "^3.257", + "babdev/pagerfanta-bundle": "^3.7", "doctrine/doctrine-bundle": "^2.8", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.14", @@ -15,6 +16,8 @@ "erusev/parsedown": "^1.7", "gregwar/captcha": "^1.1", "knplabs/knp-time-bundle": "^1.20", + "pagerfanta/doctrine-orm-adapter": "^3.7", + "pagerfanta/twig": "^3.7", "symfony/console": "6.2.*", "symfony/dotenv": "6.2.*", "symfony/flex": "^2", diff --git a/composer.lock b/composer.lock index 9f066fa46ceae20bf82e569b94b22f44f2a31814..753e981d03121c75965357f03d778ad615b33426 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": "b7ed8d333430e393ceaf403cf82be662", + "content-hash": "a8a88884414c630f8a91b748f1b3c1d1", "packages": [ { "name": "aws/aws-crt-php", @@ -150,6 +150,89 @@ }, "time": "2023-01-13T19:29:27+00:00" }, + { + "name": "babdev/pagerfanta-bundle", + "version": "v3.7.0", + "source": { + "type": "git", + "url": "https://github.com/BabDev/PagerfantaBundle.git", + "reference": "d2760ebc3d22db10f219544323bea432dedc9eb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/BabDev/PagerfantaBundle/zipball/d2760ebc3d22db10f219544323bea432dedc9eb0", + "reference": "d2760ebc3d22db10f219544323bea432dedc9eb0", + "shasum": "" + }, + "require": { + "pagerfanta/core": "^3.1", + "php": "^7.4 || ^8.0", + "symfony/config": "^4.4 || ^5.4 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", + "symfony/deprecation-contracts": "^2.1 || ^3.0", + "symfony/http-foundation": "^4.4 || ^5.4 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", + "symfony/polyfill-php80": "^1.15", + "symfony/property-access": "^4.4 || ^5.4 || ^6.0", + "symfony/routing": "^4.4 || ^5.4 || ^6.0" + }, + "conflict": { + "pagerfanta/twig": "<3.1", + "twig/twig": "<1.35 || >=2.0,<2.5", + "white-october/pagerfanta-bundle": "*" + }, + "require-dev": { + "doctrine/annotations": "^1.8", + "jms/serializer": "^3.0", + "jms/serializer-bundle": "^3.0 || ^4.0", + "matthiasnoback/symfony-dependency-injection-test": "^4.3", + "pagerfanta/twig": "^3.1", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "1.7.2", + "phpstan/phpstan-phpunit": "1.1.1", + "phpstan/phpstan-symfony": "1.2.0", + "phpunit/phpunit": "^9.5", + "symfony/phpunit-bridge": "^5.4 || ^6.0", + "symfony/serializer": "^4.4 || ^5.4 || ^6.0", + "symfony/translation": "^4.4 || ^5.4 || ^6.0", + "symfony/twig-bridge": "^4.4 || ^5.4 || ^6.0", + "symfony/twig-bundle": "^4.4 || ^5.4 || ^6.0", + "twig/twig": "^1.35 || ^2.5 || ^3.0" + }, + "suggest": { + "jms/serializer-bundle": "To use the Pagerfanta class with the JMS Serializer", + "symfony/serializer": "To use the Pagerfanta class with the Symfony Serializer", + "symfony/translation": "To use the Twig templates with translation support", + "twig/twig": "To integrate Pagerfanta with Twig through extensions" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "BabDev\\PagerfantaBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Bundle integrating Pagerfanta with Symfony", + "keywords": [ + "pagerfanta", + "pagination", + "symfony" + ], + "support": { + "issues": "https://github.com/BabDev/PagerfantaBundle/issues", + "source": "https://github.com/BabDev/PagerfantaBundle/tree/v3.7.0" + }, + "funding": [ + { + "url": "https://github.com/mbabker", + "type": "github" + } + ], + "time": "2022-05-27T20:58:26+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", @@ -2425,6 +2508,149 @@ }, "time": "2022-11-12T15:38:23+00:00" }, + { + "name": "pagerfanta/core", + "version": "v3.7.0", + "source": { + "type": "git", + "url": "https://github.com/Pagerfanta/core.git", + "reference": "53c0bfdffc18fb816ae5c08e4bdda0773651bacc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Pagerfanta/core/zipball/53c0bfdffc18fb816ae5c08e4bdda0773651bacc", + "reference": "53c0bfdffc18fb816ae5c08e4bdda0773651bacc", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.4 || ^8.0", + "symfony/deprecation-contracts": "^2.1 || ^3.0", + "symfony/polyfill-php80": "^1.15" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "symfony/phpunit-bridge": "^5.4 || ^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Pagerfanta\\": "./" + }, + "exclude-from-classmap": [ + "Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Core Pagerfanta API", + "keywords": [ + "pagerfanta" + ], + "support": { + "source": "https://github.com/Pagerfanta/core/tree/v3.7.0" + }, + "time": "2022-12-01T22:53:57+00:00" + }, + { + "name": "pagerfanta/doctrine-orm-adapter", + "version": "v3.7.0", + "source": { + "type": "git", + "url": "https://github.com/Pagerfanta/doctrine-orm-adapter.git", + "reference": "a76dccd512cd31c5400030e39bc0793caa13da51" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Pagerfanta/doctrine-orm-adapter/zipball/a76dccd512cd31c5400030e39bc0793caa13da51", + "reference": "a76dccd512cd31c5400030e39bc0793caa13da51", + "shasum": "" + }, + "require": { + "doctrine/orm": "^2.8", + "pagerfanta/core": "^3.0", + "php": "^7.4 || ^8.0", + "symfony/deprecation-contracts": "^2.1 || ^3.0" + }, + "require-dev": { + "doctrine/annotations": "^1.11.1", + "doctrine/cache": "^1.11 || ^2.0", + "phpunit/phpunit": "^9.5", + "symfony/cache": "^4.4 || ^5.4 || ^6.0", + "symfony/phpunit-bridge": "^5.4 || ^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Pagerfanta\\Doctrine\\ORM\\": "./" + }, + "exclude-from-classmap": [ + "Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Pagerfanta adapter for Doctrine ORM", + "keywords": [ + "doctrine", + "orm", + "pagerfanta" + ], + "support": { + "source": "https://github.com/Pagerfanta/doctrine-orm-adapter/tree/v3.7.0" + }, + "time": "2022-12-01T22:53:57+00:00" + }, + { + "name": "pagerfanta/twig", + "version": "v3.7.0", + "source": { + "type": "git", + "url": "https://github.com/Pagerfanta/twig.git", + "reference": "e8f60980242db0e744ef926a0263ff3722f502bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Pagerfanta/twig/zipball/e8f60980242db0e744ef926a0263ff3722f502bf", + "reference": "e8f60980242db0e744ef926a0263ff3722f502bf", + "shasum": "" + }, + "require": { + "pagerfanta/core": "^3.0", + "php": "^7.4 || ^8.0", + "symfony/polyfill-php80": "^1.15", + "twig/twig": "^1.35 || ^2.5 || ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "symfony/phpunit-bridge": "^5.4 || ^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Pagerfanta\\Twig\\": "./" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Twig integration for Pagerfanta", + "keywords": [ + "pagerfanta" + ], + "support": { + "source": "https://github.com/Pagerfanta/twig/tree/v3.7.0" + }, + "time": "2022-12-01T22:53:57+00:00" + }, { "name": "psr/cache", "version": "3.0.0", diff --git a/config/bundles.php b/config/bundles.php index c04e18498f590f358e5c9b515a54489a0f325010..daae8b6137a3293e44c303287cbccbd78b45fc75 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -15,4 +15,5 @@ return [ Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true], Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], ]; diff --git a/src/Controller/BlogController.php b/src/Controller/BlogController.php index cceb53b35d64cbc48cd63561dbb5ec9616f34d2a..a3a8beb4f6e70fe87987eaa32c8895adf694034b 100644 --- a/src/Controller/BlogController.php +++ b/src/Controller/BlogController.php @@ -3,22 +3,42 @@ namespace App\Controller; use App\Repository\BlogRepository; +use Pagerfanta\Doctrine\ORM\QueryAdapter; +use Pagerfanta\Pagerfanta; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; class BlogController extends AbstractController { - #[Route('/blog/{id}', methods: ['GET'], name: 'blog')] + #[Route('/blog/{id}', methods: ['GET'], name: 'blogEntry')] public function getBlogEntry(int $id, BlogRepository $blogRepository): Response { $blogEntry = $blogRepository->find($id); if (!$blogEntry) { throw $this->createNotFoundException(); } - return $this->render('pages/blog.html.twig', [ + return $this->render('pages/blog-entry.html.twig', [ 'blog' => $blogEntry ]); } + + #[Route('/blog', methods: ['GET'], name: 'blog')] + public function getBlog(BlogRepository $blogRepository, Request $request): Response + { + $queryBuilder = $blogRepository->createQueryBuilder('b'); + $queryBuilder->orderBy('b.date', 'DESC'); + + $pagination = Pagerfanta::createForCurrentPageWithMaxPerPage( + new QueryAdapter($queryBuilder), + (int)$request->query->get('page', '1'), + 20 + ); + + return $this->render('pages/blog.html.twig', [ + 'pagination' => $pagination, + ]); + } } diff --git a/symfony.lock b/symfony.lock index 5bbdd4f5ea4f14b058a68db98983817854bcc28f..4af3b1a152e488c9c508d102cbe89d28c0592822 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,7 @@ { + "babdev/pagerfanta-bundle": { + "version": "v3.7.0" + }, "doctrine/doctrine-bundle": { "version": "2.8", "recipe": { diff --git a/templates/components/blog_preview.html.twig b/templates/components/blog_preview.html.twig index 3bedbcd85909c3253bb69a5c996a8fc48c204c36..87c16b4c6a7bae6afa32ec29842dff06a248a5b0 100644 --- a/templates/components/blog_preview.html.twig +++ b/templates/components/blog_preview.html.twig @@ -3,7 +3,7 @@ <h2>{{ this.title }}</h2> <p class="breakWord">{{ this.blog.content | striptags |u.truncate(200, ' ...', false) }}.</p> <p class="center"> - <a href="{{ path('blog', {id: this.id}) }}"> + <a href="{{ path('blogEntry', {id: this.id}) }}"> <button>Mehr lesen</button> </a> </p> diff --git a/templates/components/footer.html.twig b/templates/components/footer.html.twig index b5e6e0da579332a4d01cc7c9e5185a26d44dc14b..00a0a9d5b7683779997b414b70b124764966bebd 100644 --- a/templates/components/footer.html.twig +++ b/templates/components/footer.html.twig @@ -9,7 +9,7 @@ <div id="newestPost"><h3>Neueste Beiträge</h3> <ul> {% for blog in blogEntries %} - <li><a href="{{ path('blog', {id: blog.id}) }}">{{ blog.title }}</a></li> + <li><a href="{{ path('blogEntry', {id: blog.id}) }}">{{ blog.title }}</a></li> {% endfor %} </ul> </div> diff --git a/templates/pages/blog-entry.html.twig b/templates/pages/blog-entry.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..996921869cab5495ffd553fe247f00ef8de4ffbd --- /dev/null +++ b/templates/pages/blog-entry.html.twig @@ -0,0 +1,8 @@ +{% extends 'base.html.twig' %} +{% block title %}{{ blog.title }}{% endblock %} +{% block content %} + {{ blog.content | raw }} + <br> + <br> + <small class="date">Veröffentlicht: {{ blog.date | date("d.m.Y") }}</small> +{% endblock %} \ No newline at end of file diff --git a/templates/pages/blog.html.twig b/templates/pages/blog.html.twig index 996921869cab5495ffd553fe247f00ef8de4ffbd..de5076bb5db49e1318e7ed97012546c1aaea05a8 100644 --- a/templates/pages/blog.html.twig +++ b/templates/pages/blog.html.twig @@ -1,8 +1,23 @@ {% extends 'base.html.twig' %} -{% block title %}{{ blog.title }}{% endblock %} +{% block title %}Blog{% endblock %} {% block content %} - {{ blog.content | raw }} - <br> - <br> - <small class="date">Veröffentlicht: {{ blog.date | date("d.m.Y") }}</small> + <div class="blogPage"> + {% for blogEntry in pagination %} + {{ component('blog_preview', {id: blogEntry.id}) }} + {% endfor %} + </div> + {% if pagination.haveToPaginate %} + <div class="pagination"> + {% if pagination.hasPreviousPage %} + <a href="{{ pagerfanta_page_url(pagination, pagination.previousPage) }}">«</a> + {% endif %} + {% for pageNum in range(1, pagination.getNbPages) %} + <a class="{% if pageNum == pagination.getCurrentPage %}active{% endif %}" + href="{{ pagerfanta_page_url(pagination, pageNum) }}">{{ pageNum }}</a> + {% endfor %} + {% if pagination.hasNextPage %} + <a href="{{ pagerfanta_page_url(pagination, pagination.nextPage) }}">»</a> + {% endif %} + </div> + {% endif %} {% endblock %} \ No newline at end of file