Loading module/Indicateur/config/merged/abonnement.config.php +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ return [ 'resilier' => [ 'type' => Segment::class, 'options' => [ 'route' => '/resilier/:abonnement', 'route' => '/resilier/:indicateur', 'defaults' => [ 'controller' => AbonnementController::class, 'action' => 'resilier' Loading module/Indicateur/src/Indicateur/Controller/Abonnement/AbonnementController.php +12 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Indicateur\Controller\Abonnement; use DateInterval; use DateTime; use Indicateur\Entity\Db\Abonnement; use Indicateur\Service\Abonnement\AbonnementService; Loading Loading @@ -39,10 +40,13 @@ class AbonnementController extends AbstractActionController { return $this->redirect()->toRoute('indicateurs', [], [], true); } public function desabonnementAction() public function resilierAction() { $abonnement = $this->getAbonnementService()->getRequestedAbonnement($this); $this->getAbonnementService()->delete($abonnement); $indicateur = $this->getIndicateurService()->getRequestedIndicateur($this); $user = $this->getUserService()->getConnectedUser(); $abonnements = $this->getAbonnementService()->getAbonnementsByUserAndIndicateur($user, $indicateur); foreach ($abonnements as $abonnement) $this->getAbonnementService()->delete($abonnement); return $this->redirect()->toRoute('indicateurs', [], [], true); } Loading @@ -53,7 +57,7 @@ class AbonnementController extends AbstractActionController { $now = new DateTime(); $listing = []; foreach ($abonnements as $abonnement) { if ($now - $abonnement->getFrequence() > $abonnement->getDernierEnvoi()) { if (date_diff($now, $abonnement->getDernierEnvoi()) > DateInterval::createFromDateString($abonnement->getFrequence())) { $listing[$abonnement->getIndicateur()->getId()][] = $abonnement; } } Loading @@ -78,8 +82,11 @@ class AbonnementController extends AbstractActionController { foreach ($list as $abonnement) { $this->getAbonnementService()->notify($abonnement, $titre, $texte, $now); $abonnement->setDernierEnvoi($now); $this->getAbonnementService()->update($abonnement); } } exit(); return $this->redirect()->toRoute('indicateurs', [], [], true); } } No newline at end of file module/Indicateur/src/Indicateur/Service/Abonnement/AbonnementService.php +19 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use DateTime; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Indicateur\Entity\Db\Abonnement; use Indicateur\Entity\Db\Indicateur; use Mailing\Service\Mailing\MailingServiceAwareTrait; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; Loading Loading @@ -131,4 +132,22 @@ class AbonnementService { $this->getMailingService()->sendMail($mail, $titre, $texte); $abonnement->setDernierEnvoi($date); } /** * @param User $user * @param Indicateur $indicateur * @return Abonnement[] */ public function getAbonnementsByUserAndIndicateur($user, $indicateur) { $qb = $this->getEntityManager()->getRepository(Abonnement::class)->createQueryBuilder('abonnement') ->andWhere('abonnement.user = :user') ->andWhere('abonnement.indicateur = :indicateur') ->setParameter('user', $user) ->setParameter('indicateur', $indicateur) ; $result = $qb->getQuery()->getResult(); return $result; } } No newline at end of file module/Indicateur/view/indicateur/indicateur/index.phtml +8 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,15 @@ $canDetruire = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPr <td> <?php echo count($indicateur->getAbonnements()); ?> <?php if ($abonnements[$indicateur->getId()]) : ?> <?php /** @see AbonnementController::resilierAction() */?> <a href="<?php echo $this->url("abonnement/resilier", ['indicateur' => $indicateur->getId()], [], true); ?>"> <span class="icon ok" style="color:darkgreen;" title="Vous êtes abonné·e à cet indicateur"></span> </a> <?php else : ?> <?php /** @see AbonnementController::souscrireAction() */?> <a href="<?php echo $this->url("abonnement/souscrire", ['indicateur' => $indicateur->getId()], [], true); ?>"> <span class="icon ko" style="color:darkred;" title="Vous n'êtes pas abonné·e à cet indicateur"></span> </a> <?php endif;?> </td> <td> Loading Loading
module/Indicateur/config/merged/abonnement.config.php +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ return [ 'resilier' => [ 'type' => Segment::class, 'options' => [ 'route' => '/resilier/:abonnement', 'route' => '/resilier/:indicateur', 'defaults' => [ 'controller' => AbonnementController::class, 'action' => 'resilier' Loading
module/Indicateur/src/Indicateur/Controller/Abonnement/AbonnementController.php +12 −5 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Indicateur\Controller\Abonnement; use DateInterval; use DateTime; use Indicateur\Entity\Db\Abonnement; use Indicateur\Service\Abonnement\AbonnementService; Loading Loading @@ -39,10 +40,13 @@ class AbonnementController extends AbstractActionController { return $this->redirect()->toRoute('indicateurs', [], [], true); } public function desabonnementAction() public function resilierAction() { $abonnement = $this->getAbonnementService()->getRequestedAbonnement($this); $this->getAbonnementService()->delete($abonnement); $indicateur = $this->getIndicateurService()->getRequestedIndicateur($this); $user = $this->getUserService()->getConnectedUser(); $abonnements = $this->getAbonnementService()->getAbonnementsByUserAndIndicateur($user, $indicateur); foreach ($abonnements as $abonnement) $this->getAbonnementService()->delete($abonnement); return $this->redirect()->toRoute('indicateurs', [], [], true); } Loading @@ -53,7 +57,7 @@ class AbonnementController extends AbstractActionController { $now = new DateTime(); $listing = []; foreach ($abonnements as $abonnement) { if ($now - $abonnement->getFrequence() > $abonnement->getDernierEnvoi()) { if (date_diff($now, $abonnement->getDernierEnvoi()) > DateInterval::createFromDateString($abonnement->getFrequence())) { $listing[$abonnement->getIndicateur()->getId()][] = $abonnement; } } Loading @@ -78,8 +82,11 @@ class AbonnementController extends AbstractActionController { foreach ($list as $abonnement) { $this->getAbonnementService()->notify($abonnement, $titre, $texte, $now); $abonnement->setDernierEnvoi($now); $this->getAbonnementService()->update($abonnement); } } exit(); return $this->redirect()->toRoute('indicateurs', [], [], true); } } No newline at end of file
module/Indicateur/src/Indicateur/Service/Abonnement/AbonnementService.php +19 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use DateTime; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Indicateur\Entity\Db\Abonnement; use Indicateur\Entity\Db\Indicateur; use Mailing\Service\Mailing\MailingServiceAwareTrait; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; Loading Loading @@ -131,4 +132,22 @@ class AbonnementService { $this->getMailingService()->sendMail($mail, $titre, $texte); $abonnement->setDernierEnvoi($date); } /** * @param User $user * @param Indicateur $indicateur * @return Abonnement[] */ public function getAbonnementsByUserAndIndicateur($user, $indicateur) { $qb = $this->getEntityManager()->getRepository(Abonnement::class)->createQueryBuilder('abonnement') ->andWhere('abonnement.user = :user') ->andWhere('abonnement.indicateur = :indicateur') ->setParameter('user', $user) ->setParameter('indicateur', $indicateur) ; $result = $qb->getQuery()->getResult(); return $result; } } No newline at end of file
module/Indicateur/view/indicateur/indicateur/index.phtml +8 −2 Original line number Diff line number Diff line Loading @@ -59,9 +59,15 @@ $canDetruire = $this->isAllowed(IndicateurPrivileges::getResourceId(IndicateurPr <td> <?php echo count($indicateur->getAbonnements()); ?> <?php if ($abonnements[$indicateur->getId()]) : ?> <?php /** @see AbonnementController::resilierAction() */?> <a href="<?php echo $this->url("abonnement/resilier", ['indicateur' => $indicateur->getId()], [], true); ?>"> <span class="icon ok" style="color:darkgreen;" title="Vous êtes abonné·e à cet indicateur"></span> </a> <?php else : ?> <?php /** @see AbonnementController::souscrireAction() */?> <a href="<?php echo $this->url("abonnement/souscrire", ['indicateur' => $indicateur->getId()], [], true); ?>"> <span class="icon ko" style="color:darkred;" title="Vous n'êtes pas abonné·e à cet indicateur"></span> </a> <?php endif;?> </td> <td> Loading