public function getImageEmission() { return $this->program->getEmission()->getMedia(); }
public function setPrograms($object) { $timeStampDay = 3600 * 24; $timeStampWeek = $timeStampDay * 7; //$object->setDiffusionStart(); $now = new \DateTime('tomorrow'); $now->setTime('00', '00'); // purge previous future programs $q = $this->createQuery()->delete('ProgramBundle:Program', 'p')->where('p.emission = :id_emission AND p.time_start >= :now')->setParameters(array('id_emission' => (string) $object->getId(), 'now' => $now)); $q->getQuery()->execute(); // Exceptionnal broadcasts $exceptional = $object->getExceptionalBroadcasts(); foreach ($exceptional as $value) { if ($value->getTimeStart() > $now) { $value->setEmission($object); $program = new Program(); $program->setTimeStart($value->getTimeStart()); //$timeValue = $value->getTimeStart()->getTimestamp() + $value->getDuration()->getTimestamp(); //$program->setTimeStop($newDate->setTimestamp($timeValue)); $duration = $value->getDuration()->format('G\\Hi\\M'); $timeStop = clone $program->getTimeStart(); $timeStop->add(new \DateInterval('PT' . $duration)); $program->setTimeStop($timeStop); $program->setEmission($object); $this->prePersist($program); $this->getModelManager()->create($program); $this->postPersist($program); $this->createObjectSecurity($program); } } // weekly broadcasts $weekly = $object->getWeeklyBroadcasts(); /*foreach ($weekly as $value) { $timestamp = $object->getDiffusionStart()->getTimestamp() + $timeStampDay; $dateDay = date("N", $timestamp); while ($dateDay != $value->getDay()) { $timestamp += $timeStampDay; $dateDay = date("N", $timestamp); } for ($timestamp; $timestamp < $object->getDiffusionStop()->getTimestamp(); $timestamp += $timeStampWeek) { $value->setEmission($object); $program = new Program(); $program->setTimeStart($newDate->setTimestamp($timestamp + $value->getHour()->getTimestamp())); $timeValue = $program->getTimeStart()->getTimestamp() + $value->getDuration()->getTimestamp(); $program->setTimeStop($newDate2->setTimestamp($timeValue)); $program->setEmission($object); $this->prePersist($program); $this->getModelManager()->create($program); $this->postPersist($program); $this->createObjectSecurity($program); } $value->setEmission($object); }*/ $currentDate = clone $now; $stopDate = $object->getDiffusionStop(); while ($currentDate < $stopDate) { $dayNum = $currentDate->format('N'); foreach ($weekly as $value) { if ($dayNum != $value->getDay()) { continue; } $program = new Program(); $program->setEmission($object); $hour = $value->getHour()->format('G\\Hi\\M'); $duration = $value->getDuration()->format('G\\Hi\\M'); $progStart = clone $currentDate; $progStart->add(new \DateInterval('PT' . $hour)); $progStop = clone $progStart; $progStop->add(new \DateInterval('PT' . $duration)); $program->setTimeStart($progStart); $program->setTimeStop($progStop); $this->prePersist($program); $this->getModelManager()->create($program); $this->postPersist($program); $this->createObjectSecurity($program); } $currentDate->modify('+1 day'); } }