fake afnor

This commit is contained in:
2023-01-03 10:50:07 +01:00
parent e7f7a348da
commit e8f528574a
9 changed files with 152 additions and 35 deletions

View File

@ -4,12 +4,14 @@ namespace App\Controller;
use App\Form\FolderType;
use App\Form\FileType;
use App\Form\AfnorType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use App\Service\SftpService;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Filesystem\Filesystem;
class HomeController extends AbstractController
{
@ -42,6 +44,31 @@ class HomeController extends AbstractController
$this->sftp->rename($folder."/".$oldname,$folder."/".$name);
}
// Fake AFNOR
$formAfnor = $this->createForm(AfnorType::class);
$formAfnor->handleRequest($request);
if ($formAfnor->get('submit')->isClicked()) {
$id = $formAfnor->get("id")->getData();
$codeproduct = $formAfnor->get("codeproduct")->getData();
$codequalifications = $formAfnor->get("codequalifications")->getData();
$filesystem = new Filesystem();
$dir = $this->getParameter('kernel.project_dir').'/var/tmp';
$file ="gc,".$id."\n";
$file.="ph\n";
$file.="pj,".$codeproduct."\n";
foreach($codequalifications as $codequalification) {
$file.="qa\n";
$file.="qh,".$codequalification."\n";
}
$filesystem->dumpFile($dir.'/DEL-'.$id.'.AFN', $file);
$return=$this->sftp->uploadFile($dir.'/DEL-'.$id.'.AFN', $folder);
}
// Lister les fichiers
$ls=$this->sftp->ls($folder);
@ -65,8 +92,11 @@ class HomeController extends AbstractController
'infolder' => $folder,
'folders' => $ls["folders"],
'files' => $ls["files"],
'fakeAfnor'=>in_array("AFNOR",$this->getParameter("fakeFiles")),
'formfolder'=>$formFolder->createView(),
'formfile'=>$formFile->createView(),
'formafnor'=>$formAfnor->createView(),
]);
}
@ -78,7 +108,7 @@ class HomeController extends AbstractController
throw new \Exception('Erreur de téléchargement');
}
if (str_starts_with(mime_content_type($tmpfile), 'image/') || 'application/pdf' == mime_content_type($tmpfile)) {
if (str_starts_with(mime_content_type($tmpfile), 'image/') || 'application/pdf' == mime_content_type($tmpfile) || 'text/plain' == mime_content_type($tmpfile)) {
$response = new BinaryFileResponse($tmpfile);
$response->headers->set('Content-Type', mime_content_type($tmpfile));
} else {