From 3ce3c47a2e2a91634c3bae88152437d1287dd8f9 Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 25 Jul 2024 22:42:50 +0200 Subject: [PATCH] =?UTF-8?q?ajoute=20le=20tri=20des=20t=C3=A2ches=20sur=20l?= =?UTF-8?q?a=20page=20projet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + composer.lock | 257 ++++++++++++++++++++++++++++++++++- config/bundles.php | 1 + config/packages/knp_paginator.yaml | 3 + config/packages/translation.yaml | 7 + src/Controller/ProjectController.php | 13 +- src/Repository/TaskRepository.php | 29 +++- symfony.lock | 16 +++ templates/macro.html.twig | 20 +++ templates/project/show.html.twig | 13 +- translations/.gitignore | 0 11 files changed, 345 insertions(+), 15 deletions(-) create mode 100644 config/packages/knp_paginator.yaml create mode 100644 config/packages/translation.yaml create mode 100644 templates/macro.html.twig create mode 100644 translations/.gitignore diff --git a/composer.json b/composer.json index 58328b3..920f55a 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "doctrine/doctrine-migrations-bundle": "^3.3", "doctrine/orm": "^3.2", "jmikola/geojson": "^1.0", + "knplabs/knp-paginator-bundle": "^6.4", "league/commonmark": "^2.4", "league/html-to-markdown": "^5.1", "stof/doctrine-extensions-bundle": "^1.12", diff --git a/composer.lock b/composer.lock index b8cdfe0..c4a161d 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": "ed07bf1e98cc998eddcf49958cb2835f", + "content-hash": "ca829d8e7eed95a138ef3f7742eaa728", "packages": [ { "name": "behat/transliterator", @@ -1714,6 +1714,167 @@ "time": "2023-12-04T17:19:43+00:00" }, { + "name": "knplabs/knp-components", + "version": "v4.4.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/knp-components.git", + "reference": "59ef316e34e814449d8718d7151946bdbb5e553f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/knp-components/zipball/59ef316e34e814449d8718d7151946bdbb5e553f", + "reference": "59ef316e34e814449d8718d7151946bdbb5e553f", + "shasum": "" + }, + "require": { + "php": "^8.0", + "symfony/event-dispatcher-contracts": "^3.0" + }, + "conflict": { + "doctrine/dbal": "<3.8" + }, + "require-dev": { + "doctrine/dbal": "^3.8 || ^4.0", + "doctrine/mongodb-odm": "^2.5.5", + "doctrine/orm": "^2.13 || ^3.0", + "doctrine/phpcr-odm": "^1.8 || ^2.0", + "ext-pdo_sqlite": "*", + "jackalope/jackalope-doctrine-dbal": "^1.12 || ^2.0", + "phpunit/phpunit": "^9.6", + "propel/propel1": "^1.7", + "ruflin/elastica": "^7.0", + "solarium/solarium": "^6.0", + "symfony/http-foundation": "^5.4.38 || ^6.4.4 || ^7.0", + "symfony/http-kernel": "^5.4.38 || ^6.4.4 || ^7.0", + "symfony/property-access": "^5.4.38 || ^6.4.4 || ^7.0" + }, + "suggest": { + "doctrine/common": "to allow usage pagination with Doctrine ArrayCollection", + "doctrine/mongodb-odm": "to allow usage pagination with Doctrine ODM MongoDB", + "doctrine/orm": "to allow usage pagination with Doctrine ORM", + "doctrine/phpcr-odm": "to allow usage pagination with Doctrine ODM PHPCR", + "propel/propel1": "to allow usage pagination with Propel ORM", + "ruflin/elastica": "to allow usage pagination with ElasticSearch Client", + "solarium/solarium": "to allow usage pagination with Solarium Client", + "symfony/http-foundation": "to retrieve arguments from Request", + "symfony/property-access": "to allow sorting arrays" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Component\\": "src/Knp/Component" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "https://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://github.com/KnpLabs/knp-components/contributors" + } + ], + "description": "Knplabs component library", + "homepage": "https://github.com/KnpLabs/knp-components", + "keywords": [ + "components", + "knp", + "knplabs", + "pager", + "paginator" + ], + "support": { + "issues": "https://github.com/KnpLabs/knp-components/issues", + "source": "https://github.com/KnpLabs/knp-components/tree/v4.4.0" + }, + "time": "2024-04-23T07:05:01+00:00" + }, + { + "name": "knplabs/knp-paginator-bundle", + "version": "v6.4.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/KnpPaginatorBundle.git", + "reference": "a9cbcb3c6be5868a2e16a599c7438149c40b4bda" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/KnpPaginatorBundle/zipball/a9cbcb3c6be5868a2e16a599c7438149c40b4bda", + "reference": "a9cbcb3c6be5868a2e16a599c7438149c40b4bda", + "shasum": "" + }, + "require": { + "knplabs/knp-components": "^4.1", + "php": "^8.1", + "symfony/config": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/translation": "^6.4 || ^7.0", + "twig/twig": "^3.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.11", + "phpunit/phpunit": "^9.6", + "symfony/expression-language": "^6.4 || ^7.0", + "symfony/templating": "^6.4 || ^7.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Bundle\\PaginatorBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "https://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://github.com/KnpLabs/KnpPaginatorBundle/contributors" + } + ], + "description": "Paginator bundle for Symfony to automate pagination and simplify sorting and other features", + "homepage": "https://github.com/KnpLabs/KnpPaginatorBundle", + "keywords": [ + "bundle", + "knp", + "knplabs", + "pager", + "pagination", + "paginator", + "symfony" + ], + "support": { + "issues": "https://github.com/KnpLabs/KnpPaginatorBundle/issues", + "source": "https://github.com/KnpLabs/KnpPaginatorBundle/tree/v6.4.0" + }, + "time": "2024-05-21T16:15:16+00:00" + }, + { "name": "league/commonmark", "version": "2.4.2", "source": { @@ -5493,6 +5654,100 @@ "time": "2024-06-28T09:27:18+00:00" }, { + "name": "symfony/translation", + "version": "v7.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3", + "reference": "cf5ae136e124fc7681b34ce9fac9d5b9ae8ceee3", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "symfony/polyfill-mbstring": "~1.0", + "symfony/translation-contracts": "^2.5|^3.0" + }, + "conflict": { + "symfony/config": "<6.4", + "symfony/console": "<6.4", + "symfony/dependency-injection": "<6.4", + "symfony/http-client-contracts": "<2.5", + "symfony/http-kernel": "<6.4", + "symfony/service-contracts": "<2.5", + "symfony/twig-bundle": "<6.4", + "symfony/yaml": "<6.4" + }, + "provide": { + "symfony/translation-implementation": "2.3|3.0" + }, + "require-dev": { + "nikic/php-parser": "^4.18|^5.0", + "psr/log": "^1|^2|^3", + "symfony/config": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/http-client-contracts": "^2.5|^3.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/intl": "^6.4|^7.0", + "symfony/polyfill-intl-icu": "^1.21", + "symfony/routing": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/yaml": "^6.4|^7.0" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/functions.php" + ], + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools to internationalize your application", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/translation/tree/v7.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-05-31T14:57:53+00:00" + }, + { "name": "symfony/translation-contracts", "version": "v3.5.0", "source": { diff --git a/config/bundles.php b/config/bundles.php index 5aab971..92324a0 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -12,4 +12,5 @@ return [ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], + Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true], ]; diff --git a/config/packages/knp_paginator.yaml b/config/packages/knp_paginator.yaml new file mode 100644 index 0000000..b620e53 --- /dev/null +++ b/config/packages/knp_paginator.yaml @@ -0,0 +1,3 @@ +knp_paginator: + template: + pagination: @KnpPaginator/Pagination/bootstrap_v5_pagination.html.twig diff --git a/config/packages/translation.yaml b/config/packages/translation.yaml new file mode 100644 index 0000000..b3f8f9c --- /dev/null +++ b/config/packages/translation.yaml @@ -0,0 +1,7 @@ +framework: + default_locale: en + translator: + default_path: '%kernel.project_dir%/translations' + fallbacks: + - en + providers: diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index f2b50e1..fb3a087 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Project; +use App\Entity\Task; use App\Form\ProjectType; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -18,8 +19,7 @@ class ProjectController extends AbstractController #[Route('/', name: 'app_project')] public function index(EntityManagerInterface $entityManager): Response { - $repository = $entityManager->getRepository(Project::class); - $projects = $repository->findAll(); + $projects = $entityManager->getRepository(Project::class)->findAll(); $this->addFlash( 'info', @@ -70,8 +70,8 @@ class ProjectController extends AbstractController #[Route('/show/{projectSlug}', name: 'app_project_show')] public function show(EntityManagerInterface $entityManager, $projectSlug): Response { - $repository = $entityManager->getRepository(Project::class); - $project = $repository->findOneBySlug($projectSlug); + $project = $entityManager->getRepository(Project::class)->findOneBySlug($projectSlug); + $tasks = $entityManager->getRepository(Task::class)->findByProjectPaginated($project); if (!$project) { $this->addFlash( @@ -82,14 +82,15 @@ class ProjectController extends AbstractController return $this->redirectToRoute('app_project'); } - $tasks = count($project->getTasks()); + $count = count($project->getTasks()); $this->addFlash( 'info', - sprintf('%s tâche%s trouvée%s', $tasks, ($tasks > 1 ? 's' : ''), ($tasks > 1 ? 's' : '')) + sprintf('%s tâche%s trouvée%s', $count, ($count > 1 ? 's' : ''), ($count > 1 ? 's' : '')) ); return $this->render('project/show.html.twig', [ 'project' => $project, + 'tasks' => $tasks, ]); } diff --git a/src/Repository/TaskRepository.php b/src/Repository/TaskRepository.php index 97061ee..c9a67c2 100644 --- a/src/Repository/TaskRepository.php +++ b/src/Repository/TaskRepository.php @@ -2,18 +2,28 @@ namespace App\Repository; +use App\Entity\Project; use App\Entity\Task; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; - +use Knp\Component\Pager\PaginatorInterface; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; + /** * @extends ServiceEntityRepository */ class TaskRepository extends ServiceEntityRepository { - public function __construct(ManagerRegistry $registry) + protected PaginatorInterface $paginator; + protected Request $request; + + public function __construct(ManagerRegistry $registry, PaginatorInterface $paginator, RequestStack $requestStack) { parent::__construct($registry, Task::class); + + $this->paginator = $paginator; + $this->request = $requestStack->getCurrentRequest(); } // /** @@ -40,4 +50,19 @@ class TaskRepository extends ServiceEntityRepository // ->getOneOrNullResult() // ; // } + + public function findByProjectPaginated(Project $project) + { + $query = $this->createQueryBuilder('t') + ->andWhere('t.project = :project') + ->setParameter('project', $project) + ->getQuery(); + + return $this->paginator->paginate( + $query, + $this->request->query->getInt('page', 1), + 100 + ); + } + } diff --git a/symfony.lock b/symfony.lock index 8491c85..c13fb9e 100644 --- a/symfony.lock +++ b/symfony.lock @@ -38,6 +38,9 @@ "migrations/.gitignore" ] }, + "knplabs/knp-paginator-bundle": { + "version": "v6.4.0" + }, "stof/doctrine-extensions-bundle": { "version": "1.12", "recipe": { @@ -156,6 +159,19 @@ "assets/controllers/hello_controller.js" ] }, + "symfony/translation": { + "version": "7.1", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "6.3", + "ref": "e28e27f53663cc34f0be2837aba18e3a1bef8e7b" + }, + "files": [ + "config/packages/translation.yaml", + "translations/.gitignore" + ] + }, "symfony/twig-bundle": { "version": "7.1", "recipe": { diff --git a/templates/macro.html.twig b/templates/macro.html.twig new file mode 100644 index 0000000..d6a2b03 --- /dev/null +++ b/templates/macro.html.twig @@ -0,0 +1,20 @@ +{% macro paginated(entities, title, column) %} +{{ knp_pagination_sortable(entities, title, column) }} +{% if entities.isSorted(column) %} + +{% if entities.params.direction == 'asc' %} + + + + +{% endif %} +{% if entities.params.direction == 'desc' %} + + + + + +{% endif %} + +{% endif %} +{% endmacro %} diff --git a/templates/project/show.html.twig b/templates/project/show.html.twig index bdb9109..fb60fc3 100644 --- a/templates/project/show.html.twig +++ b/templates/project/show.html.twig @@ -1,4 +1,5 @@ {% extends 'base.html.twig' %} +{% import 'macro.html.twig' as macro %} {% block breadcrumb %} @@ -54,15 +55,15 @@ - - - - - + + + + + - {% for task in project.tasks %} + {% for task in tasks %} diff --git a/translations/.gitignore b/translations/.gitignore new file mode 100644 index 0000000..e69de29
IdentifiantNomÉtatImportanceUrgence{{ macro.paginated(tasks, 'Identifiant', 't.id') }}{{ macro.paginated(tasks, 'Nom', 't.name') }}{{ macro.paginated(tasks, 'État', 't.status') }}{{ macro.paginated(tasks, 'Importance', 't.important') }}{{ macro.paginated(tasks, 'Urgence', 't.urgent') }}
{{ task.id }} {{ task.name }}