Skip to content

Commit 8eb3bfd

Browse files
committed
Add filters
1 parent dc3b040 commit 8eb3bfd

4 files changed

Lines changed: 457 additions & 27 deletions

File tree

‎lib/GaletteHelloasso/Controllers/HelloassoController.php‎

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
use Galette\Entity\Contribution;
1919
use Galette\Entity\ContributionsTypes;
2020
use Galette\Entity\PaymentType;
21-
use Galette\Filters\HistoryList;
2221
use GaletteHelloasso\Helloasso;
2322
use GaletteHelloasso\HelloassoHistory;
23+
use GaletteHelloasso\Filters\HelloassoHistoryList;
2424
use Slim\Exception\HttpNotFoundException;
2525
use Slim\Exception\HttpForbiddenException;
2626
use Slim\Psr7\Request;
@@ -148,6 +148,7 @@ public function formCheckout(Request $request, Response $response): Response
148148
* @param string|int|null $value Option value
149149
*/
150150
public function logs(
151+
Request $request,
151152
Response $response,
152153
?string $option = null,
153154
string|int|null $value = null
@@ -164,7 +165,11 @@ public function logs(
164165
if (isset($this->session->filter_helloasso_history)) {
165166
$filters = $this->session->filter_helloasso_history;
166167
} else {
167-
$filters = new HistoryList();
168+
$filters = new HelloassoHistoryList();
169+
}
170+
171+
if (isset($request->getQueryParams()['nbshow'])) {
172+
$filters->show = $request->getQueryParams()['nbshow'];
168173
}
169174

170175
if ($option !== null) {
@@ -175,17 +180,18 @@ public function logs(
175180
case 'order':
176181
$filters->orderby = $value;
177182
break;
178-
case 'reset':
179-
$filters = new HistoryList();
183+
default:
180184
break;
181185
}
182186
}
187+
183188
$this->session->filter_helloasso_history = $filters;
184189

185-
//assign pagination variables to the template and add pagination links
186190
$helloasso_history->setFilters($filters);
187191
$logs = $helloasso_history->getHelloassoHistory();
188192
$logs_count = $helloasso_history->getCount();
193+
194+
//assign pagination variables to the template and add pagination links
189195
$filters->setViewPagination($this->routeparser, $this->view);
190196

191197
$params = [
@@ -197,8 +203,6 @@ public function logs(
197203
'module_id' => $this->getModuleId()
198204
];
199205

200-
$this->session->filter_helloasso_history = $filters;
201-
202206
// display page
203207
$this->view->render(
204208
$response,
@@ -215,12 +219,39 @@ public function filter(Request $request, Response $response): Response
215219
{
216220
$post = $request->getParsedBody();
217221

218-
//reset history
219-
$filters = $this->session->filter_helloasso_history ?? new HistoryList();
220-
if (isset($post['reset']) && isset($post['nbshow'])) {
222+
$filters = $this->session->filter_helloasso_history ?? new HelloassoHistoryList();
223+
224+
if (isset($post['clear_filter'])) {
225+
$filters->reinit();
221226
} else {
222-
//number of rows to show
223-
$filters->show = $post['nbshow'];
227+
if (isset($post['nbshow']) && is_numeric($post['nbshow'])) {
228+
$filters->show = (int)$post['nbshow'];
229+
}
230+
231+
if (isset($post['end_date_filter']) || isset($post['start_date_filter'])) {
232+
if (isset($post['start_date_filter'])) {
233+
$filters->start_date_filter = $post['start_date_filter'];
234+
}
235+
if (isset($post['end_date_filter'])) {
236+
$filters->end_date_filter = $post['end_date_filter'];
237+
}
238+
}
239+
240+
if (isset($post['payment_filter'])) {
241+
$filters->payment_filter = $post['payment_filter'];
242+
}
243+
244+
if (isset($post['payer_filter'])) {
245+
$filters->payer_filter = $post['payer_filter'];
246+
}
247+
248+
if (isset($post['reason_filter'])) {
249+
$filters->reason_filter = $post['reason_filter'];
250+
}
251+
252+
if (isset($post['method_filter'])) {
253+
$filters->method_filter = $post['method_filter'];
254+
}
224255
}
225256

226257
$this->session->filter_helloasso_history = $filters;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Galette Helloasso plugin (https://galette-community.github.io/plugin-helloasso).
5+
* SPDX-FileCopyrightText: Copyright © 2025-2026 The Galette Team
6+
* SPDX-License-Identifier: GPL-3.0-or-later
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace GaletteHelloasso\Filters;
12+
13+
use Galette\Filters\HistoryList;
14+
use Analog\Analog;
15+
16+
/**
17+
* Helloasso History lists filters and paginator
18+
*
19+
* @author Johan Cwiklinski <johan@x-tnd.be>
20+
* @author Guillaume AGNIERAY <dev@agnieray.net>
21+
*
22+
* @property ?string $payment_filter
23+
* @property ?string $payer_filter
24+
* @property ?string $reason_filter
25+
* @property ?string $method_filter
26+
*/
27+
28+
class HelloassoHistoryList extends HistoryList
29+
{
30+
public const int ORDERBY_DATE = 0;
31+
public const int ORDERBY_PAYMENT = 1;
32+
public const int ORDERBY_PAYER = 2;
33+
public const int ORDERBY_MEMBER = 3;
34+
public const int ORDERBY_REASON = 4;
35+
public const int ORDERBY_AMOUNT = 5;
36+
public const int ORDERBY_METHOD = 6;
37+
public const int ORDERBY_STATE = 7;
38+
39+
//filters
40+
private ?string $payment_filter = null;
41+
private ?string $payer_filter = null;
42+
private ?string $reason_filter = null;
43+
private ?string $method_filter = null;
44+
45+
/** @var array<string> */
46+
protected array $list_fields = [
47+
'start_date_filter',
48+
'raw_start_date_filter',
49+
'end_date_filter',
50+
'raw_end_date_filter',
51+
'payment_filter',
52+
'payer_filter',
53+
'reason_filter',
54+
'method_filter'
55+
];
56+
57+
/**
58+
* Default constructor
59+
*/
60+
public function __construct()
61+
{
62+
$this->reinit();
63+
}
64+
65+
/**
66+
* Reinit default parameters
67+
*/
68+
public function reinit(): void
69+
{
70+
parent::reinit();
71+
$this->payment_filter = null;
72+
$this->payer_filter = null;
73+
$this->reason_filter = null;
74+
$this->method_filter = null;
75+
}
76+
77+
/**
78+
* Global getter method
79+
*
80+
* @param string $name name of the property we want to retrieve
81+
*
82+
* @return mixed the called property
83+
*/
84+
public function __get(string $name): mixed
85+
{
86+
if (in_array($name, $this->pagination_fields)) {
87+
return parent::__get($name);
88+
} elseif (in_array($name, $this->list_fields)) {
89+
return match ($name) {
90+
'raw_start_date_filter' => $this->getDate('start_date_filter', true, false),
91+
'raw_end_date_filter' => $this->getDate('end_date_filter', true, false),
92+
'start_date_filter', 'end_date_filter' => $this->getDate($name),
93+
default => $this->$name,
94+
};
95+
}
96+
97+
throw new \RuntimeException(
98+
sprintf(
99+
'Unable to get property "%s::%s"!',
100+
static::class,
101+
$name
102+
)
103+
);
104+
}
105+
106+
/**
107+
* Global isset method
108+
* Required for twig to access properties via __get
109+
*
110+
* @param string $name name of the property we want to retrieve
111+
*/
112+
public function __isset(string $name): bool
113+
{
114+
return parent::__isset($name);
115+
}
116+
117+
/**
118+
* Global setter method
119+
*
120+
* @param string $name name of the property we want to assign a value to
121+
* @param mixed $value a relevant value for the property
122+
*/
123+
public function __set(string $name, mixed $value): void
124+
{
125+
if (in_array($name, $this->pagination_fields)) {
126+
parent::__set($name, $value);
127+
} else {
128+
Analog::log(
129+
'[' . static::class . '] Setting property `' . $name . '`',
130+
Analog::DEBUG
131+
);
132+
133+
switch ($name) {
134+
case 'start_date_filter':
135+
case 'end_date_filter':
136+
$this->setFilterDate($name, $value, $name === 'start_date_filter');
137+
break;
138+
default:
139+
$this->$name = $value;
140+
break;
141+
}
142+
}
143+
}
144+
}

0 commit comments

Comments
 (0)