Commit 2f105377 authored by Mat's avatar Mat

newsletter: retourne les infos et les légumes triés

parent 391cf5dc
......@@ -82,6 +82,67 @@ class Newsletter
}
/**
* Retourne un tableau d'objets Infos triés,
* contenant un tableau d'objets OffreLegumes triés
*
* @param Lettre $lettre
* @return array
*/
private function getInfosSorted(Lettre $lettre)
{
$sortLettre = explode(",", $lettre->getSorted());
foreach ($sortLettre as $k => $v)
{
if ($v !== "-1")
{
foreach ($lettre->getInfos() as $info)
{
if ($info->getId() === intval($v))
{
$infosSorted[$k] = $info;
}
}
}
else {
$infosSorted[$k] = $this->getOffreLegumesSorted($lettre);
}
}
return $infosSorted;
}
/**
* Retourne un tableau d'objets OffreLegumes triés
*
* @param Lettre $lettre
* @return mixed
*/
private function getOffreLegumesSorted(Lettre $lettre)
{
/**
* @val Offre $offre
*/
$offre = $lettre->getOffre();
$sortLegumes = explode(",", $offre->getSorted());
foreach($sortLegumes as $k => $v)
{
/**
* @val OffreLegumes $legume
*/
foreach ($offre->getOffreLegumes() as $legume)
{
if ($legume->getId() === intval($v))
{
$legumesSorted[$k] = $legume;
}
}
}
return $legumesSorted;
}
/**
* Envoie une infolettre à un destinataire
*
......@@ -97,6 +158,8 @@ class Newsletter
{
$mailer = $this->container->get('mailer');
$twig = $this->container->get('twig');
$itemsSorted = $this->getInfosSorted($this->getBody($lettre));
$message = (new \Swift_Message())
......@@ -108,6 +171,7 @@ class Newsletter
'to' => $to,
'subject' => $subject,
'lettre' => $this->getBody($lettre),
'itemsSorted' => $itemsSorted,
)),
'text/html'
);
......
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