From 71a04d2b2f4913d1abe60b32794f3e43e97c49e8 Mon Sep 17 00:00:00 2001
From: Johan Cwiklinski
Date: Thu, 30 Sep 2021 08:41:08 +0200
Subject: [PATCH] Small rework and few typo fixes
Add constants for contribution types and use them
Rename Contribution::isCotis() to Contribution::isFee()
phpdoc
Fix information is uncountable; fix conjugation
Fix several typos
Cleanup imports
---
.../includes/routes/contributions.routes.php | 17 ++---
galette/includes/routes/groups.routes.php | 4 --
galette/includes/routes/management.routes.php | 11 ---
galette/includes/routes/members.routes.php | 10 ---
.../includes/routes/public_pages.routes.php | 2 -
.../Crud/ContributionsController.php | 69 +++++++++----------
galette/lib/Galette/Entity/Adherent.php | 4 +-
galette/lib/Galette/Entity/Contribution.php | 61 ++++++++--------
galette/lib/Galette/Entity/Entitled.php | 7 +-
galette/lib/Galette/Entity/Transaction.php | 4 +-
.../lib/Galette/Events/ContribListener.php | 4 +-
galette/lib/Galette/Util/Password.php | 2 +-
.../default/ajouter_contribution.tpl | 16 ++---
.../templates/default/ajouter_transaction.tpl | 8 +--
galette/templates/default/desktop.tpl | 2 +-
.../default/gestion_contributions.tpl | 10 +--
galette/templates/default/group.tpl | 4 +-
galette/templates/default/liste_membres.tpl | 4 +-
galette/templates/default/page.tpl | 6 +-
galette/templates/default/voir_adherent.tpl | 4 +-
.../Entity/tests/units/Contribution.php | 2 +-
21 files changed, 109 insertions(+), 142 deletions(-)
diff --git a/galette/includes/routes/contributions.routes.php b/galette/includes/routes/contributions.routes.php
index eab836cc0..a0e82ee12 100644
--- a/galette/includes/routes/contributions.routes.php
+++ b/galette/includes/routes/contributions.routes.php
@@ -37,14 +37,7 @@
use Galette\Controllers\GaletteController;
use Galette\Controllers\Crud;
use Galette\Controllers\PdfController;
-use Galette\Repository\Contributions;
-use Galette\Entity\Transaction;
-use Galette\Repository\Transactions;
-use Galette\Repository\Members;
-use Galette\Entity\Adherent;
-use Galette\Entity\ContributionsTypes;
-use Galette\Core\GaletteMail;
-use Galette\Repository\PaymentTypes;
+use Galette\Entity\Contribution;
$app->get(
'/{type:transactions|contributions}[/{option:page|order|member}/{value:\d+|all}]',
@@ -57,22 +50,22 @@ $app->post(
)->setName('payments_filter')->add($authenticate);
$app->get(
- '/contribution/{type:fee|donation}/add',
+ '/contribution/{type:' . Contribution::TYPE_FEE . '|' . Contribution::TYPE_DONATION . '}/add',
[Crud\ContributionsController::class, 'add']
)->setName('addContribution')->add($authenticate);
$app->get(
- '/contribution/{type:fee|donation}/edit/{id:\d+}',
+ '/contribution/{type:' . Contribution::TYPE_FEE . '|' . Contribution::TYPE_DONATION . '}/edit/{id:\d+}',
[Crud\ContributionsController::class, 'edit']
)->setName('editContribution')->add($authenticate);
$app->post(
- '/contribution/{type:fee|donation}/add',
+ '/contribution/{type:' . Contribution::TYPE_FEE . '|' . Contribution::TYPE_DONATION . '}/add',
[Crud\ContributionsController::class, 'doAdd']
)->setName('doAddContribution')->add($authenticate);
$app->post(
- '/contribution/{type:fee|donation}/edit/{id:\d+}',
+ '/contribution/{type:' . Contribution::TYPE_FEE . '|' . Contribution::TYPE_DONATION . '}/edit/{id:\d+}',
[Crud\ContributionsController::class, 'doEdit']
)->setName('doEditContribution')->add($authenticate);
diff --git a/galette/includes/routes/groups.routes.php b/galette/includes/routes/groups.routes.php
index 0839caff7..485eaca9d 100644
--- a/galette/includes/routes/groups.routes.php
+++ b/galette/includes/routes/groups.routes.php
@@ -36,10 +36,6 @@
use Galette\Controllers\Crud;
use Galette\Controllers\PdfController;
-use Galette\Entity\Adherent;
-use Galette\Entity\Group;
-use Galette\Repository\Groups;
-use Galette\Repository\Members;
$app->get(
'/groups[/{id:\d+}]',
diff --git a/galette/includes/routes/management.routes.php b/galette/includes/routes/management.routes.php
index 98e220989..74161d603 100644
--- a/galette/includes/routes/management.routes.php
+++ b/galette/includes/routes/management.routes.php
@@ -43,17 +43,6 @@ use Galette\Controllers\PdfController;
use Galette\Controllers\CsvController;
use Galette\Controllers\AdminToolsController;
use Galette\Controllers\TextController;
-use Galette\DynamicFields\DynamicField;
-use Galette\Repository\Members;
-use Galette\IO\News;
-use Analog\Analog;
-use Galette\IO\Csv;
-use Galette\IO\CsvOut;
-use Galette\IO\CsvIn;
-use Galette\Entity\Title;
-use Galette\Repository\Titles;
-use Galette\Core\Install;
-use Galette\Entity\Status;
//galette's dashboard
$app->get(
diff --git a/galette/includes/routes/members.routes.php b/galette/includes/routes/members.routes.php
index 4553030a9..d6c5e7b40 100644
--- a/galette/includes/routes/members.routes.php
+++ b/galette/includes/routes/members.routes.php
@@ -38,17 +38,7 @@ use Galette\Controllers\Crud;
use Galette\Controllers\CsvController;
use Galette\Controllers\GaletteController;
use Galette\Controllers\PdfController;
-use Analog\Analog;
-use Galette\Core\Password;
-use Galette\Repository\Members;
-use Galette\Filters\MembersList;
-use Galette\Repository\Groups;
-use Galette\Repository\Reminders;
use Galette\Entity\Adherent;
-use Galette\Entity\Status;
-use Galette\Repository\Titles;
-use Galette\Entity\Group;
-use Galette\IO\File;
use Galette\Middleware\MembersNavigate;
//self subscription
diff --git a/galette/includes/routes/public_pages.routes.php b/galette/includes/routes/public_pages.routes.php
index d58d8c207..c15552a2c 100644
--- a/galette/includes/routes/public_pages.routes.php
+++ b/galette/includes/routes/public_pages.routes.php
@@ -35,8 +35,6 @@
*/
use Galette\Controllers\Crud;
-use Galette\Repository\Members;
-use Galette\Filters\MembersList;
$showPublicPages = function ($request, $response, $next) use ($container) {
$login = $container->get('login');
diff --git a/galette/lib/Galette/Controllers/Crud/ContributionsController.php b/galette/lib/Galette/Controllers/Crud/ContributionsController.php
index fc7d0303e..b9ca44f43 100644
--- a/galette/lib/Galette/Controllers/Crud/ContributionsController.php
+++ b/galette/lib/Galette/Controllers/Crud/ContributionsController.php
@@ -85,11 +85,11 @@ class ContributionsController extends CrudController
): Response {
// contribution types
$ct = new ContributionsTypes($this->zdb);
- $contributions_types = $ct->getList($type === 'fee');
+ $contributions_types = $ct->getList($type === Contribution::TYPE_FEE);
// template variable declaration
$title = null;
- if ($type === 'fee') {
+ if ($type === Contribution::TYPE_FEE) {
$title = _T("Membership fee");
} else {
$title = _T("Donation");
@@ -129,7 +129,7 @@ class ContributionsController extends CrudController
}
$ext_membership = '';
- if ($contrib->isCotis() || !isset($contrib) && $type === 'fee') {
+ if ($contrib->isFee() || !isset($contrib) && $type === Contribution::TYPE_FEE) {
$ext_membership = $this->preferences->pref_membership_ext;
}
$params['pref_membership_ext'] = $ext_membership;
@@ -162,7 +162,7 @@ class ContributionsController extends CrudController
$get = $request->getQueryParams();
$ct = new ContributionsTypes($this->zdb);
- $contributions_types = $ct->getList($type === 'fee');
+ $contributions_types = $ct->getList($type === Contribution::TYPE_FEE);
$cparams = ['type' => array_keys($contributions_types)[0]];
@@ -197,9 +197,9 @@ class ContributionsController extends CrudController
/**
* Add action
*
- * @param Request $request PSR Request
- * @param Response $response PSR Response
- * @param string $type Contribution type
+ * @param Request $request PSR Request
+ * @param Response $response PSR Response
+ * @param string|null $type Contribution type
*
* @return Response
*/
@@ -266,7 +266,7 @@ class ContributionsController extends CrudController
// contribution types
$ct = new ContributionsTypes($this->zdb);
- $contributions_types = $ct->getList($type === 'fee');
+ $contributions_types = $ct->getList($type === Contribution::TYPE_FEE);
// display page
$this->view->render(
@@ -484,9 +484,9 @@ class ContributionsController extends CrudController
/**
* Filtering
*
- * @param Request $request PSR Request
- * @param Response $response PSR Response
- * @param string $type Contribution type
+ * @param Request $request PSR Request
+ * @param Response $response PSR Response
+ * @param string|null $type Contribution type
*
* @return Response
*/
@@ -580,10 +580,10 @@ class ContributionsController extends CrudController
/**
* Edit page
*
- * @param Request $request PSR Request
- * @param Response $response PSR Response
- * @param int $id Contribution id
- * @param string $type Contribution type
+ * @param Request $request PSR Request
+ * @param Response $response PSR Response
+ * @param int $id Contribution id
+ * @param string|null $type Contribution type
*
* @return Response
*/
@@ -619,10 +619,10 @@ class ContributionsController extends CrudController
/**
* Edit action
*
- * @param Request $request PSR Request
- * @param Response $response PSR Response
- * @param integer $id Contribution id
- * @param string $type Contribution type
+ * @param Request $request PSR Request
+ * @param Response $response PSR Response
+ * @param integer $id Contribution id
+ * @param string|null $type Contribution type
*
* @return Response
*/
@@ -664,7 +664,6 @@ class ContributionsController extends CrudController
}
$error_detected = [];
- $redirect_url = null;
if ($this->session->contribution !== null) {
$contrib = $this->session->contribution;
@@ -685,24 +684,22 @@ class ContributionsController extends CrudController
$error_detected = array_merge($error_detected, $valid);
}
+ //all goes well, we can proceed
if (count($error_detected) == 0) {
- //all goes well, we can proceed
- if (count($error_detected) == 0) {
- // send email to member
- if (isset($post['mail_confirm']) && $post['mail_confirm'] == '1') {
- $contrib->setSendmail(); //flag to send creation email
- }
+ // send email to member
+ if (isset($post['mail_confirm']) && $post['mail_confirm'] == '1') {
+ $contrib->setSendmail(); //flag to send creation email
+ }
- $store = $contrib->store();
- if ($store === true) {
- $this->flash->addMessage(
- 'success_detected',
- _T('Contribution has been successfully stored')
- );
- } else {
- //something went wrong :'(
- $error_detected[] = _T("An error occurred while storing the contribution.");
- }
+ $store = $contrib->store();
+ if ($store === true) {
+ $this->flash->addMessage(
+ 'success_detected',
+ _T('Contribution has been successfully stored')
+ );
+ } else {
+ //something went wrong :'(
+ $error_detected[] = _T("An error occurred while storing the contribution.");
}
}
diff --git a/galette/lib/Galette/Entity/Adherent.php b/galette/lib/Galette/Entity/Adherent.php
index 8e5b5cdc3..72fae4feb 100644
--- a/galette/lib/Galette/Entity/Adherent.php
+++ b/galette/lib/Galette/Entity/Adherent.php
@@ -1165,7 +1165,7 @@ class Adherent
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a member' . "\n" .
+ 'Some errors has been thew attempting to edit/store a member' . "\n" .
print_r($this->errors, true),
Analog::ERROR
);
@@ -1949,7 +1949,7 @@ class Adherent
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a member files' . "\n" .
+ 'Some errors has been thew attempting to edit/store a member files' . "\n" .
print_r($this->errors, true),
Analog::ERROR
);
diff --git a/galette/lib/Galette/Entity/Contribution.php b/galette/lib/Galette/Entity/Contribution.php
index aa7a433f3..3c65644b5 100644
--- a/galette/lib/Galette/Entity/Contribution.php
+++ b/galette/lib/Galette/Entity/Contribution.php
@@ -4,6 +4,7 @@
/**
* Contribution class for galette
+ * Manage membership fees and donations.
*
* PHP version 5
*
@@ -47,6 +48,7 @@ use Galette\Repository\PaymentTypes;
/**
* Contribution class for galette
+ * Manage membership fees and donations.
*
* @category Entity
* @name Contribution
@@ -64,6 +66,9 @@ class Contribution
public const TABLE = 'cotisations';
public const PK = 'id_cotis';
+ public const TYPE_FEE = 'fee';
+ public const TYPE_DONATION = 'donation';
+
private $_id;
private $_date;
private $_member;
@@ -95,7 +100,7 @@ class Contribution
* @param Login $login Login instance
* @param null|int|ResultSet $args Either a ResultSet row to load
* a specific contribution, or an type id
- * to just instanciate object
+ * to just instantiate object
*/
public function __construct(Db $zdb, Login $login, $args = null)
{
@@ -106,7 +111,7 @@ class Contribution
* Fields configuration. Each field is an array and must reflect:
* array(
* (string)label,
- * (string) propname
+ * (string) property name
* )
*
* I'd prefer a static private variable for this...
@@ -143,7 +148,7 @@ class Contribution
),
'date_debut_cotis' => array(
'label' => _T("Date of contribution:"),
- 'cotlabel' => _T("Start date of membership:"), //if contribution is a cotisation, label differs
+ 'cotlabel' => _T("Start date of membership:"), //if contribution is a membership fee, label differs
'propname' => 'begin_date'
),
'date_fin_cotis' => array(
@@ -176,7 +181,7 @@ class Contribution
$this->_amount = $this->_transaction->getMissingAmount();
}
$this->type = (int)$args['type'];
- //calculate begin date for cotisation
+ //calculate begin date for membership fee
$this->_begin_date = $this->_date;
if ($this->_is_cotis) {
$curend = self::getDueDate($this->zdb, $this->_member);
@@ -255,7 +260,7 @@ class Contribution
/**
* Loads a contribution from its id
*
- * @param int $id the identifiant for the contribution to load
+ * @param int $id the identifier for the contribution to load
*
* @return bool true if query succeed, false otherwise
*/
@@ -302,7 +307,7 @@ class Contribution
$this->_id = (int)$r->$pk;
$this->_date = $r->date_enreg;
$this->_amount = $r->montant_cotis;
- //save original amount, we need it for transactions parts calulations
+ //save original amount, we need it for transactions parts calculations
$this->_orig_amount = $r->montant_cotis;
$this->_payment_type = $r->type_paiement_cotis;
$this->_info = $r->info_cotis;
@@ -310,7 +315,7 @@ class Contribution
$enddate = $r->date_fin_cotis;
//do not work with knows bad dates...
//the one with BC comes from 0.63/pgsl demo... Why the hell a so
- //strange date? dont know :(
+ //strange date? don't know :(
if (
$enddate !== '0000-00-00'
&& $enddate !== '1901-01-01'
@@ -347,7 +352,7 @@ class Contribution
$fields = array_keys($this->_fields);
foreach ($fields as $key) {
- //first of all, let's sanitize values
+ //first, let's sanitize values
$key = strtolower($key);
$prop = '_' . $this->_fields[$key]['propname'];
@@ -475,11 +480,11 @@ class Contribution
}
}
- if ($this->isCotis() && count($this->errors) == 0) {
+ if ($this->isFee() && count($this->errors) == 0) {
$overlap = $this->checkOverlap();
if ($overlap !== true) {
if ($overlap === false) {
- $this->errors[] = _T("An error occurred checking overlaping fees :(");
+ $this->errors[] = _T("An error occurred checking overlapping fees :(");
} else {
//method directly return error message
$this->errors[] = $overlap;
@@ -491,7 +496,7 @@ class Contribution
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a contribution' .
+ 'Some errors has been threw attempting to edit/store a contribution' .
print_r($this->errors, true),
Analog::ERROR
);
@@ -546,7 +551,7 @@ class Contribution
return true;
} catch (Throwable $e) {
Analog::log(
- 'An error occurred checking overlaping fee. ' . $e->getMessage(),
+ 'An error occurred checking overlapping fee. ' . $e->getMessage(),
Analog::ERROR
);
return false;
@@ -591,7 +596,7 @@ class Contribution
}
//no end date, let's take database defaults
- if (!$this->isCotis() && !$this->_end_date) {
+ if (!$this->isFee() && !$this->_end_date) {
unset($values['date_fin_cotis']);
}
@@ -646,10 +651,10 @@ class Contribution
$event = 'contribution.edit';
}
//update deadline
- if ($this->isCotis()) {
+ if ($this->isFee()) {
$deadline = $this->updateDeadline();
if ($deadline !== true) {
- //if something went wrong, we rollback transaction
+ //if something went wrong, we roll back transaction
throw new \Exception('An error occurred updating member\'s deadline');
}
}
@@ -766,7 +771,7 @@ class Contribution
public function getFieldLabel($field)
{
$label = $this->_fields[$field]['label'];
- if ($this->isCotis() && $field == 'date_debut_cotis') {
+ if ($this->isFee() && $field == 'date_debut_cotis') {
$label = $this->_fields[$field]['cotlabel'];
}
//replace " "
@@ -923,11 +928,11 @@ class Contribution
}
/**
- * Is current contribution a cotisation
+ * Is current contribution a membership fee
*
* @return boolean
*/
- public function isCotis()
+ public function isFee()
{
return $this->_is_cotis;
}
@@ -1056,7 +1061,7 @@ class Contribution
*/
public function getRawType()
{
- if ($this->isCotis()) {
+ if ($this->isFee()) {
return 'membership';
} else {
return 'donation';
@@ -1070,7 +1075,7 @@ class Contribution
*/
public function getTypeLabel()
{
- if ($this->isCotis()) {
+ if ($this->isFee()) {
return _T("Membership");
} else {
return _T("Donation");
@@ -1095,7 +1100,7 @@ class Contribution
/**
* Global getter method
*
- * @param string $name name of the property we want to retrive
+ * @param string $name name of the property we want to retrieve
*
* @return false|object the called property
*/
@@ -1117,7 +1122,7 @@ class Contribution
switch ($name) {
case 'is_cotis':
- return $this->isCotis();
+ return $this->isFee();
break;
default:
throw new \RuntimeException("Call to __get for '$name' is forbidden!");
@@ -1187,7 +1192,7 @@ class Contribution
if ($this->_is_cotis === null) {
return null;
}
- return ($this->isCotis()) ?
+ return ($this->isFee()) ?
PdfModel::INVOICE_MODEL : PdfModel::RECEIPT_MODEL;
break;
default:
@@ -1356,7 +1361,7 @@ class Contribution
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a contribution files' . "\n" .
+ 'Some errors has been threw attempting to edit/store a contribution files' . "\n" .
print_r($this->errors, true),
Analog::ERROR
);
@@ -1373,15 +1378,13 @@ class Contribution
*/
public function getRequired(): array
{
- // required fields
- $required = [
+ return [
'id_type_cotis' => 1,
'id_adh' => 1,
'date_enreg' => 1,
'date_debut_cotis' => 1,
- 'date_fin_cotis' => $this->isCotis(),
- 'montant_cotis' => $this->isCotis() ? 1 : 0
+ 'date_fin_cotis' => $this->isFee(),
+ 'montant_cotis' => $this->isFee() ? 1 : 0
];
- return $required;
}
}
diff --git a/galette/lib/Galette/Entity/Entitled.php b/galette/lib/Galette/Entity/Entitled.php
index f8f991587..c9cf560e1 100644
--- a/galette/lib/Galette/Entity/Entitled.php
+++ b/galette/lib/Galette/Entity/Entitled.php
@@ -74,6 +74,7 @@ abstract class Entitled
public static $fields;
protected static $defaults;
+ /** @var string|false */
protected $order_field = false;
private $id;
@@ -225,11 +226,11 @@ abstract class Entitled
* Get list in an array built as:
* $array[id] = "translated label"
*
- * @param boolean $extent Filter on (non) cotisations types
+ * @param boolean|null $extent Filter on (non) cotisations types
*
* @return array|false
*/
- public function getList($extent = null)
+ public function getList(bool $extent = null)
{
$list = array();
@@ -277,7 +278,7 @@ abstract class Entitled
/**
* Complete list
*
- * @return array of all objects if succeed, false otherwise
+ * @return array of all objects if succeeded, false otherwise
*/
public function getCompleteList()
{
diff --git a/galette/lib/Galette/Entity/Transaction.php b/galette/lib/Galette/Entity/Transaction.php
index 496abf443..a9199b7c4 100644
--- a/galette/lib/Galette/Entity/Transaction.php
+++ b/galette/lib/Galette/Entity/Transaction.php
@@ -351,7 +351,7 @@ class Transaction
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a transaction' .
+ 'Some errors has been thew attempting to edit/store a transaction' .
print_r($this->errors, true),
Analog::DEBUG
);
@@ -621,7 +621,7 @@ class Transaction
if (count($this->errors) > 0) {
Analog::log(
- 'Some errors has been throwed attempting to edit/store a transaction files' . "\n" .
+ 'Some errors has been thew attempting to edit/store a transaction files' . "\n" .
print_r($this->errors, true),
Analog::ERROR
);
diff --git a/galette/lib/Galette/Events/ContribListener.php b/galette/lib/Galette/Events/ContribListener.php
index fa603b361..b2f53cbe8 100644
--- a/galette/lib/Galette/Events/ContribListener.php
+++ b/galette/lib/Galette/Events/ContribListener.php
@@ -188,7 +188,7 @@ class ContribListener implements ListenerProviderInterface
->setContribution($contrib);
$text = 'contrib';
- if (!$contrib->isCotis()) {
+ if (!$contrib->isFee()) {
$text = 'donation';
}
$mtxt = $texts->getTexts($text, $member->language);
@@ -282,7 +282,7 @@ class ContribListener implements ListenerProviderInterface
// Sent email to admin if pref checked
// Get email text in database
$text = 'newcont';
- if (!$contrib->isCotis()) {
+ if (!$contrib->isFee()) {
$text = 'newdonation';
}
$texts->getTexts($text, $this->preferences->pref_lang);
diff --git a/galette/lib/Galette/Util/Password.php b/galette/lib/Galette/Util/Password.php
index 995cbeac1..20f62e31f 100644
--- a/galette/lib/Galette/Util/Password.php
+++ b/galette/lib/Galette/Util/Password.php
@@ -241,7 +241,7 @@ class Password
}
/**
- * Set member and calculate personal informations to blacklist
+ * Set member and calculate personal information to blacklist
*
* @param Adherent $adh Adherent instance
*
diff --git a/galette/templates/default/ajouter_contribution.tpl b/galette/templates/default/ajouter_contribution.tpl
index 531bdb03d..69cb889be 100644
--- a/galette/templates/default/ajouter_contribution.tpl
+++ b/galette/templates/default/ajouter_contribution.tpl
@@ -47,14 +47,14 @@
{_T string="NB : The mandatory fields are in"} {_T string="red"}
- {if $type eq "fee"}
+ {if $type eq constant('Galette\Entity\Contribution::TYPE_FEE')}