Commit 92c881ea authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Thèses : modification de la valeur du témoin de corrections attendues d'une thèse non importée.

parent fae78fdf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ Journal des modifications
- Admission : une année universitaire d'inscription cible doit désormais être attribuée au dossier d'admission.
- Autorisation de diplomation : déplacement du bouton à la fin de la procédure de soutenance (après délibération du jury pour résultat admis). 
- Thèses : refonte de la gestion événementielle en cas de modification du résultat (manuelle ou par la synchro) ou de la correction attendue (par la synchro uniquement).
- Thèses : modification de la valeur du témoin de corrections attendues d'une thèse non importée.
- [FIX] Notification de thèse déposée : warning 'Undefined variable' à cause d'une variable non fournie au template.
- [FIX] Notification 'Corrections attendues' et 'Résultats de thèses modifiés' : correction de l'erreur 'Typed property Notification\Notification::$subject must not be accessed before initialization'.
- [FIX] Notification 'Corrections attendues' et 'Résultats de thèses modifiés' : problème dans l'algo de préparation des données (partie émergée : 'Warning: Undefined array key').
+14 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ return [
                [
                    'controller' => DepotController::class,
                    'action' => [
                        'modifier-correction-autorisee',
                        'modifier-correction-autorisee-forcee',
                    ],
                    'privileges' => [
@@ -649,6 +650,19 @@ return [
                            ],
                        ],
                    ],
                    'modifier-correction-autorisee' => [
                        'type' => 'Segment',
                        'options' => [
                            'route' => '/modifier-correction-autorisee/:these',
                            'constraints' => [
                                'these' => '\d+',
                            ],
                            'defaults' => [
                                'controller' => DepotController::class,
                                'action' => 'modifier-correction-autorisee',
                            ],
                        ],
                    ],
                    'modifier-correction-autorisee-forcee' => [
                        'type' => 'Segment',
                        'options' => [
+76 −4
Original line number Diff line number Diff line
@@ -561,7 +561,44 @@ class DepotController extends AbstractController
        return $view;
    }

    public function modifierCorrectionAutoriseeForceeAction()
    public function modifierCorrectionAutoriseeAction(): ViewModel|Response
    {
        $these = $this->requestedThese();

        // cas particulier pour une thèse importée : c'est la valeur "forcée" qui est modifiée
        if ($these->getSource()->getImportable()) {
            /** @see modifierCorrectionAutoriseeForceeAction() */
            return $this->redirect()->toRoute('these/modifier-correction-autorisee-forcee', reuseMatchedParams: true);
        }

        $form = $this->getCorrectionAutoriseeForm($these);

        if ($this->getRequest()->isPost()) {
            /** @var ParametersInterface $post */
            $post = $this->getRequest()->getPost();
            $form->setData($post);
            if ($form->isValid()) {
                $value = $post->get('correctionAutorisee') ?: null;
                $this->depotService->updateCorrectionAutorisee($these, $value);
            }
        }
        else {
            $form->get('correctionAutorisee')->setValue($these->getCorrectionAutorisee() ?: '');
        }

        $form->setAttribute('action', $this->urlDepot()->modifierCorrecAutoriseeUrl($these));

        $vm = new ViewModel([
            'these' => $these,
            'form' => $form,
            'title' => "Modification du témoin de corrections attendues",
        ]);
        $vm->setTemplate('depot/depot/modifier-correction-autorisee');

        return $vm;
    }

    public function modifierCorrectionAutoriseeForceeAction(): ViewModel
    {
        $these = $this->requestedThese();
        $form = $this->getCorrectionAutoriseeForceeForm($these);
@@ -581,14 +618,49 @@ class DepotController extends AbstractController

        $form->setAttribute('action', $this->urlDepot()->modifierCorrecAutoriseeForceeUrl($these));

        return new ViewModel([
        $vm = new ViewModel([
            'these' => $these,
            'form' => $form,
            'title' => "Forçage du témoin de corrections attendues",
        ]);
        $vm->setTemplate('depot/depot/modifier-correction-autorisee-forcee');

        return $vm;
    }

    private function getCorrectionAutoriseeForm(These $these): Form
    {
        $radioOptions = [
            These::$CORRECTION_AUTORISEE_AUCUNE      => "Aucune correction attendue",
            These::$CORRECTION_AUTORISEE_FACULTATIVE => "Corrections <strong>facultatives</strong> attendues",
            These::$CORRECTION_AUTORISEE_OBLIGATOIRE => "Corrections <strong>obligatoires</strong> attendues",
        ];

        $radio = (new Radio('correctionAutorisee'))
            ->setValueOptions($radioOptions)
            ->setLabelOption('disable_html_escape', true);

        $message = sprintf(
            "Actuellement, la valeur du témoin de corrections attendues <br>est &laquo; <strong>%s</strong> &raquo;. <br>" .
            "Vous avez ici la possibilité de modifier sa valeur.",
            $these->getCorrectionAutorisee()
        );

        $form = new Form('these');
        $form->setLabel($message);
        $form->add($radio);
        FormUtils::addSaveButton($form);

        $form->setInputFilter((new InputFilter())->getFactory()->createInputFilter([
            'correctionAutorisee' => [
                'allow_empty' => true
            ]
        ]));

        return $form;
    }

    private function getCorrectionAutoriseeForceeForm(These $these)
    private function getCorrectionAutoriseeForceeForm(These $these): Form
    {
        $isCorrectionAutoriseeFromImport = $these->isCorrectionAutorisee(false);
        $valeurCorrectionAutoriseeFromImport = $these->getCorrectionAutorisee(false);
@@ -617,7 +689,7 @@ class DepotController extends AbstractController
            ->setLabelOption('disable_html_escape', true);

        $message = sprintf(
            "Actuellement, la valeur du témoin de corrections attendues importé de %s <br>est &laquo; <strong>%s</strong> &raquo;. <br>" .
            "Actuellement, la valeur du témoin de corrections attendues importé de %s est &laquo; <strong>%s</strong> &raquo;.<br>" .
            "Vous avez ici la possibilité d'outre-passer cette valeur importée en réalisant un forçage...",
            $these->getSource(),
            $correctionAttendueImportee
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ use These\Entity\Db\These;
 * @method attestationThese(These $these, $version)
 * @method diffusionThese(These $these, $version)
 * @method modifierMetadonneesUrl(These $these)
 * @method modifierCorrecAutoriseeUrl(These $these)
 * @method modifierCorrecAutoriseeForceeUrl(These $these)
 * @method accorderSursisCorrecUrl(These $these)
 * @method certifierConformiteTheseRetraiteUrl(These $these, $version)
+35 −8
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ use Application\Service\Notification\ApplicationNotificationFactoryAwareTrait;
use Application\Service\UserContextServiceAwareTrait;
use Application\Service\Utilisateur\UtilisateurServiceAwareTrait;
use Application\Service\Variable\VariableServiceAwareTrait;
use Assert\Assertion;
use DateTime;
use Depot\Entity\Db\Attestation;
use Depot\Entity\Db\Diffusion;
@@ -25,17 +24,16 @@ use Depot\Service\Validation\DepotValidationServiceAwareTrait;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\OptimisticLockException;
use Exception;
use Fichier\Entity\Db\NatureFichier;
use Fichier\Entity\Db\VersionFichier;
use Fichier\Service\Fichier\FichierStorageServiceAwareTrait;
use InvalidArgumentException;
use Laminas\EventManager\Event;
use Laminas\EventManager\EventManagerInterface;
use Laminas\EventManager\ListenerAggregateInterface;
use Laminas\EventManager\ListenerAggregateTrait;
use Notification\Service\NotifierServiceAwareTrait;
use Soutenance\Service\Membre\MembreServiceAwareTrait;
use stdClass;
use Structure\Service\Etablissement\EtablissementServiceAwareTrait;
use These\Entity\Db\Repository\TheseRepository;
use These\Entity\Db\These;
@@ -45,6 +43,7 @@ use UnicaenApp\Exception\LogicException;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Traits\MessageAwareInterface;
use UnicaenAuthentification\Service\Traits\UserServiceAwareTrait;
use Webmozart\Assert\Assert;

class DepotService extends BaseService implements ListenerAggregateInterface
{
@@ -131,16 +130,44 @@ class DepotService extends BaseService implements ListenerAggregateInterface
        return $this->theseService->getRepository();
    }

    /**
     * Met à jour le témoin de correction autorisée.
     */
    public function updateCorrectionAutorisee(These $these, string $value = null): void
    {
        if ($value !== null) {
            Assert::inArray($value, [
                These::$CORRECTION_AUTORISEE_AUCUNE,
                These::$CORRECTION_AUTORISEE_FACULTATIVE,
                These::$CORRECTION_AUTORISEE_OBLIGATOIRE,
            ]);
        }

        $these->setCorrectionAutorisee($value);
        $these->setCorrectionAutoriseeForcee(null); // supprime un éventuel forçage

        // s'il n'y a plus de correction attendue, effacement du sursis éventuel
        if (! $these->getCorrectionAutorisee()) {
            $these->unsetDateButoirDepotVersionCorrigeeAvecSursis();
        }

        $this->entityManager->beginTransaction();
        try {
            $this->entityManager->commit();
            $this->entityManager->flush();
        } catch (Exception $e) {
            $this->entityManager->rollback();
            throw new RuntimeException("Erreur rencontrée lors de l'enregistrement", null, $e);
        }
    }

    /**
     * Met à jour le témoin de correction autorisée forcée.
     *
     * @param These  $these
     * @param string|null $forcage
     */
    public function updateCorrectionAutoriseeForcee(These $these, string $forcage = null)
    public function updateCorrectionAutoriseeForcee(These $these, ?string $forcage): void
    {
        if ($forcage !== null) {
            Assertion::inArray($forcage, [
            Assert::inArray($forcage, [
                These::$CORRECTION_AUTORISEE_FORCAGE_AUCUNE,
                These::$CORRECTION_AUTORISEE_FORCAGE_FACULTATIVE,
                These::$CORRECTION_AUTORISEE_FORCAGE_OBLIGATOIRE,
Loading