Skip to content
Snippets Groups Projects
Select Git revision
  • 3e1a1f8abf4bb7a0f6860e9fda89a7bc7b27f287
  • master default protected
  • release/8.0-perimetres
  • php84
  • detached3
  • 6.x
  • 7.x
  • detached2
  • detached
  • php82
  • 5.x
  • cherry-pick-bf3b5271
  • v5.x-test
  • laminas_migration
  • 7.2.9
  • 7.2.8
  • 7.2.7
  • 7.2.6
  • 7.2.5
  • 7.2.4
  • 7.2.3
  • 7.2.2
  • 7.2.1
  • 7.2.0
  • 7.1.3
  • 7.1.2
  • 7.1.1
  • 7.1.0
  • 7.0.1
  • 7.0.0
  • 6.1.11
  • 6.1.10
  • 6.1.9
  • 6.1.8
34 results

MailController.php

Blame
  • valleet01's avatar
    Thibaut Vallee authored
    59043953
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    MailController.php 2.46 KiB
    <?php
    
    namespace UnicaenMail\Controller;
    
    use UnicaenMail\Service\Mail\MailServiceAwareTrait;
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\View\Model\ViewModel;
    
    class MailController extends AbstractActionController {
        use MailServiceAwareTrait;
    
        public function indexAction()
        {
            $mails = $this->getMailService()->getMails();
    
            return new ViewModel([
                'title' => 'Gestion des mails',
                'mails' => $mails,
            ]);
        }
    
        public function afficherAction()
        {
            $mail = $this->getMailService()->getRequestedMail($this);
    
            return new ViewModel([
                'title' => "Affichage du mail #". $mail->getId(),
                'mail' => $mail,
            ]);
        }
    
        public function testAction()
        {
            $request = $this->getRequest();
            if ($request->isPost()) {
                $data = $request->getPost();
                if(!isset($data['mail-to']) || !filter_var($data['mail-to'], FILTER_VALIDATE_EMAIL)) {
                    return ['title' => "Envoyer un mail de test", 'error' => "L'adresse mail saisie n'est pas valide."];
                }
                $mail = $this->getMailService()->sendMail($data['mail-to'], 'Mail de test', 'Ceci est un mail de test. <br/> <hr/>Merci de ne pas en tenir compte.');
                $mail->setMotsClefs(['TEST']);
                $this->getMailService()->update($mail);
            }
            return ['title' => "Envoyer un mail de test"];
        }
    
        public function reenvoiAction()
        {
            $mail = $this->getMailService()->getRequestedMail($this);
            $this->getMailService()->reenvoi($mail);
            return $this->redirect()->toRoute('mail', [], [], true);
        }
    
        public function supprimerAction()
        {
            $mail = $this->getMailService()->getRequestedMail($this);
    
            $request = $this->getRequest();
            if ($request->isPost()) {
                $data = $request->getPost();
                if ($data["reponse"] === "oui") $this->getMailService()->delete($mail);
                exit();
            }
    
            $vm = new ViewModel();
            if ($mail !== null) {
                $vm->setTemplate('unicaen-mail/default/confirmation');
                $vm->setVariables([
                    'title' => "Suppression du mail #" . $mail->getId(),
                    'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
                    'action' => $this->url()->fromRoute('mail/supprimer', ["mail" => $mail->getId()], [], true),
                ]);
            }
            return $vm;
        }
    }