public function createGroupedTicket(Request $request, EPnr $pnr, $options = array()) { //Trick to prevent cache size exceeded //set_time_limit(0); while (ob_get_level()) { ob_end_clean(); } ob_implicit_flush(true); /* * Construct PDF with Mpdf service * Layout based on HTML twig template */ $service = $this->container->get('tfox.mpdfport'); $pdf = $service->getMpdf(array('', 'A4', 8, 'Helvetica', 35, 10, 5, 30, 10, 10)); $pdf->AliasNbPages('{NBPAGES}'); $pdf->setTitle('billet-' . date('d-m-Y-H-i', time()) . '.pdf'); //$pdf->SetHeader('Billet'); //$pdf->SetFooter('{DATE j/m/Y}|{PAGENO}/{NBPAGES}'); /*$html = $this->renderView('AppCoreBundle:Pnr:billetpdf.pdf.twig', array( 'billets' => $em->getRepository('AppCoreBundle:Billet')->findBy(array('pnr' => $pnr)) ));*/ //$test = ''; foreach ($pnr->getPassagers() as $key => $passager) { $billet = $this->em->getRepository('AppCoreBundle:Billet')->findOneBy(array('pnr' => $pnr, 'passager' => $passager)); if (!$billet) { $billet = new Billet(); $billet->setPnr($pnr); $billet->setPassager($passager); $this->em->persist($billet); $this->em->flush(); $billet->postPersist(); $this->em->persist($billet); $this->em->flush(); } $html = $this->container->get('templating')->render('AppCoreBundle:Pnr:_billetByPassagerPdf_' . $pnr->getLang() . '.pdf.twig', array('pnr' => $pnr, 'passager' => $passager, 'billet' => $billet, 'taxes' => $this->em->getRepository('AppCoreBundle:Taxe')->findBy(array('isActive' => true)))); //$test .= $html; $pdf->WriteHTML($html); if ($key < count($pnr->getPassagers()) - 1) { $pdf->AddPage(); } } $url = 'billets-pnr-' . $pnr->getNumero() . '.pdf'; $link = './media/billets/' . $url; $pdf->Output($link, 'F'); //Change pnr status if needed $this->checkPnrStatus($pnr); if (isset($options['absolute_url']) && $options['absolute_url']) { return $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . '/media/billets/' . $url; } return '/media/billets/' . $url; }
public function checkPnrStatus(EPnr $entity, EntityManager $em) { $status = true; if (!sizeof($entity->getPassagers())) { $status = false; } foreach ($entity->getPassagers() as $passager) { $billet = $this->getPassagerBillet($passager, $entity, $em); if (!$billet) { $status = false; } } if ($status && $entity->getStatus()->getCode() != 'billet-annule' && $entity->getStatus()->getCode() != 'rembourse') { $entity->setStatus($em->getRepository('AppCoreBundle:StatutPnr')->findOneBy(array('code' => 'billets-emis'))); $em->persist($entity); $em->flush(); } }