Commit 99c2d16d authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Ajout de la possiblité d'envoyer un email à un intervenant via le module note.

parent 9b8159f7
Loading
Loading
Loading
Loading
+26 −14
Changes for data/ddl/view/V_INTERVENANT_HISTORIQUE.sql: 26 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -3,11 +3,13 @@ OR REPLACE FORCE VIEW V_INTERVENANT_HISTORIQUE AS
WITH historique AS(
SELECT
  d.intervenant_id   intervenant_id,
  'Saisie des données personnelles'              label,
  ''Données personnelles''                         categorie,
  ''Saisie des données personnelles''              label,
  d.histo_modification                          histo_date,
  d.histo_createur_id                              histo_createur_id,
  u.display_name                       histo_user,
  'glyphicon glyphicon-ok' icon
  ''glyphicon glyphicon-ok'' icon,
  1                        ordre
FROM
  intervenant_dossier d
  JOIN utilisateur u ON u.id = d.histo_createur_id
@@ -17,26 +19,30 @@ FROM
--Validation des données personnelles
SELECT
  d.intervenant_id   intervenant_id,
  'Validation des données personnelles'              label,
  ''Données personnelles''                         categorie,
  ''Validation des données personnelles''              label,
  v.histo_creation                     histo_date,
v.histo_createur_id                       histo_createur_id,
  u.display_name                       histo_user,
  'glyphicon glyphicon-ok' icon
  ''glyphicon glyphicon-ok'' icon,
  1                        ordre
FROM
  validation v
  JOIN utilisateur u ON u.id = v.histo_createur_id
  JOIN type_validation tv ON tv.id = v.type_validation_id AND tv.code = 'DONNEES_PERSO_PAR_COMP'
  JOIN type_validation tv ON tv.id = v.type_validation_id AND tv.code = ''DONNEES_PERSO_PAR_COMP''
  JOIN intervenant_dossier d ON d.histo_destruction IS NULL AND d.intervenant_id = v.intervenant_id

  UNION ALL

 SELECT
  pj.intervenant_id   intervenant_id,
  'Validation pièce justificative : ' || tpj.libelle               label,
  ''Pièces justificatives''		                   categorie,
  ''Validation pièce justificative : '' || tpj.libelle               label,
  v.histo_creation           histo_date,
  v.histo_createur_id        histo_createur_id,
  u.display_name     histo_user,
  'glyphicon glyphicon-ok' icon
  ''glyphicon glyphicon-ok'' icon,
  2                        ordre
FROM
  validation v
  JOIN utilisateur u ON u.id = v.histo_createur_id
@@ -46,11 +52,13 @@ FROM
  UNION ALL

SELECT pj.intervenant_id                                      intervenant_id,
       'Dépôt pièce justificative : ' || tpj.libelle          label,
	   ''Pièces justificatives''		                   categorie,
       ''Dépôt pièce justificative : '' || tpj.libelle          label,
       pj.histo_creation                                      histo_date,
       pj.histo_createur_id                                   histo_createur_id,
       u.display_name                                         histo_user,
       'glyphicon glyphicon-ok'                               icon
       ''glyphicon glyphicon-ok''                               icon,
       2													  ordre
FROM piece_jointe pj
         JOIN type_piece_jointe tpj ON pj.type_piece_jointe_id = tpj.id
         JOIN utilisateur u ON u.id = pj.histo_createur_id
@@ -59,20 +67,24 @@ WHERE pj.histo_destruction IS NULL
UNION ALL

SELECT s.intervenant_id                                                               intervenant_id,
       'Saisi de service prévisionnel : ' || vh.heures || ' heures ' || ti.code || ', ' || p.libelle_court ||
       CASE WHEN mnp.id IS NULL THEN '' ELSE ' (NP: ' || mnp.libelle_court || ')' END label,
	   ''Services prévisionnels           		''		                   categorie,
       ''Saisi de service prévisionnel : '' || vh.heures || '' heures '' || ti.code || '', '' || p.libelle_court ||
       CASE WHEN mnp.id IS NULL THEN '''' ELSE '' (NP: '' || mnp.libelle_court || '')'' END label,
       vh.histo_creation                                                 histo_date,
       vh.histo_createur_id                                              histo_createur_id,
       u.display_name                                                    histo_user,
       'glyphicon glyphicon-calendar'                                                 icon
       ''glyphicon glyphicon-calendar''                                    icon,
       3																 ordre
FROM volume_horaire vh
         JOIN service s ON s.id = vh.service_id
         JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id AND tvh.code = 'PREVU'
         JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id AND tvh.code = ''PREVU''
         JOIN periode p ON p.id = vh.periode_id
         JOIN type_intervention ti ON ti.id = vh.type_intervention_id
         JOIN utilisateur u ON u.id = vh.histo_createur_id
         LEFT JOIN motif_non_paiement mnp ON mnp.id = vh.motif_non_paiement_id )
SELECT rownum id,
       categorie,
       ordre,
       intervenant_id,
       label,
       histo_date,
@@ -80,4 +92,4 @@ SELECT rownum id,
       histo_user,
       icon
FROM historique
ORDER BY rownum ASC
ORDER BY intervenant_id, ordre ASC, histo_date ASC
 No newline at end of file
+27
Changes for module/Application/src/Service/DossierService.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -83,6 +83,33 @@ class DossierService extends AbstractEntityService
        return $dossier;
    }

    public function getEmailsIntervenant(Intervenant $intervenant)
    {
        $emails = [
            'perso' => '',
            'pro'   => '',
        ];
        //On récupére en priorité les emails fournis dans le dossier de l'intervenant
        $sql = "SELECT email_pro, email_perso FROM intervenant_dossier WHERE intervenant_id = :intervenant AND histo_destruction IS NULL";
        $res = $this->getEntityManager()->getConnection()->fetchAssociative($sql, [
            'intervenant' => $intervenant->getId(),
        ]);

        //Si pas de dossier alors on prend les informations de la fiche intervenant
        if (!empty($res)) {
            $emailsIntervenantDossierPerso = $res['EMAIL_PERSO'] ?? '';
            $emailsIntervenantDossierPro = $res['EMAIL_PRO'] ?? '';
        }
        $emailsIntervenantPerso = $intervenant->getEmailPerso();
        $emailsIntervenantPro = $intervenant->getEmailPerso();

        $emails['perso'] = (!empty($emailsIntervenantDossierPerso)) ? $emailsIntervenantDossierPerso : $emailsIntervenantPerso;
        $emails['pro'] = (!empty($emailsIntervenantDossierPro)) ? $emailsIntervenantDossierPro : $emailsIntervenantPro;

        return $emails;

    }


    /**
     * Enregistrement d'un dossier.
+11 −2
Changes for module/Intervenant/config/module.config.php: 11 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,15 @@ return [
                    ],
                    'may_terminate' => true,
                ],
                'envoyer-email' => [
                    'options'       => [
                        'route'    => '/envoyer-email',
                        'defaults' => [
                            'action' => 'envoyer-email',
                        ],
                    ],
                    'may_terminate' => true,
                ],
            ],
        ],
        'statut' => [
@@ -131,7 +140,7 @@ return [
        ],
        [
            'controller' => 'Intervenant\Controller\Note',
            'action' => ['saisir'],
            'action'     => ['saisir', 'envoyer-email'],
            'assertion'  => Assertion\NoteAssertion::class,
        ],
        [
@@ -149,7 +158,7 @@ return [
        [
            'privileges' => [
                NoteAssertion::PRIV_EDITER_NOTE,
                NoteAssertion::PRIV_SUPPRIMER_NOTE
                NoteAssertion::PRIV_SUPPRIMER_NOTE,
            ],
            'resources'  => 'Note',
            'assertion'  => Assertion\NoteAssertion::class,
+46
Changes for module/Intervenant/src/Controller/NoteController.php: 46 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,14 +7,21 @@ use Application\Controller\AbstractController;
use Application\Provider\Privilege\Privileges;
use Intervenant\Assertion\NoteAssertion;
use Intervenant\Entity\Db\Note;
use Intervenant\Form\MailerIntervenantFormAwareTrait;
use Intervenant\Form\NoteSaisieFormAwareTrait;
use Intervenant\Service\NoteServiceAwareTrait;

use Laminas\Mail\Message as MailMessage;
use Laminas\Mime\Message;
use Laminas\Mime\Mime;
use Laminas\Mime\Part;
use UnicaenApp\View\Model\MessengerViewModel;

class NoteController extends AbstractController
{
    use NoteServiceAwareTrait;
    use NoteSaisieFormAwareTrait;
    use MailerIntervenantFormAwareTrait;

    public function indexAction()
    {
@@ -106,5 +113,44 @@ class NoteController extends AbstractController

        return new MessengerViewModel(compact('note'));
    }

    public function envoyerEmailAction()
    {
        $intervenant = $this->getEvent()->getParam('intervenant');

        $form = $this->getFormMailerIntervenant()->setIntervenant($intervenant)->initForm();

        if ($this->getRequest()->isPost()) {

            $data = $this->getRequest()->getPost();
            $from = $data['from'];
            $to = $data['to'];
            $subject = $data['subject'];
            $content = $data['content'];

            $body = new Message();

            $text = new Part($content);
            $text->type = Mime::TYPE_HTML;
            $text->charset = 'utf-8';
            $body->addPart($text);
            $message = new MailMessage();

            $message->setEncoding('UTF-8')
                ->setFrom($from)
                ->setSubject($subject)
                ->addTo($to)
                ->setBody($body);

            //Envoi du mail
            $this->mail()->send($message);
            //Création d'une trace de l'envoi dans les notes de l'intervenant
            $this->getServiceNote()->createNoteFromEmail($intervenant, $subject, $content);


        }

        return compact('intervenant', 'form');
    }
}
+x+131
Changes for module/Intervenant/src/Form/MailerIntervenantForm.php: 131 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Intervenant\Form;

use Application\Entity\Db\Intervenant;
use Application\Form\AbstractForm;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\DossierServiceAwareTrait;
use Intervenant\Entity\Db\Note;
use Application\Service\Traits\TypeIntervenantServiceAwareTrait;
use Intervenant\Entity\Db\Statut;
use Intervenant\Service\NoteServiceAwareTrait;
use Intervenant\Service\TypeNoteServiceAwareTrait;
use Laminas\Form\Element\Checkbox;
use Laminas\Form\Element\Hidden;
use Laminas\Form\Element\Text;
use Laminas\Form\Element\Textarea;
use Laminas\Form\Form;

/**
 * Description of Statut
 *
 * @author Antony Le Courtes <antony.lecourtes at unicaen.fr>
 */
class MailerIntervenantForm extends AbstractForm
{

    use DossierServiceAwareTrait;
    use ContextServiceAwareTrait;


    protected Intervenant $intervenant;

    public function initForm()
    {
        $labels = [
            'from'    => 'Expéditeur',
            'subject' => 'Objet du mail',
            'to'      => 'Email intervenant',
            'content' => 'Contenu du mail',

        ];


        $this->setAttribute('action', $this->getCurrentUrl());

        $this->setAttribute('id', 'mailer-intervenant');


        /*  $form = new Form();
          $form->setAttribute('action', $this->url()->fromRoute(null, [], [], true));
          $form->add((new Text('from'))->setValue($from));
          $form->add(new Text('cci'));
          $form->add((new Text('nombre'))->setValue(count($emails)));
          $form->add((new Text('subject'))->setValue($subject));
          $form->add((new Textarea('body'))->setValue($body));
          $form->add((new Checkbox('copy'))->setValue(1));
          $form->add((new Hidden('intervenants'))->setValue($intervenantsStringIds));
          $form->getInputFilter()->get('subject')->setRequired(true);
          $form->getInputFilter()->get('body')->setRequired(true);*/


        $this->spec([
            'from'    => [
                'type' => 'Text',
                'name' => 'from',

            ],
            'to'      => [
                'type' => 'Select',
                'name' => 'to',

            ],
            'subject' => [
                'type' => 'Text',
                'name' => 'subject',
            ],
            'content' => [
                'type'       => 'Textarea',
                'name'       => 'content',
                'attributes' => ['id' => 'content-mailer-intervenant'],
            ],
        ]);


        $this->build();


        //On set l'email de destination par rapport à l'intervenant
        $emails = $this->getServiceDossier()->getEmailsIntervenant($this->intervenant);

        $emailValues = [];
        if (!empty($emails['perso'])) {
            $emailValues[$emails['perso']] = 'E-mail perso - ' . $emails['perso'];
        }
        if (!empty($emails['pro'])) {
            $emailValues[$emails['pro']] = 'E-mail pro - ' . $emails['pro'];
        }
        $this->setValueOptions('to', $emailValues);

        //On set l'email expéditeur par rapport au contexte utilisateur
        $context = $this->getServiceContext();
        $emailUtilisateur = $context->getUtilisateur()->getEmail();
        $this->get('from')->setValue($emailUtilisateur);

        //On set les labels des champs de formulaire
        $this->setLabels($labels);

        //On définit les champs obligatoire
        $this->getInputFilter()->get('subject')->setRequired('true');
        $this->getInputFilter()->get('content')->setRequired('true');

        $this->addSubmit('Envoyer');

        return $this;
    }

    public function setIntervenant(Intervenant $intervenant)
    {
        $this->intervenant = $intervenant;

        return $this;
    }

    public function getIntervenant(): Intervenant
    {
        return $this->intervenant;
    }


}
Loading