Skip to content

Commit

Permalink
Fix empty user search in history list
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/Galette/Filters/tests/units/ContributionsList.php
#	tests/Galette/Filters/tests/units/HistoryList.php
#	tests/Galette/Filters/tests/units/TransactionsList.php
  • Loading branch information
trasher committed May 10, 2024
1 parent 33c4bcf commit 4e6d1c2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions galette/lib/Galette/Core/History.php
Expand Up @@ -221,9 +221,12 @@ private function buildLists(Select $select): void

$results = $this->zdb->execute($usersSelect);

$this->users = [];
foreach ($results as $result) {
$this->users[] = $result->adh_log;
$ulabel = $result->adh_log;
if ($ulabel === '') {
$ulabel = _T('None');
}
$this->users[] = $ulabel;
}
} catch (Throwable $e) {
Analog::log(
Expand Down Expand Up @@ -310,7 +313,10 @@ private function buildWhereClause(Select $select): void
}

//@phpstan-ignore-next-line
if ($this->filters->user_filter != null && $this->filters->user_filter != '0') {
if ($this->filters->user_filter != null) {

Check failure on line 316 in galette/lib/Galette/Core/History.php

View workflow job for this annotation

GitHub Actions / Lint on PHP 8.1

No error to ignore is reported on line 316.

Check failure on line 316 in galette/lib/Galette/Core/History.php

View workflow job for this annotation

GitHub Actions / Lint on PHP 8.3

No error to ignore is reported on line 316.
if ($this->filters->user_filter === _T('None')) {
$this->filters->user_filter = '';
}
$select->where->equalTo(
'adh_log',
$this->filters->user_filter
Expand Down
2 changes: 1 addition & 1 deletion galette/lib/Galette/Filters/HistoryList.php
Expand Up @@ -102,7 +102,7 @@ public function reinit(): void
parent::reinit();
$this->start_date_filter = null;
$this->end_date_filter = null;
$this->user_filter = '0';
$this->user_filter = null;
$this->action_filter = null;
}

Expand Down
2 changes: 1 addition & 1 deletion galette/templates/default/pages/history.html.twig
Expand Up @@ -92,7 +92,7 @@
{% if users|length > 0 %}
<label for="user_filter">{{ _T("Member") }}</label>
<select name="user_filter" id="user_filter" class="ui search dropdown">
<option value="0"{% if history.filters.user_filter == 0 %} selected="selected"{% endif %}>{{ _T("Select an user") }}</option>
<option value="0">{{ _T("Select an user") }}</option>
{% for user in users %}
<option value="{{ user }}"{% if history.filters.user_filter == user %} selected="selected"{% endif %}>{{ user }}</option>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion tests/Galette/Filters/tests/units/ContributionsList.php
Expand Up @@ -19,7 +19,7 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Galette\Entity\test\units;
namespace Galette\Filters\test\units;

use Galette\GaletteTestCase;

Expand Down
6 changes: 3 additions & 3 deletions tests/Galette/Filters/tests/units/HistoryList.php
Expand Up @@ -19,7 +19,7 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Galette\Entity\test\units;
namespace Galette\Filters\test\units;

use Galette\GaletteTestCase;

Expand All @@ -43,7 +43,7 @@ protected function testDefaults(\Galette\Filters\HistoryList $filters): void
$this->assertSame(\Galette\Filters\HistoryList::ORDER_DESC, $filters->ordered);
$this->assertNull($filters->start_date_filter);
$this->assertNull($filters->end_date_filter);
$this->assertSame('0', $filters->user_filter);
$this->assertNull($filters->user_filter);
$this->assertNull($filters->action_filter);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ public function testCreate(): void
$this->assertSame(\Galette\Filters\HistoryList::ORDER_ASC, $filters->ordered);

//set filter on user
$filters->user_filter = 42;
$filters->user_filter = '42';
$this->assertSame('42', $filters->user_filter);

//reinit and test defaults are back
Expand Down
2 changes: 1 addition & 1 deletion tests/Galette/Filters/tests/units/TransactionsList.php
Expand Up @@ -19,7 +19,7 @@
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Galette\Entity\test\units;
namespace Galette\Filters\test\units;

use Galette\GaletteTestCase;

Expand Down

0 comments on commit 4e6d1c2

Please sign in to comment.