Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
symfony_2504
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lech Sawoń
symfony_2504
Commits
f8e57532
Commit
f8e57532
authored
Oct 27, 2021
by
Lech Sawon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include simple sorting form
parent
fb19fb6b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
14 deletions
+31
-14
CategoryController.php
src/Controller/CategoryController.php
+3
-3
CategoryRepository.php
src/Repository/CategoryRepository.php
+16
-0
_simple_sorting.html.twig
templates/_embed/_simple_sorting.html.twig
+10
-0
index.html.twig
templates/category/index.html.twig
+1
-1
index.html.twig
templates/room/index.html.twig
+1
-10
No files found.
src/Controller/CategoryController.php
View file @
f8e57532
...
...
@@ -22,12 +22,12 @@ final class CategoryController extends AbstractController
/**
* @Route("/", name="category_index", methods={"GET"})
*/
public
function
index
(
CategoryRepository
$categoryRepository
)
:
Response
public
function
index
(
Request
$request
,
CategoryRepository
$categoryRepository
)
:
Response
{
$
this
->
denyAccessUnlessGranted
(
'ROLE_USER
'
);
$
sorting
=
$request
->
query
->
get
(
'sorting
'
);
return
$this
->
render
(
'category/index.html.twig'
,
[
'categories'
=>
$categoryRepository
->
find
All
(),
'categories'
=>
$categoryRepository
->
find
Sorted
(
$sorting
)
]);
}
...
...
src/Repository/CategoryRepository.php
View file @
f8e57532
...
...
@@ -19,4 +19,20 @@ class CategoryRepository extends ServiceEntityRepository
parent
::
__construct
(
$registry
,
Category
::
class
);
}
public
function
findSorted
(
$sorting
)
{
$qb
=
$this
->
createQueryBuilder
(
'category'
);
if
(
'ASC'
===
$sorting
)
{
$qb
->
addOrderBy
(
'category.name'
,
'ASC'
);
}
elseif
(
'DESC'
===
$sorting
)
{
$qb
->
addOrderBy
(
'category.name'
,
'DESC'
);
}
$query
=
$qb
->
getQuery
();
return
$query
->
getResult
();
}
}
templates/_embed/_simple_sorting.html.twig
0 → 100644
View file @
f8e57532
<form>
<label>
<select
name=
"sorting"
>
<option
value=
""
>
Brak
</option>
<option
value=
"ASC"
>
Spadająco
</option>
<option
value=
"DESC"
>
Rosnąco
</option>
</select>
</label>
<input
type=
"submit"
/>
</form>
templates/category/index.html.twig
View file @
f8e57532
...
...
@@ -4,7 +4,7 @@
{%
block
body
%}
<h1>
Category
</h1>
{{
include
(
'_embed/_simple_sorting.html.twig'
)
}}
<table
class=
"table"
>
<thead>
<tr>
...
...
templates/room/index.html.twig
View file @
f8e57532
...
...
@@ -4,16 +4,7 @@
{%
block
body
%}
<h1>
Room index
</h1>
<form>
<label>
<select
name=
"sorting"
>
<option
value=
""
>
Brak
</option>
<option
value=
"ASC"
>
Spadająco
</option>
<option
value=
"DESC"
>
Rosnąco
</option>
</select>
</label>
<input
type=
"submit"
/>
</form>
{{
include
(
'_embed/_simple_sorting.html.twig'
)
}}
<table
class=
"table"
>
<thead>
<tr>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment