Commit c87f0917 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Saise d'une thèse : recherche/utilisation d'un éventuel doctorant existant en...

Saise d'une thèse : recherche/utilisation d'un éventuel doctorant existant en cas de création ; impossible de changer le doctorant d'une thèse existante ; meilleure remontée/affichage d'erreur.
parent fd3e2c06
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ Journal des modifications
------
- Formations : petites améliorations concernant les enquêtes.
- Inscriptions administratives importées : ajout d'un error_log en cas d'échec du traitement de l'inscription.
- Saise d'une thèse : recherche/utilisation d'un éventuel doctorant existant en cas de création ; impossible de changer le doctorant d'une thèse existante ; meilleure remontée/affichage d'erreur.
- [FIX] Formations suivies : les inscriptions sans réponse à l'enquête étaient écartées à tort.
- [FIX] Formations suivies : rétablissement de l'accès au dépôt de justificatif d'absence.
- [FIX] Inscriptions administratives importées : les liens historisés avec un doctorant n'étaient pas écartés.
+4 −2
Changes for module/Individu/src/Individu/Entity/Db/Repository/IndividuRepository.php: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Individu\Entity\Db\Repository;

use Structure\Entity\Db\Etablissement;
use Application\Entity\Db\Repository\DefaultEntityRepository;
use Application\Entity\Db\Role;
use Application\Entity\UserWrapper;
@@ -12,9 +11,12 @@ use Doctrine\ORM\Query\Expr\Join;
use Individu\Entity\Db\Individu;
use Individu\Entity\Db\IndividuRole;
use Laminas\Mvc\Controller\AbstractActionController;
use Structure\Entity\Db\Etablissement;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Util;

/**
 * @method Individu|null find($id, $lockMode = null, $lockVersion = null)
 */
class IndividuRepository extends DefaultEntityRepository
{
    use SourceCodeStringHelperAwareTrait;
+46 −28
Changes for module/These/src/These/Controller/TheseSaisieController.php: 46 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace These\Controller;

use Application\Controller\AbstractController;
use Application\Entity\Db\Role;
use Application\Service\Role\ApplicationRoleServiceAwareTrait;
use Doctorant\Service\DoctorantServiceAwareTrait;
use Individu\Service\IndividuServiceAwareTrait;
@@ -19,6 +18,7 @@ use These\Form\Structures\StructuresFormAwareTrait;
use These\Form\TheseDatesMouvementsForm\TheseDatesMouvementsFormAwareTrait;
use These\Form\TheseSaisie\TheseSaisieFormAwareTrait;
use These\Service\These\TheseServiceAwareTrait;
use These\Service\These\TheseServiceException;
use UnicaenApp\Form\Element\Collection;

class TheseSaisieController extends AbstractController
@@ -34,58 +34,62 @@ class TheseSaisieController extends AbstractController
    use DirectionFormAwareTrait;
    use TheseDatesMouvementsFormAwareTrait;

    public function ajouterAction()
    public function ajouterAction(): Response|ViewModel
    {
        $request = $this->getRequest();
        $form = $this->getTheseSaisieForm();
        $form->bind($this->theseService->newThese());
        $this->theseSaisieForm->bind($this->theseService->newThese());

        $viewModel = new ViewModel([
            'form' => $form,
            'form' => $this->theseSaisieForm,
        ]);

        $request = $this->getRequest();
        if (!$request->isPost()) {
            return $viewModel;
        }

        $data = $request->getPost();
        $form->setData($data);
        if (!$form->isValid()) {
        $this->theseSaisieForm->setData($data);
        if (!$this->theseSaisieForm->isValid()) {
            $messages = $this->getErrorMessages();
            $viewModel->setVariable("errorMessages", $messages);
            return $viewModel;
        }

        /** @var These $these */
        $these = $form->getData();
        $individu = $data["generalites"]['doctorant']["id"] ? $this->individuService->getRepository()->find($data["generalites"]['doctorant']["id"]) : null;
        if ($individu) {
            $etablissement = $these->getEtablissement();
            $doctorant = $this->doctorantService->newDoctorant($individu, $etablissement);
            $these->setDoctorant($doctorant);
        $these = $this->theseSaisieForm->getData();
        $individu = $this->individuService->getRepository()->find($data['generalites']['doctorant']['id']);
        $doctorant = $this->doctorantService->getRepository()->findOneByIndividu($individu);
        if ($doctorant === null) {
            $doctorant = $this->doctorantService->newDoctorant($individu, $these->getEtablissement());
        }
        $these->setDoctorant($doctorant);
        try {
            $this->theseService->saveThese($these);

        $this->flashMessenger()->addSuccessMessage("Thèse créée avec succès.");
            $this->flashMessenger()->addSuccessMessage(sprintf("Thèse %d créée avec succès.", $these->getId()));

            return $this->redirect()->toRoute('these/identite', ['these' => $these->getId()], [], true);
        } catch (TheseServiceException $e) {
            error_log($e);
            $this->flashMessenger()->addErrorMessage("La création de la thèse a échoué ! " . $e->getMessage());
        }

        return $viewModel;
    }

    public function modifierAction()
    public function modifierAction(): Response|ViewModel
    {
        $form = $this->getTheseSaisieForm();
        $request = $this->getRequest();
        $these = $this->requestedThese();

        $form->setAttribute('action', $this->url()->fromRoute('these/modifier', ['these' => $these->getId()], [], true));
        $this->theseSaisieForm->setAttribute('action', $this->url()->fromRoute('these/modifier', ['these' => $these->getId()], [], true));
        $viewModel = new ViewModel([
            'these' => $these,
            'form' => $form,
            'form' => $this->theseSaisieForm,
        ]);
        $viewModel->setTemplate('these/these-saisie/modifier');

        $form->bind($these);
        $this->theseSaisieForm->bind($these);

        $request = $this->getRequest();
        if (!$request->isPost()) {
            return $viewModel;
        }
@@ -98,18 +102,24 @@ class TheseSaisieController extends AbstractController
            $data->set('generalites', $generalites);
        }

        $form->setData($data);
        if (!$form->isValid()) {
        $this->theseSaisieForm->setData($data);
        if (!$this->theseSaisieForm->isValid()) {
            $messages = $this->getErrorMessages();
            $viewModel->setVariable("errorMessages", $messages);
            return $viewModel;
        }

        try {
            $this->theseService->saveThese($these);

        $this->flashMessenger()->addSuccessMessage("Thèse modifiée avec succès.");
            $this->flashMessenger()->addSuccessMessage(sprintf("Thèse %d modifiée avec succès.", $these->getId()));

            return $this->redirect()->toRoute('these/identite', ['these' => $these->getId()], [], true);
        } catch (TheseServiceException $e) {
            error_log($e);
            $this->flashMessenger()->addErrorMessage("La modification de la thèse a échoué ! " . $e->getMessage());
        }

        return $viewModel;
    }

    private function getErrorMessages(): array
@@ -117,7 +127,7 @@ class TheseSaisieController extends AbstractController
        $messages = [];

        // Récupère les messages d'erreur de chaque fieldset
        foreach ($this->getTheseSaisieForm()->getFieldsets() as $fieldset) {
        foreach ($this->theseSaisieForm->getFieldsets() as $fieldset) {
            if ($fieldset instanceof Collection) {
                // Récupère les messages d'erreur de chaque élément du fieldset
                foreach ($fieldset->getFieldsets() as $f) {
@@ -205,9 +215,17 @@ class TheseSaisieController extends AbstractController

        /** @var These $these */
        $these = $form->getData();

        try {
            $this->theseService->saveThese($these);
            $this->flashMessenger()->addSuccessMessage(sprintf("Thèse %d modifiée avec succès.", $these->getId()));

        $this->flashMessenger()->addSuccessMessage("Thèse modifiée avec succès.");
            return $this->redirect()->toRoute('these/identite', ['these' => $these->getId()], [], true);
        } catch (TheseServiceException $e) {
            error_log($e);
            $this->flashMessenger()->addErrorMessage("La modification de la thèse a échoué ! " . $e->getMessage());
        }

        return $viewModel;
    }
}
 No newline at end of file
+6 −1
Changes for module/These/src/These/Fieldset/Generalites/GeneralitesHydrator.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -49,10 +49,15 @@ class GeneralitesHydrator extends DoctrineObject
    {
        /** @var These $object */

        //Nécessaire sinon Doctrine pense que c'est les données appartenant à un fieldset
        // nécessaire sinon DoctrineObject considère que ce sont les données d'un fieldset (car au format array)
        $data['doctorant'] = $data['doctorant']['id'] ?? null;
        $data['discipline'] = isset($data['discipline']) && $data['discipline'] !== "" ? $data['discipline'] : null;

        // interdit de changer le doctorant d'une thèse existante
        if ($object->getId() !== null) {
            unset($data['doctorant']);
        }

        //date
        $conf = (isset($data['confidentialite']) and $data['confidentialite'] == true);
        $data['dateFinConfidentialite'] = (!empty($data['dateFinConfidentialite']) && $conf) ? $data['dateFinConfidentialite'] : null;
+2 −16
Changes for module/These/src/These/Form/TheseSaisie/TheseSaisieFormAwareTrait.php: 2 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -2,26 +2,12 @@

namespace These\Form\TheseSaisie;

trait TheseSaisieFormAwareTrait {

    /** @var TheseSaisieForm  */
    private TheseSaisieForm $theseSaisieForm;

    /**
     * @return TheseSaisieForm
     */
    public function getTheseSaisieForm(): TheseSaisieForm
trait TheseSaisieFormAwareTrait
{
        return $this->theseSaisieForm;
    }
    protected TheseSaisieForm $theseSaisieForm;

    /**
     * @param TheseSaisieForm $theseSaisieForm
     */
    public function setTheseSaisieForm(TheseSaisieForm $theseSaisieForm): void
    {
        $this->theseSaisieForm = $theseSaisieForm;
    }


}
 No newline at end of file
Loading