Commit a7127e65 by Julien Jorry

Solidoume : add send quizz to >3 months participants + fix email layout + fix…

Solidoume : add send quizz to >3 months participants + fix email layout + fix total amount calculated on taking
parent 5a753503
......@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Command;
use App\Entity\Adherent;
use App\Entity\Flux;
use App\Entity\GlobalParameter;
use App\Entity\Prestataire;
use App\Entity\SolidoumeItem;
......@@ -94,6 +95,10 @@ class SolidoumeCommand extends Command
$this->io->title('Start');
$this->executeReminders();
// Envoi d'un quizz uniquement pour les utilisateurs de Solidoume !
if ($this->em->getRepository(SolidoumeParameter::class)->getValueOf('name') == 'Solidoume') {
$this->executeQuizz();
}
$this->executeTaking();
sleep(1);
$this->executeProgram();
......@@ -106,6 +111,25 @@ class SolidoumeCommand extends Command
}
/**
* Execute quizz : send quizz to all participant who have participated since 3 months minimum
*/
private function executeQuizz()
{
$this->io->title('START : Envoi du questionnaire');
$items = $this->em->getRepository(SolidoumeItem::class)->findBy(['enabled' => true]);
foreach ($items as $item) {
if ($this->hasToSendQuizz($item)) {
$item->setQuizzSended(true);
if (!$this->isTest) {
$this->em->persist($item);
$this->em->flush();
}
$this->sendQuizz($item);
}
}
}
/**
* Execute email reminder : If balance of account if not enough x days before date of paiement => send email.
*/
private function executeReminders()
......@@ -162,6 +186,35 @@ class SolidoumeCommand extends Command
}
/**
* Send Quizz email.
*
* @param SolidoumeItem $solidoumeItem
*/
private function sendQuizz(SolidoumeItem $solidoumeItem)
{
$adherent = $solidoumeItem->getAdherent();
$this->io->success("Envoi du questionnaire à l'adhérent : " . $adherent->__toString());
$subject = 'Vos retours sur ' . $this->em->getRepository(SolidoumeParameter::class)->getValueOf('name') . ' !';
$mail = (new \Swift_Message($subject))
->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL))
->setTo($adherent->getUser()->getEmail())
->setBody(
$this->templating->render(
'@kohinos/email/solidoume/quizz.html.twig',
[
'subject' => $subject,
'item' => $solidoumeItem,
]
),
'text/html'
);
if (!$this->isTest) {
$this->mailer->send($mail);
}
}
/**
* Take money of participant of solidoume if date of today is same as paiementDate.
*/
private function executeTaking()
......@@ -242,9 +295,11 @@ class SolidoumeCommand extends Command
$countParticipants = 0;
foreach ($items as $item) {
if ($this->isItemPayedThisMonth($item)) {
// @TODO
// $datas = $this->em->getRepository(Flux::class)->getQueryByAdherentAndDestinataire($adherent, $this->em->getRepository(Prestataire::class)->getPrestataireSolidoume());
$total += $item->getAmount();
$datas = $this->em->getRepository(Flux::class)->getQueryByAdherentAndDestinataire($item->getAdherent(), $this->em->getRepository(Prestataire::class)->getPrestataireSolidoume(), 'adherent_prestataire');
if (count($datas) > 0) {
$lastPrelevement = $datas[0];
}
$total += $lastPrelevement->getMontant();
if (!$item->getIsDonation()) {
++$countParticipants;
}
......@@ -257,7 +312,7 @@ class SolidoumeCommand extends Command
$this->io->success('Nombre de participants au programme : ' . $countParticipants . ' !');
$this->io->success('Total par participants (sans commission) : ' . ($total / $countParticipants) . ' !');
$this->io->success('Total par participants (avec commission de ' . $this->param->getCommission() . '%) : ' . $totalByParticipant . ' !');
exit();
try {
$em = $this->em;
$isTest = $this->isTest;
......@@ -325,6 +380,17 @@ class SolidoumeCommand extends Command
return false;
}
private function hasToSendQuizz(SolidoumeItem $item)
{
$datas = $this->em->getRepository(Flux::class)->getQueryByAdherentAndDestinataire($item->getAdherent(), $this->em->getRepository(Prestataire::class)->getPrestataireSolidoume(), 'adherent_prestataire');
if (count($datas) >= 3 && !$item->isQuizzSended()) {
return true;
}
return false;
}
/**
* Has to execute reminder by email ? Check date of paiement choose by adherent and number of days before remind.
*
......
......@@ -88,6 +88,13 @@ class SolidoumeItem
*/
protected $enabled = true;
/**
* @var bool
* @Assert\Type("bool")
* @ORM\Column(type="boolean")
*/
protected $quizzSended = false;
public function getId()
{
return $this->id;
......@@ -105,6 +112,18 @@ class SolidoumeItem
return $this;
}
public function isQuizzSended(): bool
{
return $this->quizzSended;
}
public function setQuizzSended(bool $quizzSended)
{
$this->quizzSended = $quizzSended;
return $this;
}
public function getAmount(): ?float
{
return $this->amount;
......
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220808113218 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE solidoume_item ADD quizz_sended TINYINT(1) NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE solidoume_item DROP quizz_sended');
}
}
<!DOCTYPE html>
<html lang="it">
<html lang="fr">
<head>
<title>{{title}}</title>
<meta charset="utf-8">
......
{% extends '@kohinos/email/email_layout.html.twig' %}
{% set title %}{% spaceless %}
{{ subject }}
{% endspaceless %}
{% endset %}
{% block content %}
<p>Bonjour,</p>
<p>Vous avez rejoint il y a trois mois le dispositif Soli'doume, et nous vous en remercions.</p>
<p>Afin de mieux cerner vos attentes et d'améliorer Soli'doume, nous vous proposons de répondre à quelques questions. Cela vous prendra environ 5 minutes.</p>
<p><a href="https://framaforms.org/retours-experience-solidoume-1655078263" alt="Lien vers les questionnaire">Lien vers les questionnaire</a></p>
<p>D'avance merci pour votre aide précieuse !</p>
<p>L'équipe Soli'doume</p>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment