diff --git a/abonnements_administrations.php b/abonnements_administrations.php index dbf10be..8bec29d 100644 --- a/abonnements_administrations.php +++ b/abonnements_administrations.php @@ -5,66 +5,68 @@ * (c) 2012 Les Développements Durables * Licence GNU/GPL v3 */ -if (!defined('_ECRIRE_INC_VERSION')) + +if (!defined('_ECRIRE_INC_VERSION')) { return; +} /** * Fonction d'installation du plugin et de mise à jour. * */ function abonnements_upgrade($nom_meta_base_version, $version_cible) { - $maj = array(); + $maj = []; - $maj['create'] = array(array('maj_tables', array('spip_abonnements_offres', 'spip_abonnements_offres_liens', 'spip_abonnements', 'spip_abonnements_offres_notifications'))); + $maj['create'] = [['maj_tables', ['spip_abonnements_offres', 'spip_abonnements_offres_liens', 'spip_abonnements', 'spip_abonnements_offres_notifications']]]; // Ajout de la config des notifications - $maj['2.1.0'] = array( - array('maj_tables', array('spip_abonnements_offres_notifications')) - ); + $maj['2.1.0'] = [ + ['maj_tables', ['spip_abonnements_offres_notifications']] + ]; // Ajout de la date d'échéance possiblement différente avec la date de fin - $maj['2.2.0'] = array( - array('maj_tables', array('spip_abonnements')), - array('sql_update', 'spip_abonnements', array('date_echeance' => 'date_fin')) - ); + $maj['2.2.0'] = [ + ['maj_tables', ['spip_abonnements']], + ['sql_update', 'spip_abonnements', ['date_echeance' => 'date_fin']] + ]; // Ajout des champs taxe et prix_ht, on copie la valeur de prix dans prix_ht - $maj['2.2.2'] = array( - array('maj_tables', array('spip_abonnements_offres')), - array('sql_alter', 'TABLE spip_abonnements_offres ADD prix_ht float(10,2) not null default 0 AFTER periode'), - array('sql_alter', 'TABLE spip_abonnements_offres ADD taxe decimal(4,4) null default 0 AFTER prix_ht'), - array('sql_update', 'spip_abonnements_offres', array('prix_ht' => 'prix')), - array('sql_update', 'spip_abonnements_offres', array('prix' => '0')) - ); - + $maj['2.2.2'] = [ + ['maj_tables', ['spip_abonnements_offres']], + ['sql_alter', 'TABLE spip_abonnements_offres ADD prix_ht float(10,2) not null default 0 AFTER periode'], + ['sql_alter', 'TABLE spip_abonnements_offres ADD taxe decimal(4,4) null default 0 AFTER prix_ht'], + ['sql_update', 'spip_abonnements_offres', ['prix_ht' => 'prix']], + ['sql_update', 'spip_abonnements_offres', ['prix' => '0']] + ]; + // Nettoyage (d'une table inexistante...) - $maj['2.2.3'] = array( - array('sql_alter',"TABLE spip_contacts_abonnements DROP prix"), - ); - + $maj['2.2.3'] = [ + ['sql_alter','TABLE spip_contacts_abonnements DROP prix'], + ]; + // relancer des abonnements après échéance - $maj['2.2.4'] = array( - array('sql_alter',"TABLE spip_abonnements_offres_notifications ADD `quand` ENUM('avant','apres') DEFAULT 'avant' NOT NULL AFTER `periode`"), - ); + $maj['2.2.4'] = [ + ['sql_alter',"TABLE spip_abonnements_offres_notifications ADD `quand` ENUM('avant','apres') DEFAULT 'avant' NOT NULL AFTER `periode`"], + ]; // Nettoyage : le champ `prix` est inutile, il suffit de `prix_ht` et `taxe` - $maj['2.2.5'] = array( - 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") - ); - + $maj['2.2.5'] = [ + ['sql_alter','TABLE spip_abonnements_offres DROP prix'], + ]; + + // Ajout d'une valeur possible au champ `quand` + $maj['2.2.6'] = [ + ['sql_alter',"TABLE spip_abonnements_offres_notifications CHANGE `quand` `quand` ENUM('avant','apres','pendant') DEFAULT 'avant' NOT NULL"] + ]; + // Ajout d'un champ immatériel pour savoir si c'est un service virtuel ou matériel - $maj['2.3.0'] = array( - array('maj_tables', array('spip_abonnements_offres')), - ); - + $maj['2.3.0'] = [ + ['maj_tables', ['spip_abonnements_offres']], + ]; + // Passage en décimal - $maj['2.3.1'] = array( - array('sql_alter', 'TABLE spip_abonnements_offres CHANGE prix_ht prix_ht DECIMAL(20,6) NOT NULL DEFAULT 0'), - ); + $maj['2.3.1'] = [ + ['sql_alter', 'TABLE spip_abonnements_offres CHANGE prix_ht prix_ht DECIMAL(20,6) NOT NULL DEFAULT 0'], + ]; include_spip('base/upgrade'); maj_plugin($nom_meta_base_version, $version_cible, $maj); @@ -74,15 +76,15 @@ function abonnements_upgrade($nom_meta_base_version, $version_cible) { * Fonction de désinstallation du plugin. * */ function abonnements_vider_tables($nom_meta_base_version) { - sql_drop_table("spip_abonnements_offres"); - sql_drop_table("spip_abonnements_offres_liens"); - sql_drop_table("spip_abonnements"); - sql_drop_table("spip_abonnements_offres_notifications"); + sql_drop_table('spip_abonnements_offres'); + sql_drop_table('spip_abonnements_offres_liens'); + sql_drop_table('spip_abonnements'); + sql_drop_table('spip_abonnements_offres_notifications'); # Nettoyer les versionnages et forums - sql_delete("spip_versions", sql_in("objet", array('abonnements_offre', 'abonnement'))); - sql_delete("spip_versions_fragments", sql_in("objet", array('abonnements_offre', 'abonnement'))); - sql_delete("spip_forum", sql_in("objet", array('abonnements_offre', 'abonnement'))); + sql_delete('spip_versions', sql_in('objet', ['abonnements_offre', 'abonnement'])); + sql_delete('spip_versions_fragments', sql_in('objet', ['abonnements_offre', 'abonnement'])); + sql_delete('spip_forum', sql_in('objet', ['abonnements_offre', 'abonnement'])); effacer_meta($nom_meta_base_version); } diff --git a/abonnements_autorisations.php b/abonnements_autorisations.php index 163acaf..1ec69e2 100644 --- a/abonnements_autorisations.php +++ b/abonnements_autorisations.php @@ -1,14 +1,17 @@ array('modulo' => 24, 'periode' => 'jour'), - 'mois' => array('modulo' => 12, 'periode' => 'an'), - ); + $simplifier = [ + 'heure' => ['modulo' => 24, 'periode' => 'jour'], + 'mois' => ['modulo' => 12, 'periode' => 'an'], + ]; if ( isset($simplifier[$periode]) and (($duree % $simplifier[$periode]['modulo']) === 0) @@ -50,8 +51,8 @@ function filtre_abonnements_afficher_duree_dist($duree, $periode) { if (substr($periode, -1, 1) !== 's') { $periode .= 's'; } - $texte = _T("abonnementsoffre:info_nb_$periode", array('nb' => $duree)); + $texte = _T("abonnementsoffre:info_nb_$periode", ['nb' => $duree]); } return $texte; -} \ No newline at end of file +} diff --git a/abonnements_pipelines.php b/abonnements_pipelines.php index c971f48..1c4761e 100644 --- a/abonnements_pipelines.php +++ b/abonnements_pipelines.php @@ -5,8 +5,10 @@ * (c) 2012 Les Développements Durables * Licence GNU/GPL v3 */ -if (!defined('_ECRIRE_INC_VERSION')) + +if (!defined('_ECRIRE_INC_VERSION')) { return; +} /** * Optimiser la base de donnees des abonnements @@ -18,20 +20,21 @@ function abonnements_optimiser_base_disparus($flux) { //Offres d'abonnement à la poubelle $mydate = sql_quote(trim($flux['args']['date'], "'")); - sql_delete("spip_abonnements_offres", "statut='poubelle' AND maj < $mydate"); + sql_delete('spip_abonnements_offres', "statut='poubelle' AND maj < $mydate"); //Supprimer les abonnements lies à une offre d'abonnement inexistante - $res = sql_select("DISTINCT abonnements.id_abonnements_offre", "spip_abonnements AS abonnements + $res = sql_select('DISTINCT abonnements.id_abonnements_offre', 'spip_abonnements AS abonnements LEFT JOIN spip_abonnements_offres AS offres - ON abonnements.id_abonnements_offre=offres.id_abonnements_offre", "offres.id_abonnements_offre IS NULL"); - while ($row = sql_fetch($res)) - sql_delete("spip_abonnements", "id_abonnements_offre=" . $row['id_abonnements_offre']); + ON abonnements.id_abonnements_offre=offres.id_abonnements_offre', 'offres.id_abonnements_offre IS NULL'); + while ($row = sql_fetch($res)) { + sql_delete('spip_abonnements', 'id_abonnements_offre=' . $row['id_abonnements_offre']); + } //Abonnements à la poubelle - sql_delete("spip_abonnements", "statut='poubelle' AND maj < $mydate"); + sql_delete('spip_abonnements', "statut='poubelle' AND maj < $mydate"); include_spip('action/editer_liens'); - $flux['data'] += objet_optimiser_liens(array('abonnement' => '*'), '*'); + $flux['data'] += objet_optimiser_liens(['abonnement' => '*'], '*'); return $flux; } @@ -60,10 +63,10 @@ function abonnements_post_edition($flux) { // Si on a mis l'abonnement inactif ou à la poubelle, on doit enlever les tâches liées if ( isset($flux['data']['statut']) - and in_array($flux['data']['statut'], array('inactif', 'poubelle')) + and in_array($flux['data']['statut'], ['inactif', 'poubelle']) ) { include_spip('action/editer_liens'); - $liens = objet_trouver_liens(array('job' => '*'), array('abonnement' => $abonnement['id_abonnement'])); + $liens = objet_trouver_liens(['job' => '*'], ['abonnement' => $abonnement['id_abonnement']]); if ($liens and is_array($liens)) { // Et on les supprime toutes ! foreach ($liens as $lien) { @@ -80,12 +83,13 @@ function abonnements_post_edition($flux) { // On lie cet abonnement avec la commande qui l'a généré include_spip('action/editer_liens'); objet_associer( - array('commande' => $id_commande), array('abonnement' => $id_abonnement) + ['commande' => $id_commande], + ['abonnement' => $id_abonnement] ); } - $modifs = array(); - $modifs_instituer = array(); + $modifs = []; + $modifs_instituer = []; // Si l'échéance est VIDE, et que pourtant l'offre parente A BIEN une durée // alors c'est qu'il faut initialiser les dates ! @@ -110,8 +114,8 @@ function abonnements_post_edition($flux) { and $jourdhui <= $abonnement['date_echeance'] ) { $modifs_instituer['statut'] = 'actif'; - spip_log("Post-édition : passage de l’abonnement $id_abonnement en actif", 'abonnements.'._LOG_INFO); - spip_log($abonnement, 'abonnements.'._LOG_INFO); + spip_log("Post-édition : passage de l’abonnement $id_abonnement en actif", 'abonnements.' . _LOG_INFO); + spip_log($abonnement, 'abonnements.' . _LOG_INFO); } // Si aujourd'hui est en dehors des dates début et FIN, on désactive // on ne teste pas date_echeance car ce sera à un génie de désactiver si trop dépassée @@ -128,8 +132,8 @@ function abonnements_post_edition($flux) { ) ) { $modifs_instituer['statut'] = 'inactif'; - spip_log("Post-édition : passage de l’abonnement $id_abonnement en inactif", 'abonnements.'._LOG_INFO); - spip_log($abonnement, 'abonnements.'._LOG_INFO); + spip_log("Post-édition : passage de l’abonnement $id_abonnement en inactif", 'abonnements.' . _LOG_INFO); + spip_log($abonnement, 'abonnements.' . _LOG_INFO); } } @@ -146,7 +150,7 @@ function abonnements_post_edition($flux) { } // Détection magique du plugin Commandes et d'une commande d'offre d'abonnement elseif ( - // Si on institue une commande + // Si on institue une commande $flux['args']['table'] == 'spip_commandes' and $id_commande = intval($flux['args']['id_objet']) and $flux['args']['action'] == 'instituer' @@ -169,7 +173,7 @@ function abonnements_post_edition($flux) { // on force toujours la création d'un nouvel abonnement $forcer_creation = false; if ( - in_array($commande['echeances_type'], array('mois', 'annee')) + in_array($commande['echeances_type'], ['mois', 'annee']) and include_spip('inc/commandes_echeances') and commandes_nb_echeances_payees($id_commande) <= 1 ) { @@ -215,14 +219,16 @@ function abonnements_taches_generales_cron($taches) { * @return array */ function abonnements_affiche_gauche($flux) { - if (isset($flux['args']['exec']) + if ( + isset($flux['args']['exec']) and $flux['args']['exec'] == 'abonnements_offre' and isset($flux['args']['id_abonnements_offre']) ) { $flux['data'] .= recuperer_fond( - 'prive/squelettes/navigation/inc-abonnements_notifications', array( + 'prive/squelettes/navigation/inc-abonnements_notifications', + [ 'id_abonnements_offre' => $flux['args']['id_abonnements_offre'] - ) + ] ); } @@ -234,7 +240,7 @@ function abonnements_affiche_gauche($flux) { */ function abonnements_affiche_milieu($flux) { $e = trouver_objet_exec($flux['args']['exec']); - + // Sur la page des auteurs if ( is_array($e) @@ -243,11 +249,11 @@ function abonnements_affiche_milieu($flux) { ) { $id_auteur = $flux['args']['id_auteur']; - $ins = recuperer_fond('prive/squelettes/inclure/abonnements_auteur', array('id_auteur' => $id_auteur)); - if (($p = strpos($flux['data'], "")) !== false) + $ins = recuperer_fond('prive/squelettes/inclure/abonnements_auteur', ['id_auteur' => $id_auteur]); + if (($p = strpos($flux['data'], '')) !== false) { $flux['data'] = substr_replace($flux['data'], $ins, $p, 0); - else - $flux['data'] .= $ins; + } else { $flux['data'] .= $ins; + } } return $flux; @@ -258,22 +264,22 @@ function abonnements_affiche_milieu($flux) { */ function abonnements_affiche_enfants($flux) { $e = trouver_objet_exec($flux['args']['exec']); - + // Sur la page d'un objet s'il fait partie de la config if ( is_array($e) and !$e['edition'] - and in_array($e['table_objet_sql'], lire_config('abonnements/objets', array())) + and in_array($e['table_objet_sql'], lire_config('abonnements/objets', [])) and $texte = recuperer_fond( 'prive/objets/editer/liens', - array( + [ 'table_source' => 'abonnements_offres', 'objet' => $e['type'], 'id_objet' => $flux['args']['id_objet'] - ) + ] ) ) { - if ($p=strpos($flux['data'], '')) { + if ($p = strpos($flux['data'], '')) { $flux['data'] = substr_replace($flux['data'], $texte, $p, 0); } else { $flux['data'] .= $texte; @@ -291,7 +297,7 @@ function abonnements_affiche_enfants($flux) { */ function abonnements_affiche_hierarchie($flux) { include_spip('inc/config'); - + // Sur la page d'une offre if ( $flux['args']['objet'] == 'abonnements_offre' @@ -299,14 +305,16 @@ function abonnements_affiche_hierarchie($flux) { ) { include_spip('action/editer_liens'); $objets = array_map('objet_type', $objets); - + // On cherche si cette offre à des liens - if ($liens = objet_trouver_liens( - array('abonnements_offre' => $flux['args']['id_objet']), - array('*' => '*') - )) { - $liens_parents = array(); - $liens_offres = array(); + if ( + $liens = objet_trouver_liens( + ['abonnements_offre' => $flux['args']['id_objet']], + ['*' => '*'] + ) + ) { + $liens_parents = []; + $liens_offres = []; foreach ($liens as $lien) { // Seulement si ce lien est actuellement prévu dans la config if (in_array($lien['objet'], $objets)) { @@ -319,18 +327,18 @@ function abonnements_affiche_hierarchie($flux) { } } } - + if ($liens_parents) { $liens_parents = PtoBR(propre(_T('abonnementsoffre:liens_parents_label') . join(', ', $liens_parents))); - $flux['data'] .= '
'.$liens_parents.'
'; + $flux['data'] .= '
' . $liens_parents . '
'; } if ($liens_offres) { $liens_offres = PtoBR(propre(_T('abonnementsoffre:liens_offres_label') . join(', ', $liens_offres))); - $flux['data'] .= '
'.$liens_offres.'
'; + $flux['data'] .= '
' . $liens_offres . '
'; } } } - + return $flux; } diff --git a/action/modifier_echeance_abonnement.php b/action/modifier_echeance_abonnement.php index 1927f7c..45be86d 100644 --- a/action/modifier_echeance_abonnement.php +++ b/action/modifier_echeance_abonnement.php @@ -1,45 +1,46 @@ 0){ - $ajout = ' +'.$ajout; + if ($duree > 0) { + $ajout = ' +' . $ajout; } // Calcul de la date de fin - $modifications['date_echeance'] = date('Y-m-d H:i:s', strtotime($date_depart.$ajout)); - + $modifications['date_echeance'] = date('Y-m-d H:i:s', strtotime($date_depart . $ajout)); + // Si la date de fin n'est PAS infinie ET qu'elle se retrouve plus petite que l'échéance // On la remet au moins au même endroit que la nouvelle échéance if ( @@ -73,14 +74,14 @@ function action_modifier_echeance_abonnement_dist($arg=null) { ) { $modifications['date_fin'] = $modifications['date_echeance']; } - + // On lance la modification include_spip('action/editer_objet'); $erreur = objet_modifier('abonnement', $id_abonnement, $modifications); - - return array($id_abonnement, $erreur); + + return [$id_abonnement, $erreur]; } } - + return false; } diff --git a/action/renouveler_abonnement.php b/action/renouveler_abonnement.php index b07c960..5e5e85c 100644 --- a/action/renouveler_abonnement.php +++ b/action/renouveler_abonnement.php @@ -1,32 +1,32 @@ 0 and $offre['periode'] ) { $action = charger_fonction('modifier_echeance_abonnement', 'action/'); - return $action($id_abonnement.'/'.$offre['duree'].'/'.$offre['periode']); + return $action($id_abonnement . '/' . $offre['duree'] . '/' . $offre['periode']); } - + return false; } - diff --git a/action/resilier_abonnement.php b/action/resilier_abonnement.php index fe3e33a..de3bc8f 100644 --- a/action/resilier_abonnement.php +++ b/action/resilier_abonnement.php @@ -4,12 +4,12 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } -function action_resilier_abonnement($id_abonnement=null) { +function action_resilier_abonnement($id_abonnement = null) { if (is_null($id_abonnement)) { $securiser_action = charger_fonction('securiser_action', 'inc'); $id_abonnement = $securiser_action(); } - + if ( $id_abonnement = intval($id_abonnement) and $id_abonnement > 0 @@ -18,24 +18,24 @@ function action_resilier_abonnement($id_abonnement=null) { ) { include_spip('action/editer_objet'); include_spip('inc/abonnements'); - + // L'abonnement SPIP sera désactivé à la fin de l'échéance, on force donc cette date de fin, et on reprogramme dès maintenant la désactivation - $date_echeance = sql_getfetsel('date_echeance', 'spip_abonnements', 'id_abonnement = '.$id_abonnement); - objet_modifier('abonnement', $id_abonnement, array( + $date_echeance = sql_getfetsel('date_echeance', 'spip_abonnements', 'id_abonnement = ' . $id_abonnement); + objet_modifier('abonnement', $id_abonnement, [ 'date_fin' => $date_echeance, - )); + ]); abonnements_programmer_desactivation($id_abonnement, $date_echeance); - + // Si on détecte qu'il est lié à un prélèvement bancaire, on lance une résiliation par l'API if ( defined('_DIR_PLUGIN_COMMANDES') and defined('_DIR_PLUGIN_BANK') and include_spip('action/editer_liens') - and $liens = objet_trouver_liens(array('commande' => '*'), array('abonnement' => $id_abonnement)) + and $liens = objet_trouver_liens(['commande' => '*'], ['abonnement' => $id_abonnement]) and is_array($liens) // On prend juste la première commande qu'on trouve and $id_commande = intval($liens[0]['id_commande']) - and $bank_uid = sql_getfetsel('bank_uid', 'spip_commandes', 'id_commande = '.$id_commande) + and $bank_uid = sql_getfetsel('bank_uid', 'spip_commandes', 'id_commande = ' . $id_commande) ) { include_spip('abos/resilier'); abos_resilier_notify_bank($bank_uid); diff --git a/base/abonnements.php b/base/abonnements.php index ac35bce..8b7a579 100644 --- a/base/abonnements.php +++ b/base/abonnements.php @@ -5,8 +5,10 @@ * (c) 2012 Les Développements Durables * Licence GNU/GPL v3 */ -if (!defined('_ECRIRE_INC_VERSION')) + +if (!defined('_ECRIRE_INC_VERSION')) { return; +} /** * Déclaration des alias de tables et filtres automatiques de champs @@ -23,52 +25,52 @@ function abonnements_declarer_tables_interfaces($interfaces) { * Déclaration des objets éditoriaux */ function abonnements_declarer_tables_objets_sql($tables) { - $tables['spip_abonnements_offres'] = array( + $tables['spip_abonnements_offres'] = [ 'type' => 'abonnements_offre', - 'principale' => "oui", - 'table_objet_surnoms' => array('abonnementsoffre'), // table_objet('abonnement') => 'abonnements_offres' - 'field' => array( - "id_abonnements_offre" => "bigint(21) NOT NULL", - "titre" => "text NOT NULL DEFAULT ''", - "descriptif" => "text NOT NULL DEFAULT ''", - "duree" => "int(11) NOT NULL DEFAULT 0", - "periode" => "varchar(25) NOT NULL DEFAULT ''", + 'principale' => 'oui', + 'table_objet_surnoms' => ['abonnementsoffre'], // table_objet('abonnement') => 'abonnements_offres' + 'field' => [ + 'id_abonnements_offre' => 'bigint(21) NOT NULL', + 'titre' => "text NOT NULL DEFAULT ''", + 'descriptif' => "text NOT NULL DEFAULT ''", + 'duree' => 'int(11) NOT NULL DEFAULT 0', + 'periode' => "varchar(25) NOT NULL DEFAULT ''", 'prix_ht' => 'decimal(20,6) not null default 0', - "taxe" => "decimal(4,4) default 0", + 'taxe' => 'decimal(4,4) default 0', 'immateriel' => 'varchar(3) default "on"', - "statut" => "varchar(20) DEFAULT '0' NOT NULL", - "maj" => "TIMESTAMP" - ), - 'key' => array( - "PRIMARY KEY" => "id_abonnements_offre", - "KEY statut" => "statut", - ), + 'statut' => "varchar(20) DEFAULT '0' NOT NULL", + 'maj' => 'TIMESTAMP' + ], + 'key' => [ + 'PRIMARY KEY' => 'id_abonnements_offre', + 'KEY statut' => 'statut', + ], 'titre' => "titre AS titre, '' AS lang", #'date' => "", - 'champs_editables' => array('titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'), - 'champs_versionnes' => array('titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'), - 'rechercher_champs' => array("titre" => 10, "descriptif" => 5), - 'tables_jointures' => array('spip_abonnements_offres_liens'), - 'statut_textes_instituer' => array( + 'champs_editables' => ['titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'], + 'champs_versionnes' => ['titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'], + 'rechercher_champs' => ['titre' => 10, 'descriptif' => 5], + 'tables_jointures' => ['spip_abonnements_offres_liens'], + 'statut_textes_instituer' => [ 'prepa' => 'texte_statut_en_cours_redaction', 'prive' => 'abonnementsoffre:statut_prive', 'publie' => 'abonnementsoffre:statut_publie', 'poubelle' => 'texte_statut_poubelle', - ), - 'statut_images' => array( + ], + 'statut_images' => [ 'prepa' => 'puce-preparer-8.png', 'prive' => 'puce-refuser-8.png', 'publie' => 'puce-publier-8.png', 'poubelle' => 'puce-supprimer-8.png', - ), - 'statut' => array( - array( + ], + 'statut' => [ + [ 'champ' => 'statut', 'publie' => 'publie', 'previsu' => 'publie,prepa', - 'exception' => array('statut', 'tout') - ) - ), + 'exception' => ['statut', 'tout'] + ] + ], 'texte_modifier' => 'abonnementsoffre:icone_modifier_abonnementsoffre', 'texte_creer' => 'abonnementsoffre:icone_creer_abonnementsoffre', 'texte_creer_associer' => 'abonnementsoffre:texte_creer_associer_abonnementsoffre', @@ -81,59 +83,59 @@ function abonnements_declarer_tables_objets_sql($tables) { 'info_1_objet' => 'abonnementsoffre:info_1_abonnementsoffre', 'info_nb_objets' => 'abonnementsoffre:info_nb_abonnementsoffres', 'texte_changer_statut' => 'abonnementsoffre:texte_changer_statut_abonnementsoffre', - ); + ]; - $tables['spip_abonnements'] = array( + $tables['spip_abonnements'] = [ 'type' => 'abonnement', - 'principale' => "oui", + 'principale' => 'oui', # 'url_voir' => false, # 'url_edit' => false, - 'field' => array( - "id_abonnement" => "bigint(21) NOT NULL", - "id_abonnements_offre" => "bigint(21) NOT NULL DEFAULT 0", - "id_auteur" => "bigint(21) NOT NULL DEFAULT 0", - "date_debut" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", - "date_echeance" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", - "date_fin" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", - "statut" => "varchar(20) DEFAULT '0' NOT NULL", - "maj" => "TIMESTAMP" - ), - 'key' => array( - "PRIMARY KEY" => "id_abonnement", - "KEY statut" => "statut", - "KEY id_abonnements_offre" => "id_abonnements_offre", - "KEY id_auteur" => "id_auteur", - ), + 'field' => [ + 'id_abonnement' => 'bigint(21) NOT NULL', + 'id_abonnements_offre' => 'bigint(21) NOT NULL DEFAULT 0', + 'id_auteur' => 'bigint(21) NOT NULL DEFAULT 0', + 'date_debut' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'date_echeance' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'date_fin' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'", + 'statut' => "varchar(20) DEFAULT '0' NOT NULL", + 'maj' => 'TIMESTAMP' + ], + 'key' => [ + 'PRIMARY KEY' => 'id_abonnement', + 'KEY statut' => 'statut', + 'KEY id_abonnements_offre' => 'id_abonnements_offre', + 'KEY id_auteur' => 'id_auteur', + ], 'titre' => "'' AS titre, '' AS lang", - 'date' => "maj", - 'champs_editables' => array('id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'), - 'champs_versionnes' => array('id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'), - 'rechercher_champs' => array('date_echeance ' => 1), - 'rechercher_jointures' => array( - 'auteur' => array('nom' => 10, 'email' => 10), - ), - 'tables_jointures' => array(), - 'join' => array('id_auteur' => 'id_auteur'), - 'statut_textes_instituer' => array( + 'date' => 'maj', + 'champs_editables' => ['id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'], + 'champs_versionnes' => ['id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'], + 'rechercher_champs' => ['date_echeance ' => 1], + 'rechercher_jointures' => [ + 'auteur' => ['nom' => 10, 'email' => 10], + ], + 'tables_jointures' => [], + 'join' => ['id_auteur' => 'id_auteur'], + 'statut_textes_instituer' => [ 'inactif' => 'abonnement:statut_inactif', 'actif' => 'abonnement:statut_actif', 'poubelle' => 'texte_statut_poubelle', - ), - 'statut_images' => array( + ], + 'statut_images' => [ 'inactif' => 'puce-refuser-8.png', 'actif' => 'puce-publier-8.png', 'poubelle' => 'puce-supprimer-8.png', - ), - 'statut' => array( - array( + ], + 'statut' => [ + [ 'champ' => 'statut', 'publie' => 'actif', 'previsu' => 'actif,inactif', - 'exception' => array('statut', 'tout') - ) - ), + 'exception' => ['statut', 'tout'] + ] + ], 'texte_changer_statut' => 'abonnement:texte_changer_statut_abonnement', - ); + ]; return $tables; } @@ -143,19 +145,19 @@ function abonnements_declarer_tables_objets_sql($tables) { */ function abonnements_declarer_tables_principales($tables) { - $tables['spip_abonnements_offres_notifications'] = array( - 'field' => array( + $tables['spip_abonnements_offres_notifications'] = [ + 'field' => [ 'id_abonnements_offres_notification' => 'bigint(21) not null', '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","pendant") DEFAULT "avant" NOT NULL', - ), - 'key' => array( + ], + 'key' => [ 'PRIMARY KEY' => 'id_abonnements_offres_notification', 'KEY id_abonnements_offre' => 'id_abonnements_offre', - ), - ); + ], + ]; return $tables; } @@ -164,18 +166,18 @@ function abonnements_declarer_tables_principales($tables) { * Déclaration des tables secondaires (liaisons) */ function abonnements_declarer_tables_auxiliaires($tables) { - $tables['spip_abonnements_offres_liens'] = array( - 'field' => array( - "id_abonnements_offre" => "bigint(21) DEFAULT '0' NOT NULL", - "id_objet" => "bigint(21) DEFAULT '0' NOT NULL", - "objet" => "VARCHAR(25) DEFAULT '' NOT NULL", - "vu" => "VARCHAR(6) DEFAULT 'non' NOT NULL" - ), - 'key' => array( - "PRIMARY KEY" => "id_abonnements_offre,id_objet,objet", - "KEY id_abonnements_offre" => "id_abonnements_offre" - ) - ); + $tables['spip_abonnements_offres_liens'] = [ + 'field' => [ + 'id_abonnements_offre' => "bigint(21) DEFAULT '0' NOT NULL", + 'id_objet' => "bigint(21) DEFAULT '0' NOT NULL", + 'objet' => "VARCHAR(25) DEFAULT '' NOT NULL", + 'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL" + ], + 'key' => [ + 'PRIMARY KEY' => 'id_abonnements_offre,id_objet,objet', + 'KEY id_abonnements_offre' => 'id_abonnements_offre' + ] + ]; return $tables; } diff --git a/formulaires/configurer_abonnements.php b/formulaires/configurer_abonnements.php index 342a96b..e918657 100644 --- a/formulaires/configurer_abonnements.php +++ b/formulaires/configurer_abonnements.php @@ -5,16 +5,16 @@ if (!defined('_ECRIRE_INC_VERSION')) { } function formulaires_configurer_abonnements_saisies_dist() { - $saisies = array( - array( + $saisies = [ + [ 'saisie' => 'choisir_objets', - 'options' => array( + 'options' => [ 'nom' => 'objets', 'label' => _T('abonnementsoffre:configurer_objets_label'), 'explication' => _T('abonnementsoffre:configurer_objets_explication'), - ), - ), - ); - + ], + ], + ]; + return $saisies; } diff --git a/formulaires/editer_abonnement.php b/formulaires/editer_abonnement.php index 9288177..27b0590 100644 --- a/formulaires/editer_abonnement.php +++ b/formulaires/editer_abonnement.php @@ -1,11 +1,13 @@ 'hidden', - 'options' => array( + 'options' => [ 'nom' => 'id_abonnements_offre', 'defaut' => $id_abonnements_offre, - ), - ), - array( + ], + ], + [ 'saisie' => 'auteurs', - 'options' => array( + 'options' => [ 'nom' => 'id_auteur', 'label' => _T('abonnement:champ_id_auteur_label'), 'obligatoire' => 'oui', 'cacher_option_intro' => 'oui', - ), - ), - ); + ], + ], + ]; } // Sinon si c'est une demande de création et qu'on trouve un auteur, on ne doit donner que les offres et l'utilisateur est défini caché elseif ($id_abonnement == 0 and $id_auteur = _request('id_auteur')) { - $saisies = array( - array( + $saisies = [ + [ 'saisie' => 'hidden', - 'options' => array( + 'options' => [ 'nom' => 'id_auteur', 'defaut' => $id_auteur, - ), - ), - array( + ], + ], + [ 'saisie' => 'abonnements_offres', - 'options' => array( + 'options' => [ 'nom' => 'id_abonnements_offre', 'label' => _T('abonnement:champ_id_abonnements_offre_label'), 'obligatoire' => 'oui', 'cacher_option_intro' => 'oui', - ), - ), - ); + ], + ], + ]; } // Sinon si c'est une demande de modification, on ne peut modifier que les dates elseif ($id_abonnement > 0) { - $saisies = array( - array( + $saisies = [ + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_debut', 'label' => _T('abonnement:champ_date_debut_label'), 'horaire' => 'on', 'heure_pas' => 5, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'date', - 'options' => array( + 'options' => [ 'normaliser' => 'datetime', - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_echeance', 'label' => _T('abonnement:champ_date_echeance_label'), 'horaire' => 'on', 'heure_pas' => 5, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'date', - 'options' => array( + 'options' => [ 'normaliser' => 'datetime', - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_fin', 'label' => _T('abonnement:champ_date_fin_label'), 'horaire' => 'on', 'heure_pas' => 5, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'date', - 'options' => array( + 'options' => [ 'normaliser' => 'datetime', - ), - ), - ), - ); + ], + ], + ], + ]; } - + return $saisies; } /** * Identifier le formulaire en faisant abstraction des parametres qui ne representent pas l'objet edite */ -function formulaires_editer_abonnement_identifier_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){ - return serialize(array(intval($id_abonnement))); +function formulaires_editer_abonnement_identifier_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { + return serialize([intval($id_abonnement)]); } /** * Declarer les champs postes et y integrer les valeurs par defaut */ -function formulaires_editer_abonnement_charger_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){ - $valeurs = formulaires_editer_objet_charger('abonnement',$id_abonnement,'',$lier_trad,$retour,$config_fonc,$row,$hidden); +function formulaires_editer_abonnement_charger_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { + $valeurs = formulaires_editer_objet_charger('abonnement', $id_abonnement, '', $lier_trad, $retour, $config_fonc, $row, $hidden); unset($valeurs['id_abonnement']); return $valeurs; } @@ -131,27 +133,27 @@ function formulaires_editer_abonnement_charger_dist($id_abonnement='new', $retou /** * Verifier les champs postes et signaler d'eventuelles erreurs */ -function formulaires_editer_abonnement_verifier_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){ - $erreurs = array();//formulaires_editer_objet_verifier('abonnement',$id_abonnement); - +function formulaires_editer_abonnement_verifier_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { + $erreurs = [];//formulaires_editer_objet_verifier('abonnement',$id_abonnement); + // Pour une création on vérifie l'offre if ( !intval($id_abonnement) and ( !$id_abonnements_offre = _request('id_abonnements_offre') - or !sql_getfetsel('id_abonnements_offre', 'spip_abonnements_offres', 'id_abonnements_offre = '.intval($id_abonnements_offre)) + or !sql_getfetsel('id_abonnements_offre', 'spip_abonnements_offres', 'id_abonnements_offre = ' . intval($id_abonnements_offre)) ) ) { $erreurs['message_erreur'] = _T('abonnement:erreur_id_abonnements_offre'); } - + return $erreurs; } /** * Traiter les champs postes */ -function formulaires_editer_abonnement_traiter_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){ +function formulaires_editer_abonnement_traiter_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { # // Si c'est pour une modif on appelle l'allongement # if (intval($id_abonnement) > 0) { # // On récupère les champs qui ne font pas partie de la table @@ -162,16 +164,17 @@ function formulaires_editer_abonnement_traiter_dist($id_abonnement='new', $retou # $modifier_echeance("$id_abonnement/$duree/$periode"); # } // Normaliser les dates vides pour éviter une erreur SQL - foreach(array('date_debut', 'date_echeance', 'date_fin') as $champ_date){ - if ($date = _request($champ_date) + foreach (['date_debut', 'date_echeance', 'date_fin'] as $champ_date) { + if ( + $date = _request($champ_date) and is_array($date) and !count(array_filter(array_values($date))) - ){ + ) { set_request($champ_date, '0000-00-00 00:00:00'); } } - - $retours = formulaires_editer_objet_traiter('abonnement',$id_abonnement,'',$lier_trad,$retour,$config_fonc,$row,$hidden); - + + $retours = formulaires_editer_objet_traiter('abonnement', $id_abonnement, '', $lier_trad, $retour, $config_fonc, $row, $hidden); + return $retours; } diff --git a/formulaires/editer_abonnements_offre.php b/formulaires/editer_abonnements_offre.php index edd999f..b1bb867 100644 --- a/formulaires/editer_abonnements_offre.php +++ b/formulaires/editer_abonnements_offre.php @@ -5,8 +5,10 @@ * (c) 2012 Les Développements Durables * Licence GNU/GPL v3 */ -if (!defined('_ECRIRE_INC_VERSION')) + +if (!defined('_ECRIRE_INC_VERSION')) { return; +} include_spip('inc/actions'); include_spip('inc/editer'); @@ -15,114 +17,114 @@ include_spip('inc/editer'); * Déclaration des champs du formulaire */ -function formulaires_editer_abonnements_offre_saisies_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') { +function formulaires_editer_abonnements_offre_saisies_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { $taxe_default = lire_config('produits/taxe', 0); - return array( - array( + return [ + [ 'saisie' => 'input', - 'options' => array( + 'options' => [ 'nom' => 'titre', 'label' => _T('abonnementsoffre:champ_titre_label'), 'obligatoire' => 'oui', - ), - ), - array( + ], + ], + [ 'saisie' => 'textarea', - 'options' => array( + 'options' => [ 'nom' => 'descriptif', 'label' => _T('abonnementsoffre:champ_descriptif_label'), 'rows' => 10, 'inserer_barre' => 'edition', - ), - ), - array( + ], + ], + [ 'saisie' => 'input', - 'options' => array( + 'options' => [ 'nom' => 'duree', 'label' => _T('abonnementsoffre:champ_duree_label'), 'obligatoire' => 'oui', 'defaut' => 0, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'entier', - 'options' => array( + 'options' => [ 'min' => 0, - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'selection', - 'options' => array( + 'options' => [ 'nom' => 'periode', 'label' => _T('abonnementsoffre:champ_periode_label'), 'obligatoire' => 'oui', 'cacher_option_intro' => 'oui', - 'data' => array( + 'data' => [ 'mois' => _T('abonnementsoffre:champ_periode_choix_mois'), 'jours' => _T('abonnementsoffre:champ_periode_choix_jours'), 'heures' => _T('abonnementsoffre:champ_periode_choix_heures'), - ), + ], 'defaut' => 'mois', - ), - ), - array( + ], + ], + [ 'saisie' => 'input', - 'options' => array( + 'options' => [ 'nom' => 'prix_ht', 'label' => _T('abonnementsoffre:champ_prix_ht_label'), 'obligatoire' => 'oui', 'defaut' => 0, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'decimal', - 'options' => array( + 'options' => [ 'min' => 0, - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'input', - 'options' => array( + 'options' => [ 'nom' => 'taxe', 'label' => _T('abonnementsoffre:champ_taxe_label'), 'obligatoire' => 'oui', 'defaut' => $taxe_default, - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'decimal', - 'options' => array( + 'options' => [ 'min' => 0, 'max' => 100 - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'case', - 'options' => array( + 'options' => [ 'nom' => 'immateriel', 'label' => _T('abonnementsoffre:champ_immateriel_label'), 'label_case' => _T('abonnementsoffre:champ_immateriel_label_case'), - ), - ), - ); + ], + ], + ]; } /** * Identifier le formulaire en faisant abstraction des parametres qui ne representent pas l'objet edite */ -function formulaires_editer_abonnements_offre_identifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') { - return serialize(array(intval($id_abonnements_offre))); +function formulaires_editer_abonnements_offre_identifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { + return serialize([intval($id_abonnements_offre)]); } /** * Declarer les champs postes et y integrer les valeurs par defaut */ -function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') { +function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { $valeurs = formulaires_editer_objet_charger('abonnements_offre', $id_abonnements_offre, '', $lier_trad, $retour, $config_fonc, $row, $hidden); unset($valeurs['id_abonnements_offre']); - if ($valeurs['taxe'] == 0) + if ($valeurs['taxe'] == 0) { $valeurs['taxe'] = '0'; - else { + } else { $valeurs['taxe'] = $valeurs['taxe'] * 100; } return $valeurs; @@ -131,17 +133,15 @@ function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre /** * Verifier les champs postes et signaler d'eventuelles erreurs */ -function formulaires_editer_abonnements_offre_verifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') { - return formulaires_editer_objet_verifier('abonnements_offre', $id_abonnements_offre, array('titre')); +function formulaires_editer_abonnements_offre_verifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { + return formulaires_editer_objet_verifier('abonnements_offre', $id_abonnements_offre, ['titre']); } /** * Traiter les champs postes */ -function formulaires_editer_abonnements_offre_traiter_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') { +function formulaires_editer_abonnements_offre_traiter_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') { $taxe = _request('taxe') / 100; set_request('taxe', $taxe); return formulaires_editer_objet_traiter('abonnements_offre', $id_abonnements_offre, '', $lier_trad, $retour, $config_fonc, $row, $hidden); } - -?> diff --git a/formulaires/editer_abonnements_offre_notifications.php b/formulaires/editer_abonnements_offre_notifications.php index 061420c..82e088a 100644 --- a/formulaires/editer_abonnements_offre_notifications.php +++ b/formulaires/editer_abonnements_offre_notifications.php @@ -1,94 +1,96 @@ 'fieldset', - 'options' => array( + 'options' => [ 'nom' => 'fieldset_ajouter', 'label' => _T('abonnementsoffre:champ_ajouter_notification_label'), 'pliable' => 'oui', 'plie' => 'oui', - ), - 'saisies' => array( - array( + ], + 'saisies' => [ + [ 'saisie' => 'selection', - 'options' => array( + 'options' => [ 'nom' => 'quand', 'label' => _T('abonnementsoffre:champ_quand_label'), 'cacher_option_intro' => 'oui', - 'data' => array( + 'data' => [ '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( + 'options' => [ 'nom' => 'duree', 'label' => _T('abonnementsoffre:champ_duree_label'), 'defaut' => '', 'afficher_si_remplissage' => '@quand@ !== "pendant"', - ), - 'verifier' => array( + ], + 'verifier' => [ 'type' => 'entier', - 'options' => array( + 'options' => [ 'min' => 0, - ), - ), - ), - array( + ], + ], + ], + [ 'saisie' => 'selection', - 'options' => array( + 'options' => [ 'nom' => 'periode', 'label' => _T('abonnementsoffre:champ_periode_label'), 'cacher_option_intro' => 'oui', - 'data' => array( + 'data' => [ 'mois' => _T('abonnementsoffre:champ_periode_choix_mois'), 'jours' => _T('abonnementsoffre:champ_periode_choix_jours'), - ), + ], 'defaut' => 'mois', 'afficher_si_remplissage' => '@quand@ !== "pendant"', - ), - ), - ), - ), - ); + ], + ], + ], + ], + ]; } -function formulaires_editer_abonnements_offre_notifications_charger_dist($id_abonnements_offre, $retour=''){ - if (!$id_abonnements_offre or !autoriser('configurer')){ +function formulaires_editer_abonnements_offre_notifications_charger_dist($id_abonnements_offre, $retour = '') { + if (!$id_abonnements_offre or !autoriser('configurer')) { return false; } - - $contexte = array( - 'supprimer' => array(), + + $contexte = [ + 'supprimer' => [], 'id_abonnements_offre' => $id_abonnements_offre, - '_hidden' => '', - ); + '_hidden' => '', + ]; return $contexte; } -function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_abonnements_offre, $retour=''){ - $erreurs = array(); - - if (!$supprimer = _request('supprimer')){ +function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_abonnements_offre, $retour = '') { + $erreurs = []; + + if (!$supprimer = _request('supprimer')) { $duree = _request('duree'); $periode = _request('periode'); $quand = _request('quand'); // Normalisons les valeurs pour les notifs le jour même - if ($quand == 'pendant' + if ( + $quand == 'pendant' or ( $quand != 'pendant' and $duree == 0 ) - ){ + ) { $duree = 0; $periode = 'jours'; $quand = 'pendant'; @@ -98,38 +100,40 @@ function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_ab } // Durée obligatoire // (ne pas utiliser l'option "obligatoire" des saisies car on ne pourrait pas supprimer) - if (!strlen($duree)){ + if (!strlen($duree)) { $erreurs['duree'] = _T('info_obligatoire'); } // Vérifier les doublons - if (sql_countsel('spip_abonnements_offres_notifications', array( + if ( + sql_countsel('spip_abonnements_offres_notifications', [ '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; } -function formulaires_editer_abonnements_offre_notifications_traiter_dist($id_abonnements_offre, $retour=''){ +function formulaires_editer_abonnements_offre_notifications_traiter_dist($id_abonnements_offre, $retour = '') { // Si on demande à enregistrer une nouvelle notif - if (!$supprimer = _request('supprimer')){ + if (!$supprimer = _request('supprimer')) { include_spip('inc/editer'); - $retours = formulaires_editer_objet_traiter('abonnements_offres_notification','new','','',$retour,'','',''); + $retours = formulaires_editer_objet_traiter('abonnements_offres_notification', 'new', '', '', $retour, '', '', ''); } // Sinon c'est pour en supprimer - elseif (is_array($supprimer)){ - foreach ($supprimer as $id_notification=>$valeur){ - if ($id_notification = intval($id_notification)){ - sql_delete('spip_abonnements_offres_notifications', 'id_abonnements_offres_notification = '.$id_notification); - $retours = array('redirect' => $retour); + elseif (is_array($supprimer)) { + foreach ($supprimer as $id_notification => $valeur) { + if ($id_notification = intval($id_notification)) { + sql_delete('spip_abonnements_offres_notifications', 'id_abonnements_offres_notification = ' . $id_notification); + $retours = ['redirect' => $retour]; } } } - + return $retours; } diff --git a/formulaires/notifier_echeances_abonnementsoffre.php b/formulaires/notifier_echeances_abonnementsoffre.php index 1d4fe5a..8092038 100644 --- a/formulaires/notifier_echeances_abonnementsoffre.php +++ b/formulaires/notifier_echeances_abonnementsoffre.php @@ -1,7 +1,8 @@ 'selection', - 'options' => array( + 'options' => [ 'nom' => 'statut', 'label' => _T('abonnement:champ_notifier_statut_label'), - 'data' => array( + 'data' => [ '' => ucfirst(_T('abonnement:statut_tous')), 'actif' => ucfirst(_T('abonnement:statut_actifs')), 'inactif' => ucfirst(_T('abonnement:statut_inactifs')), - ), + ], 'cacher_option_intro' => 'oui', - ), - ), - array( + ], + ], + [ 'saisie' => 'fieldset', - 'options' => array( + 'options' => [ 'nom' => 'fieldset_date_debut', 'label' => _T('abonnement:champ_dates_debut_label'), 'pliable' => 'oui', 'plie' => 'oui', - ), - 'saisies' => array( - array( + ], + 'saisies' => [ + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_debut_du', 'label' => _T('abonnement:champ_date_du_label'), 'conteneur_class' => 'date_inline', - ), - ), - array( + ], + ], + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_debut_au', 'label' => _T('abonnement:champ_date_au_label'), 'conteneur_class' => 'date_inline', - ), - ), - ), - ), - array( + ], + ], + ], + ], + [ 'saisie' => 'fieldset', - 'options' => array( + 'options' => [ 'nom' => 'fieldset_date_fin', 'label' => _T('abonnement:champ_dates_fin_label'), 'pliable' => 'oui', 'plie' => 'oui', - ), - 'saisies' => array( - array( + ], + 'saisies' => [ + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_fin_du', 'label' => _T('abonnement:champ_date_du_label'), 'conteneur_class' => 'date_inline', - ), - ), - array( + ], + ], + [ 'saisie' => 'date', - 'options' => array( + 'options' => [ 'nom' => 'date_fin_au', 'label' => _T('abonnement:champ_date_au_label'), 'conteneur_class' => 'date_inline', - ), - ), - ), - ), - ); - + ], + ], + ], + ], + ]; + return $saisies; } @@ -103,21 +104,21 @@ function formulaires_notifier_echeances_abonnementsoffre_saisies_dist($id_abonne * URL de redirection * @return array */ -function formulaires_notifier_echeances_abonnementsoffre_charger_dist($id_abonnements_offre, $retour = ''){ +function formulaires_notifier_echeances_abonnementsoffre_charger_dist($id_abonnements_offre, $retour = '') { - $contexte = array( + $contexte = [ 'id_abonnements_offre' => $id_abonnements_offre, 'is_verifie' => false, 'is_annule' => false, 'confirmer_verifier' => false, - ); - + ]; + // Il faut obligatoirement un ID valide - if (!intval($id_abonnements_offre)){ + if (!intval($id_abonnements_offre)) { $contexte['message_erreur'] = _T('erreur'); $contexte['editable'] = false; } - + return $contexte; } @@ -131,8 +132,8 @@ function formulaires_notifier_echeances_abonnementsoffre_charger_dist($id_abonne * URL de redirection * @return array */ -function formulaires_notifier_echeances_abonnementsoffre_verifier_dist($id_abonnements_offre, $retour = ''){ - $erreurs = array(); +function formulaires_notifier_echeances_abonnementsoffre_verifier_dist($id_abonnements_offre, $retour = '') { + $erreurs = []; return $erreurs; } @@ -146,16 +147,16 @@ function formulaires_notifier_echeances_abonnementsoffre_verifier_dist($id_abonn * URL de redirection * @return array */ -function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonnements_offre, $retour = ''){ - $res = array(); +function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonnements_offre, $retour = '') { + $res = []; $message_ok = ''; $message_erreur = ''; - + // Empêcher le traitement AJAX en cas de redirection if ($retour) { refuser_traiter_formulaire_ajax(); } - + // Récupérer et normaliser les valeurs postées $statut = _request('statut'); $date_debut_du = normaliser_date(str_replace('/', '-', _request('date_debut_du'))); @@ -164,7 +165,7 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne $date_fin_au = _request('date_fin_au') ? normaliser_date(str_replace('/', '-', _request('date_fin_au')) . ' 23:59:59') : ''; // Préparer la partie du WHERE conçernant les dates, utilisée dans le SQL et le JS - $where = array("date_fin > 0"); // Il faut forcément une date de fin + $where = ['date_fin > 0']; // Il faut forcément une date de fin if ($date_debut_du and !$date_debut_au) { $where[] = 'date_debut >= ' . sql_quote($date_debut_du); } elseif (!$date_debut_du and $date_debut_au) { @@ -179,30 +180,30 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne } elseif ($date_fin_du and $date_fin_au) { $where[] = '(date_fin BETWEEN ' . sql_quote($date_fin_du) . ' AND ' . sql_quote($date_fin_au) . ')'; } - + // Préparer le JS pour remettre les listes à zéro $js_reset = ''; - + // ======================================================== // Vérification des abonnements à notifier avant validation // ======================================================== - if (_request('btn_verifier')){ + if (_request('btn_verifier')) { // Renvoyer du JS dans le squelette pour recharger la liste avec les abonnements à notifier // On cache la 2ème liste en passant un statut inexistant - $params = array( + $params = [ '"titre_singulier":"abonnement:info_1_abonnement_notifier"', '"titre_pluriel":"abonnement:info_nb_abonnements_notifier"', '"sinon":"' . _T('abonnement:info_aucun_abonnement_notifier') . '"', '"nb":"50"', '"where":"' . join(' AND ', $where) . '"', '"statut":"' . $statut . '"', - ); + ]; $params = join(',', array_filter($params)); $js = ''; $res['editable'] = true; @@ -211,39 +212,41 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne set_request('confirmer_verifier', true); $message_ok = $js; } - + // ============================= // Annulation après vérification // ============================= - if (_request('btn_annuler')){ + if (_request('btn_annuler')) { $res['editable'] = true; set_request('is_verifie', false); set_request('is_annule', true); set_request('confirmer_verifier', false); $message_ok = $js_reset; } - + // ============================ // OK : envoi des notifications // ============================ // Récupérer tous les abonnements qui n'ont pas de job ce jour (éviter 2 notifs le même jour !) - if (_request('btn_notifier')){ + if (_request('btn_notifier')) { $where[] = 'id_abonnements_offre = ' . intval($id_abonnements_offre); $where[] = 'email IS NOT NULL'; $where[] = '(j.id_job IS NULL ' . 'OR (j.id_job IS NOT NULL AND DATE_FORMAT(j.date, "%Y-%m-%d") != ' . sql_quote(date('Y-m-d')) . '))'; $where[] = $statut ? 'abo.statut = ' . sql_quote($statut) : ''; $where = array_filter($where); - if ($a_notifier = sql_allfetsel( - 'id_abonnement, nom, email, date_fin', - 'spip_abonnements as abo' . + if ( + $a_notifier = sql_allfetsel( + 'id_abonnement, nom, email, date_fin', + 'spip_abonnements as abo' . ' INNER JOIN spip_auteurs AS aut ON abo.id_auteur = aut.id_auteur' . ' LEFT JOIN spip_jobs_liens AS l ON abo.id_abonnement = l.id_objet AND l.objet = "abonnement"' . ' LEFT JOIN spip_jobs AS j ON l.id_job = j.id_job AND j.fonction = "abonnements_notifier_echeance"', - $where - )){ + $where + ) + ) { // Pour chacun on programme un envoi de mail - foreach ($a_notifier as $abonnement){ + foreach ($a_notifier as $abonnement) { $aujourdhui = new DateTime('now'); $echeance = new DateTime($abonnement['date_fin']); $difference = $aujourdhui->diff($echeance); @@ -255,27 +258,27 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne $id_job = job_queue_add( 'abonnements_notifier_echeance', "Notifier manuellement {$abonnement['nom']} $duree $periode $quand l'échéance de son abonnement {$abonnement['id_abonnement']}", - array( + [ $abonnement['id_abonnement'], $abonnement['nom'], $abonnement['email'], $duree, $periode, $quand, - ), + ], 'inc/abonnements', true ); job_queue_link( $id_job, - array( + [ 'objet' => 'abonnement', 'id_objet' => $abonnement['id_abonnement'] - ) + ] ); } } - + if (count($a_notifier) > 0) { $message_ok = _T('abonnementsoffre:message_notifier_ok'); $message_ok .= $js_reset; @@ -287,7 +290,7 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne set_request('is_annule', false); set_request('is_verifie', false); set_request('confirmer_verifier', false); - + // Redirection éventuelle if ($retour) { $res['redirect'] = $retour; @@ -300,6 +303,6 @@ function formulaires_notifier_echeances_abonnementsoffre_traiter_dist($id_abonne } elseif ($message_ok) { $res['message_ok'] = $message_ok; } - + return $res; } diff --git a/genie/abonnements_verifier_desactivation.php b/genie/abonnements_verifier_desactivation.php index 689db0b..1a530c9 100644 --- a/genie/abonnements_verifier_desactivation.php +++ b/genie/abonnements_verifier_desactivation.php @@ -1,31 +1,34 @@ ' . sql_quote('0000-00-00 00:00:00'), 'l.id_job IS NULL', - ) - ) and is_array($a_changer)) { + ] + ) and is_array($a_changer) + ) { include_spip('inc/abonnements'); - foreach ($a_changer as $abonnement){ + foreach ($a_changer as $abonnement) { abonnements_programmer_desactivation($abonnement['id_abonnement'], $abonnement['date_fin']); } } - + return 1; } diff --git a/genie/abonnements_verifier_echeances.php b/genie/abonnements_verifier_echeances.php index cdf923b..8d2ff5c 100644 --- a/genie/abonnements_verifier_echeances.php +++ b/genie/abonnements_verifier_echeances.php @@ -1,33 +1,34 @@ '$jourdhui')", "date_echeance < '$date_max_retard'", - ) + ] ) and is_array($abonnements_retard) ) { include_spip('action/editer_objet'); - + // Pour chaque abonnement trop dépassé, on met la date de fin à maintenant // ce qui va normalement provoquer la désactivation immédiate foreach ($abonnements_retard as $abonnement) { @@ -35,12 +36,12 @@ function genie_abonnements_verifier_echeances_dist($time){ autoriser_exception('modifier', 'abonnement', $abonnement['id_abonnement']); autoriser_exception('instituer', 'abonnement', $abonnement['id_abonnement']); // On change la date de fin - objet_modifier('abonnement', $abonnement['id_abonnement'], array('date_fin' => $jourdhui)); + objet_modifier('abonnement', $abonnement['id_abonnement'], ['date_fin' => $jourdhui]); // On remet les autorisations autoriser_exception('instituer', 'abonnement', $abonnement['id_abonnement'], false); autoriser_exception('modifier', 'abonnement', $abonnement['id_abonnement'], false); } } - + return 1; } diff --git a/genie/abonnements_verifier_notifications.php b/genie/abonnements_verifier_notifications.php index 63bb976..35962f9 100644 --- a/genie/abonnements_verifier_notifications.php +++ b/genie/abonnements_verifier_notifications.php @@ -1,34 +1,34 @@ 'abonnement', 'id_objet'=>$abonne['id_abonnement'])); + job_queue_link($id_job, ['objet' => 'abonnement', 'id_objet' => $abonne['id_abonnement']]); } } } } - + return 1; } - -?> diff --git a/inc/abonnements.php b/inc/abonnements.php index 0021adb..f6badfa 100644 --- a/inc/abonnements.php +++ b/inc/abonnements.php @@ -1,21 +1,23 @@ 0 @@ -32,10 +34,10 @@ function abonnements_creer_ou_renouveler($id_auteur, $id_abonnements_offre, $for ) { include_spip('inc/config'); include_spip('inc/autoriser'); - + // On cherche la durée limite pour renouveler un abonnement $heures_limite = lire_config('abonnements/renouvellement_heures_limite', 48); - + // Si on trouve un abonnement de cette offre (le dernier en date) // et qu'il n'est pas trop vieux, ou sans de date de fin // et qu'on a pas forcé la création… @@ -44,17 +46,17 @@ function abonnements_creer_ou_renouveler($id_auteur, $id_abonnements_offre, $for and $abonnement = sql_fetsel( 'id_abonnement, date_fin', 'spip_abonnements', - array( - 'id_auteur = '.$id_auteur, - 'id_abonnements_offre = '.$id_abonnements_offre, + [ + 'id_auteur = ' . $id_auteur, + 'id_abonnements_offre = ' . $id_abonnements_offre, 'statut != "poubelle"' - ), + ], '', 'statut asc, maj desc', '0,1' ) and ( - $abonnement['date_fin'] >= date('Y-m-d H:i:s', strtotime('- '.$heures_limite.' hours')) + $abonnement['date_fin'] >= date('Y-m-d H:i:s', strtotime('- ' . $heures_limite . ' hours')) or $abonnement['date_fin'] == '0000-00-00 00:00:00' ) and $id_abonnement = intval($abonnement['id_abonnement']) @@ -74,24 +76,25 @@ function abonnements_creer_ou_renouveler($id_auteur, $id_abonnements_offre, $for autoriser_exception('creer', 'abonnement', '', false); autoriser_exception('modifier', 'abonnement', $id_abonnement, true); $erreur = objet_modifier( - 'abonnement', $id_abonnement, - array( + 'abonnement', + $id_abonnement, + [ 'id_auteur' => $id_auteur, 'id_abonnements_offre' => $id_abonnements_offre, - ) + ] ); autoriser_exception('modifier', 'abonnement', $id_abonnement, false); - return array($id_abonnement, $erreur); + return [$id_abonnement, $erreur]; } } } - + return false; } /** * Initialiser les dates d'échéance et de fin pour un abonnement créé - * + * * @pipeline_appel abonnement_initialisation_dates * @param array $abonnement * Informations sur l'abonnement à initialiser @@ -100,12 +103,12 @@ function abonnements_creer_ou_renouveler($id_auteur, $id_abonnements_offre, $for * @return array * Retourne les modifications de dates initialisées **/ -function abonnements_initialisation_dates($abonnement, $offre){ - $modifs = array(); - +function abonnements_initialisation_dates($abonnement, $offre) { + $modifs = []; + // De combien doit-on augmenter la date $duree = $offre['duree']; - switch ($offre['periode']){ + switch ($offre['periode']) { case 'heures': $ajout = " + ${duree} hours"; break; @@ -119,35 +122,35 @@ function abonnements_initialisation_dates($abonnement, $offre){ $ajout = ''; break; } - + // S'il n'y a pas eu de date de début déjà forcée à la création, alors on démarre l'abonnement maintenant if ($abonnement['date_debut'] == '0000-00-00 00:00:00') { $modifs['date_debut'] = $abonnement['date_debut'] = date('Y-m-d H:i:s'); } - + // Par défaut les dates de fin et de la prochaine échéance sont les mêmes - $modifs['date_echeance'] = date('Y-m-d H:i:s', strtotime($abonnement['date_debut'].$ajout)); + $modifs['date_echeance'] = date('Y-m-d H:i:s', strtotime($abonnement['date_debut'] . $ajout)); $modifs['date_fin'] = $modifs['date_echeance']; - + // Mais si c'est un renouvellement auto avec Commandes et Bank if ($date_fin = abonnements_bank_date_fin($abonnement['id_abonnement'])) { $modifs['date_fin'] = $date_fin; } - + $modifs = pipeline( 'abonnement_initialisation_dates', - array( - 'args' => array('abonnement' => $abonnement, 'offre' => $offre), + [ + 'args' => ['abonnement' => $abonnement, 'offre' => $offre], 'data' => $modifs - ) + ] ); - + return $modifs; } /** * Trouver la date de fin d'un renouvellement automatique éventuel - * + * * @param int $id_abonnement * Identifiant de l'abonnement dont on veut trouver la date de fin * @param int $id_commande @@ -155,9 +158,9 @@ function abonnements_initialisation_dates($abonnement, $offre){ * @return bool|datetime * Retourne la date de fin du renouvellement si on trouve, sinon false pour ne rien faire **/ -function abonnements_bank_date_fin($id_abonnement, $id_commande=0){ +function abonnements_bank_date_fin($id_abonnement, $id_commande = 0) { $date_fin = false; - + // On teste si on trouve un renouvellement auto if ( defined('_DIR_PLUGIN_COMMANDES') @@ -172,7 +175,7 @@ function abonnements_bank_date_fin($id_abonnement, $id_commande=0){ or ( include_spip('action/editer_liens') - and $lien_commande = objet_trouver_liens(array('commande' => '*'), array('abonnement' => $id_abonnement)) + and $lien_commande = objet_trouver_liens(['commande' => '*'], ['abonnement' => $id_abonnement]) and is_array($lien_commande) // On prend juste la première commande qu'on trouve and $id_commande = intval($lien_commande[0]['id_commande']) @@ -180,7 +183,9 @@ function abonnements_bank_date_fin($id_abonnement, $id_commande=0){ ) // On cherche un paiement bien payé pour cette commande and $transaction = sql_fetsel( - '*', 'spip_transactions', array('id_commande = '.$id_commande, 'statut = "ok"') + '*', + 'spip_transactions', + ['id_commande = ' . $id_commande, 'statut = "ok"'] ) // Et que c'est un renouvellement auto ! and $transaction['abo_uid'] @@ -197,7 +202,7 @@ function abonnements_bank_date_fin($id_abonnement, $id_commande=0){ $date_fin = bank_date_fin_mois($year, $month); } } - + return $date_fin; } @@ -209,49 +214,49 @@ function abonnements_bank_date_fin($id_abonnement, $id_commande=0){ * @param datetime $date_fin * Optionnellement la date de fin si on la connait déjà, ce qui évite une requête */ -function abonnements_programmer_desactivation($id_abonnement, $date_fin=null){ +function abonnements_programmer_desactivation($id_abonnement, $date_fin = null) { include_spip('action/editer_liens'); $id_abonnement = intval($id_abonnement); - + // Si on a pas de date, on va chercher - if (!$date_fin){ - $date_fin = sql_getfetsel('date_fin', 'spip_abonnements', 'id_abonnement = '.$id_abonnement); + if (!$date_fin) { + $date_fin = sql_getfetsel('date_fin', 'spip_abonnements', 'id_abonnement = ' . $id_abonnement); } - + // Dans tous les cas on cherche s'il y des tâches liées à cet abonnement - $liens = objet_trouver_liens(array('job' => '*'), array('abonnement' => $id_abonnement)); - if ($liens and is_array($liens)){ + $liens = objet_trouver_liens(['job' => '*'], ['abonnement' => $id_abonnement]); + if ($liens and is_array($liens)) { // Et on les supprime toutes ! - foreach ($liens as $lien){ + foreach ($liens as $lien) { job_queue_remove($lien['id_job']); } } - + // Seulement si on a bien une date de fin, on reprogramme, sans duplication possible - if ($date_fin and $date_fin != '0000-00-00 00:00:00'){ + if ($date_fin and $date_fin != '0000-00-00 00:00:00') { $id_job = job_queue_add( 'abonnements_desactiver', - _T('abonnement:job_desactivation', array('id'=>$id_abonnement)), - array($id_abonnement), + _T('abonnement:job_desactivation', ['id' => $id_abonnement]), + [$id_abonnement], 'inc/abonnements', true, strtotime($date_fin) ); - job_queue_link($id_job, array('objet'=>'abonnement', 'id_objet'=>$id_abonnement)); + job_queue_link($id_job, ['objet' => 'abonnement', 'id_objet' => $id_abonnement]); } } /* * Désactiver un abonnement en utilisant l'API et sans autorisation */ -function abonnements_desactiver($id_abonnement){ +function abonnements_desactiver($id_abonnement) { include_spip('inc/autoriser'); include_spip('action/editer_objet'); // On inhibe les autorisations autoriser_exception('modifier', 'abonnement', $id_abonnement); autoriser_exception('instituer', 'abonnement', $id_abonnement); // On désactive l'abonnement - objet_modifier('abonnement', $id_abonnement, array('statut' => 'inactif')); + objet_modifier('abonnement', $id_abonnement, ['statut' => 'inactif']); // On remet les autorisations autoriser_exception('instituer', 'abonnement', $id_abonnement, false); autoriser_exception('modifier', 'abonnement', $id_abonnement, false); @@ -285,17 +290,17 @@ function abonnements_desactiver($id_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, $quand = 'avant'){ +function abonnements_notifier_echeance($id_abonnement, $nom, $email, $duree, $periode, $quand = 'avant') { // Assurons nous que le "quand" est cohérent - if ($duree === 0){ + if ($duree === 0) { $quand = 'pendant'; } $quoi = 'abonnement_echeance'; - + // envoyer la notif dans la langue de l'auteur, ou sinon dans la langue du site. $langue = ($id_auteur = sql_getfetsel('id_auteur', 'spip_abonnements', 'id_abonnement=' . $id_abonnement) and $langue_auteur = sql_getfetsel('lang', 'spip_auteurs', 'id_auteur=' . $id_auteur)) ? $langue_auteur : $GLOBALS['meta']['langue_site'] ; - - $options = array( + + $options = [ 'email' => $email, 'nom' => $nom, 'email' => $email, @@ -303,41 +308,41 @@ function abonnements_notifier_echeance($id_abonnement, $nom, $email, $duree, $pe 'periode' => $periode, 'quand' => $quand, 'lang' => $langue, - ); - + ]; + $notifications = charger_fonction('notifications', 'inc'); $notifications($quoi, $id_abonnement, $options); } /** * Lister tous les abonnements d'un utilisateur, classés par statut - * + * * @param int $id_auteur * Identifiant de l'utilisateur dont on cherche les abonnements * @return array * Tableau des abonnements, rangés dans une clé pour chaque statut */ -function abonnements_auteur_lister($id_auteur, $forcer=false) { - static $abonnements_auteurs = array(); +function abonnements_auteur_lister($id_auteur, $forcer = false) { + static $abonnements_auteurs = []; $id_auteur = intval($id_auteur); - + if ($forcer or is_null($abonnements_auteurs[$id_auteur])) { - $abonnements_auteurs[$id_auteur] = array(); - - if ($abonnements = sql_allfetsel('*', 'spip_abonnements', 'id_auteur ='.$id_auteur)) { - foreach($abonnements as $abonnement) { + $abonnements_auteurs[$id_auteur] = []; + + if ($abonnements = sql_allfetsel('*', 'spip_abonnements', 'id_auteur =' . $id_auteur)) { + foreach ($abonnements as $abonnement) { $statut = $abonnement['statut']; - + // Initialiser pour ce statut if (!isset($abonnements_auteurs[$id_auteur][$statut])) { - $abonnements_auteurs[$id_auteur][$statut] = array(); + $abonnements_auteurs[$id_auteur][$statut] = []; } - + // Ajouter l'abonnement à ce statut $abonnements_auteurs[$id_auteur][$statut][] = $abonnement; } } } - + return $abonnements_auteurs[$id_auteur]; } diff --git a/notifications/abonnement_echeance.php b/notifications/abonnement_echeance.php index babaebb..839bd7f 100644 --- a/notifications/abonnement_echeance.php +++ b/notifications/abonnement_echeance.php @@ -1,6 +1,6 @@ $options['duree'], 'spip_lang' => $options['lang'] - ) + ] ); // Destinataires - $destinataires = pipeline('notifications_destinataires', - array( - 'args' => array( + $destinataires = pipeline( + 'notifications_destinataires', + [ + 'args' => [ 'quoi' => $quoi, 'id' => $id, 'options' => $options - ), + ], 'data' => $options['email'], - ) + ] ); // Modèle $texte = recuperer_fond( 'notifications/abonnement_echeance', - array( + [ 'id_abonnement' => $id, 'nom' => $options['nom'], 'email' => $options['email'], @@ -44,7 +45,7 @@ function notifications_abonnement_echeance_dist($quoi, $id, $options) { 'periode' => $options['periode'], 'quand' => $options['quand'], 'lang' => $options['lang'], - ) + ] ); // Go go go notifications_envoyer_mails($destinataires, $texte, $sujet); diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..d9eeaef --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,15 @@ + + + . + vendor/* + lang/* + lib/* + + + + + + + + + diff --git a/prix/abonnements_offre.php b/prix/abonnements_offre.php index 43bf181..9fee581 100644 --- a/prix/abonnements_offre.php +++ b/prix/abonnements_offre.php @@ -1,26 +1,26 @@ 0 - and include_spip('base/abstract_sql') - and ( $taxe = sql_getfetsel('taxe', 'spip_abonnements_offres', 'id_abonnements_offre = ' . $id_produit)) !== null - ) { - $prix += $prix * $taxe; - } - // Sinon on applique la taxe par défaut - else { - include_spip('inc/config'); - $prix += $prix * lire_config('produits/taxe', 0); - } + // S'il y a une taxe de définie explicitement dans le produit, on applique en priorité + if ( + ($id_produit = intval($id_objet)) > 0 + and include_spip('base/abstract_sql') + and ( $taxe = sql_getfetsel('taxe', 'spip_abonnements_offres', 'id_abonnements_offre = ' . $id_produit)) !== null + ) { + $prix += $prix * $taxe; + } + // Sinon on applique la taxe par défaut + else { + include_spip('inc/config'); + $prix += $prix * lire_config('produits/taxe', 0); + } - return $prix; + return $prix; } - -?>