Commit 55df0f3c authored by Mat's avatar Mat

Insertion de l'offre dans la lettre, au milieu des infos sortables

parent 10bf134e
...@@ -261,4 +261,15 @@ class LettreAPIController extends MasterAPIController ...@@ -261,4 +261,15 @@ class LettreAPIController extends MasterAPIController
return $this->api($legumes); return $this->api($legumes);
} }
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function readOffreLegumesAction($id)
{
$em = $this->getDoctrine()->getManager();
$legumes = $em->getRepository('PotageBundle:Lettre')->findAllOffreLegumes($id);
return $this->api($legumes, 200, array('readOffreLegumes'));
}
} }
...@@ -252,6 +252,13 @@ api_lettre_count_legumes: ...@@ -252,6 +252,13 @@ api_lettre_count_legumes:
_controller: APIBundle:LettreAPI:countLegumes _controller: APIBundle:LettreAPI:countLegumes
methods: [ GET ] methods: [ GET ]
api_lettre_offre_legumes_read:
path: /lettre/{id}/offre/legumes
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:readOffreLegumes
methods: [ GET ]
## CRUD InfoAPI ## CRUD InfoAPI
......
...@@ -21,7 +21,7 @@ class Lettre ...@@ -21,7 +21,7 @@ class Lettre
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"}) * @Serializer\Groups({"readLettres", "readOffreLegumes"})
*/ */
private $id; private $id;
...@@ -29,7 +29,7 @@ class Lettre ...@@ -29,7 +29,7 @@ class Lettre
* @var int * @var int
* @ORM\ManyToOne(targetEntity="PotageBundle\Entity\Offre", inversedBy="lettres") * @ORM\ManyToOne(targetEntity="PotageBundle\Entity\Offre", inversedBy="lettres")
* @ORM\JoinColumn(name="id_offre", nullable=false) * @ORM\JoinColumn(name="id_offre", nullable=false)
* @Serializer\Groups({"readLettres"}) * @Serializer\Groups({"readLettres", "readOffreLegumes"})
*/ */
private $offre; private $offre;
......
...@@ -22,14 +22,14 @@ class Offre ...@@ -22,14 +22,14 @@ class Offre
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres", "readOffres"}) * @Serializer\Groups({"readLettres", "readOffres", "readOffreLegumes"})
*/ */
private $id; private $id;
/** /**
* @var OffreLegumes[] * @var OffreLegumes[]
* @ORM\OneToMany(targetEntity="PotageBundle\Entity\OffreLegumes", mappedBy="offre") * @ORM\OneToMany(targetEntity="PotageBundle\Entity\OffreLegumes", mappedBy="offre")
* @Serializer\Groups({"readOffres"}) * @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/ */
private $offreLegumes; private $offreLegumes;
......
...@@ -25,7 +25,7 @@ class OffreLegumes ...@@ -25,7 +25,7 @@ class OffreLegumes
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readOffres"}) * @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/ */
private $id; private $id;
...@@ -47,6 +47,7 @@ class OffreLegumes ...@@ -47,6 +47,7 @@ class OffreLegumes
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $createdAt; private $createdAt;
...@@ -54,6 +55,7 @@ class OffreLegumes ...@@ -54,6 +55,7 @@ class OffreLegumes
* @var \DateTime * @var \DateTime
* *
* @ORM\Column(name="updated_at", type="datetime", nullable=true) * @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $updatedAt; private $updatedAt;
...@@ -61,7 +63,7 @@ class OffreLegumes ...@@ -61,7 +63,7 @@ class OffreLegumes
* @var string * @var string
* *
* @ORM\Column(name="nom", type="string", length=100) * @ORM\Column(name="nom", type="string", length=100)
* @Serializer\Groups({"readOffres"}) * @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/ */
private $nom; private $nom;
...@@ -69,18 +71,21 @@ class OffreLegumes ...@@ -69,18 +71,21 @@ class OffreLegumes
* @var string * @var string
* *
* @ORM\Column(name="description", type="text") * @ORM\Column(name="description", type="text")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $description; private $description;
/** /**
* @var boolean * @var boolean
* @ORM\Column(name="is_fruit", type="boolean") * @ORM\Column(name="is_fruit", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $fruit; private $fruit;
/** /**
* @var boolean * @var boolean
* @ORM\Column(name="is_revente", type="boolean") * @ORM\Column(name="is_revente", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $revente; private $revente;
...@@ -88,6 +93,7 @@ class OffreLegumes ...@@ -88,6 +93,7 @@ class OffreLegumes
* @var string * @var string
* *
* @ORM\Column(name="origine", type="string", length=100, nullable=true) * @ORM\Column(name="origine", type="string", length=100, nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $origine; private $origine;
...@@ -95,6 +101,7 @@ class OffreLegumes ...@@ -95,6 +101,7 @@ class OffreLegumes
* @var float * @var float
* *
* @ORM\Column(name="prix_unitaire", type="float") * @ORM\Column(name="prix_unitaire", type="float")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $prixUnitaire; private $prixUnitaire;
...@@ -102,6 +109,7 @@ class OffreLegumes ...@@ -102,6 +109,7 @@ class OffreLegumes
* @var string * @var string
* *
* @ORM\Column(name="unite", type="string", length=25) * @ORM\Column(name="unite", type="string", length=25)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $unite; private $unite;
...@@ -109,6 +117,7 @@ class OffreLegumes ...@@ -109,6 +117,7 @@ class OffreLegumes
* @var float * @var float
* *
* @ORM\Column(name="quantite_min", type="float", nullable=true) * @ORM\Column(name="quantite_min", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $quantiteMin; private $quantiteMin;
...@@ -116,6 +125,7 @@ class OffreLegumes ...@@ -116,6 +125,7 @@ class OffreLegumes
* @var float * @var float
* *
* @ORM\Column(name="quantite_max", type="float", nullable=true) * @ORM\Column(name="quantite_max", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $quantiteMax; private $quantiteMax;
...@@ -123,12 +133,14 @@ class OffreLegumes ...@@ -123,12 +133,14 @@ class OffreLegumes
* @var float * @var float
* *
* @ORM\Column(name="quantite_step", type="float", nullable=true) * @ORM\Column(name="quantite_step", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $quantiteStep; private $quantiteStep;
/** /**
* @ORM\Column(type="string", length=255, nullable=true) * @ORM\Column(type="string", length=255, nullable=true)
* @var string * @var string
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $image; private $image;
...@@ -142,6 +154,7 @@ class OffreLegumes ...@@ -142,6 +154,7 @@ class OffreLegumes
* @var float * @var float
* *
* @ORM\Column(name="volume_max", type="float", nullable=true) * @ORM\Column(name="volume_max", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $volumeMax; private $volumeMax;
...@@ -149,6 +162,7 @@ class OffreLegumes ...@@ -149,6 +162,7 @@ class OffreLegumes
* @var bool * @var bool
* *
* @ORM\Column(name="is_promo", type="boolean") * @ORM\Column(name="is_promo", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $isPromo; private $isPromo;
...@@ -156,6 +170,7 @@ class OffreLegumes ...@@ -156,6 +170,7 @@ class OffreLegumes
* @var string * @var string
* *
* @ORM\Column(name="promo", type="string", length=100, nullable=true) * @ORM\Column(name="promo", type="string", length=100, nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/ */
private $promo; private $promo;
......
...@@ -192,6 +192,20 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository ...@@ -192,6 +192,20 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
->where('l.id = :id') ->where('l.id = :id')
->setParameter(':id', $id); ->setParameter(':id', $id);
return $qb->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getSingleScalarResult();
} }
/**
* @param $id
* @return array
*/
public function findAllOffreLegumes($id)
{
$qb = $this->createQueryBuilder('l')
->join('l.offre', 'o')
->join('o.offreLegumes', 'ol')
->where('l.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getResult();
}
} }
...@@ -46,7 +46,13 @@ function insertOffre() ...@@ -46,7 +46,13 @@ function insertOffre()
{ {
if (parseInt(order[i]) === -1) if (parseInt(order[i]) === -1)
{ {
let offre = getDisplayOffreLegumes(id_lettre); let offre = document.createElement('div');
offre.classList.add('ui-state-default', 'info', 'offre');
offre.id = 'offre';
offre.dataset.infoId = -1;
getDisplayOffreLegumes(id_lettre);
sortable.insertBefore(offre, infoItem[i]); sortable.insertBefore(offre, infoItem[i]);
} }
...@@ -61,15 +67,26 @@ function insertOffre() ...@@ -61,15 +67,26 @@ function insertOffre()
*/ */
function getDisplayOffreLegumes(id_lettre) function getDisplayOffreLegumes(id_lettre)
{ {
//console.log(id_lettre); let URL = Routing.generate('api_lettre_offre_legumes_read', {'id': id_lettre });
AJAX('GET', URL, function(request)
{
let offre = document.querySelector('div#offre');
let div = document.createElement('div'); let json = JSON.parse(request.responseText);
div.classList.add('ui-state-default', 'info', 'offre'); let jsonLegumes = json[0].offre.offre_legumes;
div.dataset.infoId = -1;
div.textContent = "OFFRE DE LEGUMES, liée à la lettre " + id_lettre;
//displayPeriodAndOffre(json)
return div; for (let i = 0; i < jsonLegumes.length; i++ )
{
let div = buildItemOffreLegumes(jsonLegumes[i]);
//console.log(div);
//console.log(offre);
offre.appendChild(div);
}
});
} }
......
...@@ -22,62 +22,6 @@ function reloadGridLegumes() ...@@ -22,62 +22,6 @@ function reloadGridLegumes()
} }
/*
* Construit une rangée du tableau des Offres
* @param json object jsonRow
*/
function buildItemOffreLegumes(jsonRow)
{
//console.log(jsonRow);
let div = document.createElement('div');
div.classList.add('ui-state-default', 'legume');
div.dataset.legumeId = jsonRow.id;
let logo = document.createElement('div');
logo.classList.add('logo', 'lg');
let crop = document.createElement('div');
crop.classList.add('crop');
let img = document.createElement('img');
img.setAttribute('src', '/web/uploads/images/legumes/' + jsonRow.image);
crop.appendChild(img);
logo.appendChild(crop);
div.appendChild(logo);
let texte = document.createElement('div');
texte.classList.add('texte');
let title = document.createElement('h5');
title.innerHTML = jsonRow.nom;
texte.appendChild(title);
div.appendChild(texte);
let dprix = document.createElement('div');
dprix.classList.add('prix');
let prix = document.createElement('span');
prix.classList.add('prix');
prix.textContent = jsonRow.prixUnitaire;
dprix.appendChild(prix);
let devise = document.createElement('span');
devise.classList.add('devise');
devise.textContent = '';
dprix.appendChild(devise);
let unite = document.createElement('span');
unite.classList.add('unite');
unite.textContent = '/' + jsonRow.unite;
dprix.appendChild(unite);
div.appendChild(dprix);
return div;
}
/* /*
* ================================= * =================================
......
...@@ -330,6 +330,63 @@ function countLegumes(lettre) ...@@ -330,6 +330,63 @@ function countLegumes(lettre)
} }
/*
* Construit une rangée du tableau des Offres
* @param json object jsonRow
*/
function buildItemOffreLegumes(jsonRow)
{
console.log(jsonRow);
let div = document.createElement('div');
div.classList.add('ui-state-default', 'legume');
div.dataset.legumeId = jsonRow.id;
let logo = document.createElement('div');
logo.classList.add('logo', 'lg');
let crop = document.createElement('div');
crop.classList.add('crop');
let img = document.createElement('img');
img.setAttribute('src', '/web/uploads/images/legumes/' + jsonRow.image);
crop.appendChild(img);
logo.appendChild(crop);
div.appendChild(logo);
let texte = document.createElement('div');
texte.classList.add('texte');
let title = document.createElement('h5');
title.innerHTML = jsonRow.nom;
texte.appendChild(title);
div.appendChild(texte);
let dprix = document.createElement('div');
dprix.classList.add('prix');
let prix = document.createElement('span');
prix.classList.add('prix');
prix.textContent = jsonRow.prixUnitaire;
dprix.appendChild(prix);
let devise = document.createElement('span');
devise.classList.add('devise');
devise.textContent = '';
dprix.appendChild(devise);
let unite = document.createElement('span');
unite.classList.add('unite');
unite.textContent = '/' + jsonRow.unite;
dprix.appendChild(unite);
div.appendChild(dprix);
return div;
}
/* /*
* F O N C T I O N S A J A X * F O N C T I O N S A J A X
......
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