/** * @param $spot * @param $datePrev * @return renvoie la notesDate de spot à $datePrev, ou une nouvelle instance si elle n'existe pas */ static function getNotesDate($spot, $datePrev, $em) { // On pourrait utiliser: // $entityManager->getRepository('LaPoizWindBundle:NotesDate')->getNotesDateForDatePrev($spot,$currentDay); // Dans le cas où l'on n'efface pas les anciennes notesDate ... $datePrev->setTime(0, 0, 0); $noteDatesFind = null; $listeNotesDate = $spot->getNotesDate(); foreach ($listeNotesDate as $notesDate) { if ($notesDate->getDatePrev() == $datePrev) { $noteDatesFind = $notesDate; } } if ($noteDatesFind == null) { $noteDatesFind = new NotesDate(); $noteDatesFind->setSpot($spot); $noteDatesFind->setDatePrev($datePrev); $spot->addNotesDate($noteDatesFind); $em->persist($noteDatesFind); $em->persist($spot); $em->flush(); } return $noteDatesFind; }
/** * @param $prevTempWater: tableau du des T°C depuis aujourd'hui [0]=12 [1]=13 (issue de TempWaterGetData::getTempWater) * Aujourd'hui: 12°C, demain : 13°C ... * */ static function saveTempWater($spot, $prevTempWaterTab, $entityManager, $output) { $output->writeln('<info>****** function saveTempWater ****</info>'); //TempWaterGetData::deleteOldTempWater($spot,$entityManager,$output); -> on n'efface pas les ancienne valeur $futureNotesDate = $entityManager->getRepository('LaPoizWindBundle:NotesDate')->getFutureNotesDate($spot); $currentDay = new \DateTime("now"); foreach ($prevTempWaterTab as $jour => $prevTempWater) { // $jour=0 puis 1 ... $previsionNotesDate = $entityManager->getRepository('LaPoizWindBundle:NotesDate')->getNotesDateForDatePrev($spot, $currentDay); if ($previsionNotesDate != null) { $previsionNotesDate->setTempWater($prevTempWater); $entityManager->persist($previsionNotesDate); } else { // N'existe pas dans le BD -> on le créé => pas normal !!!!! $previsionNotesDate = new NotesDate(); $previsionNotesDate->setTempWater($prevTempWater); $previsionNotesDate->setDatePrev(clone $currentDay); $previsionNotesDate->setSpot($spot); $spot->addNotesDate($previsionNotesDate); $entityManager->persist($previsionNotesDate); $entityManager->persist($spot); } $output->writeln('save tempWater:' . $previsionNotesDate->getTempWater() . '°C for ' . $previsionNotesDate->getDatePrev()->format('d/m/Y')); $currentDay = date_add($currentDay, new \DateInterval('P1D')); } $entityManager->flush(); }