Commit 752e9dca authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Refacto : createNotificationCorrectionAttendue() est mieux dans...

Refacto : createNotificationCorrectionAttendue() est mieux dans DepotNotificationFactory que dans TheseNotificationFactory.
parent 60adf9b1
Loading
Loading
Loading
Loading
+10 −25
Changes for module/Depot/src/Depot/Notification/ChangementCorrectionAttendueNotification.php: 10 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ namespace Depot\Notification;
use Notification\Exception\RuntimeException;
use Notification\Notification;
use These\Entity\Db\Interfaces\TheseAwareTrait;
use UnicaenApp\Exception\LogicException;

class ChangementCorrectionAttendueNotification extends Notification
{
@@ -13,17 +12,20 @@ class ChangementCorrectionAttendueNotification extends Notification

    protected ?string $templatePath = 'depot/depot/mail/notif-depot-version-corrigee-attendu';

    private bool $estPremiereNotif;

    public function setEstPremiereNotif(bool $estPremiereNotif = true): static
    {
        $this->estPremiereNotif = $estPremiereNotif;

        return $this;
    }

    /**
     * Initialisation, préparation, etc. nécessaires avant de pouvoir envoyer la notification.
     *
     * @return static
     */
    public function prepare()
    public function prepare(): static
    {
        if ($this->estPremiereNotif === null) {
            throw new LogicException("Attribut estPremiereNotif non sp avant l'appel de prepare()");
        }

        $directeursTheseEnCopie = false;
        if ($this->these->getCorrectionAutoriseeEstObligatoire() && !$this->estPremiereNotif) {
            $directeursTheseEnCopie = true;
@@ -54,21 +56,4 @@ class ChangementCorrectionAttendueNotification extends Notification

        return $this;
    }

    /**
     * @var bool
     */
    private $estPremiereNotif;

    /**
     * @param bool $estPremiereNotif
     * @return $this
     */
    public function setEstPremiereNotif($estPremiereNotif = true)
    {
        $this->estPremiereNotif = $estPremiereNotif;

        return $this;
    }

}
 No newline at end of file
+45 −26
Changes for module/Depot/src/Depot/Service/Notification/DepotNotificationFactory.php: 45 added lines, 26 removed lines.
Original line number Diff line number Diff line
@@ -9,10 +9,13 @@ use Application\Service\Email\EmailTheseServiceAwareTrait;
use Application\Service\Role\RoleServiceAwareTrait;
use Application\Service\Variable\VariableServiceAwareTrait;
use Depot\Entity\Db\FichierThese;
use Depot\Notification\ChangementCorrectionAttendueNotification;
use Depot\Notification\ValidationDepotTheseCorrigeeNotification;
use Depot\Notification\ValidationPageDeCouvertureNotification;
use Depot\Notification\ValidationRdvBuNotification;
use Depot\Rule\NotificationDepotVersionCorrigeeAttenduRule;
use Fichier\Entity\Db\VersionFichier;
use Import\Model\ImportObservResult;
use Laminas\View\Helper\Url as UrlHelper;
use Notification\Exception\RuntimeException;
use Notification\Notification;
@@ -34,36 +37,21 @@ class DepotNotificationFactory extends \Notification\Factory\NotificationFactory
    use RoleServiceAwareTrait;
    use EmailTheseServiceAwareTrait;

    /**
     * @var UrlHelper
     */
    protected UrlHelper $urlHelper;

    /**
     * @var ModuleOptions
     */
    private ModuleOptions $appModuleOptions;

    /**
     * @param UrlHelper $urlHelper
     */
    public function setUrlHelper(UrlHelper $urlHelper)
    public function setUrlHelper(UrlHelper $urlHelper): void
    {
        $this->urlHelper = $urlHelper;
    }

    /**
     * @param ModuleOptions $options
     */
    public function setAppModuleOptions(ModuleOptions $options)
    public function setAppModuleOptions(ModuleOptions $options): void
    {
        $this->appModuleOptions = $options;
    }

    /**
     * {@inheritdoc}
     */
    public function initNotification(Notification $notification)
    public function initNotification(Notification $notification): void
    {
        parent::initNotification($notification);

@@ -82,7 +70,6 @@ class DepotNotificationFactory extends \Notification\Factory\NotificationFactory
     * @param FichierThese         $fichierTheseRetraite Fichier retraité concerné
     * @param ValiditeFichier|null $validite             Résultat du test d'archivabilité éventuel
     * @return Notification
     * @return Notification
     */
    public function createNotificationForRetraitementFini(
        string $destinataires,
@@ -160,9 +147,6 @@ class DepotNotificationFactory extends \Notification\Factory\NotificationFactory

    /**
     * Notification à l'issue du dépôt d'un fichier.
     *
     * @param These $these
     * @return Notification
     */
    public function createNotificationForFichierTeleverse(These $these): Notification
    {
@@ -178,10 +162,6 @@ class DepotNotificationFactory extends \Notification\Factory\NotificationFactory
        return $notif;
    }

    /**
     * @param These $these
     * @return Notification
     */
    public function createNotificationForAccordSursisCorrection(These $these): Notification
    {
        $emailBDD = $this->emailTheseService->fetchEmailAspectsDoctorat($these);
@@ -257,6 +237,45 @@ class DepotNotificationFactory extends \Notification\Factory\NotificationFactory
        return $notification;
    }

    /**
     * Notification à propos de corrections attendues.
     *
     * @param ImportObservResult $record
     * @param These $these
     * @param string|null $message
     * @return \Notification\NotificationResult|null
     */
    public function createNotificationCorrectionAttendue(ImportObservResult $record, These $these, ?string &$message = null): ?Notification
    {
        // interrogation de la règle métier pour savoir comment agir...
        $rule = new NotificationDepotVersionCorrigeeAttenduRule();
        $rule
            ->setThese($these)
            ->setDateDerniereNotif($record->getDateNotif())
            ->execute();
        $message = $rule->getMessage(' ');
        $estPremiereNotif = $rule->estPremiereNotif();
        $dateProchaineNotif = $rule->getDateProchaineNotif();

        if ($dateProchaineNotif === null) {
            return null;
        }

        $dateProchaineNotif->setTime(0, 0, 0);
        $now = (new \DateTime())->setTime(0, 0, 0);

        if ($now != $dateProchaineNotif) {
            return null;
        }

        $notif = new ChangementCorrectionAttendueNotification();
        $notif
            ->setThese($these)
            ->setEstPremiereNotif($estPremiereNotif);

        return $notif;
    }

    /**
     * Notification pour inviter à valider les corrections.
     */
+4 −2
Changes for module/Import/src/Import/Model/Service/ImportObservResultService.php: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Import\Model\Service;
use Application\Constants;
use Application\Service\Variable\VariableServiceAwareTrait;
use Depot\Rule\NotificationDepotVersionCorrigeeAttenduRule;
use Depot\Service\Notification\DepotNotificationFactoryAwareTrait;
use Doctrine\ORM\Exception\ORMException;
use Import\Model\ImportObserv;
use Import\Model\ImportObservResult;
@@ -25,6 +26,7 @@ class ImportObservResultService extends \UnicaenDbImport\Entity\Db\Service\Impor
    use TheseServiceAwareTrait;
    use NotifierServiceAwareTrait;
    use TheseNotificationFactoryAwareTrait;
    use DepotNotificationFactoryAwareTrait;
    use VariableServiceAwareTrait;
    use LoggerAwareTrait;

@@ -258,9 +260,9 @@ class ImportObservResultService extends \UnicaenDbImport\Entity\Db\Service\Impor

            $these->setCorrectionAutorisee($ior->getImportObserv()->getToValue()); // anticipation nécessaire !

            // notification
            // notification par mail
            try {
                $notif = $this->theseNotificationFactory->createNotificationCorrectionAttendue($ior, $these, $message);
                $notif = $this->depotNotificationFactory->createNotificationCorrectionAttendue($ior, $these, $message);
                if ($notif === null) {
                    $this->logger->info(sprintf("Aucune notif n'est nécessaire pour la thèse '%s'. ", $these->getSourceCode()) . $message);
                    continue; // si le service de notif renvoie null, aucune notif n'était nécessaire, on passe au suivant
+5 −0
Changes for module/Import/src/Import/Model/Service/ImportObservResultServiceFactory.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Import\Model\Service;

use Depot\Service\Notification\DepotNotificationFactory;
use Notification\Service\NotifierService;
use These\Service\Notification\TheseNotificationFactory;
use These\Service\These\TheseService;
@@ -48,6 +49,10 @@ class ImportObservResultServiceFactory
        $theseNotificationFactory = $container->get(TheseNotificationFactory::class);
        $service->setTheseNotificationFactory($theseNotificationFactory);

        /** @var \Depot\Service\Notification\DepotNotificationFactory $depotNotificationFactory */
        $depotNotificationFactory = $container->get(DepotNotificationFactory::class);
        $service->setDepotNotificationFactory($depotNotificationFactory);

        if ($logger = $this->getLogger($container)) {
            $service->setLogger($logger);
        }
+0 −42
Changes for module/These/src/These/Service/Notification/TheseNotificationFactory.php: 0 added lines, 42 removed lines.
Original line number Diff line number Diff line
@@ -3,10 +3,7 @@
namespace These\Service\Notification;

use Application\Service\Email\EmailTheseServiceAwareTrait;
use Depot\Notification\ChangementCorrectionAttendueNotification;
use Depot\Notification\PasDeMailPresidentJury;
use Depot\Rule\NotificationDepotVersionCorrigeeAttenduRule;
use Import\Model\ImportObservResult;
use Notification\Exception\RuntimeException;
use Notification\Factory\NotificationFactory;
use Notification\Notification;
@@ -79,45 +76,6 @@ class TheseNotificationFactory extends NotificationFactory
    }


    /**
     * Notification à propos de corrections attendues.
     *
     * @param ImportObservResult $record
     * @param These $these
     * @param string|null $message
     * @return \Notification\NotificationResult|null
     */
    public function createNotificationCorrectionAttendue(ImportObservResult $record, These $these, ?string &$message = null): ?Notification
    {
        // interrogation de la règle métier pour savoir comment agir...
        $rule = new NotificationDepotVersionCorrigeeAttenduRule();
        $rule
            ->setThese($these)
            ->setDateDerniereNotif($record->getDateNotif())
            ->execute();
        $message = $rule->getMessage(' ');
        $estPremiereNotif = $rule->estPremiereNotif();
        $dateProchaineNotif = $rule->getDateProchaineNotif();

        if ($dateProchaineNotif === null) {
            return null;
        }

        $dateProchaineNotif->setTime(0, 0, 0);
        $now = (new \DateTime())->setTime(0, 0, 0);

        if ($now != $dateProchaineNotif) {
            return null;
        }

        $notif = new ChangementCorrectionAttendueNotification();
        $notif
            ->setThese($these)
            ->setEstPremiereNotif($estPremiereNotif);

        return $notif;
    }

    /**
     * Notification à propos du dépassement de la date butoir de dépôt de la version corrigée de la thèse.
     *