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

Passage à l'id pour les URLs

parent bc05909b
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -14,10 +14,9 @@ class ConventionAdministrationController extends AbstractOscarController
            $conventions = $this->getEntityManager()->getRepository(\Oscar\Entity\Convention::class)->findAll();
            return ['conventions' => $conventions];
        }
        if ($this->params()->fromPost('action') == "convention_creer") {
            $this->conventionService->creerNouvelle($this->params()->fromPost('nom'), $this->getCurrentPerson());
        } else if ($this->params()->fromPost('action') == "convention_supprimer") {
            $this->conventionService->supprimer($this->params()->fromPost('nom'), $this->getCurrentPerson());

        if ($this->params()->fromPost('action') == "créer") {
            $this->conventionService->créerNouvelle($this->params()->fromPost('nom'), $this->getCurrentPerson());
        }

        return $this->redirect()->toRoute('administration/conventions');
@@ -31,11 +30,17 @@ class ConventionAdministrationController extends AbstractOscarController
            return $this->getResponseNotFound("La convention n'a pas été trouvée.");
        }

        if ($this->params()->fromPost('action') == "modifier_nom") {
        if (!$this->getRequest()->isPost()) {
            return ['convention' => $convention];
        }

        if ($this->params()->fromPost('action') == "supprimer") {
            $this->conventionService->supprimer($convention, $this->getCurrentPerson());
            return $this->redirect()->toRoute('administration/conventions');
        } else if ($this->params()->fromPost('action') == "modifier_nom") {
            $this->conventionService->modifierNom($convention, $this->params()->fromPost('nom'), $this->getCurrentPerson());
            return $this->redirect()->toRoute('administration/conventions/configurer', ['id' => $convention->nom]);
        }

        return ['convention' => $convention];
        return $this->redirect()->toRoute('administration/conventions/configurer', ['id' => $convention->id]);
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -12,8 +12,14 @@ use Doctrine\ORM\Mapping as ORM;
class Convention
{
    /**
     * @var string
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Column(type="integer")
     */
    public $id;

    /**
     * @var string
     * @ORM\Column(type="text")
     */
    public $nom;
+4 −7
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ class ConventionService implements UseEntityManager, UseLoggerService, UseOscarC
{
  use UseEntityManagerTrait, UseLoggerServiceTrait, UseOscarConfigurationServiceTrait;

  public function creerNouvelle(string $nom, \Oscar\Entity\Person $person): void
  public function créerNouvelle(string $nom, \Oscar\Entity\Person $person): void
  {
    $this->getLoggerService()->info("ConventionService creerNouvelle");
    $this->getLoggerService()->info("by: " . $person);
@@ -29,16 +29,13 @@ class ConventionService implements UseEntityManager, UseLoggerService, UseOscarC
    $this->getEntityManager()->flush();
  }

  public function supprimer(string $nom, \Oscar\Entity\Person $person): void
  public function supprimer(\Oscar\Entity\Convention $convention, \Oscar\Entity\Person $person): void
  {
    $this->getLoggerService()->info("ConventionService supprimer");
    $this->getLoggerService()->info("by: " . $person);
    $convention = $this->getEntityManager()->find(\Oscar\Entity\Convention::class, $nom);
    if ($convention) {
    $this->getEntityManager()->remove($convention);
    $this->getEntityManager()->flush();
  }
  }

  public function modifierNom(\Oscar\Entity\Convention $convention, string $nom, \Oscar\Entity\Person $person): void
  {
+4 −5
Original line number Diff line number Diff line
@@ -79,13 +79,12 @@
          <?php foreach( $conventions as $convention ): ?>
          <tr>
            <td><?= $convention->nom ?></td>
            <td><a href="<?= $this->url('administration/conventions/configurer', ['id' => $convention->nom]) ?>"><span aria-label="crayon" role="img"></span> configurer</a></td>
            <td><a href="<?= $this->url('administration/conventions/configurer', ['id' => $convention->id]) ?>"><span aria-label="crayon" role="img"></span> configurer</a></td>
            <td>
              <details>
                <summary>Supprimer la convention 🗑</summary>
                <form method="post" style="padding-left: 2em;">
                  <input type="hidden" name="action" value="convention_supprimer">
                  <input type="hidden" name="nom" value="<?= $convention->nom ?>">
                <form method="post" style="padding-left: 2em;" action="<?= $this->url('administration/conventions/configurer', ['id' => $convention->id]) ?>">
                  <input type="hidden" name="action" value="supprimer">
                  <input type="submit" value="Confirmer la suppression">
                </form>
              </details>
@@ -99,7 +98,7 @@

    <h3 style="margin-top: 3rem; margin-bottom: 2rem;"><span aria-label="signe plus" role="img"></span> Création d'une nouvelle convention</h3>
    <form method="post">
      <input type="hidden" name="action" value="convention_creer">
      <input type="hidden" name="action" value="cer">
      <label for="nom">Nom</label>
      <input type="text" id="nom" name="nom" required placeholder="Nom de la nouvelle convention à créer" size="80">
      <input type="submit" value="➕ Créer la nouvelle convention">