Skip to content

Commit

Permalink
add pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentG committed Feb 26, 2019
1 parent b2c4fa9 commit 34cceca
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 9 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"knplabs/knp-paginator-bundle": "^2.8",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "4.2.*",
"symfony/console": "4.2.*",
Expand Down
130 changes: 129 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true],
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
];
13 changes: 13 additions & 0 deletions config/packages/knp_paginator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 parameter 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Form\ContactType;
use App\Repository\ProprieteBienRepository;
use Doctrine\Common\Persistence\ObjectManager;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -44,11 +45,17 @@ public function home():Response
}

/**
* @param PaginatorInterface $paginator
* @param Request $request
* @return Response
*/
public function buyHome():Response
public function buyHome(PaginatorInterface $paginator, Request $request):Response
{
$propriete_bien = $this->repository->findAll();
$propriete_bien = $paginator->paginate(
$this->repository->findAllVisibleBien(),
$request->query->getInt('page', 1),
6
);

return $this->render('buy.html.twig', [
'current_menu' => 'buy_properties',
Expand Down
1 change: 0 additions & 1 deletion src/Entity/ProprieteBien.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ProprieteBien

/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(min=5, max=30)
*/
private $name;

Expand Down
15 changes: 14 additions & 1 deletion src/Repository/ProprieteBienRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\ProprieteBien;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
Expand All @@ -26,14 +27,26 @@ public function __construct(RegistryInterface $registry)
public function latestBien()
{
return $this->createQueryBuilder('b')
->andwhere('b.sold = false')
->where('b.sold = false')
->orderBy('b.make_at', 'DESC')
->setMaxResults(3)
->getQuery()
->getResult()
;
}

/**
* @return Query
*/
public function findAllVisibleBien(): Query
{
return $this->createQueryBuilder('b')
->where('b.sold = false')
->getQuery()
;

}

// /**
// * @return ProprieteBien[] Returns an array of ProprieteBien objects
// */
Expand Down
6 changes: 6 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
"jms/metadata": {
"version": "1.7.0"
},
"knplabs/knp-components": {
"version": "v1.3.10"
},
"knplabs/knp-paginator-bundle": {
"version": "v2.8.0"
},
"monolog/monolog": {
"version": "1.24.0"
},
Expand Down
12 changes: 9 additions & 3 deletions templates/buy.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<!-- Condition for -->
{% for property in properties %}
<div class="col-4 mt-3">
<a href="{{ path('show', {id: property.id }) }}" class="text-dark card-hover">
<a href="{{ path('show', {id: property.id }) }}" class="text-dark card-hover">
<div class="card">
<div class="card-body">
<img class="card-img-top img-size-2" src="{{ asset('upload/img/image_bien/') }}{{ property.image }}" alt="Card image cap">
<img class="card-img-top img-size-2" src="{{ asset('upload/img/image_bien/') }}{{ property.image }}" alt="Card image cap"/>
<h5 class="card-title">
<p class="text-center">{{ property.name }}</p>
</h5>
Expand All @@ -30,7 +30,13 @@
</div>
</div>
</div>
{% endfor %}
</a>
{% endfor %}
</div>

<div class="panigation mt-5 text-right">
{# (l'objet qui est paginable) #}
{{ knp_pagination_render(properties) }}
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="col-md-4">
<h1>{{ propriety.name }}</h1>
<h2>{{ propriety.nbrrooms }} pieces - {{ propriety.surface }} m2</h2>
<div class="text" style="font-size: 4rem;font-weight: bold;">{{ propriety.price| number_format(0, ",", " ") }}€</div>
<div class="text flex" style="font-size: 4rem;font-weight: bold;">{{ propriety.price| number_format(0, ",", " ") }}€</div>
<div id="myBtn" class="btn btn-primary mt-3"> Contacter l'agence</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions translations/KnpPaginatorBundle.fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label_next: Suivant
label_previous: Précédent

0 comments on commit 34cceca

Please sign in to comment.