Skip to content

Commit

Permalink
Fix: #5017 - wrong counts on individual page
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Aug 20, 2024
1 parent 01b92fd commit 6039542
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 44 deletions.
64 changes: 25 additions & 39 deletions app/Http/RequestHandlers/CalendarEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,13 @@
*/
class CalendarEvents implements RequestHandlerInterface
{
private CalendarService $calendar_service;

/**
* @param CalendarService $calendar_service
*/
public function __construct(CalendarService $calendar_service)
{
$this->calendar_service = $calendar_service;
public function __construct(
private readonly CalendarService $calendar_service,
) {
}

/**
* Show anniversaries that occurred on a given day/month/year.
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
Expand Down Expand Up @@ -109,9 +100,21 @@ public function handle(ServerRequestInterface $request): ResponseInterface

$individual_anniversaries = $anniversaries->filter(static fn (Fact $f): bool => $f->record() instanceof Individual);

$family_count = $family_anniversaries
->map(static fn (Fact $x): string => $x->record()->xref())
->unique()
->count();

$individual_count = $individual_anniversaries
->map(static fn (Fact $x): string => $x->record()->xref())
->unique()
->count();

return response(view('calendar-list', [
'family_anniversaries' => $family_anniversaries,
'individual_anniversaries' => $individual_anniversaries,
'family_count' => $family_count,
'individual_count' => $individual_count,
]));
}

Expand Down Expand Up @@ -216,30 +219,16 @@ public function handle(ServerRequestInterface $request): ResponseInterface
}
// Show a converted date
foreach (explode('_and_', $CALENDAR_FORMAT) as $convcal) {
switch ($convcal) {
case 'french':
$alt_date = new FrenchDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'gregorian':
$alt_date = new GregorianDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'jewish':
$alt_date = new JewishDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'julian':
$alt_date = new JulianDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'hijri':
$alt_date = new HijriDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'jalali':
$alt_date = new JalaliDate($cal_date->minimumJulianDay() + $d - 1);
break;
case 'none':
default:
$alt_date = $cal_date;
break;
}
$alt_date = match ($convcal) {
'french' => new FrenchDate($cal_date->minimumJulianDay() + $d - 1),
'gregorian' => new GregorianDate($cal_date->minimumJulianDay() + $d - 1),
'jewish' => new JewishDate($cal_date->minimumJulianDay() + $d - 1),
'julian' => new JulianDate($cal_date->minimumJulianDay() + $d - 1),
'hijri' => new HijriDate($cal_date->minimumJulianDay() + $d - 1),
'jalali' => new JalaliDate($cal_date->minimumJulianDay() + $d - 1),
default => $cal_date,
};

if (get_class($alt_date) !== get_class($cal_date) && $alt_date->inValidRange()) {
echo '<span class="rtl_cal_day">' . $alt_date->format('%j %M') . '</span>';
// Just show the first conversion
Expand All @@ -266,9 +255,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
* Format a list of facts for display
*
* @param array<string> $list
* @param Tree $tree
*
* @return string
*/
private function calendarListText(array $list, Tree $tree): string
{
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4005,6 +4005,12 @@
'count' => 1,
'path' => __DIR__ . '/app/Report/ReportParserGenerate.php',
];
$ignoreErrors[] = [
// identifier: postInc.type
'message' => '#^Cannot use \\+\\+ on array\\<string\\>\\|float\\|int\\.$#',
'count' => 4,
'path' => __DIR__ . '/app/Report/ReportParserGenerate.php',
];
$ignoreErrors[] = [
// identifier: offsetAccess.nonArray
'message' => '#^Cannot use array destructuring on array\\<int, array\\<string\\>\\|int\\>\\|null\\.$#',
Expand Down
11 changes: 6 additions & 5 deletions resources/views/calendar-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ declare(strict_types=1);

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\I18N;
use Illuminate\Support\Collection;

/**
* @var Collection<int,Fact> $family_anniversaries
* @var Collection<int,Fact> $individual_anniversaries
* @var iterable<int,Fact> $family_anniversaries
* @var iterable<int,Fact> $individual_anniversaries
* @var int $family_count
* @var int $individual_count
*/

?>
Expand All @@ -17,12 +18,12 @@ use Illuminate\Support\Collection;
<tr>
<td class="wt-page-options-label text-center w-50">
<?= view('icons/individual') ?>
<?= I18N::plural('%s individual', '%s individuals', $individual_anniversaries->count(), I18N::number($individual_anniversaries->count())) ?>
<?= I18N::plural('%s individual', '%s individuals', $individual_count, I18N::number($individual_count)) ?>
</td>

<td class="wt-page-options-label text-center w-50">
<?= view('icons/family') ?>
<?= I18N::plural('%s family', '%s families', $family_anniversaries->count(), I18N::number($family_anniversaries->count())) ?>
<?= I18N::plural('%s family', '%s families', $family_count, I18N::number($family_count)) ?>
</td>
</tr>

Expand Down

0 comments on commit 6039542

Please sign in to comment.