Skip to content
Snippets Groups Projects
Select Git revision
  • ca24df071ad192a685e99bd1d8dc9d1327c1730a
  • master default protected
  • main
  • update_github_actions
  • 144_rocky8_support
  • 195-update-pdk-to-300
  • 144-rocky8
  • add_test_github_test_workflow
  • pdk_2.4.0
  • fix_unclosed_let_block_in_defines_client_spec
  • validation_fixes
  • freeradius_3_0_21_config_updates
  • data_types
  • PrepareBuster
  • travis
  • 4.0.1
  • 4.0.0
  • 3.9.2
  • 3.9.1
  • 3.9.0
  • 3.8.2
  • 3.8.1
  • 3.8.0
  • 3.7.0
  • 3.6.0
  • 3.5.0
  • 3.4.3
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.3.1
35 results

dictionary.header

Blame
  • 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;
        }
    }