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

Ajout suppression de réponse

parent c8009d21
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -71,6 +71,14 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl
            }
            $this->conventionModeleEtapeService->ajouterInformationReponse($conventionModeleEtapeInformation, $this->params()->fromPost('reponse'), $this->getCurrentPerson());

        } else if ($this->params()->fromPost('action') == "supprimer_information_reponse") {
            /** @var \Oscar\Entity\ConventionModeleEtapeInformation $conventionModeleEtapeInformation */
            $conventionModeleEtapeInformation = $this->getEntityManager()->find(\Oscar\Entity\ConventionModeleEtapeInformation::class, $this->params()->fromPost('id'));
            if (!$conventionModeleEtapeInformation) {
                return $this->getResponseNotFound("L'information à saisir pour l'étape de saisie du modèle de convention n'a pas été trouvée.");
            }
            $this->conventionModeleEtapeService->supprimerInformationReponse($conventionModeleEtapeInformation, $this->params()->fromPost('reponse'), $this->getCurrentPerson());
        
        } else if ($this->params()->fromPost('action') == "téléverser_fichier") {


+19 −0
Original line number Diff line number Diff line
@@ -86,4 +86,23 @@ class ConventionModeleEtapeService implements UseEntityManager, UseLoggerService
    $conventionModeleEtapeInformation->reponses[] = $reponse;
    $this->getEntityManager()->flush();
  }

  public function supprimerInformationReponse(\Oscar\Entity\ConventionModeleEtapeInformation $conventionModeleEtapeInformation, string $reponse, \Oscar\Entity\Person $person): void
  {
    $this->getLoggerService()->info("ConventionModeleEtapeService supprimerInformationReponse");
    $this->getLoggerService()->info("by: " . $person);
    $key_to_delete = NULL;
    foreach ($conventionModeleEtapeInformation->reponses as $key => $value) {
      if ($value == $reponse) {
        $key_to_delete = $key;
        break;
      }
    }
    if ($key_to_delete != NULL) {
      $conventionModeleEtapeInformation->updatedBy = $person;
      $conventionModeleEtapeInformation->dateUpdated = new \DateTime();
      unset($conventionModeleEtapeInformation->reponses[$key_to_delete]);
      $this->getEntityManager()->flush();
    }
  }
}
+14 −1
Original line number Diff line number Diff line
@@ -54,7 +54,20 @@
    <p>Réponses proposées :</p>
    <ul>
      <?php foreach( $information->reponses as $reponse ): ?>
      <li><?= $reponse ?></li>
      <li style="padding-bottom: 1em;">
        <div style="display: flex; align-items: baseline; justify-content: space-between; width: 100%;">
          <span style="font-weight: bold;"><?= $reponse ?></span>
          <details style="font-weight: normal;">
            <summary>Supprimer la réponse 🗑</summary>
            <form method="post" style="padding-left: 2em;">
              <input type="hidden" name="action" value="supprimer_information_reponse">
              <input type="hidden" name="id" value="<?= $information->id ?>">
              <input type="hidden" name="reponse" value="<?= $reponse ?>">
              <input type="submit" value="Confirmer la suppression">
            </form>
          </details>
        </div>
      </li>
      <?php endforeach; ?>
    </ul>