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

Ajout information obligatoire ou non dans formulaire

parent 3ca1a7ec
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -63,6 +63,14 @@ class ConventionModeleEtapeAdministrationController extends AbstractOscarControl
                return $this->getResponseNotFound("L'information à saisir pour l'étape de saisie du modèle de convention n'a pas été trouvée.");
            }
            $this->conventionModeleEtapeService->supprimerInformation($conventionModeleEtapeInformation, $this->getCurrentPerson());
        } else if ($this->params()->fromPost('action') == "modifier_information") {
            /** @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->modifierInformation($conventionModeleEtape, $conventionModeleEtapeInformation,
            $this->params()->fromPost('obligatoire'), $this->getCurrentPerson());
        } else if ($this->params()->fromPost('action') == "ajouter_information_reponse") {
            /** @var \Oscar\Entity\ConventionModeleEtapeInformation $conventionModeleEtapeInformation */
            $conventionModeleEtapeInformation = $this->getEntityManager()->find(\Oscar\Entity\ConventionModeleEtapeInformation::class, $this->params()->fromPost('id'));
+6 −0
Original line number Diff line number Diff line
@@ -74,6 +74,12 @@ class ConventionModeleEtapeInformation
     */
    public $reponses;

    /**
     * @var bool
     * @ORM\Column(type="boolean", options={"default" : false}, nullable=false)
     */
    public $obligatoire = false;

    public function __construct()
    {
        $this->dateCreated = new \DateTime();
+19 −0
Original line number Diff line number Diff line
@@ -83,6 +83,25 @@ class ConventionModeleEtapeService implements UseEntityManager, UseLoggerService
    $this->getEntityManager()->flush();
  }

  public function modifierInformation(\Oscar\Entity\ConventionModeleEtape $etape, \Oscar\Entity\ConventionModeleEtapeInformation $conventionModeleEtapeInformation, ?string $obligatoire, \Oscar\Entity\Person $person): void
  {
    $this->getLoggerService()->info("ConventionModeleEtapeService modifierInformation");
    $this->getLoggerService()->info("by: " . $person);
    $etape->updatedBy = $person;
    $etape->dateUpdated = new \DateTime();
    
    $conventionModeleEtapeInformation->updatedBy = $person;
    $conventionModeleEtapeInformation->dateUpdated = new \DateTime();

    if ($obligatoire) {
      $conventionModeleEtapeInformation->obligatoire = true;
    } else {
      $conventionModeleEtapeInformation->obligatoire = false;
    }

    $this->getEntityManager()->flush();
  }

  public function ajouterInformationReponse(\Oscar\Entity\ConventionModeleEtapeInformation $conventionModeleEtapeInformation, string $reponse, \Oscar\Entity\Person $person): void
  {
    $this->getLoggerService()->info("ConventionModeleEtapeService ajouterInformationReponse");
+9 −0
Original line number Diff line number Diff line
@@ -52,6 +52,15 @@
    </div>

    <p><b>Type :</b> <?= $information->type ?></p>
    <form method="post">
      <input type="hidden" name="action" value="modifier_information">
      <input type="hidden" name="id" value="<?= $information->id ?>">
      <div>
        <label style="color: black;" for="obligatoire">Obligatoire : </label>
        <input type="checkbox" id="obligatoire" name="obligatoire" <?= $information->obligatoire ? 'checked' : '' ?> />
      </div>
      <input type="submit" value="Enregistrer les modifications">
    </form>

    <?php if($information->type == \Oscar\Entity\ConventionModeleEtapeInformation::TYPE_CHOIX_D_UNE_SEULE_REPONSE_PARMI_DES_PROPOSITIONS): ?>
    <p><b>Réponses proposées :</b></p>
+2 −2
Original line number Diff line number Diff line
@@ -79,13 +79,13 @@
          <?php elseif ($information->type == \Oscar\Entity\ConventionModeleEtapeInformation::TYPE_SAISIE_LIBRE): ?>

          <div>
            <input type="text" size="80" id="<?= $reponse ?>" name="reponse-<?= $information->id ?>" />
            <input type="text" size="80" id="<?= $reponse ?>" name="reponse-<?= $information->id ?>" <?= $information->obligatoire ? 'required' : '' ?> />
          </div>

          <?php elseif ($information->type == \Oscar\Entity\ConventionModeleEtapeInformation::TYPE_DATE): ?>

          <div>
            <input type="date" id="<?= $reponse ?>" name="reponse-<?= $information->id ?>" />
            <input type="date" id="<?= $reponse ?>" name="reponse-<?= $information->id ?>" <?= $information->obligatoire ? 'required' : '' ?> />
          </div>

          <?php endif; ?>