fake afnor
This commit is contained in:
@ -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 {
|
||||
|
53
src/Form/AfnorType.php
Normal file
53
src/Form/AfnorType.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AfnorType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('submit',
|
||||
SubmitType::class, [
|
||||
'label' => 'Valider',
|
||||
'attr' => ['class' => 'btn btn-success mb-5'],
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('id',
|
||||
TextType::class, [
|
||||
'mapped' => false,
|
||||
'label' => 'ID Déliverance',
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$builder->add('codeproduct',
|
||||
TextType::class, [
|
||||
'mapped' => false,
|
||||
'label' => 'Code Produit',
|
||||
'required' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$builder->add('codequalifications', CollectionType::class, [
|
||||
'entry_type' => TextType::class,
|
||||
'label' => 'Codes Qualification',
|
||||
'allow_add' => true,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
]);
|
||||
}
|
||||
}
|
@ -71,10 +71,8 @@ class SftpService
|
||||
|
||||
$sftp = $this->sftp;
|
||||
$remotePath = 'ssh2.sftp://'.join(DIRECTORY_SEPARATOR, [$sftp, $this->folder.$remoteFolder."/".$baseName]);
|
||||
echo($remotePath);
|
||||
$stream = @fopen($remotePath, 'w');
|
||||
if (!$stream) {
|
||||
echo "here";
|
||||
return false;
|
||||
}
|
||||
$localStream = fopen($localFile, 'r');
|
||||
|
Reference in New Issue
Block a user