Commit ab0bf31a authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

Ajout suppression du fichier de convention

parent 5f03b5f9
Loading
Loading
Loading
Loading
+33 −26
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Oscar\Controller;

class ConventionModeleEtapeAdministrationController extends AbstractOscarController implements \Oscar\Traits\UseOscarConfigurationService
class ConventionModeleEtapeAdministrationController extends AbstractOscarController implements \Oscar\Traits\UseOscarConfigurationService, \Oscar\Traits\UseLoggerService
{
    use \Oscar\Traits\UseOscarConfigurationServiceTrait;
    use \Oscar\Traits\UseOscarConfigurationServiceTrait, \Oscar\Traits\UseLoggerServiceTrait;

    /** @var \Oscar\Service\ConventionModeleEtapeService */
    public $conventionModeleEtapeService;
@@ -76,7 +76,8 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl
            $originalFilename = $_FILES['file']['name'];
            $slugify = new \Cocur\Slugify\Slugify();
            $renamed = sprintf(
                "oscar-jb-%s",
                "oscar-conventions-%s-%s",
                $slugify->slugify((new \DateTime())->format(\DateTime::ATOM)),
                $slugify->slugify($originalFilename)
            );

@@ -89,31 +90,37 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl
                ->setMimesAllowed($mimes);
            $uploader->updoad($_FILES['file']);

            // $html_tmp = '/tmp' . DIRECTORY_SEPARATOR . uniqid('htmltmp_') . '.html';
            // $pdf_path = $this->getOscarConfigurationService()->getDocumentDropLocation() . DIRECTORY_SEPARATOR . $renamed;
            $conventionModeleEtape->fichier = $uploader->getUploadName();
            $conventionModeleEtape->fichierNom = $originalFilename;
            $conventionModeleEtape->fichierDateAjout = new \DateTime();
            $conventionModeleEtape->dateUpdated = new \DateTime();
            $conventionModeleEtape->updatedBy = $this->getCurrentPerson();
            $this->getEntityManager()->flush();

        } else if ($this->params()->fromPost('action') == "supprimer_fichier") {

            // $html = $this->getConventionHtml($formulaire->getTexteConvention(), $this->params()->fromPost('dateStart'), $this->params()->fromPost('dateEnd'), $this->params()->fromPost('amount'), $this->params()->fromPost('partenaire'));

            // if (!file_put_contents($html_tmp, $html)) {
            //     throw new OscarException("Impossible de créer le fichier temporaire '$html_tmp'");
            // }
            if (mb_strlen(trim($conventionModeleEtape->fichier)) == 0) {
                return $this->redirect()->toRoute('administration/conventionModeles/configurer/etapes/configurer', ['id' => $conventionModele->id, 'idEtape' => $conventionModeleEtape->id]);
            }
            
            // $cmd = sprintf(
            //     'export QT_QPA_FONTDIR=%s && export QT_QPA_PLATFORM=offscreen && wkhtmltopdf -O portrait %s %s',
            //     '',
            //     $html_tmp,
            //     $pdf_path
            // );
            // $done = false;
            // if (shell_exec($cmd) === false) {
            //     unlink($html_tmp);
            //     throw new OscarException("Impossible de créer le fichier PDF");
            // }
            // unlink($html_tmp);
            $documentLocation = $this->getOscarConfigurationService()->getDocumentDropLocation();
            $documentPath = $documentLocation . DIRECTORY_SEPARATOR . $conventionModeleEtape->fichier;

            // $fileSize = filesize($pdf_path);
            // Suppression du fichier
            try {
                \Oscar\Utils\FileSystemUtils::getInstance()->unlink($documentPath);
            } catch (\Exception $exception) {
                $this->getLoggerService()->error(
                    "Suppression du fichier '$documentPath' impossible car : " . $exception->getMessage()
                );
            }

            $conventionModeleEtape->fichier = NULL;
            $conventionModeleEtape->fichierNom = NULL;
            $conventionModeleEtape->fichierDateAjout = NULL;
            $conventionModeleEtape->dateUpdated = new \DateTime();
            $conventionModeleEtape->updatedBy = $this->getCurrentPerson();
            $this->getEntityManager()->flush();
        }

        return $this->redirect()->toRoute('administration/conventionModeles/configurer/etapes/configurer', ['id' => $conventionModele->id, 'idEtape' => $conventionModeleEtape->id]);
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ class ConventionModeleEtapeAdministrationControllerFactory implements FactoryInt
        $c = new ConventionModeleEtapeAdministrationController();
        $c->setEntityManager($container->get(EntityManager::class));
        $c->setOscarUserContextService($container->get(OscarUserContext::class));
        $c->setLoggerService($container->get('Logger'));
        $c->setOscarConfigurationService($container->get(\Oscar\Service\OscarConfigurationService::class));
        $c->conventionModeleEtapeService = $container->get(\Oscar\Service\ConventionModeleEtapeService::class);
        return $c;
+19 −1
Original line number Diff line number Diff line
@@ -75,6 +75,24 @@ class ConventionModeleEtape
     */
    public $informations;

    /**
     * @var string
     * @ORM\Column(type="text", nullable=true)
     */
    public $fichier;

    /**
     * @var string
     * @ORM\Column(type="text", nullable=true)
     */
    public $fichierNom;

    /**
     * @var \DateTime
     * @ORM\Column(type="datetime", nullable=true)
     */
    public $fichierDateAjout;

    public function __construct()
    {
        $this->dateCreated = new \DateTime();
+27 −3
Original line number Diff line number Diff line
@@ -77,13 +77,37 @@
  <div style="margin-bottom: 4rem; background-color: white; border-radius: 1rem; padding: 1rem; margin-top: 1rem;">
    <h2 style="margin-bottom: 2rem;">📄 Document de la convention</h2>

    <form action="" method="post" enctype="multipart/form-data">
    <?php if($conventionModeleEtape->fichier === NULL): ?>
    <p>Aucun document de convention n'a pour l'instant été associé à cette étape. Si ce n'est qu'une étape intermédiaire, c'est normal. Si c'est une étape finale, téléversez un document en remplissant le formulaire ci-dessous.</p>
    <?php else: ?>
    <div style="display: flex; justify-content: space-between;">
      <div>
        <div>
          <label>Nom du fichier :</label> <span><?= $conventionModeleEtape->fichierNom ?></span>
        </div>
        <div>
          <label>Téléversé le :</label> <span><?= $conventionModeleEtape->fichierDateAjout->format('d/m/Y') ?> à <?= $conventionModeleEtape->fichierDateAjout->format('H:i:s') ?></span>
        </div>
      </div>
      <div>
        <details>
          <summary>Supprimer le fichier 🗑</summary>
          <form method="post">
            <input type="hidden" name="action" value="supprimer_fichier">
            <input type="submit" value="Confirmer la suppression">
          </form>
        </details>
      </div>
    </div>
    <?php endif; ?>

    <form method="post" enctype="multipart/form-data" style="margin-top: 2rem;">
      <input type="hidden" name="action" value="téléverser_fichier">
      <div>
        <label for="file">Fichier</label>
        <label for="file">Sélection du fichier à téléverser : </label>
        <input type="file" name="file" id="file" />
      </div>
      <input type="submit" value="📤 Téléverser le fichier">
      <input type="submit" value="📤 <?= $conventionModeleEtape->fichier === NULL ? "Téléverser" : "Remplacer" ?> le fichier">
    </form>

  </div>