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
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:
_controller: APIBundle:LettreAPI:countLegumes
methods: [ GET ]
api_lettre_offre_legumes_read:
path: /lettre/{id}/offre/legumes
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:readOffreLegumes
methods: [ GET ]
## CRUD InfoAPI
......
......@@ -21,7 +21,7 @@ class Lettre
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres"})
* @Serializer\Groups({"readLettres", "readOffreLegumes"})
*/
private $id;
......@@ -29,7 +29,7 @@ class Lettre
* @var int
* @ORM\ManyToOne(targetEntity="PotageBundle\Entity\Offre", inversedBy="lettres")
* @ORM\JoinColumn(name="id_offre", nullable=false)
* @Serializer\Groups({"readLettres"})
* @Serializer\Groups({"readLettres", "readOffreLegumes"})
*/
private $offre;
......
......@@ -22,14 +22,14 @@ class Offre
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readLettres", "readOffres"})
* @Serializer\Groups({"readLettres", "readOffres", "readOffreLegumes"})
*/
private $id;
/**
* @var OffreLegumes[]
* @ORM\OneToMany(targetEntity="PotageBundle\Entity\OffreLegumes", mappedBy="offre")
* @Serializer\Groups({"readOffres"})
* @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/
private $offreLegumes;
......
......@@ -25,7 +25,7 @@ class OffreLegumes
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Serializer\Groups({"readOffres"})
* @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/
private $id;
......@@ -47,6 +47,7 @@ class OffreLegumes
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $createdAt;
......@@ -54,6 +55,7 @@ class OffreLegumes
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $updatedAt;
......@@ -61,7 +63,7 @@ class OffreLegumes
* @var string
*
* @ORM\Column(name="nom", type="string", length=100)
* @Serializer\Groups({"readOffres"})
* @Serializer\Groups({"readOffres", "readOffreLegumes"})
*/
private $nom;
......@@ -69,18 +71,21 @@ class OffreLegumes
* @var string
*
* @ORM\Column(name="description", type="text")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $description;
/**
* @var boolean
* @ORM\Column(name="is_fruit", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $fruit;
/**
* @var boolean
* @ORM\Column(name="is_revente", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $revente;
......@@ -88,6 +93,7 @@ class OffreLegumes
* @var string
*
* @ORM\Column(name="origine", type="string", length=100, nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $origine;
......@@ -95,6 +101,7 @@ class OffreLegumes
* @var float
*
* @ORM\Column(name="prix_unitaire", type="float")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $prixUnitaire;
......@@ -102,6 +109,7 @@ class OffreLegumes
* @var string
*
* @ORM\Column(name="unite", type="string", length=25)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $unite;
......@@ -109,6 +117,7 @@ class OffreLegumes
* @var float
*
* @ORM\Column(name="quantite_min", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $quantiteMin;
......@@ -116,6 +125,7 @@ class OffreLegumes
* @var float
*
* @ORM\Column(name="quantite_max", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $quantiteMax;
......@@ -123,12 +133,14 @@ class OffreLegumes
* @var float
*
* @ORM\Column(name="quantite_step", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $quantiteStep;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
* @Serializer\Groups({"readOffreLegumes"})
*/
private $image;
......@@ -142,6 +154,7 @@ class OffreLegumes
* @var float
*
* @ORM\Column(name="volume_max", type="float", nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $volumeMax;
......@@ -149,6 +162,7 @@ class OffreLegumes
* @var bool
*
* @ORM\Column(name="is_promo", type="boolean")
* @Serializer\Groups({"readOffreLegumes"})
*/
private $isPromo;
......@@ -156,6 +170,7 @@ class OffreLegumes
* @var string
*
* @ORM\Column(name="promo", type="string", length=100, nullable=true)
* @Serializer\Groups({"readOffreLegumes"})
*/
private $promo;
......
......@@ -192,6 +192,20 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
->where('l.id = :id')
->setParameter(':id', $id);
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()
{
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]);
}
......@@ -61,15 +67,26 @@ function insertOffre()
*/
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 json = JSON.parse(request.responseText);
let jsonLegumes = json[0].offre.offre_legumes;
for (let i = 0; i < jsonLegumes.length; i++ )
{
let div = buildItemOffreLegumes(jsonLegumes[i]);
let div = document.createElement('div');
div.classList.add('ui-state-default', 'info', 'offre');
div.dataset.infoId = -1;
div.textContent = "OFFRE DE LEGUMES, liée à la lettre " + id_lettre;
//displayPeriodAndOffre(json)
//console.log(div);
//console.log(offre);
return div;
offre.appendChild(div);
}
});
}
......
......@@ -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)
}
/*
* 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
......
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