version 3.1.14 : gestion des notifications *après* et *le jour même* des échéances. Depuis r99536 (version 3.1.6) on peut configurer des notifications après la date d'échéance, sauf que ces notifications ne partaient pas (attention aux copier/coller dans le code !), et de plus le contenu du mail ne prévoyait pas ce cas de figure.

Donc on fait les adaptations nécessaires pour ça. Quelques retouches au formulaire de configuration des notifs pour les afficher de façon un peu plus claire (« un jour avant » au lieu de « -1 jours » par ex.), les trier par date (avant, le jour même, après), et ajout d'une option « le jour même » dans le select, plus simple que de devoir mettre une durée de 0.

Pour le contenu du mail, obligé de scinder l'unique chaîne de langue en plusieurs parties pour prendre en compte tous les cas de figure.
svn/attic/shelves/BoOz/122940
tcharlss@bravecassine.com 7 years ago
parent fe2d3020c2
commit 2b9dc17b36

@ -51,6 +51,11 @@ function abonnements_upgrade($nom_meta_base_version, $version_cible) {
array('sql_alter',"TABLE spip_abonnements_offres DROP prix"),
);
// Ajout d'une valeur possible au champ `quand`
$maj['2.2.6'] = array(
array('sql_alter',"TABLE spip_abonnements_offres_notifications CHANGE `quand` `quand` ENUM('avant','apres','pendant') DEFAULT 'avant' NOT NULL")
);
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
}

@ -139,7 +139,7 @@ function abonnements_declarer_tables_principales($tables) {
'id_abonnements_offre' => 'bigint(21) DEFAULT 0 NOT NULL',
'duree' => 'int(11) NOT NULL DEFAULT 0',
'periode' => 'varchar(25) NOT NULL DEFAULT ""',
'quand' => 'ENUM("avant","apres") DEFAULT "avant" NOT NULL',
'quand' => 'ENUM("avant","apres","pendant") DEFAULT "avant" NOT NULL',
),
'key' => array(
'PRIMARY KEY' => 'id_abonnements_offres_notification',

@ -1,4 +1,5 @@
<div class="formulaire_spip formulaire_editer formulaire_#ENV{form}[ formulaire_#ENV{form}-(#ENV{id,nouveau})]">
<h3 class="titrem">[(#CHEMIN_IMAGE{notifications-24}|balise_img{'','cadre-icone'})]<:abonnementsoffre:configurer_notifications:></h3>
[<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
[<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
@ -7,9 +8,9 @@
parametre : url d'action ]
#ACTION_FORMULAIRE{#ENV{action}}
[(#REM) Liste des notifications enregistrées ]
<div class="liste-objets liste-objets-lies abonnements_offres_notifications">
<table class="spip liste">
<caption><strong class="caption"><:abonnementsoffre:configurer_notifications:></strong></caption>
<thead>
<tr class="first_row">
<th class="duree principale" scope="col'"><:abonnementsoffre:configurer_notifications_quand:></th>
@ -17,10 +18,20 @@
</tr>
</thead>
<tbody>
<BOUCLE_notifications(ABONNEMENTS_OFFRES_NOTIFICATIONS){id_abonnements_offre}{!par periode}{!par duree}>
[(#REM) Afficher les notifications dans l'ordre : avant, pendant, puis après l'échéance ]
<BOUCLE_ordre(DATA){source table, #LISTE{avant,pendant,apres}}>
<BOUCLE_notifications(ABONNEMENTS_OFFRES_NOTIFICATIONS)
{id_abonnements_offre}
{quand=#VALEUR}
{par periode}{inverse #VALEUR|=={apres}|?{0,1}}
{par duree}{inverse #VALEUR|=={apres}|?{0,1}}>
#SET{is_notifications,oui}
<tr>
<td class="duree principale">
[(#QUAND|=={avant}|oui)-][(#QUAND|=={avant}|non)+][(#VAL{abonnementsoffre:champ_periode_nb_}|concat{#PERIODE}|_T{#ARRAY{nb,#DUREE}})]
[(#QUAND|=={pendant}|?{
<:abonnementsoffre:champ_quand_choix_pendant:>,
[(#DUREE|singulier_ou_pluriel{abonnementsoffre:info_1_[(#PERIODE)]_[(#QUAND)],abonnementsoffre:info_nb_[(#PERIODE)]_[(#QUAND)]})]
})]
</td>
<td class="supprimer">
<button type="submit" class="button link delete" name="supprimer[#ID_ABONNEMENTS_OFFRES_NOTIFICATION]" value="X">
@ -30,17 +41,19 @@
</td>
</tr>
</BOUCLE_notifications>
</BOUCLE_ordre>
[(#GET{is_notifications}|non)
<tr>
<td colspan="2">Aucune notification</td>
<td colspan="2"><:abonnementsoffre:info_aucune_notification:></td>
</tr>
<//B_notifications>
]
</tbody>
</table>
</div>
<ul>
<[(#DIV|sinon{ul})] class="editer-groupe">
#GENERER_SAISIES{#ENV{_saisies}}
</ul>
</[(#DIV|sinon{ul})]>
[(#REM) ajouter les saisies supplementaires : extra et autre, a cet endroit ]
<!--extra-->

@ -5,17 +5,32 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
function formulaires_editer_abonnements_offre_notifications_saisies_dist($id_abonnements_offre, $retour=''){
return array(
array(
'saisie' => 'selection',
'options' => array(
'nom' => 'quand',
'label' => _T('abonnementsoffre:champ_quand_label'),
'cacher_option_intro' => 'oui',
'datas' => array(
'apres' => _T('abonnementsoffre:champ_quand_choix_apres'),
'avant' => _T('abonnementsoffre:champ_quand_choix_avant'),
'pendant' => _T('abonnementsoffre:champ_quand_choix_pendant'),
),
'defaut' => 'avant',
),
),
array(
'saisie' => 'input',
'options' => array(
'nom' => 'duree',
'label' => _T('abonnementsoffre:champ_duree_label'),
'defaut' => '',
'afficher_si_remplissage' => '@quand@ !== "pendant"',
),
'verifier' => array(
'type' => 'entier',
'options' => array(
'min' => (_request('periode') == 'jours') ? 0 : 1,
'min' => 0,
),
),
),
@ -30,19 +45,7 @@ function formulaires_editer_abonnements_offre_notifications_saisies_dist($id_abo
'jours' => _T('abonnementsoffre:champ_periode_choix_jours'),
),
'defaut' => 'mois',
),
),
array(
'saisie' => 'selection',
'options' => array(
'nom' => 'quand',
'label' => _T('abonnementsoffre:champ_quand_label'),
'cacher_option_intro' => 'oui',
'datas' => array(
'apres' => _T('abonnementsoffre:champ_quand_choix_apres'),
'avant' => _T('abonnementsoffre:champ_quand_choix_avant'),
),
'defaut' => 'avant',
'afficher_si_remplissage' => '@quand@ !== "pendant"',
),
),
);
@ -65,9 +68,37 @@ function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_ab
$erreurs = array();
if (!$supprimer = _request('supprimer')){
if (!strlen(_request('duree'))){
$duree = _request('duree');
$periode = _request('periode');
$quand = _request('quand');
// Normalisons les valeurs pour les notifs le jour même
if ($quand == 'pendant'
or (
$quand != 'pendant'
and $duree == 0
)
){
$duree = 0;
$periode = 'jours';
$quand = 'pendant';
set_request('duree', $duree);
set_request('periode', $periode);
set_request('quand', $quand);
}
// Durée obligatoire
// (ne pas utiliser l'option "obligatoire" des saisies car on ne pourrait pas supprimer)
if (!strlen($duree)){
$erreurs['duree'] = _T('info_obligatoire');
}
// Vérifier les doublons
if (sql_countsel('spip_abonnements_offres_notifications', array(
'id_abonnements_offre = ' . intval($id_abonnements_offre),
'duree = ' . intval($duree),
'periode = ' . sql_quote($periode),
'quand = ' . sql_quote($quand),
))){
$erreurs['message_erreur'] = _T('abonnementsoffre:erreur_notification_doublon');
}
}
return $erreurs;

@ -18,11 +18,16 @@ function genie_abonnements_verifier_notifications_dist($time){
// Pour chaque notification on va chercher les abonnés dont c'est le moment
foreach ($notifications as $notification){
//avant ou après la date de fin de l'abonnement?
if($relance['quand'] == "apres") $operateur = " - ";
else $operateur = " + ";
// Avant ou après la date de fin de l'abonnement ?
switch ($notification['quand']){
case 'apres':
$operateur = " - ";
break;
default:
$operateur = " + ";
}
// De combien doit-on modifier la date
// De combien doit-on modifier la date ?
switch ($notification['periode']){
case 'jours':
$ajout = " $operateur ${notification['duree']} days";
@ -40,7 +45,7 @@ function genie_abonnements_verifier_notifications_dist($time){
$echeance = date('Y-m-d', strtotime($jourdhui.$ajout));
}
// Pour cette notification on cherche donc tous les abonnés ayant cet échéance avec la même offre
// Pour cette notification on cherche donc tous les abonnés ayant cette échéance avec la même offre
if ($a_notifier = sql_allfetsel(
'id_abonnement, nom, email',
'spip_abonnements as a left join spip_auteurs as u on a.id_auteur=u.id_auteur',
@ -54,8 +59,15 @@ function genie_abonnements_verifier_notifications_dist($time){
foreach ($a_notifier as $abonne){
$id_job = job_queue_add(
'abonnements_notifier_echeance',
"Notifier ${abonne['nom']} ${notification['duree']} ${notification['periode']} avant la fin de son abonnement ${abonne['id_abonnement']}",
array($abonne['id_abonnement'], $abonne['nom'], $abonne['email'], $notification['duree'], $notification['periode']),
"Notifier ${abonne['nom']} ${notification['duree']} ${notification['periode']} ${notification['quand']} l'échéance de son abonnement ${abonne['id_abonnement']}",
array(
$abonne['id_abonnement'],
$abonne['nom'],
$abonne['email'],
$notification['duree'],
$notification['periode'],
$notification['quand'],
),
'inc/abonnements',
true
);

@ -249,10 +249,39 @@ function abonnements_desactiver($id_abonnement){
autoriser_exception('modifier', 'abonnement', $id_abonnement, false);
}
/*
* Envoyer un courriel à l'abonné pour lui rappeler combien de temps il lui reste
/**
* Envoyer un courriel à l'abonné pour lui rappeler une échéance.
*
* @example
* Échéances dans 15 jours, il y a 1 mois, et le jour même :
* ````
* abonnements_notifier_echeance(1, 'untel', 'x@email.ltd', 15, 'jours', 'avant');
* abonnements_notifier_echeance(1, 'untel', 'x@email.ltd', 1, 'mois', 'apres');
* abonnements_notifier_echeance(1, 'untel', 'x@email.ltd', 0, 'jours', 'pendant');
* ````
*
* @param int $id_abonnement
* Numéro de l'abonnement
* @param string $nom
* Nom de la personne à notifier
* @param string $email
* Email de la personne à notifier
* @param int $duree
* Durée de l'échéance
* @param string $periode
* Période de l'échéance : `jours` | `mois`
* @param string $quand
* Indique si on est avant, après, ou le jour même de l'échéance
* - `avant` : on est avant la fin de l'abonnement (par défaut pour rétro compat)
* - `après` : on est après la fin de l'abonnement
* - `pendant` : on est le jour même de la fin de l'abonnement
* @return void
*/
function abonnements_notifier_echeance($id_abonnement, $nom, $email, $duree, $periode){
function abonnements_notifier_echeance($id_abonnement, $nom, $email, $duree, $periode, $quand = 'avant'){
// Assurons nous que le "quand" est cohérent
if ($duree === 0){
$quand = 'pendant';
}
$quoi = 'abonnement_echeance';
$options = array(
'email' => $email,
@ -260,6 +289,7 @@ function abonnements_notifier_echeance($id_abonnement, $nom, $email, $duree, $pe
'email' => $email,
'duree' => $duree,
'periode' => $periode,
'quand' => $quand,
);
$notifications = charger_fonction('notifications', 'inc');
$notifications($quoi, $id_abonnement, $options);

@ -42,13 +42,23 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
'job_desactivation' => 'Désactivation de labonnement @id@',
// N
'notification_echeance_corps' => '<p>Bonjour @nom@,</p>
<p>Vous recevez ce courriel car vous êtes abonné au site @nom_site_spip@ avec loffre "@offre@".</p>
<p>Votre abonnement arrive à échéance dans : <strong>@echeance@</strong>.<br/>
Nous vous invitons donc à le renouveler avant son expiration.</p>
<p>Merci de votre confiance, et nhésitez pas à nous contacter pour toute information complémentaire.</p>',
'notification_echeance_sujet_jours' => 'Votre abonnement se termine dans @duree@ jour(s) !',
'notification_echeance_sujet_mois' => 'Votre abonnement se termine dans @duree@ mois !',
'notification_echeance_chapo' => '<p>Bonjour @nom@,</p>',
'notification_echeance_corps_avant' => '<p>Vous recevez ce courriel car vous êtes abonné.e au site @nom_site_spip@ avec loffre « @offre@ ».</p>
<p>Votre abonnement arrive à échéance dans : <strong>@echeance@</strong>.<br/>
Nous vous invitons donc à le renouveler avant son expiration.</p>',
'notification_echeance_corps_apres' => '<p>Vous recevez ce courriel car vous étiez abonné.e au site @nom_site_spip@ avec loffre « @offre@ ».</p>
<p>Votre abonnement est arrivé à échéance il y a : <strong>@echeance@</strong>.<br/>
Nous vous invitons donc à le renouveler.</p>',
'notification_echeance_corps_pendant' => '<p>Vous recevez ce courriel car vous êtes abonné.e au site @nom_site_spip@ avec loffre « @offre@ ».</p>
<p>Votre abonnement arrive à échéance aujourd\'hui.<br/>
Nous vous invitons donc à le renouveler avant son expiration.</p>',
'notification_echeance_signature' => '<p>Merci de votre confiance, et nhésitez pas à nous contacter pour toute information complémentaire.</p>',
'notification_echeance_sujet_jours_avant' => 'Votre abonnement se termine dans @duree@ jour(s) !',
'notification_echeance_sujet_jours_pendant' => 'Votre abonnement se termine aujourd\'hui !',
'notification_echeance_sujet_jours_apres' => 'Votre abonnement est terminé depuis @duree@ jour(s) !',
'notification_echeance_sujet_mois_avant' => 'Votre abonnement se termine dans @duree@ mois !',
'notification_echeance_sujet_mois_pendant' => 'Votre abonnement se termine ce mois-ci !',
'notification_echeance_sujet_mois_apres' => 'Votre abonnement est terminé depuis @duree@ mois !',
// R
'retirer_lien_abonnement' => 'Retirer cet abonnement',

@ -27,12 +27,16 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
'champ_prix_ttc_label' => 'Prix TTC',
'champ_quand_choix_apres' => 'Après',
'champ_quand_choix_avant' => 'Avant',
'champ_quand_choix_pendant' => 'Le jour même',
'champ_quand_label' => 'Quand ?',
'champ_taxe_label' => 'Tva (%)',
'champ_titre_label' => 'Titre',
'configurer_notifications' => 'Configurer les notifications',
'configurer_notifications_quand' => 'Quand ?',
// E
'erreur_notification_doublon' => 'Cette notification est déjà enregistrée',
// I
'icone_creer_abonnementsoffre' => 'Créer une offre dabonnement',
'icone_modifier_abonnementsoffre' => 'Modifier cette offre dabonnement',
@ -40,6 +44,15 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
'info_abonnementsoffres_auteur' => 'Les offres dabonnement de cet auteur',
'info_aucun_abonnementsoffre' => 'Aucune offre dabonnement',
'info_nb_abonnementsoffres' => '@nb@ offres dabonnement',
'info_1_jours_apres' => '1 jour après',
'info_nb_jours_apres' => '@nb@ jours après',
'info_1_jours_avant' => '1 jour avant',
'info_nb_jours_avant' => '@nb@ jours avant',
'info_1_mois_apres' => '1 mois après',
'info_nb_mois_apres' => '@nb@ mois après',
'info_1_mois_avant' => '1 mois avant',
'info_nb_mois_avant' => '@nb@ mois avant',
'info_aucune_notification' => 'Aucune notification',
// N
'nb_abonnements' => 'Nb. abo.',

@ -1,10 +1,42 @@
<BOUCLE_abonnement(ABONNEMENTS){id_abonnement}>
#SET{nom,#ENV{nom}}
[(#REM)
Modèle pour la notification d'une échéance d'un abonnement
Paramètres :
** obligatoire
* conseillé
- id_abonnement**
- nom* : nom du destinataire
- email* : email du destinataire
- duree* : nombre indiquant la durée par rapport à l'échéance
- periode* : unité de la durée
jours | mois
- quand* : indique quand on se situe par rapport à l'échéance
avant | apres | pendant
]
<BOUCLE_abonnement(ABONNEMENTS){id_abonnement}{tout}>
[(#REM)
Pour la date, si on n'a pas les valeurs requises dans l'env, on prévoit un fallback
]
<BOUCLE_date(CONDITION){si #ENV{duree}|is_null|ou{#ENV{periode}|is_null}|ou{#ENV{quand}|is_null}}>
#SET{duree,#ENV{date}|strtotime|moins{#DATE_FIN|strtotime}|div{86400}|abs|round}
#SET{periode,jours}
#SET{quand,#GET{duree}|=={0}|?{pendant,#ENV{date}|strtotime|>{#DATE_FIN|strtotime}|?{apres,avant}}}
</BOUCLE_date>
#SET{duree,#ENV{duree}}
#SET{periode,#ENV{periode}}
#SET{quand,#ENV{quand}}
<//B_date>
#SET{nom,#ENV{nom}|sinon{#INFO_NOM{auteur,#ID_AUTEUR}}}
#SET{email,#ENV{email}|sinon{#INFO_EMAIL{auteur,#ID_AUTEUR}}}
#SET{offre,#INFO_TITRE{abonnements_offre,#ID_ABONNEMENTS_OFFRE}}
#SET{echeance, #VAL{abonnementsoffre:champ_periode_nb_}|concat{#ENV{periode}}|_T{#ARRAY{nb,#ENV{duree}}}}
#SET{echeance, #VAL{abonnementsoffre:champ_periode_nb_}|concat{#GET{periode}}|_T{#ARRAY{nb,#GET{duree}}}}
<body>
<:abonnement:notification_echeance_corps{nom=#GET{nom}, nom_site_spip=#NOM_SITE_SPIP, offre=#GET{offre}, echeance=#GET{echeance}}:>
<:abonnement:notification_echeance_chapo{nom=#GET{nom}}:>
[(#VAL{abonnement:notification_echeance_corps_}|concat{#GET{quand}}|_T{#ARRAY{echeance,#GET{echeance},nom_site_spip,#NOM_SITE_SPIP,offre,#GET{offre}}})]
<:abonnement:notification_echeance_signature:>
</body>
</BOUCLE_abonnement>
#FILTRE{facteur_email_wrap_to_html}

@ -15,7 +15,12 @@ if (!defined("_ECRIRE_INC_VERSION")) {
* Options de notification
*/
function notifications_abonnement_echeance_dist($quoi, $id, $options) {
$sujet = _T('abonnement:notification_echeance_sujet_'.$options['periode'], array('duree'=>$options['duree']));
$sujet = _T(
"abonnement:notification_echeance_sujet_{$options['periode']}_{$options['quand']}",
array(
'duree' => $options['duree'],
)
);
// Destinataires
$destinataires = pipeline('notifications_destinataires',
array(
@ -36,6 +41,7 @@ function notifications_abonnement_echeance_dist($quoi, $id, $options) {
'email' => $options['email'],
'duree' => $options['duree'],
'periode' => $options['periode'],
'quand' => $options['quand'],
)
);
// Go go go

@ -1,8 +1,8 @@
<paquet
prefix="abonnements"
categorie="auteur"
version="3.1.13"
schema="2.2.5"
version="3.1.14"
schema="2.2.6"
etat="test"
compatibilite="[3.0.0;3.1.*]"
logo="prive/themes/spip/images/abonnements-64.png"

Loading…
Cancel
Save