Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
5a96f0b4
Commit
5a96f0b4
authored
Jun 14, 2018
by
Mat
Browse files
hop
parent
4f6d5b88
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/APIBundle/Controller/OffreAPIController.php
View file @
5a96f0b4
...
...
@@ -71,7 +71,6 @@ class OffreAPIController extends MasterAPIController
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$offres
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findAllByStatusForRead
(
$status
);
//dump($offres);
return
$this
->
api
(
$offres
);
}
...
...
@@ -112,7 +111,7 @@ class OffreAPIController extends MasterAPIController
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
s
ortedAction
(
Request
$request
,
$id
)
public
function
updateS
ortedAction
(
Request
$request
,
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$offre
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForSorted
(
$id
);
...
...
@@ -143,6 +142,7 @@ class OffreAPIController extends MasterAPIController
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$offre
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForDelete
(
$id
);
// TODO enlever une offre, mais aussi tous les légumes qu'elle contient !!
if
(
$offre
!==
null
)
{
...
...
src/APIBundle/Controller/OffreLegumesAPIController.php
View file @
5a96f0b4
...
...
@@ -7,31 +7,39 @@ class OffreLegumesAPIController extends MasterAPIController
{
/**
* Affichage des légumes classés selon 'sorted'
*
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
readAction
(
$id
)
{
$em
=
$this
->
getDoctrine
()
->
getManager
();
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForRead
(
$id
);
/*
$offre = $em->getRepository('PotageBundle:Offre')->findOneForAPIRead($id);
// TODO utilise actuellement le repository d'une autre action !
$sorted = $offre->getSorted();
if (count($sorted) > 0)
{
$legumes = $em->getRepository('PotageBundle:OffreLegumes')->findAllForSortedRead($id, $sorted);
}
else {
// Récupère l'ordre de tri
$sorted
=
$em
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForAPIRead
(
$id
)
->
getSorted
();
}
*/
if
(
!
empty
(
$sorted
))
{
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForSortedRead
(
$id
,
$sorted
);
$ici
=
'coucou'
;
}
else
{
$legumes
=
$em
->
getRepository
(
'PotageBundle:OffreLegumes'
)
->
findAllForRead
(
$id
);
$ici
=
''
;
}
return
$this
->
render
(
'PotageBundle:Default:test.html.twig'
,
array
(
'ici'
=>
$ici
,
'sorted'
=>
$sorted
,
'c_sorted'
=>
empty
(
$sorted
),
'legumes'
=>
$legumes
));
/*
return $this->api($legumes);
*/
}
}
src/APIBundle/Resources/config/routing.yml
View file @
5a96f0b4
...
...
@@ -101,7 +101,7 @@ api_offre_update_sorted:
requirements
:
id
:
\d+
defaults
:
_controller
:
APIBundle:OffreAPI:
s
orted
_controller
:
APIBundle:OffreAPI:
updateS
orted
methods
:
[
POST
]
api_offre_delete
:
...
...
src/PotageBundle/Controller/OffreLegumesController.php
View file @
5a96f0b4
...
...
@@ -17,7 +17,7 @@ class OffreLegumesController extends MasterController
public
function
ajaxDisplayAction
(
$id
)
{
$offre
=
$this
->
getDoctrine
()
->
getManager
()
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForA
PIRead
(
$id
);
->
getRepository
(
'PotageBundle:Offre'
)
->
findOneForA
jaxDisplay
(
$id
);
if
(
$offre
===
null
)
{
return
$this
->
createNotFoundException
(
'Non trouvé'
);
...
...
src/PotageBundle/Entity/Offre.php
100755 → 100644
View file @
5a96f0b4
...
...
@@ -73,7 +73,7 @@ class Offre
/**
* @var array
* @ORM\Column(name="sorted", type="
array"
)
* @ORM\Column(name="sorted", type="
string", nullable=true
)
*/
private
$sorted
;
...
...
@@ -324,18 +324,16 @@ class Offre
}
/**
* Set sorted
*
* @param
mixed
$sorted
_in
* @param
string
$sorted
*
* @return Offre
*/
public
function
setSorted
(
$sorted
_in
)
public
function
setSorted
(
$sorted
)
{
//$sorted = is_array($sorted_in) ? $sorted_in : explode(",", $sorted_in);
$this
->
sorted
=
$sorted_in
;
$this
->
sorted
=
$sorted
;
return
$this
;
}
...
...
@@ -343,7 +341,7 @@ class Offre
/**
* Get sorted
*
* @return
array
* @return
string
*/
public
function
getSorted
()
{
...
...
src/PotageBundle/Repository/OffreLegumesRepository.php
View file @
5a96f0b4
...
...
@@ -68,6 +68,9 @@ class OffreLegumesRepository extends \Doctrine\ORM\EntityRepository
* @param $id_offre = '22'
* @param $sorted = '20,26,22,27,45,46'
*
//->add('orderBy',
// $qb->expr()->field('ol.id', ':sorted')
//)
*/
//1
...
...
@@ -77,13 +80,10 @@ class OffreLegumesRepository extends \Doctrine\ORM\EntityRepository
'ol.quantiteMin'
,
'ol.quantiteMax'
,
'ol.quantiteStep'
,
'ol.prixUnitaire'
,
'ol.unite'
)
->
where
(
'ol.offre = :id_offre'
)
//->add('orderBy',
// $qb->expr()->field('ol.id', ':sorted')
//)
//->orderBy(FIELD( ol.id, :sorted))
->
orderBy
(
'FIELD( ol.id, :sorted)'
)
->
setParameters
(
array
(
':id_offre'
=>
$id_offre
,
//
':sorted' => $sorted
':sorted'
=>
$sorted
))
;
return
$qb
->
getQuery
()
->
getResult
();
...
...
src/PotageBundle/Repository/OffreRepository.php
View file @
5a96f0b4
...
...
@@ -68,7 +68,6 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
public
function
findOneForSorted
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'o'
)
//->select('o.sorted')
->
where
(
'o.id = :id'
)
->
andWhere
(
'o.status = :status '
)
->
setParameters
(
array
(
...
...
@@ -107,5 +106,18 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public
function
findOneForAjaxDisplay
(
$id
)
{
$qb
=
$this
->
createQueryBuilder
(
'o'
)
->
where
(
'o.id = :id'
)
->
setParameter
(
':id'
,
$id
);
return
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
}
src/PotageBundle/Resources/views/Default/test.html.twig
0 → 100644
View file @
5a96f0b4
{%
extends
'@Potage/layout.html.twig'
%}
{%
block
title
%}
Page de test
{%
endblock
%}
{%
block
body
%}
{{
block
(
'breadcrumb'
)
}}
<h1>
{{
block
(
'title'
)
}}
</h1>
{{
dump
()
}}
{%
endblock
%}
\ No newline at end of file
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