2022-01-19 16:04:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Garradin\Plugin\RecusFiscaux;
|
|
|
|
|
|
|
|
use Garradin\DB;
|
2022-01-25 17:19:31 +01:00
|
|
|
use KD2\ZipWriter;
|
2022-01-19 16:04:42 +01:00
|
|
|
|
2022-01-27 09:10:00 +01:00
|
|
|
class Utils
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
2022-02-10 17:05:24 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return informations sur les tarifs
|
2022-02-10 17:05:24 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getTarifs()
|
2022-02-10 17:05:24 +01:00
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
2022-05-18 12:29:19 +02:00
|
|
|
'SELECT
|
|
|
|
id,
|
|
|
|
id_service as idActivite,
|
|
|
|
label,
|
|
|
|
description,
|
|
|
|
amount as montant
|
|
|
|
FROM services_fees');
|
|
|
|
return Utils::toAssoc($db->get($sql), 'id');
|
2022-02-10 17:05:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return informations sur les activités
|
2022-02-10 17:05:24 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getActivites()
|
2022-02-10 17:05:24 +01:00
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
2022-05-18 12:29:19 +02:00
|
|
|
'SELECT
|
|
|
|
services.id,
|
|
|
|
services.label,
|
|
|
|
services.description
|
|
|
|
FROM services');
|
|
|
|
return Utils::toAssoc($db->get($sql), 'id');
|
2022-02-10 17:05:24 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 19:00:39 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return comptes sur lesquels des versements de membres ont été faits
|
|
|
|
* @param string $annee
|
|
|
|
* @param $op : opérateur de combinaison des comptes
|
|
|
|
* @param array $comptes
|
2022-03-24 19:00:39 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getComptes($annee, $op, $comptes)
|
2022-03-24 19:00:39 +01:00
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.id,
|
|
|
|
acc_accounts.code as codeCompte,
|
|
|
|
acc_accounts.label as nomCompte
|
2022-03-24 19:00:39 +01:00
|
|
|
FROM acc_transactions_users
|
2022-05-18 12:29:19 +02:00
|
|
|
INNER JOIN membres
|
|
|
|
ON acc_transactions_users.id_user = membres.id
|
|
|
|
INNER JOIN acc_transactions
|
|
|
|
ON acc_transactions_users.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_transactions_lines
|
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_accounts
|
|
|
|
ON acc_transactions_lines.id_account = acc_accounts.id
|
2022-03-24 19:00:39 +01:00
|
|
|
WHERE
|
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
|
|
|
AND
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.%s
|
|
|
|
)
|
|
|
|
GROUP by acc_accounts.id
|
|
|
|
ORDER by acc_accounts.id',
|
2022-03-24 19:00:39 +01:00
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
2022-05-18 12:29:19 +02:00
|
|
|
$db->where('code', $op, $comptes)
|
|
|
|
);
|
|
|
|
return Utils::toAssoc($db->get($sql), 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return tarifs des activités et comptes ayant des versements de
|
|
|
|
* membres dans l'année
|
|
|
|
* @param string $annee
|
|
|
|
* @param $op : opérateur de combinaison des comptes
|
|
|
|
* @param array $comptes
|
|
|
|
*/
|
|
|
|
public static function getTarifsComptes($annee, $op, $comptes)
|
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'
|
|
|
|
SELECT
|
|
|
|
services_users.id_fee as idTarif,
|
|
|
|
acc_accounts.id as idCompte,
|
|
|
|
acc_accounts.code as codeCompte
|
|
|
|
FROM acc_transactions_users
|
|
|
|
INNER JOIN acc_transactions
|
|
|
|
ON acc_transactions_users.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN services_users
|
|
|
|
ON acc_transactions_users.id_service_user = services_users.id
|
|
|
|
INNER JOIN services_fees
|
|
|
|
ON services_users.id_fee = services_fees.id
|
|
|
|
INNER JOIN acc_transactions_lines
|
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_accounts
|
|
|
|
ON acc_transactions_lines.id_account = acc_accounts.id
|
|
|
|
WHERE
|
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
|
|
|
AND
|
|
|
|
acc_accounts.%s
|
|
|
|
)
|
|
|
|
GROUP BY services_fees.id,acc_accounts.id
|
|
|
|
',
|
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
|
|
|
$db->where('code', $op, $comptes)
|
2022-03-24 19:00:39 +01:00
|
|
|
);
|
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:05:24 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* faire un tableau associatif avec le résultat d'une requête
|
|
|
|
*/
|
|
|
|
static function toAssoc($array, $nomCle)
|
|
|
|
{
|
|
|
|
$assoc = array();
|
|
|
|
foreach ($array as $elem)
|
|
|
|
{
|
|
|
|
$ro = new \ReflectionObject($elem);
|
|
|
|
$proprietes = $ro->getProperties();
|
|
|
|
$obj = new \stdClass();
|
|
|
|
foreach ($proprietes as $p)
|
|
|
|
{
|
|
|
|
$pname = $p->getName();
|
|
|
|
if ($pname == $nomCle) {
|
|
|
|
$key = $p->getValue($elem);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$obj->$pname = $p->getValue($elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$assoc[$key] = $obj;
|
|
|
|
}
|
|
|
|
return $assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return versements correspondants à l'année donnée
|
2022-02-10 17:05:24 +01:00
|
|
|
* @param $annee
|
2022-03-18 20:39:02 +01:00
|
|
|
* @param array $champsNom : liste non vide des champs de nom/prénom
|
2022-02-10 17:05:24 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getVersementsPersonnes($annee, $op, $comptes, $champsNom)
|
2022-02-10 17:05:24 +01:00
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
2022-03-18 20:39:02 +01:00
|
|
|
$tri = Utils::combinerTri($champsNom);
|
2022-02-10 17:05:24 +01:00
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
|
|
|
membres.id as idUser,
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.id as idCompte,
|
|
|
|
acc_accounts.code as codeCompte,
|
2022-02-10 17:05:24 +01:00
|
|
|
acc_transactions_lines.credit as versement,
|
|
|
|
acc_transactions.date
|
|
|
|
FROM acc_transactions_users
|
2022-05-18 12:29:19 +02:00
|
|
|
INNER JOIN membres
|
|
|
|
ON acc_transactions_users.id_user = membres.id
|
|
|
|
INNER JOIN acc_transactions
|
|
|
|
ON acc_transactions_users.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_transactions_lines
|
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_accounts
|
|
|
|
ON acc_transactions_lines.id_account = acc_accounts.id
|
2022-02-10 17:05:24 +01:00
|
|
|
WHERE
|
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
|
|
|
AND
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.%s
|
|
|
|
)
|
|
|
|
ORDER by %s, acc_accounts.id, acc_transactions.date',
|
2022-02-10 17:05:24 +01:00
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
2022-05-18 12:29:19 +02:00
|
|
|
$db->where('code', $op, $comptes),
|
2022-03-18 20:39:02 +01:00
|
|
|
$tri
|
|
|
|
);
|
2022-02-10 17:05:24 +01:00
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
2022-03-24 19:00:39 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return versements correspondants à :
|
|
|
|
* @param $annee : année fiscale
|
|
|
|
* @param $tarifs : tarifs sélectionnés
|
|
|
|
* @param array $comptes : comptes associés aux tarifs
|
2022-03-24 19:00:39 +01:00
|
|
|
* @param array $champsNom : liste non vide des champs de nom/prénom
|
2022-05-18 12:29:19 +02:00
|
|
|
* @remarks tri par tarif, nom, compte, date
|
2022-03-24 19:00:39 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getVersementsTarifsComptes($annee,
|
|
|
|
$tarifs,
|
|
|
|
$comptes,
|
|
|
|
$champsNom)
|
2022-03-24 19:00:39 +01:00
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$tri = Utils::combinerTri($champsNom);
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
2022-04-24 14:07:36 +02:00
|
|
|
services_fees.id as idTarif,
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.id as idCompte,
|
|
|
|
acc_accounts.code as codeCompte,
|
2022-04-24 14:07:36 +02:00
|
|
|
membres.id as idUser,
|
|
|
|
acc_transactions_lines.credit as versement,
|
|
|
|
acc_transactions.date
|
2022-03-24 19:00:39 +01:00
|
|
|
FROM acc_transactions_users
|
2022-04-24 14:07:36 +02:00
|
|
|
INNER JOIN membres
|
|
|
|
ON acc_transactions_users.id_user = membres.id
|
|
|
|
INNER JOIN acc_transactions
|
|
|
|
ON acc_transactions_users.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN services_users
|
|
|
|
ON acc_transactions_users.id_service_user = services_users.id
|
|
|
|
INNER JOIN services_fees
|
|
|
|
ON services_users.id_fee = services_fees.id
|
|
|
|
INNER JOIN acc_transactions_lines
|
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_accounts
|
|
|
|
ON acc_transactions_lines.id_account = acc_accounts.id
|
2022-03-24 19:00:39 +01:00
|
|
|
WHERE
|
2022-04-24 14:07:36 +02:00
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
2022-03-24 19:00:39 +01:00
|
|
|
AND
|
2022-05-18 12:29:19 +02:00
|
|
|
services_fees.%s
|
2022-03-24 19:00:39 +01:00
|
|
|
AND
|
2022-04-24 14:07:36 +02:00
|
|
|
acc_accounts.%s
|
2022-05-18 12:29:19 +02:00
|
|
|
)
|
|
|
|
ORDER by services_fees.id, %s, acc_accounts.id, acc_transactions.date',
|
2022-03-24 19:00:39 +01:00
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
2022-05-18 12:29:19 +02:00
|
|
|
$db->where('id', 'in', $tarifs),
|
|
|
|
$db->where('id', 'in', $comptes),
|
2022-03-24 19:00:39 +01:00
|
|
|
$tri
|
|
|
|
);
|
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
2022-02-17 10:21:33 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return versements correspondants à :
|
|
|
|
* @param $annee année fiscale
|
|
|
|
* @param $comptesIsoles comptes NON associés à un tarif
|
|
|
|
* @param array $champsNom : liste non vide des champs de nom/prénom
|
|
|
|
* @remarks tri par nom, compte, date
|
2022-02-17 10:21:33 +01:00
|
|
|
*/
|
2022-05-18 12:29:19 +02:00
|
|
|
public static function getVersementsComptes($annee,
|
|
|
|
$comptesIsoles,
|
|
|
|
$champsNom)
|
2022-02-17 10:21:33 +01:00
|
|
|
{
|
2022-05-18 12:29:19 +02:00
|
|
|
$db = DB::getInstance();
|
2022-03-18 20:39:02 +01:00
|
|
|
$tri = Utils::combinerTri($champsNom);
|
|
|
|
$sql = sprintf(
|
2022-05-18 12:29:19 +02:00
|
|
|
'
|
|
|
|
SELECT
|
|
|
|
0 as idTarif,
|
|
|
|
acc_accounts.id as idCompte,
|
|
|
|
acc_accounts.code as codeCompte,
|
2022-02-17 10:21:33 +01:00
|
|
|
membres.id as idUser,
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_transactions_lines.credit as versement,
|
|
|
|
acc_transactions.date
|
|
|
|
FROM acc_transactions_users
|
|
|
|
INNER JOIN membres
|
|
|
|
ON acc_transactions_users.id_user = membres.id
|
|
|
|
INNER JOIN acc_transactions
|
|
|
|
ON acc_transactions_users.id_transaction = acc_transactions.id
|
2022-02-17 10:21:33 +01:00
|
|
|
INNER JOIN acc_transactions_lines
|
2022-05-18 12:29:19 +02:00
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
INNER JOIN acc_accounts
|
|
|
|
ON acc_transactions_lines.id_account = acc_accounts.id
|
|
|
|
WHERE
|
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
2022-02-17 10:21:33 +01:00
|
|
|
AND
|
2022-05-18 12:29:19 +02:00
|
|
|
acc_accounts.%s
|
2022-02-17 10:21:33 +01:00
|
|
|
)
|
2022-05-18 12:29:19 +02:00
|
|
|
|
|
|
|
ORDER by %s, acc_accounts.id, acc_transactions.date
|
|
|
|
',
|
2022-03-18 20:39:02 +01:00
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
2022-05-18 12:29:19 +02:00
|
|
|
$db->where('id', 'in', $comptesIsoles),
|
2022-03-24 19:00:39 +01:00
|
|
|
$tri
|
|
|
|
);
|
|
|
|
return $db->get($sql);
|
2022-02-17 10:21:33 +01:00
|
|
|
}
|
|
|
|
|
2022-02-17 08:49:04 +01:00
|
|
|
/**
|
|
|
|
* @return personnes ayant versé des dons pour une année donnée
|
|
|
|
* @param $annee
|
2022-04-24 14:07:36 +02:00
|
|
|
* @param array $champsNom : champs qui définissent le nom et le prénom d'une personne
|
2022-02-17 08:49:04 +01:00
|
|
|
*/
|
2022-04-24 14:07:36 +02:00
|
|
|
public static function getDonateurs($annee, $champsNom) : array
|
2022-02-17 08:49:04 +01:00
|
|
|
{
|
2022-03-18 20:39:02 +01:00
|
|
|
// concaténer les champs nom/prénoms pour la sélection
|
2022-04-24 14:07:36 +02:00
|
|
|
$nom = Utils::combinerChamps($champsNom);
|
2022-03-18 20:39:02 +01:00
|
|
|
// et pour le tri
|
|
|
|
$tri = Utils::combinerTri($champsNom);
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
2022-02-17 08:49:04 +01:00
|
|
|
membres.id as idUser,
|
2022-04-24 14:07:36 +02:00
|
|
|
row_number() over(order by %s) as rang,
|
|
|
|
%s as nom,
|
2022-02-17 08:49:04 +01:00
|
|
|
membres.adresse as adresse,
|
|
|
|
membres.code_postal as codePostal,
|
|
|
|
membres.ville as ville
|
|
|
|
FROM
|
|
|
|
acc_transactions_users,
|
|
|
|
membres,
|
|
|
|
acc_transactions
|
|
|
|
INNER JOIN acc_transactions_lines
|
|
|
|
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
WHERE (
|
2022-03-18 20:39:02 +01:00
|
|
|
strftime(%s, acc_transactions.date) = "%d"
|
2022-02-17 08:49:04 +01:00
|
|
|
AND
|
|
|
|
acc_transactions_users.id_transaction = acc_transactions.id
|
|
|
|
AND
|
|
|
|
acc_transactions_users.id_user = membres.id
|
|
|
|
)
|
|
|
|
GROUP by membres.id
|
2022-04-24 14:07:36 +02:00
|
|
|
ORDER by %1$s COLLATE U_NOCASE
|
|
|
|
',
|
|
|
|
$tri,
|
|
|
|
$nom,
|
2022-03-18 20:39:02 +01:00
|
|
|
'"%Y"',
|
2022-04-24 14:07:36 +02:00
|
|
|
$annee
|
|
|
|
);
|
2022-03-25 16:09:55 +01:00
|
|
|
$donateurs = array();
|
2022-04-24 14:07:36 +02:00
|
|
|
foreach (DB::getInstance()->iterate($sql) as $personne)
|
2022-03-25 16:09:55 +01:00
|
|
|
{
|
|
|
|
$donateurs[$personne->idUser] = new Personne($personne->idUser,
|
2022-04-24 14:07:36 +02:00
|
|
|
$personne->rang,
|
2022-03-25 16:09:55 +01:00
|
|
|
$personne->nom,
|
|
|
|
$personne->adresse,
|
|
|
|
$personne->codePostal,
|
|
|
|
$personne->ville);
|
|
|
|
}
|
|
|
|
return $donateurs;
|
2022-02-17 08:49:04 +01:00
|
|
|
}
|
|
|
|
|
2022-04-27 13:42:45 +02:00
|
|
|
/**
|
2022-03-18 20:39:02 +01:00
|
|
|
* combiner les champs avec un opérateur
|
|
|
|
* @param array $champs : liste (non vide) de champs
|
|
|
|
* @return chaîne combinée
|
2022-04-27 13:42:45 +02:00
|
|
|
*/
|
2022-03-18 20:39:02 +01:00
|
|
|
private static function combinerChamps($champs)
|
2022-02-18 12:51:13 +01:00
|
|
|
{
|
2022-03-18 20:39:02 +01:00
|
|
|
$op = ' || " " || ';
|
|
|
|
$result = 'ifnull(membres.' . $champs[0] . ', "")';
|
|
|
|
for ($i = 1; $i < count($champs); ++$i)
|
2022-02-18 12:51:13 +01:00
|
|
|
{
|
2022-03-18 20:39:02 +01:00
|
|
|
$result .= $op . 'ifnull(membres.' . $champs[$i] . ', "")';
|
2022-02-18 12:51:13 +01:00
|
|
|
}
|
2022-04-24 14:07:36 +02:00
|
|
|
return 'trim(' . $result . ')';
|
2022-02-18 12:51:13 +01:00
|
|
|
}
|
|
|
|
|
2022-01-19 16:04:42 +01:00
|
|
|
/**
|
2022-05-21 10:02:48 +02:00
|
|
|
* combiner les clés de tri
|
|
|
|
* @param clés de tri
|
|
|
|
* @return chaîne combinée
|
2022-01-19 16:04:42 +01:00
|
|
|
*/
|
2022-05-21 10:02:48 +02:00
|
|
|
private static function combinerTri(array $champs) : string
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
2022-03-18 20:39:02 +01:00
|
|
|
$tri = 'membres.' . $champs[0];
|
|
|
|
for ($i = 1; $i < count($champs); ++$i)
|
|
|
|
{
|
|
|
|
$tri .= ', membres.' . $champs[$i];
|
|
|
|
}
|
|
|
|
return $tri;
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 09:10:00 +01:00
|
|
|
/**
|
2022-05-18 12:29:19 +02:00
|
|
|
* @return liste des années fiscales
|
2022-01-27 09:10:00 +01:00
|
|
|
*/
|
2022-03-29 14:49:03 +02:00
|
|
|
public static function getAnneesFiscales() : array
|
|
|
|
{
|
2022-01-28 15:40:21 +01:00
|
|
|
$rows = DB::getInstance()->get(
|
2022-01-27 09:10:00 +01:00
|
|
|
"SELECT strftime('%Y', start_date) as annee
|
|
|
|
FROM acc_years
|
2022-11-30 18:47:00 +01:00
|
|
|
UNION
|
|
|
|
SELECT strftime('%Y', end_date) as annee
|
|
|
|
FROM acc_years
|
|
|
|
ORDER by annee DESC"
|
2022-01-28 15:40:21 +01:00
|
|
|
);
|
|
|
|
$anneesFiscales = array();
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$anneesFiscales[] = $row->annee;
|
|
|
|
}
|
|
|
|
return $anneesFiscales;
|
2022-01-27 09:10:00 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 12:51:13 +01:00
|
|
|
public static function getLignesReduction($lesTaux)
|
|
|
|
{
|
|
|
|
foreach ($lesTaux as $elem)
|
|
|
|
{
|
2022-02-25 15:51:48 +01:00
|
|
|
$lignes[$elem->taux] = $elem->remarque;
|
2022-02-18 12:51:13 +01:00
|
|
|
}
|
|
|
|
return $lignes;
|
|
|
|
}
|
2022-04-24 14:07:36 +02:00
|
|
|
|
2022-03-29 14:49:03 +02:00
|
|
|
/**
|
|
|
|
* récupérer dans la config du plugin les champs des membres
|
|
|
|
* utilisés pour le nom et le prénom ; ajouter/supprimer les
|
|
|
|
* modifications par rapport à la config garradin
|
2022-04-27 13:42:45 +02:00
|
|
|
* @return array tableau des champs : clé = nom, valeur = { titre, position }
|
2022-03-29 14:49:03 +02:00
|
|
|
*/
|
|
|
|
public static function getChampsNom($config, $plugin) : array
|
|
|
|
{
|
|
|
|
// récupérer dans la config du plugin les champs mémorisés
|
|
|
|
// pour le nom et le prénom (le tableau est vide si pas mémorisé)
|
|
|
|
$champsNom = (array) $plugin->getConfig('champsNom');
|
|
|
|
|
|
|
|
// récupérer dans la config Garradin les champs des membres
|
|
|
|
// utilisés pour le nom et le préno
|
|
|
|
$champsGarradin = $config->get('champs_membres')->listAssocNames();
|
|
|
|
|
|
|
|
foreach ($champsGarradin as $name => $title)
|
|
|
|
{
|
|
|
|
if (stristr($title, 'nom'))
|
|
|
|
{
|
|
|
|
// retenir les champs dont le titre contient le terme 'nom'
|
|
|
|
// est-il présent dans la config du plugin ?
|
|
|
|
if (! array_key_exists($name, $champsNom))
|
|
|
|
{
|
|
|
|
// absent => l'ajouter
|
|
|
|
$champ = new \stdClass();
|
|
|
|
$champ->titre = $title;
|
|
|
|
$champ->position = 0;
|
|
|
|
$champsNom[$name] = $champ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// opération symétrique : un champ mémorisé dans la config du
|
|
|
|
// plugin a-t-il disparu de la config garradin ?
|
|
|
|
foreach ($champsNom as $nom => $champ)
|
|
|
|
{
|
|
|
|
if (! array_key_exists($nom, $champsGarradin))
|
|
|
|
{
|
|
|
|
// absent => le supprimer
|
|
|
|
unset($champsNom[$nom]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// mettre à jour la config du plugin
|
|
|
|
$plugin->setConfig('champsNom', $champsNom);
|
|
|
|
return $champsNom;
|
|
|
|
}
|
|
|
|
|
2022-01-28 15:40:21 +01:00
|
|
|
/**
|
|
|
|
* enregistrer les fichiers dans une archive zip
|
|
|
|
* @param $fileList : liste des fichiers à archiver
|
|
|
|
* @param $year : pour générer le nom de l'archive
|
|
|
|
* @param $archiveDir : ne sert plus
|
|
|
|
*/
|
2022-01-25 17:19:31 +01:00
|
|
|
static function makeArchive(
|
|
|
|
$fileList,
|
|
|
|
$year,
|
2022-01-28 15:40:21 +01:00
|
|
|
$archiveDir = null)
|
2022-01-25 17:19:31 +01:00
|
|
|
{
|
|
|
|
$zipFilename = "recus_dons" . $year . ".zip";
|
|
|
|
header('Content-type: application/zip');
|
|
|
|
header(sprintf('Content-Disposition: attachment; filename="%s"', $zipFilename));
|
|
|
|
$zip = new ZipWriter('php://output');
|
|
|
|
$zip->setCompression(0);
|
|
|
|
foreach ($fileList as $fileName)
|
|
|
|
{
|
|
|
|
$zip->add(basename($fileName), null, $fileName);
|
|
|
|
}
|
|
|
|
$zip->close();
|
|
|
|
} // makeArchive
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|