diff --git a/.idea/php.xml b/.idea/php.xml index 7a74033..b7b18d6 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -107,6 +107,8 @@ + + diff --git a/composer.json b/composer.json index 6836bb1..782d4c3 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "doctrine/doctrine-bundle": "^2.3", "doctrine/doctrine-migrations-bundle": "^3.0", "doctrine/orm": "^2.8", + "knplabs/knp-paginator-bundle": "^5.4", "nelmio/cors-bundle": "^2.1", "phpdocumentor/reflection-docblock": "^5.2", "sensio/framework-extra-bundle": "^5.1", diff --git a/composer.lock b/composer.lock index 7a52ebd..38b4a07 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": "ae2e9c67c9b1291a357031a97bb24bb9", + "content-hash": "7f19c1fbf5a162c6ac24cf3f55978592", "packages": [ { "name": "api-platform/core", @@ -1683,6 +1683,151 @@ ], "time": "2021-01-14T21:52:44+00:00" }, + { + "name": "knplabs/knp-components", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/knp-components.git", + "reference": "7db2eb032591ded5809455af8a4dfdfda079041c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/knp-components/zipball/7db2eb032591ded5809455af8a4dfdfda079041c", + "reference": "7db2eb032591ded5809455af8a4dfdfda079041c", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "symfony/event-dispatcher-contracts": "^1.1 || ^2.0", + "symfony/http-foundation": "^4.4 || ^5.1" + }, + "require-dev": { + "doctrine/mongodb-odm": "^2.0", + "doctrine/orm": "^2.7", + "doctrine/phpcr-odm": "^1.2", + "ext-pdo_sqlite": "*", + "jackalope/jackalope-doctrine-dbal": "^1.2", + "phpunit/phpunit": "^9.5", + "ruflin/elastica": "^7.0", + "symfony/http-kernel": "^4.4 || ^5.1", + "symfony/property-access": "^4.4 || ^5.1" + }, + "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/property-access": "To allow sorting arrays" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.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": "http://github.com/KnpLabs/knp-components", + "keywords": [ + "components", + "knp", + "knplabs", + "pager", + "paginator" + ], + "time": "2021-03-16T13:52:01+00:00" + }, + { + "name": "knplabs/knp-paginator-bundle", + "version": "v5.4.2", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/KnpPaginatorBundle.git", + "reference": "8a7255062dd9f6ff8a3a4712a4b34bdbbc9f31f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/KnpPaginatorBundle/zipball/8a7255062dd9f6ff8a3a4712a4b34bdbbc9f31f7", + "reference": "8a7255062dd9f6ff8a3a4712a4b34bdbbc9f31f7", + "shasum": "" + }, + "require": { + "knplabs/knp-components": "^2.4 || ^3.0", + "php": "^7.3 || ^8.0", + "symfony/config": "^4.4 || ^5.0", + "symfony/dependency-injection": "^4.4 || ^5.0", + "symfony/event-dispatcher": "^4.4 || ^5.0", + "symfony/http-foundation": "^4.4 || ^5.0", + "symfony/http-kernel": "^4.4 || ^5.0", + "symfony/routing": "^4.4 || ^5.0", + "symfony/translation": "^4.4 || ^5.0", + "twig/twig": "^2.0 || ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.5 || ^9.4", + "symfony/expression-language": "^4.4 || ^5.0", + "symfony/templating": "^4.4 || ^5.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": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle/contributors" + } + ], + "description": "Paginator bundle for Symfony to automate pagination and simplify sorting and other features", + "homepage": "http://github.com/KnpLabs/KnpPaginatorBundle", + "keywords": [ + "bundle", + "knp", + "knplabs", + "pager", + "pagination", + "paginator", + "symfony" + ], + "time": "2020-12-17T08:19:16+00:00" + }, { "name": "laminas/laminas-code", "version": "4.0.0", diff --git a/config/bundles.php b/config/bundles.php index d208c11..3e721a1 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -14,4 +14,5 @@ return [ Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true], + Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true], ]; diff --git a/config/packages/paginator.yaml b/config/packages/paginator.yaml new file mode 100644 index 0000000..6e86e99 --- /dev/null +++ b/config/packages/paginator.yaml @@ -0,0 +1,14 @@ +# config/packages/paginator.yaml +knp_paginator: + page_range: 5 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6) + default_options: + page_name: page # page query parameter name + sort_field_name: sort # sort field query parameter name + sort_direction_name: direction # sort direction query parameter name + distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements + filter_field_name: filterField # filter field query parameter name + filter_value_name: filterValue # filter value query paameter name + template: + pagination: '@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig' # sliding pagination controls template + sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template + filtration: '@KnpPaginator/Pagination/filtration.html.twig' # filters template \ No newline at end of file diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..a97cac5 Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000..88a9afe Binary files /dev/null and b/public/icon.png differ diff --git a/src/Controller/PokemonController.php b/src/Controller/PokemonController.php index d9114d5..28314df 100644 --- a/src/Controller/PokemonController.php +++ b/src/Controller/PokemonController.php @@ -5,11 +5,11 @@ namespace App\Controller; use App\Entity\Pokemon; use App\Form\PokemonType; use App\Repository\PokemonRepository; -use phpDocumentor\Reflection\Types\Array_; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Knp\Component\Pager\PaginatorInterface; /** * @Route("/pokemon") @@ -19,18 +19,27 @@ class PokemonController extends AbstractController /** * @Route("/", name="pokemon_index", methods={"GET"}) */ - public function index(PokemonRepository $pokemonRepository, Request $request): Response + public function index(PokemonRepository $pokemonRepository, Request $request, PaginatorInterface $paginator): Response { // Si l'utilisateur saisit un mot clé if ($pokemonSearchTerm = $request->query->get('keyword')) { - return $this->render('pokemon/index.html.twig', [ - 'pokemon' => $pokemonRepository->findPokemonsWithSearchTerm($pokemonSearchTerm), - ]); + $qr = $pokemonRepository->findPokemonsWithSearchTerm($pokemonSearchTerm); + } else { + // Sinon on affichera tout les pokemons + $qr = $pokemonRepository->findAll(); } - // Sinon on affiche tout les pokemons + // Paginate the results of the query + $pokemons = $paginator->paginate( + // TODO: poser la question à Simon (performances moindres avec passage du result ?) + $qr, /*query NOT result*/ + $request->query->getInt('page', 1), /*page number*/ + 15 /*Items per page*/ + ); + + return $this->render('pokemon/index.html.twig', [ - 'pokemon' => $pokemonRepository->findAll(), + 'pokemon' => $pokemons, ]); } diff --git a/symfony.lock b/symfony.lock index ce5c9e5..5e21b47 100644 --- a/symfony.lock +++ b/symfony.lock @@ -105,6 +105,12 @@ "friendsofphp/proxy-manager-lts": { "version": "v1.0.3" }, + "knplabs/knp-components": { + "version": "v3.0.2" + }, + "knplabs/knp-paginator-bundle": { + "version": "v5.4.2" + }, "laminas/laminas-code": { "version": "4.0.0" }, diff --git a/templates/base.html.twig b/templates/base.html.twig index 4dcff18..42c6fac 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -10,18 +10,22 @@ {% endblock %} + +