Skip to content

Commit

Permalink
There were 2 default constants with different values
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Apr 30, 2024
1 parent 0751dad commit f22cbb0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
8 changes: 4 additions & 4 deletions galette/lib/Galette/Entity/Contribution.php
Expand Up @@ -261,7 +261,7 @@ private function retrieveEndDate(): void
$now = new \DateTime();
$begin_date = new \DateTime($this->begin_date);

if ($this->type->extension > ContributionsTypes::TYPE_DONATION) {
if ($this->type->extension > ContributionsTypes::DONATION_TYPE) {
$dext = new DateInterval('P' . $this->type->extension . 'M');
$end_date = $begin_date->add($dext);
} elseif ($preferences->pref_beg_membership != '') {
Expand Down Expand Up @@ -566,7 +566,7 @@ public function checkOverlap(): bool|string
'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
array()
)->where([Adherent::PK => $this->member])
->where->notEqualTo('cotis_extension', ContributionsTypes::TYPE_DONATION)
->where->notEqualTo('cotis_extension', ContributionsTypes::DONATION_TYPE)
->where->nest->nest
->greaterThanOrEqualTo('date_debut_cotis', $this->begin_date)
->lessThanOrEqualTo('date_debut_cotis', $this->end_date)
Expand Down Expand Up @@ -864,7 +864,7 @@ public static function getDueDate(Db $zdb, ?int $member_id): ?string
)->where(
[Adherent::PK => $member_id]
)
->where->notEqualTo('cotis_extension', ContributionsTypes::TYPE_DONATION);
->where->notEqualTo('cotis_extension', ContributionsTypes::DONATION_TYPE);

$results = $zdb->execute($select);
$result = $results->current();
Expand Down Expand Up @@ -1376,7 +1376,7 @@ public function setContributionType(int $type): self
//set type
$this->type = new ContributionsTypes($this->zdb, $type);
//set is_cotis according to type
if ($this->type->extension == ContributionsTypes::TYPE_DONATION) {
if ($this->type->extension == ContributionsTypes::DONATION_TYPE) {
$this->is_cotis = false;
} else {
$this->is_cotis = true;
Expand Down
22 changes: 10 additions & 12 deletions galette/lib/Galette/Entity/ContributionsTypes.php
Expand Up @@ -44,13 +44,12 @@ class ContributionsTypes
{
use I18n;

public const DEFAULT_TYPE = 1;
public const DEFAULT_TYPE = -1;
public const DONATION_TYPE = 0;

public const TABLE = 'types_cotisation';
public const PK = 'id_type_cotis';

public const TYPE_DEFAULT = -1;
public const TYPE_DONATION = 0;

private Db $zdb;

private int $id;
Expand All @@ -65,13 +64,13 @@ class ContributionsTypes

/** @var array<int, array<string, mixed>> */
protected static array $defaults = array(
array('id' => 1, 'libelle' => 'annual fee', 'extension' => ContributionsTypes::TYPE_DEFAULT),
array('id' => 2, 'libelle' => 'reduced annual fee', 'extension' => ContributionsTypes::TYPE_DEFAULT),
array('id' => 3, 'libelle' => 'company fee', 'extension' => ContributionsTypes::TYPE_DEFAULT),
array('id' => 4, 'libelle' => 'donation in kind', 'extension' => ContributionsTypes::TYPE_DONATION),
array('id' => 5, 'libelle' => 'donation in money', 'extension' => ContributionsTypes::TYPE_DONATION),
array('id' => 6, 'libelle' => 'partnership', 'extension' => ContributionsTypes::TYPE_DONATION),
array('id' => 7, 'libelle' => 'annual fee (to be paid)', 'extension' => ContributionsTypes::TYPE_DEFAULT)
array('id' => 1, 'libelle' => 'annual fee', 'extension' => self::DEFAULT_TYPE),
array('id' => 2, 'libelle' => 'reduced annual fee', 'extension' => self::DEFAULT_TYPE),
array('id' => 3, 'libelle' => 'company fee', 'extension' => self::DEFAULT_TYPE),
array('id' => 4, 'libelle' => 'donation in kind', 'extension' => self::DONATION_TYPE),
array('id' => 5, 'libelle' => 'donation in money', 'extension' => self::DONATION_TYPE),
array('id' => 6, 'libelle' => 'partnership', 'extension' => self::DONATION_TYPE),
array('id' => 7, 'libelle' => 'annual fee (to be paid)', 'extension' => self::DEFAULT_TYPE)
);

/**
Expand All @@ -83,7 +82,6 @@ class ContributionsTypes
public function __construct(Db $zdb, int|ArrayObject $args = null)
{
$this->zdb = $zdb;
$this->extension = self::DEFAULT_TYPE;
if (is_int($args)) {
$this->load($args);
} elseif ($args instanceof ArrayObject) {
Expand Down
Expand Up @@ -34,8 +34,8 @@
<input type="text" name="amount" id="amount" value="{{ entry.amount }}"/>
</div>
{% set cotisextensions = {
(constant("Galette\\Entity\\ContributionsTypes::TYPE_DEFAULT")): _T("Default"),
(constant("Galette\\Entity\\ContributionsTypes::TYPE_DONATION")): _T("No"),
(constant("Galette\\Entity\\ContributionsTypes::DEFAULT_TYPE")): _T("Default"),
(constant("Galette\\Entity\\ContributionsTypes::DONATION_TYPE")): _T("No"),
(1): _Tn('%1$s month', '%1$s months', 1)|format(1)
} %}
{% for m in 2..11 %}
Expand Down
Expand Up @@ -54,16 +54,16 @@
</td>
<td class="left" data-col-label="{{ _T("Membership extension") }}">
{% set cotisextensions = {
(constant("Galette\\Entity\\ContributionsTypes::TYPE_DEFAULT")): _T("Default"),
(constant("Galette\\Entity\\ContributionsTypes::TYPE_DONATION")): _T("No"),
(constant("Galette\\Entity\\ContributionsTypes::DEFAULT_TYPE")): _T("Default"),
(constant("Galette\\Entity\\ContributionsTypes::DONATION_TYPE")): _T("No"),
(1): _Tn('%1$s month', '%1$s months', 1)|format(1)
} %}
{% for m in 2..11 %}
{% set cotisextensions = cotisextensions + {(m): _Tn('%1$s month', '%1$s months', m)|format(m)} %}
{% endfor %}
{% include "components/forms/select.html.twig" with {
id: 'cotis_extension',
value: constant("Galette\\Entity\\ContributionsTypes::TYPE_DEFAULT"),
value: constant("Galette\\Entity\\ContributionsTypes::DEFAULT_TYPE"),
values: cotisextensions
} %}
</td>
Expand Down

0 comments on commit f22cbb0

Please sign in to comment.