Loading module/Application/src/Application/Service/File/FileService.php +5 −0 Original line number Diff line number Diff line Loading @@ -184,4 +184,9 @@ class FileService return $content; } public function computeDirectoryPathForInformation() { $path = $this->rootDirectoryPathForUploadedFiles . '/' . 'information'; return $path; } } No newline at end of file module/Information/config/module.config.php +0 −12 Original line number Diff line number Diff line Loading @@ -110,7 +110,6 @@ return [ 'controller' => FichierController::class, 'action' => [ 'index', 'ajouter', 'supprimer', 'telecharger', ], Loading Loading @@ -145,17 +144,6 @@ return [ ], ], 'child_routes' => [ 'ajouter' => [ 'type' => Literal::class, 'may_terminate' => true, 'options' => [ 'route' => '/ajouter', 'defaults' => [ 'controller' => FichierController::class, 'action' => 'ajouter', ], ], ], 'supprimer' => [ 'type' => Segment::class, 'may_terminate' => true, Loading module/Information/src/Information/Controller/FichierController.php +21 −26 Original line number Diff line number Diff line Loading @@ -24,38 +24,16 @@ class FichierController extends AbstractActionController public function indexAction() { $fichiers = $this->getInformationFichierService()->getInformationFichiers(); return new ViewModel([ 'fichiers' => $fichiers, ]); } public function supprimerAction() { /** @var InformationFichier $fichier */ $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); $this->redirect()->toRoute('informations/fichiers', [], [], true); } /** ***************************************************************************************************************/ public function ajouterAction() { /** @var FichierForm $form */ $form = $this->getServiceLocator()->get('FormElementManager')->get(FichierForm::class); $form->setAttribute('action', $this->url()->fromRoute('informations/fichiers/ajouter', [], [], true)); $form->setAttribute('action', $this->url()->fromRoute("informations/fichiers", [], [], true)); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { var_dump("here"); $file = $request->getFiles()->toArray(); var_dump($file); if ($file['chemin'] !== null) { $logoDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($logoDir); Loading @@ -74,15 +52,32 @@ class FichierController extends AbstractActionController $fichier->setCreateur($user); $fichier->setDateCreation(new \DateTime()); $this->getInformationFichierService()->create($fichier); $this->redirect()->toRoute("informations/fichiers"); } } return new ViewModel([ 'title' => 'Sélection du fichier à déposer', 'fichiers' => $fichiers, 'form' => $form, ]); } public function supprimerAction() { /** @var InformationFichier $fichier */ $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); $this->redirect()->toRoute('informations/fichiers', [], [], true); } /** TELECHARGEMENT ************************************************************************************************/ /** Action permettant le téléchargement */ Loading module/Information/src/Information/Form/FichierForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -13,12 +13,12 @@ class FichierForm extends Form { $this ->add(( new File('chemin')) ->setLabel('Fichier à téléverser :') //->setLabel('Fichier à téléverser :') ); $this ->add(( new Submit('submit')) ->setValue("Enregistrer") new Submit('televerser')) ->setValue("Téléverser") ->setAttribute('class', 'btn btn-primary') ); } Loading module/Information/src/Information/Service/InformationFichierService.php +2 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ class InformationFichierService { public function getInformationFichiers() { $qb = $this->getEntityManager()->getRepository(InformationFichier::class)->createQueryBuilder('fichier') ->addSelect('createur') ->join('fichier.createur', 'createur') ->orderBy('fichier.id') ; return $qb->getQuery()->getResult(); Loading Loading
module/Application/src/Application/Service/File/FileService.php +5 −0 Original line number Diff line number Diff line Loading @@ -184,4 +184,9 @@ class FileService return $content; } public function computeDirectoryPathForInformation() { $path = $this->rootDirectoryPathForUploadedFiles . '/' . 'information'; return $path; } } No newline at end of file
module/Information/config/module.config.php +0 −12 Original line number Diff line number Diff line Loading @@ -110,7 +110,6 @@ return [ 'controller' => FichierController::class, 'action' => [ 'index', 'ajouter', 'supprimer', 'telecharger', ], Loading Loading @@ -145,17 +144,6 @@ return [ ], ], 'child_routes' => [ 'ajouter' => [ 'type' => Literal::class, 'may_terminate' => true, 'options' => [ 'route' => '/ajouter', 'defaults' => [ 'controller' => FichierController::class, 'action' => 'ajouter', ], ], ], 'supprimer' => [ 'type' => Segment::class, 'may_terminate' => true, Loading
module/Information/src/Information/Controller/FichierController.php +21 −26 Original line number Diff line number Diff line Loading @@ -24,38 +24,16 @@ class FichierController extends AbstractActionController public function indexAction() { $fichiers = $this->getInformationFichierService()->getInformationFichiers(); return new ViewModel([ 'fichiers' => $fichiers, ]); } public function supprimerAction() { /** @var InformationFichier $fichier */ $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); $this->redirect()->toRoute('informations/fichiers', [], [], true); } /** ***************************************************************************************************************/ public function ajouterAction() { /** @var FichierForm $form */ $form = $this->getServiceLocator()->get('FormElementManager')->get(FichierForm::class); $form->setAttribute('action', $this->url()->fromRoute('informations/fichiers/ajouter', [], [], true)); $form->setAttribute('action', $this->url()->fromRoute("informations/fichiers", [], [], true)); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { var_dump("here"); $file = $request->getFiles()->toArray(); var_dump($file); if ($file['chemin'] !== null) { $logoDir = $this->fileService->computeDirectoryPathForInformation(); $this->fileService->createWritableDirectory($logoDir); Loading @@ -74,15 +52,32 @@ class FichierController extends AbstractActionController $fichier->setCreateur($user); $fichier->setDateCreation(new \DateTime()); $this->getInformationFichierService()->create($fichier); $this->redirect()->toRoute("informations/fichiers"); } } return new ViewModel([ 'title' => 'Sélection du fichier à déposer', 'fichiers' => $fichiers, 'form' => $form, ]); } public function supprimerAction() { /** @var InformationFichier $fichier */ $id = $this->params()->fromRoute('id'); $fichier = $this->getInformationFichierService()->getInformationFichier($id); $this->getInformationFichierService()->delete($fichier); $logoDir = $this->fileService->computeDirectoryPathForInformation(); $filePath = implode("/", [$logoDir,$fichier->getNom()]); $success = unlink($filePath); if (!$success) throw new RuntimeException("Un problème s'est produit lors de l'effacement sur le disque du fichier ".$filePath); $this->redirect()->toRoute('informations/fichiers', [], [], true); } /** TELECHARGEMENT ************************************************************************************************/ /** Action permettant le téléchargement */ Loading
module/Information/src/Information/Form/FichierForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -13,12 +13,12 @@ class FichierForm extends Form { $this ->add(( new File('chemin')) ->setLabel('Fichier à téléverser :') //->setLabel('Fichier à téléverser :') ); $this ->add(( new Submit('submit')) ->setValue("Enregistrer") new Submit('televerser')) ->setValue("Téléverser") ->setAttribute('class', 'btn btn-primary') ); } Loading
module/Information/src/Information/Service/InformationFichierService.php +2 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,8 @@ class InformationFichierService { public function getInformationFichiers() { $qb = $this->getEntityManager()->getRepository(InformationFichier::class)->createQueryBuilder('fichier') ->addSelect('createur') ->join('fichier.createur', 'createur') ->orderBy('fichier.id') ; return $qb->getQuery()->getResult(); Loading