Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
technobel.sf
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mathieu
technobel.sf
Commits
c0f35cd6
Commit
c0f35cd6
authored
Jul 10, 2018
by
Mat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
un select qui affiche les brasseries par pays
parent
f0759c74
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
2 deletions
+97
-2
0ne/orig/ajax/index4.html
0ne/orig/ajax/index4.html
+35
-0
src/Api2Bundle/Controller/BrasserieController.php
src/Api2Bundle/Controller/BrasserieController.php
+16
-2
src/Api2Bundle/Controller/PaysController.php
src/Api2Bundle/Controller/PaysController.php
+32
-0
src/Api2Bundle/Repository/BrasserieRepository.php
src/Api2Bundle/Repository/BrasserieRepository.php
+14
-0
No files found.
0ne/orig/ajax/index4.html
View file @
c0f35cd6
...
...
@@ -7,6 +7,7 @@
</head>
<body>
<select
id=
"pays"
></select>
<ul
id=
"brasserie"
></ul>
<button
id=
"new"
>
New
</button>
<form
id=
"form"
>
...
...
@@ -20,11 +21,45 @@
$
(
document
).
ready
(
function
()
{
let
targetedId
;
$
.
ajax
({
url
:
"
http://0.0.0.0:81/web/app_dev.php/API/v2/pays/used
"
,
method
:
'
GET
'
,
dataType
:
'
JSON
'
,
success
:
function
(
data
)
{
for
(
let
elem
of
data
)
{
$
(
'
#pays
'
).
append
(
`<option value="
${
elem
.
id
}
">
${
elem
.
nom
}
</option>`
);
}
},
error
:
(
error
)
=>
{
console
.
log
(
error
);
}
});
$
(
'
#pays
'
).
change
(
function
(
e
)
{
$
.
ajax
({
url
:
"
http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie/parPays/
"
+
$
(
this
).
val
(),
dataType
:
'
JSON
'
,
method
:
'
GET
'
,
success
:
data
=>
{
$
(
'
#brasserie
'
).
empty
();
for
(
let
elem
of
data
)
{
$
(
'
#brasserie
'
).
append
(
`<li data-target="
${
elem
.
id
}
">
${
elem
.
nom
}
</li>`
);
}
}
});
});
$
(
'
#new
'
).
click
(
function
(
e
)
{
e
.
preventDefault
();
targetedId
=
undefined
;
$
(
'
input
'
).
val
(
''
);
});
$
.
ajax
({
url
:
"
http://0.0.0.0:81/web/app_dev.php/API/v2/brasserie
"
,
dataType
:
'
JSON
'
,
...
...
src/Api2Bundle/Controller/BrasserieController.php
View file @
c0f35cd6
...
...
@@ -3,6 +3,7 @@
namespace
Api2Bundle\Controller
;
use
Api2Bundle\Entity\Brasserie
;
use
Api2Bundle\Entity\Pays
;
use
Api2Bundle\Form\BrasserieType
;
use
FOS\RestBundle\Controller\Annotations
as
Rest
;
use
FOS\RestBundle\Controller\FOSRestController
;
...
...
@@ -28,7 +29,7 @@ class BrasserieController extends FOSRestController
* @param Brasserie $id
* @Rest\Put(path="/brasserie/{id}")
* @Rest\View()
* @return Brasserie
* @return Brasserie
|\Symfony\Component\Form\FormInterface
*/
public
function
putAction
(
Request
$request
,
Brasserie
$id
)
{
...
...
@@ -67,7 +68,7 @@ class BrasserieController extends FOSRestController
* @param Request $request
* @Rest\Post(path="/brasserie")
* @Rest\View()
* @return Brasserie
* @return Brasserie
|\Symfony\Component\Form\FormInterface
*/
public
function
newAction
(
Request
$request
)
{
...
...
@@ -84,4 +85,17 @@ class BrasserieController extends FOSRestController
}
return
$form
;
}
/**
* @Rest\Get(path="/brasserie/parPays/{paysID}")
* @Rest\View()
* @return Brasserie[]
*/
public
function
getByCountryAction
(
Pays
$paysID
)
{
return
$this
->
getDoctrine
()
->
getRepository
(
Brasserie
::
class
)
->
findBy
(
array
(
'pays'
=>
$paysID
));
}
}
src/Api2Bundle/Controller/PaysController.php
0 → 100644
View file @
c0f35cd6
<?php
namespace
Api2Bundle\Controller
;
use
Api2Bundle\Entity\Brasserie
;
use
Api2Bundle\Entity\Pays
;
use
FOS\RestBundle\Controller\Annotations
as
Rest
;
use
FOS\RestBundle\Controller\FOSRestController
;
class
PaysController
extends
FOSRestController
{
/**
* @Rest\Get(path="/pays/used")
* @Rest\View()
* @return Pays
*/
public
function
getUsedPaysAction
()
{
$repo
=
$this
->
getDoctrine
()
->
getRepository
(
Brasserie
::
class
);
$pays
=
array_map
(
function
(
$brasserie
)
{
/**
* @var $brasserie Brasserie
*/
return
$brasserie
->
getPays
();
},
$repo
->
getPays
());
return
$pays
;
}
}
src/Api2Bundle/Repository/BrasserieRepository.php
View file @
c0f35cd6
<?php
namespace
Api2Bundle\Repository
;
use
Api2Bundle\Entity\Pays
;
/**
* BrasserieRepository
...
...
@@ -10,4 +11,17 @@ namespace Api2Bundle\Repository;
*/
class
BrasserieRepository
extends
\
Doctrine\ORM\EntityRepository
{
/**
* @return Pays
*/
public
function
getPays
()
{
$qb
=
$this
->
createQueryBuilder
(
'b'
)
->
leftJoin
(
'b.pays'
,
'p'
)
->
addSelect
(
'p'
)
->
groupBy
(
'p'
)
;
return
$qb
->
getQuery
()
->
getResult
();
}
}
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