/** * Displays a form to edit an existing ArchiveParam entity. * * @param Request $request * @param ArchiveParam $archiveParam * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function editAction(Request $request, ArchiveParam $archiveParam) { $deleteForm = $this->createDeleteForm($archiveParam); $editForm = $this->createForm('DocBundle\\Form\\ArchiveParamType', $archiveParam); $editForm->handleRequest($request); if ($editForm->isSubmitted() && $editForm->isValid()) { $em = $this->getDoctrine()->getManager(); $newArchive = $archiveParam->hydrateNewArchive(); if ($archiveParam->getCurrentPdf()->getFile() !== null) { $pdf = new Pdf(); $pdf->setCurrent(0); $stream = fopen($archiveParam->getCurrentPdf()->getFile(), 'rb'); $pdf->setFile(stream_get_contents($stream)); $pdf->setTitle($archiveParam->generateFileName('.pdf')); $pdf->addArchive($newArchive); $newArchive->addPdfSource($pdf); } $currentVersion = $archiveParam->getVersions()->last(); $numero = $currentVersion->getNumero() + 0.1; $currentVersion->removeArchive($archiveParam); // $archives = $currentVersion->getArchives(); $version = new Version(); $version->setNumero($numero); // $version->addGroupArchives($archives); $version->setReseau($currentVersion->getReseau()); $version->setEnCours(0); $version->addArchive($newArchive); $newArchive->addVersion($version); $em->persist($version); $em->flush(); return $this->redirectToRoute('archiveparam_edit', array('id' => $archiveParam->getId())); } return $this->render('@Doc/archiveparam/edit.html.twig', array('archiveParam' => $archiveParam, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView())); }
/** * Get pdfSources * * @return Pdf */ public function getLastPdfSource() { return $this->pdfSources->last(); }
/** * Import a reseau params infos from CSV file. * TODO: refactor this method for performance * * @param Request $request */ public function importCSVAction(Request $request) { $form = $this->createFormBuilder()->add('submitFile', FileType::class, array('label' => 'Fichier CSV'))->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { ini_set('max_execution_time', 0); // TODO: Change pdf file names column in the CSV file $pdfDir = $this->container->getParameter('resources_dir'); $file = $form->get('submitFile')->getData(); $data = $this->csvToArray($file); $em = $this->getDoctrine()->getManager(); foreach ($data as $row) { $stream = fopen($pdfDir . '/' . $row['contrat'] . '/' . $row['pdf_source'], 'rb'); $param = new Parametrage(); $pdfSource = new Pdf(); $pdfSource->setCurrent(1); $reseau = $em->getRepository('DocBundle:Reseau')->findOneByCode($row['reseaux']); if (null === $reseau) { throw $this->createNotFoundException("Le réseau " . $row['reseaux'] . " n'existe pas."); } $param->setReseau($reseau); $pdfSource->setFile(stream_get_contents($stream)); $pdfSource->setTitle($row['pdf_source']); $pdfSource->setParametrage($param); $param->addPdfSource($pdfSource); $param->setContrat($row['contrat']); $param->setCollectivites($row['collectivites']); $param->setType($row['type']); $param->setLibelle($row['libelle']); $param->setPartenaires('Tous'); $param->setOrdre($row['ordre']); $param->setReference($row['reference']); $em->persist($param); } $em->flush(); return $this->redirectToRoute('parametrage_index'); } ini_set('max_execution_time', 60); return $this->render('DocBundle:parametrage:csv_form.html.twig', array('form' => $form->createView())); }