Commit 5a96f0b4 authored by Mat's avatar Mat
Browse files

hop

parent 4f6d5b88
......@@ -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 sortedAction(Request $request, $id)
public function updateSortedAction(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)
{
......
......@@ -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);
*/
}
}
......@@ -101,7 +101,7 @@ api_offre_update_sorted:
requirements:
id: \d+
defaults:
_controller: APIBundle:OffreAPI:sorted
_controller: APIBundle:OffreAPI:updateSorted
methods: [ POST ]
api_offre_delete:
......
......@@ -17,7 +17,7 @@ class OffreLegumesController extends MasterController
public function ajaxDisplayAction($id)
{
$offre = $this->getDoctrine()->getManager()
->getRepository('PotageBundle:Offre')->findOneForAPIRead($id);
->getRepository('PotageBundle:Offre')->findOneForAjaxDisplay($id);
if ($offre === null) {
return $this->createNotFoundException('Non trouvé');
......
......@@ -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()
{
......
......@@ -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();
......
......@@ -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();
}
}
{% 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment